From patchwork Tue Jun 26 16:19:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 140032 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5460703lji; Tue, 26 Jun 2018 09:37:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcrCui6ukxzt58KFCRD/m+BJ4Z0NnkZ0S6HqmRU3U851Z/2zBotdEKczI9ChN5rLQeTZBNk X-Received: by 2002:ac8:2c23:: with SMTP id d32-v6mr2147858qta.54.1530031041934; Tue, 26 Jun 2018 09:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530031041; cv=none; d=google.com; s=arc-20160816; b=tikp+JluYHzPJcsCZiplwAYSAOinIFSCCsSZT4Y6OtcDzn5awP3btJ3/pZ2vvdQyxD lo4cE7mN6B2KnvvFQyb5g7KS6SKYfTIIYbscjHV02V5WrOxm88PddXaIYAJPVxDKAkZZ gbDsSd5Ih4vzxq4cJ6uzAoSE+8vmFnKZmjxZD7VMRfiT94AYhcJIHn2X5CcvELZBZvKP IAft9DwD3vk0BdjFvnaG8bz+kR8zAVRewohpI9jIkI+OlPj0/UZmFrbCV64XbJ9Dtb4h iYmBTUKYfi2NHKC/4I3VrVVs22svpxP0P7zeeD7042r7l1M2s5p/lwOn/gB91Lf4QyXx YImA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=vCbWV12C7Rm1WDLGSl608zFQKJGXdryQ+O/Dxik0j8Q=; b=upzUa0tKHAGTFltucfEMN0IM5Y4LFCcfV6XUJG2SuXr3klvaiyIfC7jWjfmxW6OoYI TvWJnyBBwUtv5oR6mKHUO7nHsEh2ClMbp8MmqAHvMKxtB4BUQo6Y5QZJ6RAUYyr9+FHy i/bZT2RtA2EGyrFKN2+9c/r+Yx5ku6JbnabvnXENIGy7SoAyambdwXK6N1KL7K2JOrZS 6u0iFt0P2oeFxa7FuWV3sNBAN7kdoCraI+xRD0hX2h4+WkGzkK6OtFQeSVKBm/zhKTrV wINTHb/v046da2uBbPN9UhvKIKQJX0UaawKpiu5ctBViUOv7M8Kooe7agWXvsydGVPJt 6WtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NJqX5kFw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p5-v6si1198021qkc.230.2018.06.26.09.37.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 26 Jun 2018 09:37:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NJqX5kFw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXqy1-0006ZJ-37 for patch@linaro.org; Tue, 26 Jun 2018 12:37:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXqgz-00015d-W2 for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXqgy-00060o-PR for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:45 -0400 Received: from mail-pl0-x22c.google.com ([2607:f8b0:400e:c01::22c]:33541) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fXqgy-00060U-JZ for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:44 -0400 Received: by mail-pl0-x22c.google.com with SMTP id 6-v6so8787447plb.0 for ; Tue, 26 Jun 2018 09:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vCbWV12C7Rm1WDLGSl608zFQKJGXdryQ+O/Dxik0j8Q=; b=NJqX5kFw8zW25KakevCG+/boqhd0uj+NT7Cj8X7FgP6eI5OHYXJIGv71/AT6loqafy VRPEHmL8BTsncocJj8KRHXYzJjfotAXIjdgqYAsSdgLhqDGwC2Z6aprxpakvPYVXKq+7 uZofry0Kb96i6J+MlJMNUCCMHle0qAnglGUgE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vCbWV12C7Rm1WDLGSl608zFQKJGXdryQ+O/Dxik0j8Q=; b=Y4BZGNm2pbSOdzsdZe4smUvwE5IAi6+3/GKhRS7MX1znfg1vezVvrMTRxowAoZrefI zygf1vwJFV91WHS5rprSV1O1acEjrx206UzTBJbQrmYVZxseNnanI/0ZJz9PhEGaknNh FDZ/c1gCpMI5yp1VdlgUMhlRqo6JpbUhbLp1+TeHc6IP9ioGAhBrUI8nuwwMNJBR5LsJ OgKXvjmudCaWTssrilrLt1k1tYTHBiG3WQ3WLlzimIdN8p6P6TootMl/3NcfFnpEjvA5 HXDjPOqGyf8gD5VWEf9bgjmhHGvrZlZ65urq5RlOrrIp8WvhkEYGzD0ANQYya25aeosL KyQA== X-Gm-Message-State: APt69E2B/gTg8wgrU/Dg9aUn2/U4zbyes+bbeFSTgeRUhl5sSqrAr3fG YCpoB5vdBrHv5YcRV0ll5LMBDt7GVyM= X-Received: by 2002:a17:902:8a81:: with SMTP id p1-v6mr2266879plo.33.1530029983236; Tue, 26 Jun 2018 09:19:43 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id 67-v6sm5054306pfm.171.2018.06.26.09.19.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 09:19:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 26 Jun 2018 09:19:20 -0700 Message-Id: <20180626161921.27941-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626161921.27941-1-richard.henderson@linaro.org> References: <20180626161921.27941-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::22c Subject: [Qemu-devel] [PATCH 12/13] target/ppc: Implement the rest of gen_ld_atomic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These cases were stubbed out. For now, implement them only within a serial context, forcing parallel execution to synchronize. It would be possible to implement these with cmpxchg loops, if we care. Signed-off-by: Richard Henderson --- target/ppc/translate.c | 89 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 79285b6698..597a37d3ec 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3078,16 +3078,45 @@ LARX(lbarx, DEF_MEMOP(MO_UB)) LARX(lharx, DEF_MEMOP(MO_UW)) LARX(lwarx, DEF_MEMOP(MO_UL)) +static void gen_fetch_inc_conditional(DisasContext *ctx, TCGMemOp memop, + TCGv EA, TCGCond cond, int addend) +{ + TCGv t = tcg_temp_new(); + TCGv t2 = tcg_temp_new(); + TCGv u = tcg_temp_new(); + + tcg_gen_qemu_ld_tl(t, EA, ctx->mem_idx, memop); + tcg_gen_addi_tl(t2, EA, MEMOP_GET_SIZE(memop)); + tcg_gen_qemu_ld_tl(t2, t2, ctx->mem_idx, memop); + tcg_gen_addi_tl(u, t, addend); + + /* E.g. for fetch and increment bounded... */ + /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */ + tcg_gen_movcond_tl(cond, u, t, t2, u, t); + tcg_gen_qemu_st_tl(u, EA, ctx->mem_idx, memop); + + /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */ + tcg_gen_movi_tl(u, 1 << (MEMOP_GET_SIZE(memop) * 8 - 1)); + tcg_gen_movcond_tl(cond, cpu_gpr[rD(ctx->opcode)], t, t2, t, u); + + tcg_temp_free(t); + tcg_temp_free(t2); + tcg_temp_free(u); +} + static void gen_ld_atomic(DisasContext *ctx, TCGMemOp memop) { uint32_t gpr_FC = FC(ctx->opcode); TCGv EA = tcg_temp_new(); + int rt = rD(ctx->opcode); + bool need_serial; TCGv src, dst; gen_addr_register(ctx, EA); - dst = cpu_gpr[rD(ctx->opcode)]; - src = cpu_gpr[rD(ctx->opcode) + 1]; + dst = cpu_gpr[rt]; + src = cpu_gpr[(rt + 1) & 31]; + need_serial = false; memop |= MO_ALIGN; switch (gpr_FC) { case 0: /* Fetch and add */ @@ -3117,17 +3146,63 @@ static void gen_ld_atomic(DisasContext *ctx, TCGMemOp memop) case 8: /* Swap */ tcg_gen_atomic_xchg_tl(dst, EA, src, ctx->mem_idx, memop); break; - case 16: /* compare and swap not equal */ - case 24: /* Fetch and increment bounded */ - case 25: /* Fetch and increment equal */ - case 28: /* Fetch and decrement bounded */ - gen_invalid(ctx); + + case 16: /* Compare and swap not equal */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + TCGv t0 = tcg_temp_new(); + TCGv t1 = tcg_temp_new(); + + tcg_gen_qemu_ld_tl(t0, EA, ctx->mem_idx, memop); + if ((memop & MO_SIZE) == MO_64 || TARGET_LONG_BITS == 32) { + tcg_gen_mov_tl(t1, src); + } else { + tcg_gen_ext32u_tl(t1, src); + } + tcg_gen_movcond_tl(TCG_COND_NE, t1, t0, t1, + cpu_gpr[(rt + 2) & 31], t0); + tcg_gen_qemu_st_tl(t1, EA, ctx->mem_idx, memop); + tcg_gen_mov_tl(dst, t0); + + tcg_temp_free(t0); + tcg_temp_free(t1); + } break; + + case 24: /* Fetch and increment bounded */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, 1); + } + break; + case 25: /* Fetch and increment equal */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_EQ, 1); + } + break; + case 28: /* Fetch and decrement bounded */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, -1); + } + break; + default: /* invoke data storage error handler */ gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); } tcg_temp_free(EA); + + if (need_serial) { + /* Restart with exclusive lock. */ + gen_helper_exit_atomic(cpu_env); + ctx->base.is_jmp = DISAS_NORETURN; + } } static void gen_lwat(DisasContext *ctx)