From patchwork Fri Apr 27 00:26:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134539 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp89495lji; Thu, 26 Apr 2018 17:29:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoiv/0MIEQdNT5upmYR7tqx8Z9FBxsjuuk42GRM+K1Ap0/zBpFBKh+tMbBicOP8MQefRXnv X-Received: by 2002:a0c:d0ce:: with SMTP id b14-v6mr166071qvh.195.1524788995660; Thu, 26 Apr 2018 17:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524788995; cv=none; d=google.com; s=arc-20160816; b=whhO+cENnuuAYpGxpD0RtJwz4Muyz6wZM/4ysKgdUGddwvOBxfXk3jyaggMTXxDp/e WVQmk9P0+S1F8lddPeSciecTh+gEtMrYwBvUMeHcZbYxjnkWY2C9oSrroHRUgTRy92Yo kF/iqZHtCT6BAP+ODnTA0RqdOCE/2ZJnASZN0ecoRW4toQxlZAytzbIihL2K+p1GliOI waJxAgQu8jFGmAVi3S/k1ZX7zDzy7m7UH+cVR1yvC2ZXn1xfiwGRVffF8R6MwSUNIoqq oP/XJsRd5vFQN2P3DJbZ/kUBDLwdIgDZWkbthf/FlHbF11EsxSpxaQsyHG8XAfcpOW+8 J9Nw== 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=QeahTyooBey/fkgn97QY2/OE+3ePjf1njf4Fk85eWiw=; b=bcljTHJvJbzra5qEuiU8LidSzXmPyUA1u7jzd/ZatmQ11vKsBZu3GoDvl7kQKwJ/qV RBiMFVsoA+w9twVrsd3vz8wkg+EPqOpVCgbvGZdZocD15W403YL6FIuFEg7JaC0ivk3o S3iUB7NCtennb111AO4cJ04lCgb/Zsmqy2Gyb/lk6VXF2CXuvJoBvZuPIXbihuUftXxi uZxa6fJGZHBoZEsxjkzT4N4WaIr+D7dOdQHOpjujQ6IFnxSKvHZnUGuWZamVEfWSJnQX IXzyW2iazHsqHMPsS5PyrohPrKwA6BDtA16TB1ZyNCLnO6qdBsys7YlRDv99e2NjmJLo SdGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JzZqxuLi; 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 h6si87073qkj.352.2018.04.26.17.29.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:29:55 -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=JzZqxuLi; 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]:45108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrGt-0003P9-1v for patch@linaro.org; Thu, 26 Apr 2018 20:29:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrE8-0001x4-Iu for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrE7-0004PN-E3 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:04 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:36873) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrE7-0004P5-7r for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:03 -0400 Received: by mail-pg0-x242.google.com with SMTP id a13-v6so149203pgu.4 for ; Thu, 26 Apr 2018 17:27:03 -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=QeahTyooBey/fkgn97QY2/OE+3ePjf1njf4Fk85eWiw=; b=JzZqxuLi/7pCvfLu0/pxK4n6ij5hONN+PdFuDOKxercO3aCGlNO8neonEuT/cuAs4T N2kT3A7Zyi5QIWgp+sJWRot3d3+dKURCgnDYUOmti3dw38oPnMhgiK8Wc+UutIv46Qv2 hQA3askTbYqJo3+5WyKZycLBsgrq9CmiYtklw= 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=QeahTyooBey/fkgn97QY2/OE+3ePjf1njf4Fk85eWiw=; b=EjLQIN9wmJnUEEAyACVYRPD2FX6wwli55/PYnnJX8+P8V+ZG+1cvOWYo6OOXAQ1HEa kliL3rDCE+FPdpybI0u3Yg269+isNd3r0kFHh8IIEOqcn2E0g6tLNbu5knqZtYO7NKub eoLUKBQtrow5J7cNBaR+5JkfReGCsK4qWWS43SvrOvDMvBpuiDZmBTA8M+n6xb+GjrPn /q3+7UgnDRH1Y3t0SA8Y+taD0qN/GEDswWWZmVfiohA4KTQ+1pCymLUszJKr9hCg8eAH RGWsIctVz5QPSWmYb65Gpc7NIkbwLUw9K/AHklyzghJetye+NZXqvU97hlc3sVqzsSkP ud2A== X-Gm-Message-State: ALQs6tDWXZE4kEZFP3AnCEC17TVpsoffmYDVmfB/vTv8APzBjr7Tf5BV 0SR274v3JeFPjQid44JkzKsamtW1Klc= X-Received: by 2002:a65:438b:: with SMTP id m11-v6mr160802pgp.153.1524788821930; Thu, 26 Apr 2018 17:27:01 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:43 -1000 Message-Id: <20180427002651.28356-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::242 Subject: [Qemu-devel] [PATCH 1/9] tcg: Introduce helpers for integer min/max 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These operations are re-invented by several targets so far. Several supported hosts have insns for these, so place the expanders out-of-line for a future introduction of tcg opcodes. Signed-off-by: Richard Henderson --- tcg/tcg-op.h | 16 ++++++++++++++++ tcg/tcg-op.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 75bb55aeac..540337e605 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -324,6 +324,10 @@ void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg); void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg); void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg); void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg); +void tcg_gen_smin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2); +void tcg_gen_smax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2); +void tcg_gen_umin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2); +void tcg_gen_umax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2); static inline void tcg_gen_discard_i32(TCGv_i32 arg) { @@ -517,6 +521,10 @@ void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg); void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg); void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg); void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg); +void tcg_gen_smin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2); +void tcg_gen_smax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2); +void tcg_gen_umin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2); +void tcg_gen_umax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2); #if TCG_TARGET_REG_BITS == 64 static inline void tcg_gen_discard_i64(TCGv_i64 arg) @@ -1025,6 +1033,10 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_mulu2_tl tcg_gen_mulu2_i64 #define tcg_gen_muls2_tl tcg_gen_muls2_i64 #define tcg_gen_mulsu2_tl tcg_gen_mulsu2_i64 +#define tcg_gen_smin_tl tcg_gen_smin_i64 +#define tcg_gen_umin_tl tcg_gen_umin_i64 +#define tcg_gen_smax_tl tcg_gen_smax_i64 +#define tcg_gen_umax_tl tcg_gen_umax_i64 #define tcg_gen_atomic_cmpxchg_tl tcg_gen_atomic_cmpxchg_i64 #define tcg_gen_atomic_xchg_tl tcg_gen_atomic_xchg_i64 #define tcg_gen_atomic_fetch_add_tl tcg_gen_atomic_fetch_add_i64 @@ -1123,6 +1135,10 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_mulu2_tl tcg_gen_mulu2_i32 #define tcg_gen_muls2_tl tcg_gen_muls2_i32 #define tcg_gen_mulsu2_tl tcg_gen_mulsu2_i32 +#define tcg_gen_smin_tl tcg_gen_smin_i32 +#define tcg_gen_umin_tl tcg_gen_umin_i32 +#define tcg_gen_smax_tl tcg_gen_smax_i32 +#define tcg_gen_umax_tl tcg_gen_umax_i32 #define tcg_gen_atomic_cmpxchg_tl tcg_gen_atomic_cmpxchg_i32 #define tcg_gen_atomic_xchg_tl tcg_gen_atomic_xchg_i32 #define tcg_gen_atomic_fetch_add_tl tcg_gen_atomic_fetch_add_i32 diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 34b96d68f3..5b82c3be8d 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -1033,6 +1033,26 @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg) } } +void tcg_gen_smin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b) +{ + tcg_gen_movcond_i32(TCG_COND_LT, ret, a, b, a, b); +} + +void tcg_gen_umin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b) +{ + tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, a, b); +} + +void tcg_gen_smax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b) +{ + tcg_gen_movcond_i32(TCG_COND_LT, ret, a, b, b, a); +} + +void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b) +{ + tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, b, a); +} + /* 64-bit ops */ #if TCG_TARGET_REG_BITS == 32 @@ -2438,6 +2458,26 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) tcg_temp_free_i64(t2); } +void tcg_gen_smin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) +{ + tcg_gen_movcond_i64(TCG_COND_LT, ret, a, b, a, b); +} + +void tcg_gen_umin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) +{ + tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, a, b); +} + +void tcg_gen_smax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) +{ + tcg_gen_movcond_i64(TCG_COND_LT, ret, a, b, b, a); +} + +void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) +{ + tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, b, a); +} + /* Size changing operations. */ void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg) From patchwork Fri Apr 27 00:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134548 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp102999lji; Thu, 26 Apr 2018 17:48:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoBl4cUHl4FgSIa1SiCoNZwzfpZbOTCQNjh/tcPKX7ReaasqBdbPwJg+v6An7vc6LdMJByQ X-Received: by 2002:aed:3802:: with SMTP id j2-v6mr206929qte.205.1524790100821; Thu, 26 Apr 2018 17:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524790100; cv=none; d=google.com; s=arc-20160816; b=TlG6+meJ66zDKRtektINg9M4v3ACPK8yFxUHs4JgvRlKR2BZHO2+UpmxHiLIvMFqJi xWZpZTYmDIYOwMk5qkSJVY65YG06sHeEdtAWC7+xDdVAKNZ1xsGDoNKVZB+5EgGGSjqI xt1ZgPVzzq+tYIqZ1MvPb4CfqfIAqmp+gstcErcT920HibtOoRI5oq9Hk7Tw+2DKSYSx U29gSEiBSZpx+tfO9IiLm+01wWreHzc7Obounu0oF2TrPkF4XGc5X4Ul4VCb4Z2v/dWx 0X86cq+gdbD4auyncNQYEiyqsePo4/Kx8YGJ5BcYXAY9DOcjMS8Mw6z17a3dxxbKeTVn XH1A== 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=FcnQaKOY5FiYcN1YZAPz8IfJW4izctQEpJ8H6gTzcVU=; b=dMMvzPf9fA0tgELiPkyJ1uSHucx9032zq+tYVVvLChZGxEqfX6sZV3vtnSkECbKOLJ EGBsEQFK4uvI/HDmGXR7Kv77cb76DPgPIZbnV0agGSInOttpax4F9bmfosU1cAHKoQeh 0bddnFx91gZJFyDgV8bM9sjacrX0iThD/1y/o3HwPBUXUbYY4ezfg/k+pavSRSWfn7Ux YMEwIyI+LtQOeJYCocHMrVhTM/GiXS6Onor8TKd1Otqe8zEtELdk6Y3yehN2JcUYBOji S3R2e0iyoGuhqSkcuRutzRiDMu7mbrasyiiPKz5ri6ZBBqxTjt/EXbA93Lee+AMgqLcm FYmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bPOys9K5; 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 v47-v6si133544qtg.82.2018.04.26.17.48.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:48:20 -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=bPOys9K5; 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]:45221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrYi-00025j-AE for patch@linaro.org; Thu, 26 Apr 2018 20:48:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrE9-0001xe-Tj for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrE8-0004Qo-Ts for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:05 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:38627) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrE8-0004Pn-PK for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:04 -0400 Received: by mail-pg0-x242.google.com with SMTP id n9-v6so150132pgq.5 for ; Thu, 26 Apr 2018 17:27:04 -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=FcnQaKOY5FiYcN1YZAPz8IfJW4izctQEpJ8H6gTzcVU=; b=bPOys9K5bvbyeZ5Jm5EXU9ej0n7y4YpE61DBD2Hya2qVOFw3UfRqkuH5+aqeczPqoq 7vgfXPbvToFLBOyH7IbAT2IptIW/y9T49oPuWkYBajzPEVO8GfAFDDdf85onDkVo6Xcb evYXjWVaep2YA0SM50AUfzFUllwmSkvpA4O3Q= 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=FcnQaKOY5FiYcN1YZAPz8IfJW4izctQEpJ8H6gTzcVU=; b=qzfNDDGjEQl3JdwoQFd5TdNeNpV1EdUT1ODftgEC6dfcl+ZfqqmnYHu5H9j+qyZSPh Dxw7ezsZBclGPiAdpBl4C3LGn8BdvAl0XqZj92B9kW9Do9c6sN3kF6aa1DVFhqc4Bo00 Kh5lsqkJAcyPaCEpR0wA9wLaaQ0xFreATepvjg0Kaa5Pic8xbWGrs5CukewQG5YKk9um RL3szE5Knezc7Blx9zjdgz23RozmMlmOXK4PBcMIjN6m8Fpl+8snSpIGO1av+tIgjqKI iH4mRRK874jGQOflIxjw/fdgtQFVPfftD4KwBlm4u0TMMAmw2fpKLcTfT4WXjRduVPx8 TG8g== X-Gm-Message-State: ALQs6tAVJVoxm53oKCuk5jJ86jafcbLkajjTuh04hLNhbGmgLRJTHwsi /qDgyOV7hA/FilL/yUGMs2MjR8G8d5o= X-Received: by 2002:a63:6385:: with SMTP id x127-v6mr190438pgb.50.1524788823585; Thu, 26 Apr 2018 17:27:03 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:44 -1000 Message-Id: <20180427002651.28356-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::242 Subject: [Qemu-devel] [PATCH 2/9] target/arm: Use new min/max expanders 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The generic expanders replace nearly identical code in the translator. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index bff4e13bf6..d916fea3a3 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -6021,15 +6021,18 @@ static void disas_simd_across_lanes(DisasContext *s, uint32_t insn) tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt); break; case 0x0a: /* SMAXV / UMAXV */ - tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE, - tcg_res, - tcg_res, tcg_elt, tcg_res, tcg_elt); + if (is_u) { + tcg_gen_umax_i64(tcg_res, tcg_res, tcg_elt); + } else { + tcg_gen_smax_i64(tcg_res, tcg_res, tcg_elt); + } break; case 0x1a: /* SMINV / UMINV */ - tcg_gen_movcond_i64(is_u ? TCG_COND_LEU : TCG_COND_LE, - tcg_res, - tcg_res, tcg_elt, tcg_res, tcg_elt); - break; + if (is_u) { + tcg_gen_umin_i64(tcg_res, tcg_res, tcg_elt); + } else { + tcg_gen_smin_i64(tcg_res, tcg_res, tcg_elt); + } break; default: g_assert_not_reached(); @@ -9931,27 +9934,6 @@ static void disas_simd_3same_logic(DisasContext *s, uint32_t insn) } } -/* Helper functions for 32 bit comparisons */ -static void gen_max_s32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2) -{ - tcg_gen_movcond_i32(TCG_COND_GE, res, op1, op2, op1, op2); -} - -static void gen_max_u32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2) -{ - tcg_gen_movcond_i32(TCG_COND_GEU, res, op1, op2, op1, op2); -} - -static void gen_min_s32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2) -{ - tcg_gen_movcond_i32(TCG_COND_LE, res, op1, op2, op1, op2); -} - -static void gen_min_u32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2) -{ - tcg_gen_movcond_i32(TCG_COND_LEU, res, op1, op2, op1, op2); -} - /* Pairwise op subgroup of C3.6.16. * * This is called directly or via the handle_3same_float for float pairwise @@ -10051,7 +10033,7 @@ static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode, static NeonGenTwoOpFn * const fns[3][2] = { { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 }, { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 }, - { gen_max_s32, gen_max_u32 }, + { tcg_gen_smax_i32, tcg_gen_umax_i32 }, }; genfn = fns[size][u]; break; @@ -10061,7 +10043,7 @@ static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode, static NeonGenTwoOpFn * const fns[3][2] = { { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 }, { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 }, - { gen_min_s32, gen_min_u32 }, + { tcg_gen_smin_i32, tcg_gen_umin_i32 }, }; genfn = fns[size][u]; break; @@ -10516,7 +10498,7 @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) static NeonGenTwoOpFn * const fns[3][2] = { { gen_helper_neon_max_s8, gen_helper_neon_max_u8 }, { gen_helper_neon_max_s16, gen_helper_neon_max_u16 }, - { gen_max_s32, gen_max_u32 }, + { tcg_gen_smax_i32, tcg_gen_umax_i32 }, }; genfn = fns[size][u]; break; @@ -10527,7 +10509,7 @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) static NeonGenTwoOpFn * const fns[3][2] = { { gen_helper_neon_min_s8, gen_helper_neon_min_u8 }, { gen_helper_neon_min_s16, gen_helper_neon_min_u16 }, - { gen_min_s32, gen_min_u32 }, + { tcg_gen_smin_i32, tcg_gen_umin_i32 }, }; genfn = fns[size][u]; break; From patchwork Fri Apr 27 00:26:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134549 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp103798lji; Thu, 26 Apr 2018 17:49:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqyAlcmwTepeBdqhxaD/W+fodOK0JbablosAdswi2C8Psm11kFFAB4WBsJ7bIG10fuVdkjB X-Received: by 2002:ac8:1204:: with SMTP id x4-v6mr227868qti.35.1524790173884; Thu, 26 Apr 2018 17:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524790173; cv=none; d=google.com; s=arc-20160816; b=xjU23LIt06q5/wNAszfLfHPe4cl4k50YaJdKTZd3lgPnxDQW5EqVhX27UBHKVgrbSY B7P/wQEdP+LGAmP6jNB3edQ80V42rtoyyIBgywC86PI90vedstL4TrYRQ27s6aiE0QPP 7NevAhDcS+x1z0ZvCjW442lMY2ToWQmFgPM2WmKItg9wIwFfZ+vrEBQw8gL98xngGNpT P/agPdqEZclcsRr1OpkNocApGkjkiALKWK9NCwCwud7jBXxy1NJMl8Gj+qrPZs+6ELbO 5PDLJ+VtBMethCJAj2aWFujJmKXTti2CdLsWZ/tomb8/+u6Md1nDyNGa2m7uFBUmzTeQ +QiQ== 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=AK0p4SpyvZ3J/I+GdUe6KW90oSn4gSKkgLtPrMjVrLk=; b=h1XeTgTMn9jBE4rAxO0/jYPYw1gt1+RdIe/5J4p+XoHj/l1empGCjZk8VviCNhic2+ yJyBlpSFocG0kG4Cql9pfUlZvHoK4FhXI2LDxgkOjCpFRTGPUuCfcOqtag4quhcLap4k p38ZHNpV1wV4Spz7aqQa4ipGqgg6jfC3vQzW+CtaUvdwNBXrmNB7mmYDpCE2TQCWB0fh gukP21etDjQK5+M+OFngM9UJDhJ6oW5gGmnDXu3j5I1ahM5z9kILbGut9pqgJ2hrU/ZO TVmMAfi20hTtVUMogEZQzezlTcCv9wqWr73UukOpI7yjExFDzDiocYDUZu+ZsyKN+gTo qtzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q7tGKSCO; 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 m10-v6si124108qth.328.2018.04.26.17.49.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:49:33 -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=Q7tGKSCO; 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]:45224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrZt-00030g-DW for patch@linaro.org; Thu, 26 Apr 2018 20:49:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEB-000200-P2 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEA-0004SY-P8 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:07 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:36462) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEA-0004SG-JZ for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:06 -0400 Received: by mail-pg0-x241.google.com with SMTP id i6-v6so152510pgv.3 for ; Thu, 26 Apr 2018 17:27:06 -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=AK0p4SpyvZ3J/I+GdUe6KW90oSn4gSKkgLtPrMjVrLk=; b=Q7tGKSCOHhY7X8Msutm3H4PZBcM3r0r8/vpBaAJCB1NG5F951Kth5pDQtXPlcpDuVg HFitHinDoGjgbUoUk4em/0v7zAnmieYAj84/5NrRqtg/LDYvp7M0tU3bKvwvKa2DjzSX Xnr/2e+HiHE67YBGUb8FgKhKcaO1OasJsrvN4= 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=AK0p4SpyvZ3J/I+GdUe6KW90oSn4gSKkgLtPrMjVrLk=; b=QFfP2rOl47u4uLPVU9UNk47moBs0Oz+h+L6GXKW6fonMXqcd2ckmRH7D+Vp2uamT2k 9F8trRjYqYUU/PKb5Qz7Gy1Pp5guM/AdPIbcp18nCqpmeKiQ0gEyQajl0JSm2qFCH7M1 wJdzBy18ILD8FpWkAqPK2k7F069d3fMq0HTdjn3vWeeZeAC2RQ/8YAw0H5Rq/jH8eYPD XWME56Xqw3jbqzJUiwc82vmT7E3NBr3vZlsRpMt8Ji2puPEAis1CLR8R5u5NTopIOhV0 N4IsineCOgOT+RlRtXnzuFoUKDZF+9DzwrS95HBMy6jUNIiLTZXvpoFqs2hWxcj6G4NP I2fA== X-Gm-Message-State: ALQs6tAtYZI61JVyJg8LgCGJyOL+2kjVj4q/lTYF+7+xfLoRfTcpn0VS wdv7RBouHCzBCmnMGDrHFtoKtSgohjE= X-Received: by 2002:a65:6301:: with SMTP id g1-v6mr153110pgv.307.1524788825391; Thu, 26 Apr 2018 17:27:05 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:45 -1000 Message-Id: <20180427002651.28356-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::241 Subject: [Qemu-devel] [PATCH 3/9] target/xtensa: Use new min/max expanders 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: Max Filippov , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The generic expanders replace nearly identical code in the translator. Cc: Max Filippov Signed-off-by: Richard Henderson --- target/xtensa/translate.c | 50 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) -- 2.14.3 Acked-by: Max Filippov diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 4f6d03059f..bad5cdb009 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1527,10 +1527,8 @@ static void translate_clamps(DisasContext *dc, const uint32_t arg[], TCGv_i32 tmp1 = tcg_const_i32(-1u << arg[2]); TCGv_i32 tmp2 = tcg_const_i32((1 << arg[2]) - 1); - tcg_gen_movcond_i32(TCG_COND_GT, tmp1, - cpu_R[arg[1]], tmp1, cpu_R[arg[1]], tmp1); - tcg_gen_movcond_i32(TCG_COND_LT, cpu_R[arg[0]], - tmp1, tmp2, tmp1, tmp2); + tcg_gen_smax_i32(tmp1, tmp1, cpu_R[arg[1]]); + tcg_gen_smin_i32(cpu_R[arg[0]], tmp1, tmp2); tcg_temp_free(tmp1); tcg_temp_free(tmp2); } @@ -1855,13 +1853,35 @@ static void translate_memw(DisasContext *dc, const uint32_t arg[], tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); } -static void translate_minmax(DisasContext *dc, const uint32_t arg[], - const uint32_t par[]) +static void translate_smin(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) { if (gen_window_check3(dc, arg[0], arg[1], arg[2])) { - tcg_gen_movcond_i32(par[0], cpu_R[arg[0]], - cpu_R[arg[1]], cpu_R[arg[2]], - cpu_R[arg[1]], cpu_R[arg[2]]); + tcg_gen_smin_i32(cpu_R[arg[0]], cpu_R[arg[1]], cpu_R[arg[2]]); + } +} + +static void translate_umin(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check3(dc, arg[0], arg[1], arg[2])) { + tcg_gen_umin_i32(cpu_R[arg[0]], cpu_R[arg[1]], cpu_R[arg[2]]); + } +} + +static void translate_smax(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check3(dc, arg[0], arg[1], arg[2])) { + tcg_gen_smax_i32(cpu_R[arg[0]], cpu_R[arg[1]], cpu_R[arg[2]]); + } +} + +static void translate_umax(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check3(dc, arg[0], arg[1], arg[2])) { + tcg_gen_umax_i32(cpu_R[arg[0]], cpu_R[arg[1]], cpu_R[arg[2]]); } } @@ -2984,23 +3004,19 @@ static const XtensaOpcodeOps core_ops[] = { .par = (const uint32_t[]){TCG_COND_NE}, }, { .name = "max", - .translate = translate_minmax, - .par = (const uint32_t[]){TCG_COND_GE}, + .translate = translate_smax, }, { .name = "maxu", - .translate = translate_minmax, - .par = (const uint32_t[]){TCG_COND_GEU}, + .translate = translate_umax, }, { .name = "memw", .translate = translate_memw, }, { .name = "min", - .translate = translate_minmax, - .par = (const uint32_t[]){TCG_COND_LT}, + .translate = translate_smin, }, { .name = "minu", - .translate = translate_minmax, - .par = (const uint32_t[]){TCG_COND_LTU}, + .translate = translate_umin, }, { .name = "mov", .translate = translate_mov, From patchwork Fri Apr 27 00:26:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134550 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp104832lji; Thu, 26 Apr 2018 17:50:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoln3B027UTknslb+AwZshPggoRoJDAuboMDB/jy3xlXGM+pdO4AOdnTK9VKDLdVOkHsYRt X-Received: by 2002:ac8:2724:: with SMTP id g33-v6mr216680qtg.37.1524790247637; Thu, 26 Apr 2018 17:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524790247; cv=none; d=google.com; s=arc-20160816; b=b8jXxSjjPgDoEVJdt250e/VRYvTUy1Rz3azkeGLXGlZkaPwqXUCPSl2y7Fh8XNPq1s SheOQgCrCAOuO1zpkI4tZhKZVcp37L5t49g/0xuZRqOvqfQbCfEc5OE3xsNTDM69jiV8 0l9vMzJqSRQvUn7DlynChv+TBcBm+zxBB9iR81SepuLm1eJ8ngHSCwLXG1ECGIHJnoaB jPFrqbRtGZ0a46ThPaFRxYdQEPdLX7UR6SsrdwapeSP1t70oYIkRE0nG/yGquVETWkXx SV5nL9l3u4Oapc1ALdAq1pjlx8Xy5thlnPWTeLnmLpPU5AiGuAlaFO0W2IfxESZjVh8r fCKg== 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=j+e6tEOmz3LZY3JQvIupYxvRHddEfIGDkdSICHSK7xc=; b=L1a0VrXwcLR19CP+h+M5QwWIa19xFHlZgM5sHpVqgk0K5G01lGhqXBfa9WlnkarmqD cus5Mt+QqRqkbmYUDfnBUyYqa8uBv1IIzPZUrYuq/W1s+03IDGTxRC0jH8kgoh5PODhM jcB877xGQcp4gv2b8VF8LIiLvahIGCsNN+AI9SJlbEtMsShqxJSePfPspOsDZxfATMsz yXvzmyVeZYL07+YeLGDFdwsL9pbTwRN4oq3hPKRq7O6GR/DM7jdkiT00UJ78whZQ1smc TzgtavNHi528vnBBticDmjHhyfYWj3cLaA/3j640hmyYJPZN1mn1R2c+9+v7N1DWwzSS HSyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CKGHAWyQ; 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 k187si144894qkd.126.2018.04.26.17.50.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:50:47 -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=CKGHAWyQ; 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]:45235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrb5-0003mJ-4y for patch@linaro.org; Thu, 26 Apr 2018 20:50:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEE-00023D-BZ for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEC-0004Ti-Pv for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:10 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEC-0004TE-I4 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:08 -0400 Received: by mail-pg0-x243.google.com with SMTP id p10-v6so156642pgn.1 for ; Thu, 26 Apr 2018 17:27:08 -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=j+e6tEOmz3LZY3JQvIupYxvRHddEfIGDkdSICHSK7xc=; b=CKGHAWyQ9qaDZC3QDBoLx5jA0bowIifKSieQa8xNSYd5BvOezI8BZl/jXPgIFn2ieG yHy7Kl6B5vLVUeIgJQCEBE9vYOu4CSb1ovo7ztCnlIqcraEAVclyWImpk2CuXre3JMyf vY9htw1Q1N9NgWL4sV/TISovDIggpEoN5mErM= 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=j+e6tEOmz3LZY3JQvIupYxvRHddEfIGDkdSICHSK7xc=; b=O7BD8S5SOLVsxyBuIeqLxIgUe3hAh4XuRamqzGN4moWldWx/v7yp1oKF6rPL9BM3eA 4vAz5tflQXEORc2bgpLE3hdyVqxo9wJg/NRMeZYjpM62xne+PfM4eGa1bOaqt+comTuF eQpDdJjJkZEqpo3SguF8dU3d58rn4MeHZmh/ujU1IlE67clv/gEWvejParxCbk8lf3Kb /mVMlggwYuppnKLWlga984ZhvQbfT+qQKC3M407R8YFFSq2uEACGUp41Cm9ePV0cUj2w 5x6CJw4gfx+SG9plmShgciMXhqpmvFI3Kd6ToMje7365WZDAFxtM3ud9xeePyBVPyshf u8fw== X-Gm-Message-State: ALQs6tDMLeSirk2dbzMrup9re1l7p/xhbaJl0wxiRzWb3lwcbDstmwSo yxhXBtSdTnu2gLBT8mh8PvoEowMP1Mk= X-Received: by 2002:a63:b047:: with SMTP id z7-v6mr188495pgo.74.1524788827263; Thu, 26 Apr 2018 17:27:07 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:46 -1000 Message-Id: <20180427002651.28356-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::243 Subject: [Qemu-devel] [PATCH 4/9] tcg: Introduce atomic helpers for integer min/max 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Given that this atomic operation will be used by both risc-v and aarch64, let's not duplicate code across the two targets. Signed-off-by: Richard Henderson --- accel/tcg/atomic_template.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ accel/tcg/tcg-runtime.h | 8 +++++ tcg/tcg-op.h | 34 ++++++++++++++++++++++ tcg/tcg.h | 8 +++++ tcg/tcg-op.c | 8 +++++ 5 files changed, 129 insertions(+) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index e022df4571..2489dd3ec1 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -25,18 +25,22 @@ #elif DATA_SIZE == 8 # define SUFFIX q # define DATA_TYPE uint64_t +# define SDATA_TYPE int64_t # define BSWAP bswap64 #elif DATA_SIZE == 4 # define SUFFIX l # define DATA_TYPE uint32_t +# define SDATA_TYPE int32_t # define BSWAP bswap32 #elif DATA_SIZE == 2 # define SUFFIX w # define DATA_TYPE uint16_t +# define SDATA_TYPE int16_t # define BSWAP bswap16 #elif DATA_SIZE == 1 # define SUFFIX b # define DATA_TYPE uint8_t +# define SDATA_TYPE int8_t # define BSWAP #else # error unsupported data size @@ -118,6 +122,39 @@ GEN_ATOMIC_HELPER(or_fetch) GEN_ATOMIC_HELPER(xor_fetch) #undef GEN_ATOMIC_HELPER + +/* These helpers are, as a whole, full barriers. Within the helper, + * the leading barrier is explicit and the trailing barrier is within + * cmpxchg primitive. + */ +#define GEN_ATOMIC_HELPER_FN(X, FN, XDATA_TYPE, RET) \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ + ABI_TYPE xval EXTRA_ARGS) \ +{ \ + ATOMIC_MMU_DECLS; \ + XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ + XDATA_TYPE cmp, old, new, val = xval; \ + smp_mb(); \ + cmp = atomic_read__nocheck(haddr); \ + do { \ + old = cmp; new = FN(old, val); \ + cmp = atomic_cmpxchg__nocheck(haddr, old, new); \ + } while (cmp != old); \ + ATOMIC_MMU_CLEANUP; \ + return RET; \ +} + +GEN_ATOMIC_HELPER_FN(fetch_smin, MIN, SDATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_umin, MIN, DATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_smax, MAX, SDATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_umax, MAX, DATA_TYPE, old) + +GEN_ATOMIC_HELPER_FN(smin_fetch, MIN, SDATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(umin_fetch, MIN, DATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(smax_fetch, MAX, SDATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(umax_fetch, MAX, DATA_TYPE, new) + +#undef GEN_ATOMIC_HELPER_FN #endif /* DATA SIZE >= 16 */ #undef END @@ -233,6 +270,39 @@ ABI_TYPE ATOMIC_NAME(add_fetch)(CPUArchState *env, target_ulong addr, ldo = ldn; } } + +/* These helpers are, as a whole, full barriers. Within the helper, + * the leading barrier is explicit and the trailing barrier is within + * cmpxchg primitive. + */ +#define GEN_ATOMIC_HELPER_FN(X, FN, XDATA_TYPE, RET) \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ + ABI_TYPE xval EXTRA_ARGS) \ +{ \ + ATOMIC_MMU_DECLS; \ + XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ + XDATA_TYPE ldo, ldn, old, new, val = xval; \ + smp_mb(); \ + ldn = atomic_read__nocheck(haddr); \ + do { \ + ldo = ldn; old = BSWAP(ldo); new = FN(old, val); \ + ldn = atomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ + } while (ldo != ldn); \ + ATOMIC_MMU_CLEANUP; \ + return RET; \ +} + +GEN_ATOMIC_HELPER_FN(fetch_smin, MIN, SDATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_umin, MIN, DATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_smax, MAX, SDATA_TYPE, old) +GEN_ATOMIC_HELPER_FN(fetch_umax, MAX, DATA_TYPE, old) + +GEN_ATOMIC_HELPER_FN(smin_fetch, MIN, SDATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(umin_fetch, MIN, DATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(smax_fetch, MAX, SDATA_TYPE, new) +GEN_ATOMIC_HELPER_FN(umax_fetch, MAX, DATA_TYPE, new) + +#undef GEN_ATOMIC_HELPER_FN #endif /* DATA_SIZE >= 16 */ #undef END @@ -241,5 +311,6 @@ ABI_TYPE ATOMIC_NAME(add_fetch)(CPUArchState *env, target_ulong addr, #undef BSWAP #undef ABI_TYPE #undef DATA_TYPE +#undef SDATA_TYPE #undef SUFFIX #undef DATA_SIZE diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h index 2536959a18..1bd39d136d 100644 --- a/accel/tcg/tcg-runtime.h +++ b/accel/tcg/tcg-runtime.h @@ -125,11 +125,19 @@ GEN_ATOMIC_HELPERS(fetch_add) GEN_ATOMIC_HELPERS(fetch_and) GEN_ATOMIC_HELPERS(fetch_or) GEN_ATOMIC_HELPERS(fetch_xor) +GEN_ATOMIC_HELPERS(fetch_smin) +GEN_ATOMIC_HELPERS(fetch_umin) +GEN_ATOMIC_HELPERS(fetch_smax) +GEN_ATOMIC_HELPERS(fetch_umax) GEN_ATOMIC_HELPERS(add_fetch) GEN_ATOMIC_HELPERS(and_fetch) GEN_ATOMIC_HELPERS(or_fetch) GEN_ATOMIC_HELPERS(xor_fetch) +GEN_ATOMIC_HELPERS(smin_fetch) +GEN_ATOMIC_HELPERS(umin_fetch) +GEN_ATOMIC_HELPERS(smax_fetch) +GEN_ATOMIC_HELPERS(umax_fetch) GEN_ATOMIC_HELPERS(xchg) diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 540337e605..9326b52312 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -898,6 +898,7 @@ void tcg_gen_atomic_cmpxchg_i64(TCGv_i64, TCGv, TCGv_i64, TCGv_i64, void tcg_gen_atomic_xchg_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_xchg_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); + void tcg_gen_atomic_fetch_add_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_fetch_add_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); void tcg_gen_atomic_fetch_and_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); @@ -906,6 +907,15 @@ void tcg_gen_atomic_fetch_or_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_fetch_or_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); void tcg_gen_atomic_fetch_xor_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_fetch_xor_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_smin_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_smin_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_umin_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_umin_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_smax_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_smax_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_umax_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_fetch_umax_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); + void tcg_gen_atomic_add_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_add_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); void tcg_gen_atomic_and_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); @@ -914,6 +924,14 @@ void tcg_gen_atomic_or_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_or_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); void tcg_gen_atomic_xor_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); void tcg_gen_atomic_xor_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_smin_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_smin_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_umin_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_umin_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_smax_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_smax_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); +void tcg_gen_atomic_umax_fetch_i32(TCGv_i32, TCGv, TCGv_i32, TCGArg, TCGMemOp); +void tcg_gen_atomic_umax_fetch_i64(TCGv_i64, TCGv, TCGv_i64, TCGArg, TCGMemOp); void tcg_gen_mov_vec(TCGv_vec, TCGv_vec); void tcg_gen_dup_i32_vec(unsigned vece, TCGv_vec, TCGv_i32); @@ -1043,10 +1061,18 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_atomic_fetch_and_tl tcg_gen_atomic_fetch_and_i64 #define tcg_gen_atomic_fetch_or_tl tcg_gen_atomic_fetch_or_i64 #define tcg_gen_atomic_fetch_xor_tl tcg_gen_atomic_fetch_xor_i64 +#define tcg_gen_atomic_fetch_smin_tl tcg_gen_atomic_fetch_smin_i64 +#define tcg_gen_atomic_fetch_umin_tl tcg_gen_atomic_fetch_umin_i64 +#define tcg_gen_atomic_fetch_smax_tl tcg_gen_atomic_fetch_smax_i64 +#define tcg_gen_atomic_fetch_umax_tl tcg_gen_atomic_fetch_umax_i64 #define tcg_gen_atomic_add_fetch_tl tcg_gen_atomic_add_fetch_i64 #define tcg_gen_atomic_and_fetch_tl tcg_gen_atomic_and_fetch_i64 #define tcg_gen_atomic_or_fetch_tl tcg_gen_atomic_or_fetch_i64 #define tcg_gen_atomic_xor_fetch_tl tcg_gen_atomic_xor_fetch_i64 +#define tcg_gen_atomic_smin_fetch_tl tcg_gen_atomic_smin_fetch_i64 +#define tcg_gen_atomic_umin_fetch_tl tcg_gen_atomic_umin_fetch_i64 +#define tcg_gen_atomic_smax_fetch_tl tcg_gen_atomic_smax_fetch_i64 +#define tcg_gen_atomic_umax_fetch_tl tcg_gen_atomic_umax_fetch_i64 #define tcg_gen_dup_tl_vec tcg_gen_dup_i64_vec #else #define tcg_gen_movi_tl tcg_gen_movi_i32 @@ -1145,10 +1171,18 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_atomic_fetch_and_tl tcg_gen_atomic_fetch_and_i32 #define tcg_gen_atomic_fetch_or_tl tcg_gen_atomic_fetch_or_i32 #define tcg_gen_atomic_fetch_xor_tl tcg_gen_atomic_fetch_xor_i32 +#define tcg_gen_atomic_fetch_smin_tl tcg_gen_atomic_fetch_smin_i32 +#define tcg_gen_atomic_fetch_umin_tl tcg_gen_atomic_fetch_umin_i32 +#define tcg_gen_atomic_fetch_smax_tl tcg_gen_atomic_fetch_smax_i32 +#define tcg_gen_atomic_fetch_umax_tl tcg_gen_atomic_fetch_umax_i32 #define tcg_gen_atomic_add_fetch_tl tcg_gen_atomic_add_fetch_i32 #define tcg_gen_atomic_and_fetch_tl tcg_gen_atomic_and_fetch_i32 #define tcg_gen_atomic_or_fetch_tl tcg_gen_atomic_or_fetch_i32 #define tcg_gen_atomic_xor_fetch_tl tcg_gen_atomic_xor_fetch_i32 +#define tcg_gen_atomic_smin_fetch_tl tcg_gen_atomic_smin_fetch_i32 +#define tcg_gen_atomic_umin_fetch_tl tcg_gen_atomic_umin_fetch_i32 +#define tcg_gen_atomic_smax_fetch_tl tcg_gen_atomic_smax_fetch_i32 +#define tcg_gen_atomic_umax_fetch_tl tcg_gen_atomic_umax_fetch_i32 #define tcg_gen_dup_tl_vec tcg_gen_dup_i32_vec #endif diff --git a/tcg/tcg.h b/tcg/tcg.h index 30896ca304..55e2747966 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -1389,12 +1389,20 @@ GEN_ATOMIC_HELPER_ALL(fetch_sub) GEN_ATOMIC_HELPER_ALL(fetch_and) GEN_ATOMIC_HELPER_ALL(fetch_or) GEN_ATOMIC_HELPER_ALL(fetch_xor) +GEN_ATOMIC_HELPER_ALL(fetch_smin) +GEN_ATOMIC_HELPER_ALL(fetch_umin) +GEN_ATOMIC_HELPER_ALL(fetch_smax) +GEN_ATOMIC_HELPER_ALL(fetch_umax) GEN_ATOMIC_HELPER_ALL(add_fetch) GEN_ATOMIC_HELPER_ALL(sub_fetch) GEN_ATOMIC_HELPER_ALL(and_fetch) GEN_ATOMIC_HELPER_ALL(or_fetch) GEN_ATOMIC_HELPER_ALL(xor_fetch) +GEN_ATOMIC_HELPER_ALL(smin_fetch) +GEN_ATOMIC_HELPER_ALL(umin_fetch) +GEN_ATOMIC_HELPER_ALL(smax_fetch) +GEN_ATOMIC_HELPER_ALL(umax_fetch) GEN_ATOMIC_HELPER_ALL(xchg) diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 5b82c3be8d..6a914654f5 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -3051,11 +3051,19 @@ GEN_ATOMIC_HELPER(fetch_add, add, 0) GEN_ATOMIC_HELPER(fetch_and, and, 0) GEN_ATOMIC_HELPER(fetch_or, or, 0) GEN_ATOMIC_HELPER(fetch_xor, xor, 0) +GEN_ATOMIC_HELPER(fetch_smin, smin, 0) +GEN_ATOMIC_HELPER(fetch_umin, umin, 0) +GEN_ATOMIC_HELPER(fetch_smax, smax, 0) +GEN_ATOMIC_HELPER(fetch_umax, umax, 0) GEN_ATOMIC_HELPER(add_fetch, add, 1) GEN_ATOMIC_HELPER(and_fetch, and, 1) GEN_ATOMIC_HELPER(or_fetch, or, 1) GEN_ATOMIC_HELPER(xor_fetch, xor, 1) +GEN_ATOMIC_HELPER(smin_fetch, smin, 1) +GEN_ATOMIC_HELPER(umin_fetch, umin, 1) +GEN_ATOMIC_HELPER(smax_fetch, smax, 1) +GEN_ATOMIC_HELPER(umax_fetch, umax, 1) static void tcg_gen_mov2_i32(TCGv_i32 r, TCGv_i32 a, TCGv_i32 b) { From patchwork Fri Apr 27 00:26:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134540 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp90225lji; Thu, 26 Apr 2018 17:30:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrI0Dp8IYODvjQZx3De6or5it8mSWvbWIHEb6y0FLudlS+VyExk8HG5cxLJiDcoi5yUcRlp X-Received: by 2002:ac8:2dbb:: with SMTP id p56-v6mr212198qta.104.1524789047789; Thu, 26 Apr 2018 17:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524789047; cv=none; d=google.com; s=arc-20160816; b=kJhjXIzaV2VLj/GHcOUQO+xZasVJVRy1K8sgt2HU/b4RfnGIKBTgOP6bNTXy5OkLkf /XpqV8KqLrW7jZp7LqKnWSoIEBw0bXQyHaKzLFofsUKJ4PmStflNl62XIJ+KvTteacKr 9CjWeG3x5iUifUw6Lu7mJ74tOl9MWXLzVgZf2bxTHG2fojQz+tkU09pG/NSgnwEozr+f /ukO3EsfNmfi32OOkLCNYvJYRA6Vra7twp8UjsHLcl1y7fFRmAGmye3zhQzCGMeObA/w yZKKbq6mz9af8MQs76zNkXnKC3Sv+mawQEPtVQkSpRDwMKjRkNQR1WF0A2zyAjcjDc2r teng== 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=sEh2wGJE6rgMpMZZf3odblZRKaPH0BOzj0JTtUcsDDE=; b=FcqD6/ctDDBXc0l0EBDsBojeZAA86gK6TGd5oYGuPnMvLQJ0XjLjWhLoXH02OV6U/D +6TG6gt9LapHVb5NIGaYd4V42+cpQuexwVSK8PWBY5URROpGps1gn8LBasit/Pt/BNq3 Ej7+/pQTaFTUZFTPpzZr+PihsKRA3gLP+xFkQvXxbOS0Mjvpa2FcQwJMbUxBY/rruFkt gFn78L1y2eItpXK5jyBwcZp3QBRsqVATDzvHXxtz75wBXkUpIJ6eleCwVC3Mg7khNmrA AacyYIYdpyj1882klyIYQW4e7nuXOBMkNF2rjhTZg4NYVeCu/52RAUJLYYlAEThr1/Z+ wwXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FI1pOc0W; 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 z7-v6si110487qvc.143.2018.04.26.17.30.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:30:47 -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=FI1pOc0W; 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]:45126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrHj-0005N0-7G for patch@linaro.org; Thu, 26 Apr 2018 20:30:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEF-00026G-L1 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEE-0004Uc-F1 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:11 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:46801) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEE-0004U5-AR for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:10 -0400 Received: by mail-pg0-x244.google.com with SMTP id z4-v6so134262pgu.13 for ; Thu, 26 Apr 2018 17:27:10 -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=sEh2wGJE6rgMpMZZf3odblZRKaPH0BOzj0JTtUcsDDE=; b=FI1pOc0WIAJOl2HQNSah4DIlYL2rd2/cHstiGpsYsuHJIn+XueVQVzmXYL0mWPdgPd MbNl9A8QziqmF8rtCHmu9JW0sqIJbDVYYVHaVKUaUEv+9NI0wem4S+HT1TTWaCMdmTUl gLcRyx6FHLJ9HyH/brwdBD+p/XRcYfYmFtYbQ= 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=sEh2wGJE6rgMpMZZf3odblZRKaPH0BOzj0JTtUcsDDE=; b=PzFgc97/fkTfbP0sYpS0i4nWHEzpu9GMbHU1tD/57wAKTnL8mhIMsxnL0mYYeHytVS T/bmmhY5XKTpN5uCptD+r8EwWkdZsyaNtltP2M5lx2deOppZIDshWzHpTnqRhS/w2Qw0 5hy38YY4Ube/2VP8qJ6exmNchH6AUN7gHRay/iWuiue4D7JrO4vn1wb+XzngKZsbNM4l vormsvyyDRtayimG3dUatEXeTT3Yp5VYSDnHYUOpZNRYJLiv4dhn9e0KFpwtFjjSS0Pq GB6+MAdhaWXuXY4F3vfOBOmOQYyT24QVAcs4g04hygu8Ntehp44rtaaE2GA1v4hCv0xx xqcQ== X-Gm-Message-State: ALQs6tBzEuCTIWUzbJvJaZLDUgWAcufFBWGiSFReRLiDaDgB2gfb3cSZ 942uvaxG7Ysu/6RuwnZFYoVhtM7ugNM= X-Received: by 2002:a63:af44:: with SMTP id s4-v6mr147975pgo.295.1524788829145; Thu, 26 Apr 2018 17:27:09 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:47 -1000 Message-Id: <20180427002651.28356-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::244 Subject: [Qemu-devel] [PATCH 5/9] target/riscv: Use new atomic min/max expanders 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: Bastian Koppelmann , qemu-arm@nongnu.org, Michael Clark , Sagar Karandikar , Palmer Dabbelt Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Michael Clark Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Signed-off-by: Richard Henderson --- target/riscv/translate.c | 72 ++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 52 deletions(-) -- 2.14.3 Reviewed-by: Michael Clark diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 808eab7f50..9cab717088 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -725,7 +725,6 @@ static void gen_atomic(DisasContext *ctx, uint32_t opc, TCGv src1, src2, dat; TCGLabel *l1, *l2; TCGMemOp mop; - TCGCond cond; bool aq, rl; /* Extract the size of the atomic operation. */ @@ -823,60 +822,29 @@ static void gen_atomic(DisasContext *ctx, uint32_t opc, tcg_gen_atomic_fetch_or_tl(src2, src1, src2, ctx->mem_idx, mop); gen_set_gpr(rd, src2); break; - case OPC_RISC_AMOMIN: - cond = TCG_COND_LT; - goto do_minmax; - case OPC_RISC_AMOMAX: - cond = TCG_COND_GT; - goto do_minmax; - case OPC_RISC_AMOMINU: - cond = TCG_COND_LTU; - goto do_minmax; - case OPC_RISC_AMOMAXU: - cond = TCG_COND_GTU; - goto do_minmax; - do_minmax: - /* Handle the RL barrier. The AQ barrier is handled along the - parallel path by the SC atomic cmpxchg. On the serial path, - of course, barriers do not matter. */ - if (rl) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); - } - if (tb_cflags(ctx->tb) & CF_PARALLEL) { - l1 = gen_new_label(); - gen_set_label(l1); - } else { - l1 = NULL; - } - gen_get_gpr(src1, rs1); gen_get_gpr(src2, rs2); - if ((mop & MO_SSIZE) == MO_SL) { - /* Sign-extend the register comparison input. */ - tcg_gen_ext32s_tl(src2, src2); - } - dat = tcg_temp_local_new(); - tcg_gen_qemu_ld_tl(dat, src1, ctx->mem_idx, mop); - tcg_gen_movcond_tl(cond, src2, dat, src2, dat, src2); - - if (tb_cflags(ctx->tb) & CF_PARALLEL) { - /* Parallel context. Make this operation atomic by verifying - that the memory didn't change while we computed the result. */ - tcg_gen_atomic_cmpxchg_tl(src2, src1, dat, src2, ctx->mem_idx, mop); - - /* If the cmpxchg failed, retry. */ - /* ??? There is an assumption here that this will eventually - succeed, such that we don't live-lock. This is not unlike - a similar loop that the compiler would generate for e.g. - __atomic_fetch_and_xor, so don't worry about it. */ - tcg_gen_brcond_tl(TCG_COND_NE, dat, src2, l1); - } else { - /* Serial context. Directly store the result. */ - tcg_gen_qemu_st_tl(src2, src1, ctx->mem_idx, mop); - } - gen_set_gpr(rd, dat); - tcg_temp_free(dat); + tcg_gen_atomic_fetch_smin_tl(src2, src1, src2, ctx->mem_idx, mop); + gen_set_gpr(rd, src2); + break; + case OPC_RISC_AMOMAX: + gen_get_gpr(src1, rs1); + gen_get_gpr(src2, rs2); + tcg_gen_atomic_fetch_smax_tl(src2, src1, src2, ctx->mem_idx, mop); + gen_set_gpr(rd, src2); + break; + case OPC_RISC_AMOMINU: + gen_get_gpr(src1, rs1); + gen_get_gpr(src2, rs2); + tcg_gen_atomic_fetch_umin_tl(src2, src1, src2, ctx->mem_idx, mop); + gen_set_gpr(rd, src2); + break; + case OPC_RISC_AMOMAXU: + gen_get_gpr(src1, rs1); + gen_get_gpr(src2, rs2); + tcg_gen_atomic_fetch_umax_tl(src2, src1, src2, ctx->mem_idx, mop); + gen_set_gpr(rd, src2); break; default: From patchwork Fri Apr 27 00:26:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134538 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp88360lji; Thu, 26 Apr 2018 17:28:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpIX3NJHyFZk7BUr8fQEgIeVo/tJwzpVDer+GeUDtuQ2qBY039CjaHfPcvq/oDuMwnWXsgL X-Received: by 10.55.75.205 with SMTP id y196mr195175qka.44.1524788881583; Thu, 26 Apr 2018 17:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524788881; cv=none; d=google.com; s=arc-20160816; b=URfi7bVBBUSKYUKV0OFH+TsvdYzh7hS/EMJw+EnAq06CLhlXab9L5eCS5Ve5wiU8y0 ysRmXU6PnsVP+Lz57lVKcwOpAL/Q7gW6m0zZcEVkXBIE5moGJvD574D41jrX3sl4EBl8 OVc0LPSKrfiWEjtSQZUEd/pWcupjN7Wpxm26Q/oyMnJORLojtbehfcorhzWyjiWhI9TJ jzcEPAJHXsYEvwbppfPOjAhx7/ugCZk3hKUjlM3fQedUwQbrJ4d04PP0EK5EhWqg1lMp X83HEvkLduBNfqDYX+UTtwrpOi61cC36HUMNXiUcz/jQYdPY1xreVQlBasMHpcm/S1CF E7BA== 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=/OKQUbApuVUtLjo2vK1xvxA0ICytFh53I028FicEKSU=; b=tHKg+Rgy/vGeloctUVvSKfvl2ZaZOMFeARIj591y5rQCvQ9SPgrSTgoRt6jr7hULoP GVegjbc5NhHl0hDMmJERvkMl6ks19mw3BxTWp7vLrAcbM5+mnp51kjpZcB23RnM8X6yK i8k4EeoUZEIDSOMA+9/Xo0T2EgrADUOuIfAHU8botcJN9P/pGCxvTc75GuCramEH/v+m IyH6OA3TKDsBsh4ofdpS0lUX24eNJ+d/EB5Vqztt9KyjBAglQJgvreH7f6tldA0m6Lj7 ZsjUekCcYQ7JOd7Hxk0+z3sUu81j5Jsu+Zr7oY1RtjRleLyc5YDjTIYjVj/39lAYZ1FO pceQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fzApzNUT; 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 v13-v6si81502qvb.255.2018.04.26.17.28.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:28:01 -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=fzApzNUT; 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]:45105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrF2-0002Tj-VR for patch@linaro.org; Thu, 26 Apr 2018 20:28:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEI-000291-5M for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEG-0004Yo-LQ for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:14 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33871) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEG-0004XI-DE for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:12 -0400 Received: by mail-pf0-x242.google.com with SMTP id a14so142478pfi.1 for ; Thu, 26 Apr 2018 17:27:12 -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=/OKQUbApuVUtLjo2vK1xvxA0ICytFh53I028FicEKSU=; b=fzApzNUTfn5otIM2RgqTI757SUJiQVemakMS1Rhm8pEcQyQD/numKYdxcjTo4kEVgX VBSb4rjFvLSt2e3R0rbs44fdUVTVM4mBWq/21zVfXVDQUoABVm/JYKHycUEqEwOJRP/2 OUwbaJ+dK1w7efd6hKIuIKrBQOJ4IFM1uuLGY= 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=/OKQUbApuVUtLjo2vK1xvxA0ICytFh53I028FicEKSU=; b=c2b+K0vWj7BEqur9XEJVBregR4REtvsgR3iWXogtXBWowrOdmZzLNWr8+mhczzGfo0 p4gFE8Ije9AJ3ohWIs+hHP89Xv9kBJ9nl6oczi3SEeSaE0RM3p24J/ZSqHG8ji+Wb22W 4vcqbANmaNuj6Ts6TiJpq+rPxjciikbhpPPbmX18Kcr+MOyUJ/OoL5HjlbzM3gAGZKAK AFRYXdOpBpXyczZNImCAJ0sNQvEMmTPz3DlMyyD+Kds77Y7HtLzUaX0+w1lJRg6g/YpQ V8LwMxFQWoA1/zihxdAtGmSwB4wcw/Y88I76XawQWzSmZiZfeuweGV8pIKgYXZo4Fbyu DBxg== X-Gm-Message-State: ALQs6tApMHNEu9BdIsHrGH5UuyoTeElNQ2szo2BuxUlIfbgRVS6iKBWs yJAW9JpxPYhpDk7Ok5aOzmcwrh0kBts= X-Received: by 2002:a63:6110:: with SMTP id v16-v6mr172686pgb.292.1524788830951; Thu, 26 Apr 2018 17:27:10 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:48 -1000 Message-Id: <20180427002651.28356-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c00::242 Subject: [Qemu-devel] [PATCH 6/9] target/arm: Introduce ARM_FEATURE_V8_ATOMICS and initial decode 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The insns in the ARMv8.1-Atomics are added to the existing load/store exclusive and load/store reg opcode spaces. Rearrange the top-level decoders for these to accomodate. The Atomics insns themselves still generate Unallocated. Signed-off-by: Richard Henderson --- target/arm/cpu.h | 1 + linux-user/elfload.c | 1 + target/arm/translate-a64.c | 182 +++++++++++++++++++++++++++++++++------------ 3 files changed, 138 insertions(+), 46 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 44e6b77151..013f785306 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1449,6 +1449,7 @@ enum arm_features { ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_ATOMICS, /* implements v8.1 Atomic Memory Extensions */ ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */ ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ ARM_FEATURE_V8_FCMA, /* has complex number part of v8.3 extensions. */ diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c77ed1bb01..a12b7b9d8c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -557,6 +557,7 @@ static uint32_t get_elf_hwcap(void) GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); GET_FEATURE(ARM_FEATURE_V8_FP16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); + GET_FEATURE(ARM_FEATURE_V8_ATOMICS, ARM_HWCAP_A64_ATOMICS); GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM); GET_FEATURE(ARM_FEATURE_V8_FCMA, ARM_HWCAP_A64_FCMA); #undef GET_FEATURE diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index d916fea3a3..0706c8c394 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2147,62 +2147,98 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) int rt = extract32(insn, 0, 5); int rn = extract32(insn, 5, 5); int rt2 = extract32(insn, 10, 5); - int is_lasr = extract32(insn, 15, 1); int rs = extract32(insn, 16, 5); - int is_pair = extract32(insn, 21, 1); - int is_store = !extract32(insn, 22, 1); - int is_excl = !extract32(insn, 23, 1); + int is_lasr = extract32(insn, 15, 1); + int o2_L_o1_o0 = extract32(insn, 21, 3) * 2 | is_lasr; int size = extract32(insn, 30, 2); TCGv_i64 tcg_addr; - if ((!is_excl && !is_pair && !is_lasr) || - (!is_excl && is_pair) || - (is_pair && size < 2)) { - unallocated_encoding(s); + switch (o2_L_o1_o0) { + case 0x0: /* STXR */ + case 0x1: /* STLXR */ + if (rn == 31) { + gen_check_sp_alignment(s); + } + if (is_lasr) { + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); + } + tcg_addr = read_cpu_reg_sp(s, rn, 1); + gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, false); return; - } - if (rn == 31) { - gen_check_sp_alignment(s); - } - tcg_addr = read_cpu_reg_sp(s, rn, 1); - - /* Note that since TCG is single threaded load-acquire/store-release - * semantics require no extra if (is_lasr) { ... } handling. - */ - - if (is_excl) { - if (!is_store) { - s->is_ldex = true; - gen_load_exclusive(s, rt, rt2, tcg_addr, size, is_pair); - if (is_lasr) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); - } - } else { - if (is_lasr) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); - } - gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, is_pair); + case 0x4: /* LDXR */ + case 0x5: /* LDAXR */ + if (rn == 31) { + gen_check_sp_alignment(s); } - } else { - TCGv_i64 tcg_rt = cpu_reg(s, rt); - bool iss_sf = disas_ldst_compute_iss_sf(size, false, 0); + tcg_addr = read_cpu_reg_sp(s, rn, 1); + s->is_ldex = true; + gen_load_exclusive(s, rt, rt2, tcg_addr, size, false); + if (is_lasr) { + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); + } + return; + case 0x9: /* STLR */ /* Generate ISS for non-exclusive accesses including LASR. */ - if (is_store) { + if (rn == 31) { + gen_check_sp_alignment(s); + } + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); + tcg_addr = read_cpu_reg_sp(s, rn, 1); + do_gpr_st(s, cpu_reg(s, rt), tcg_addr, size, true, rt, + disas_ldst_compute_iss_sf(size, false, 0), is_lasr); + return; + + case 0xd: /* LDARB */ + /* Generate ISS for non-exclusive accesses including LASR. */ + if (rn == 31) { + gen_check_sp_alignment(s); + } + tcg_addr = read_cpu_reg_sp(s, rn, 1); + do_gpr_ld(s, cpu_reg(s, rt), tcg_addr, size, false, false, true, rt, + disas_ldst_compute_iss_sf(size, false, 0), is_lasr); + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); + return; + + case 0x2: case 0x3: /* CASP / STXP */ + if (size & 2) { /* STXP / STLXP */ + if (rn == 31) { + gen_check_sp_alignment(s); + } if (is_lasr) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); } - do_gpr_st(s, tcg_rt, tcg_addr, size, - true, rt, iss_sf, is_lasr); - } else { - do_gpr_ld(s, tcg_rt, tcg_addr, size, false, false, - true, rt, iss_sf, is_lasr); + tcg_addr = read_cpu_reg_sp(s, rn, 1); + gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, true); + return; + } + /* CASP / CASPL */ + break; + + case 0x6: case 0x7: /* CASP / LDXP */ + if (size & 2) { /* LDXP / LDAXP */ + if (rn == 31) { + gen_check_sp_alignment(s); + } + tcg_addr = read_cpu_reg_sp(s, rn, 1); + s->is_ldex = true; + gen_load_exclusive(s, rt, rt2, tcg_addr, size, true); if (is_lasr) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); } + return; } + /* CASPA / CASPAL */ + break; + + case 0xa: /* CAS */ + case 0xb: /* CASL */ + case 0xe: /* CASA */ + case 0xf: /* CASAL */ + break; } + unallocated_encoding(s); } /* @@ -2715,6 +2751,55 @@ static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn, } } +/* Atomic memory operations + * + * 31 30 27 26 24 22 21 16 15 12 10 5 0 + * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+ + * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt | + * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+ + * + * Rt: the result register + * Rn: base address or SP + * Rs: the source register for the operation + * V: vector flag (always 0 as of v8.3) + * A: acquire flag + * R: release flag + */ +static void disas_ldst_atomic(DisasContext *s, uint32_t insn, + int size, int rt, bool is_vector) +{ + int rs = extract32(insn, 16, 5); + int rn = extract32(insn, 5, 5); + int o3_opc = extract32(insn, 12, 4); + int feature = ARM_FEATURE_V8_ATOMICS; + + if (is_vector) { + unallocated_encoding(s); + return; + } + switch (o3_opc) { + case 000: /* LDADD */ + case 001: /* LDCLR */ + case 002: /* LDEOR */ + case 003: /* LDSET */ + case 004: /* LDSMAX */ + case 005: /* LDSMIN */ + case 006: /* LDUMAX */ + case 007: /* LDUMIN */ + case 010: /* SWP */ + default: + unallocated_encoding(s); + return; + } + if (!arm_dc_feature(s, feature)) { + unallocated_encoding(s); + return; + } + + (void)rs; + (void)rn; +} + /* Load/store register (all forms) */ static void disas_ldst_reg(DisasContext *s, uint32_t insn) { @@ -2725,23 +2810,28 @@ static void disas_ldst_reg(DisasContext *s, uint32_t insn) switch (extract32(insn, 24, 2)) { case 0: - if (extract32(insn, 21, 1) == 1 && extract32(insn, 10, 2) == 2) { - disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector); - } else { + if (extract32(insn, 21, 1) == 0) { /* Load/store register (unscaled immediate) * Load/store immediate pre/post-indexed * Load/store register unprivileged */ disas_ldst_reg_imm9(s, insn, opc, size, rt, is_vector); + return; + } + switch (extract32(insn, 10, 2)) { + case 0: + disas_ldst_atomic(s, insn, size, rt, is_vector); + return; + case 2: + disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector); + return; } break; case 1: disas_ldst_reg_unsigned_imm(s, insn, opc, size, rt, is_vector); - break; - default: - unallocated_encoding(s); - break; + return; } + unallocated_encoding(s); } /* AdvSIMD load/store multiple structures From patchwork Fri Apr 27 00:26:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134542 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp92850lji; Thu, 26 Apr 2018 17:34:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqowWpVrvXzHnO23H6k2XvOXPsBvsMGREJaUcg4oYVcL/Fs1nHQn8DrDG+9pCKm9Vawofjp X-Received: by 2002:a0c:c242:: with SMTP id w2-v6mr180282qvh.91.1524789265466; Thu, 26 Apr 2018 17:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524789265; cv=none; d=google.com; s=arc-20160816; b=eViCrmBAAWPcVDLIEd1W+NyMfBK4SD6U8GjQUxaI7c2ZJfJmDd00XT15l6iD4/df+R TZebXwCK+Sc6Tar2rnNxzpylgVsqJiz08/13yBxMKSoU5sCrC6xA3SJN6j7L5wVAMwzk W649fnmBMSdDJmot+OH/2oz+5vcsoymLz4G1K+85sOMXHMgJxcw/IHB7VYWNJyqfCmz9 YA/Wddc0bjLSA8uuitdGyYzXgDxVnskBN0TP7M23ZHYE+Z4Z9G/fpT8yfE8K4Plo0PLL O1RLSqrkTRggNtSWg5TubbYcnWIufCg3Hr7rBbes4uCmaqE3IlZ0n+HCN9PnsGsaTsQ1 HQFQ== 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=PEHUreWTV/acmi7x+XdpvFcJ/L5D2uAinn5jMrYd4EU=; b=Dm+CQZk6/yWilCbYoWqTkAF0tGCSnKFBukmTsBqoGm/N8LCR+l+j+K1f+Q5ApGoBCM hhV/tyO+xpVotzYkYibrbcalF8QYhTh4DnFUp3/rZt4k5ew4A0/ISGi4Mg+SEm0hT8U1 4rlOhAz9zpVA0SfMCIRbQUrrZBfkeP4pD3LN5b31QSm/G/RgspH/+vHSTJs+updDbdGz tw3lz2lrEJfA/CqpPwcAt0Gh2tLQmvkrkXPDZ75Zz9kzMCDYJPn7tvH7eWR8/ZtzMHp3 m5nhaJ1yT8TqB8hkk1ig5KffTmuUGrxNqCcqPq6fHgd64cGm66R6VJ2/SOIUN8cgfwPV D3nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FLNN+sJd; 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 w21-v6si96788qtg.389.2018.04.26.17.34.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:34:25 -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=FLNN+sJd; 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]:45141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrLE-0007n0-Qq for patch@linaro.org; Thu, 26 Apr 2018 20:34:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEJ-0002A9-9P for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEI-0004by-7j for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:15 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:39973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEI-0004b1-2q for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:14 -0400 Received: by mail-pg0-x244.google.com with SMTP id l2-v6so146604pgc.7 for ; Thu, 26 Apr 2018 17:27:14 -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=PEHUreWTV/acmi7x+XdpvFcJ/L5D2uAinn5jMrYd4EU=; b=FLNN+sJdxxxdiPxv4H2aykvYSnSE7lg3m1ZrqWCuaCpW3lLc/haGpA701JMWTiJ3Q2 DzfXRHFPxkIJZLoxZwyRAGmkOJWC2PV7ob0rK8jL0YqGCq/a9rZzpuaUJ2/ISTNSxlez RFdKjCW9LwzXJwoO3VtIvWk3ZGfhkKH+BUnMQ= 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=PEHUreWTV/acmi7x+XdpvFcJ/L5D2uAinn5jMrYd4EU=; b=dupbacrsf+h29vwZFekI62gvkHeKa3NsAlPlpfo/l+bBRegTHvf+Eog8p/IvT9SfRx WPa5dLns7lWoqa5cg/+2CPDp7fdlie089/nhcI26kpP49n4ykKDc4F8a1YCUAIAp/1tL 8K1ns5R7LJkqKM9HKUaIEIubyV1XcP0YvYXLgOy2WR2Zjf2bTjO0AOd3O6Z8v/8I+VnQ JT0W7jQR1WeH6oOrKLWSr1zbTDcE01I6ELwwO7uClk83z6fb88oOu48zqYB82dsPtU61 M8YrRTe3t9QMjEzHahrbARESmJFf3AS5oCSh6rUl0RpPZG/Xt0bcF/YLLV5ljZH+bDjz 4XIg== X-Gm-Message-State: ALQs6tA9qDI85LA0mViOhemWbWKpHG6GClJnZirzWN9Gi+2/9spc2QdZ SkAC37KmbMtZrkKl9mBCHAhitg2Zu3Q= X-Received: by 2002:a65:4648:: with SMTP id k8-v6mr169735pgr.47.1524788832880; Thu, 26 Apr 2018 17:27:12 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:49 -1000 Message-Id: <20180427002651.28356-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::244 Subject: [Qemu-devel] [PATCH 7/9] target/arm: Fill in disas_ldst_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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This implements all of the v8.1-Atomics instructions except for compare-and-swap, which is decoded elsewhere. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 0706c8c394..6ed7627d79 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -84,6 +84,7 @@ typedef void NeonGenOneOpFn(TCGv_i64, TCGv_i64); typedef void CryptoTwoOpFn(TCGv_ptr, TCGv_ptr); typedef void CryptoThreeOpIntFn(TCGv_ptr, TCGv_ptr, TCGv_i32); typedef void CryptoThreeOpFn(TCGv_ptr, TCGv_ptr, TCGv_ptr); +typedef void AtomicThreeOpFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGArg, TCGMemOp); /* Note that the gvec expanders operate on offsets + sizes. */ typedef void GVecGen2Fn(unsigned, uint32_t, uint32_t, uint32_t, uint32_t); @@ -2772,6 +2773,8 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, int rn = extract32(insn, 5, 5); int o3_opc = extract32(insn, 12, 4); int feature = ARM_FEATURE_V8_ATOMICS; + TCGv_i64 tcg_rn, tcg_rs; + AtomicThreeOpFn *fn; if (is_vector) { unallocated_encoding(s); @@ -2779,14 +2782,32 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, } switch (o3_opc) { case 000: /* LDADD */ + fn = tcg_gen_atomic_fetch_add_i64; + break; case 001: /* LDCLR */ + fn = tcg_gen_atomic_fetch_and_i64; + break; case 002: /* LDEOR */ + fn = tcg_gen_atomic_fetch_xor_i64; + break; case 003: /* LDSET */ + fn = tcg_gen_atomic_fetch_or_i64; + break; case 004: /* LDSMAX */ + fn = tcg_gen_atomic_fetch_smax_i64; + break; case 005: /* LDSMIN */ + fn = tcg_gen_atomic_fetch_smin_i64; + break; case 006: /* LDUMAX */ + fn = tcg_gen_atomic_fetch_umax_i64; + break; case 007: /* LDUMIN */ + fn = tcg_gen_atomic_fetch_umin_i64; + break; case 010: /* SWP */ + fn = tcg_gen_atomic_xchg_i64; + break; default: unallocated_encoding(s); return; @@ -2796,8 +2817,21 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, return; } - (void)rs; - (void)rn; + if (rn == 31) { + gen_check_sp_alignment(s); + } + tcg_rn = cpu_reg_sp(s, rn); + tcg_rs = read_cpu_reg(s, rs, false); + + if (o3_opc == 1) { /* LDCLR */ + tcg_gen_not_i64(tcg_rs, tcg_rs); + } + + /* The tcg atomic primitives are all full barriers. Therefore we + * can ignore the Acquire and Release bits of this instruction. + */ + fn(cpu_reg(s, rt), tcg_rn, tcg_rs, get_mem_index(s), + s->be_data | size | MO_ALIGN); } /* Load/store register (all forms) */ From patchwork Fri Apr 27 00:26:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134541 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp92007lji; Thu, 26 Apr 2018 17:33:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpZdPazXJHCRnqlfMeMiYhTh/nGtzRRJjB3ldsFM0dJworKvokLvcEWSEJ5k1YxMOxuf361 X-Received: by 2002:a0c:d5a3:: with SMTP id g32-v6mr170643qvi.197.1524789196596; Thu, 26 Apr 2018 17:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524789196; cv=none; d=google.com; s=arc-20160816; b=cQv8gWcX376ml+U4GISpjNanQjjDF1NSM6ueUd1JvP7FtCQFvAfpISxzOFsZ+lqGC8 ZslDT9cUg13bYtD61g9lkNfRTxI9Y4mYYFz+uH0JhQhkADL1so4Jjpko6AYmcboEB5mr ZVFu/BlmLmXgtW9e1jxRX+JXIbTwYthoDJeAKzKYA9lUx8MYh5QvQBfZK31vSGJ820sK E7sSAaC6qhEK5WGO3SVMlgjdGKyQIrNoml89+3X80ODDT4jEKvLqu8ZThVk12H7wFP1i Tf+YCyuXZ6imGhkMzPGeiZD/689+KCMVLp/FBzXAYZpZxtQL1mhwqTGzmeiIPmETYGz9 e9ng== 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=DiEfPBXa1tZdSoYd4oqClGzv1br1rQBTzDefUMnyBbs=; b=m6fdrPysiJWt13GmSQJz/uwXnzbSDiYkgfx3Pc+plB8JsLx5lSfigt1QdGAhyl6QuA lv/RhDkkd+6d8husqfPpJNBQFuX+IUBFcO9ii88rgU3O5gqq3v/0wVw+EmnFBzFhXNSG XUayLdWh+pj+Kl2pWix1FnSe/CfCrUcffOr/QU3mGGcYldhDIQSAMQ6QO3wSHQ4IgLq0 3RAaHOg9AF8/tpgdvPDf5i0UB27YsuzKdEpm8LK1Fc8Js5uqkqI13U3k3IVPcYqc3u0U ccNCiL/8mRw9AFY7pLaiyS+1JPtwTvk/H3/dBBIRrHN9Yr0NetHaeZ7iPZx4Co+iBelO hDGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=e6QBorTE; 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 6-v6si100794qtz.364.2018.04.26.17.33.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:33:16 -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=e6QBorTE; 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]:45131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrK7-0006Fn-TG for patch@linaro.org; Thu, 26 Apr 2018 20:33:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEL-0002CU-Ia for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEK-0004ew-33 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:17 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:34308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEJ-0004dw-SK for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:16 -0400 Received: by mail-pg0-x242.google.com with SMTP id p10-v6so156815pgn.1 for ; Thu, 26 Apr 2018 17:27:15 -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=DiEfPBXa1tZdSoYd4oqClGzv1br1rQBTzDefUMnyBbs=; b=e6QBorTEydxmykXbGVCMc7jWbB4t9xdUna/vFUmLUT0rC3esPLskjeIvrYw3LuuCq7 vN+o+8jeQ8t1LJH4+0eEA8kxNB17y0Uwcd1fLNpPhpWunqRzoNL6K+Mcxtf62Z62/Hoo It4VHBZItY5wILe7QpQTRjna4lJKIoe1dIzCI= 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=DiEfPBXa1tZdSoYd4oqClGzv1br1rQBTzDefUMnyBbs=; b=rqIqToAPqPx4z1Qk8Wqdvs5oeoL1uUICD1iVji5HXJ+HSz4DBt/5IgPGJ3MZSA21Gn xDuX77Rpq6dCRpdjKKW1df3f0GiIJQpQhPM7uAry3j9wueWpBCAv+BkNMAnLbg5Pkqyl K6NJRs3FeVd0dF41wxkiZeioNGxZg33kKUu1SnU3DKeTMYo+UodtDRlXSO7Y/KSWZlO/ HfE+ttQkP+zEwD3EcHOgHrxUW4Zk/EcWf0I2DWRKS/Pg4wptmUCnWAgBSIR0fXJvWU9I lFD68zJDkOdJIdTYfXv+9yMaE7k2mXkVZTb1uKYmOxmjY+J9scGHTBOFP1jzGB+Vmn7+ +eMQ== X-Gm-Message-State: ALQs6tBN46gmeb7obDHxufDPlrl2oOd9pQAORyKM7QjxTayEct+27F3e Tcch1q0ZKi/t29+VwxVeTq+2VLSvcIU= X-Received: by 2002:a63:a503:: with SMTP id n3-v6mr163953pgf.19.1524788834603; Thu, 26 Apr 2018 17:27:14 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:50 -1000 Message-Id: <20180427002651.28356-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::242 Subject: [Qemu-devel] [PATCH 8/9] target/arm: Implement CAS and CASP 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/helper-a64.h | 2 + target/arm/helper-a64.c | 43 ++++++++++++++++ target/arm/translate-a64.c | 119 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 161 insertions(+), 3 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index ef4ddfe9d8..b8028ac98c 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -51,6 +51,8 @@ DEF_HELPER_FLAGS_4(paired_cmpxchg64_le_parallel, TCG_CALL_NO_WG, DEF_HELPER_FLAGS_4(paired_cmpxchg64_be, TCG_CALL_NO_WG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(paired_cmpxchg64_be_parallel, TCG_CALL_NO_WG, i64, env, i64, i64, i64) +DEF_HELPER_5(casp_le_parallel, void, env, i32, i64, i64, i64) +DEF_HELPER_5(casp_be_parallel, void, env, i32, i64, i64, i64) DEF_HELPER_FLAGS_3(advsimd_maxh, TCG_CALL_NO_RWG, f16, f16, f16, ptr) DEF_HELPER_FLAGS_3(advsimd_minh, TCG_CALL_NO_RWG, f16, f16, f16, ptr) DEF_HELPER_FLAGS_3(advsimd_maxnumh, TCG_CALL_NO_RWG, f16, f16, f16, ptr) diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index afb25ad20c..549ed3513e 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -636,6 +636,49 @@ uint64_t HELPER(paired_cmpxchg64_be_parallel)(CPUARMState *env, uint64_t addr, return do_paired_cmpxchg64_be(env, addr, new_lo, new_hi, true, GETPC()); } +/* Writes back the old data into Rs. */ +void HELPER(casp_le_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr, + uint64_t new_lo, uint64_t new_hi) +{ + uintptr_t ra = GETPC(); +#ifndef CONFIG_ATOMIC128 + cpu_loop_exit_atomic(ENV_GET_CPU(env), ra); +#else + Int128 oldv, cmpv, newv; + + cmpv = int128_make128(env->xregs[rs], env->xregs[rs + 1]); + newv = int128_make128(new_lo, new_hi); + + int mem_idx = cpu_mmu_index(env, false); + TCGMemOpIdx oi = make_memop_idx(MO_LEQ | MO_ALIGN_16, mem_idx); + oldv = helper_atomic_cmpxchgo_le_mmu(env, addr, cmpv, newv, oi, ra); + + env->xregs[rs] = int128_getlo(oldv); + env->xregs[rs + 1] = int128_gethi(oldv); +#endif +} + +void HELPER(casp_be_parallel)(CPUARMState *env, uint32_t rs, uint64_t addr, + uint64_t new_hi, uint64_t new_lo) +{ + uintptr_t ra = GETPC(); +#ifndef CONFIG_ATOMIC128 + cpu_loop_exit_atomic(ENV_GET_CPU(env), ra); +#else + Int128 oldv, cmpv, newv; + + cmpv = int128_make128(env->xregs[rs + 1], env->xregs[rs]); + newv = int128_make128(new_lo, new_hi); + + int mem_idx = cpu_mmu_index(env, false); + TCGMemOpIdx oi = make_memop_idx(MO_LEQ | MO_ALIGN_16, mem_idx); + oldv = helper_atomic_cmpxchgo_be_mmu(env, addr, cmpv, newv, oi, ra); + + env->xregs[rs + 1] = int128_getlo(oldv); + env->xregs[rs] = int128_gethi(oldv); +#endif +} + /* * AdvSIMD half-precision */ diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 6ed7627d79..dce86a5488 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2114,6 +2114,103 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2, tcg_gen_movi_i64(cpu_exclusive_addr, -1); } +static void gen_compare_and_swap(DisasContext *s, int rs, int rt, + int rn, int size) +{ + TCGv_i64 tcg_rs = cpu_reg(s, rs); + TCGv_i64 tcg_rt = cpu_reg(s, rt); + int memidx = get_mem_index(s); + TCGv_i64 addr = cpu_reg_sp(s, rn); + + if (rn == 31) { + gen_check_sp_alignment(s); + } + tcg_gen_atomic_cmpxchg_i64(tcg_rs, addr, tcg_rs, tcg_rt, memidx, + size | MO_ALIGN | s->be_data); +} + +static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt, + int rn, int size) +{ + TCGv_i64 s1 = cpu_reg(s, rs); + TCGv_i64 s2 = cpu_reg(s, rs + 1); + TCGv_i64 t1 = cpu_reg(s, rt); + TCGv_i64 t2 = cpu_reg(s, rt + 1); + TCGv_i64 addr = cpu_reg_sp(s, rn); + int memidx = get_mem_index(s); + + if (rn == 31) { + gen_check_sp_alignment(s); + } + + if (size == 2) { + TCGv_i64 cmp = tcg_temp_new_i64(); + TCGv_i64 val = tcg_temp_new_i64(); + + if (s->be_data == MO_LE) { + tcg_gen_concat32_i64(val, t1, t2); + tcg_gen_concat32_i64(cmp, s1, s2); + } else { + tcg_gen_concat32_i64(val, t2, t1); + tcg_gen_concat32_i64(cmp, s2, s1); + } + + tcg_gen_atomic_cmpxchg_i64(cmp, addr, cmp, val, memidx, + MO_64 | MO_ALIGN | s->be_data); + tcg_temp_free_i64(val); + + if (s->be_data == MO_LE) { + tcg_gen_extr32_i64(s1, s2, cmp); + } else { + tcg_gen_extr32_i64(s2, s1, cmp); + } + tcg_temp_free_i64(cmp); + } else if (tb_cflags(s->base.tb) & CF_PARALLEL) { + TCGv_i32 tcg_rs = tcg_const_i32(rs); + + if (s->be_data == MO_LE) { + gen_helper_casp_le_parallel(cpu_env, tcg_rs, addr, t1, t2); + } else { + gen_helper_casp_be_parallel(cpu_env, tcg_rs, addr, t1, t2); + } + tcg_temp_free_i32(tcg_rs); + } else { + TCGv_i64 d1 = tcg_temp_new_i64(); + TCGv_i64 d2 = tcg_temp_new_i64(); + TCGv_i64 a2 = tcg_temp_new_i64(); + TCGv_i64 c1 = tcg_temp_new_i64(); + TCGv_i64 c2 = tcg_temp_new_i64(); + TCGv_i64 zero = tcg_const_i64(0); + + /* Load the two words, in memory order. */ + tcg_gen_qemu_ld_i64(d1, addr, memidx, + MO_64 | MO_ALIGN_16 | s->be_data); + tcg_gen_addi_i64(a2, addr, 8); + tcg_gen_qemu_ld_i64(d2, addr, memidx, MO_64 | s->be_data); + + /* Compare the two words, also in memory order. */ + tcg_gen_setcond_i64(TCG_COND_EQ, c1, d1, s1); + tcg_gen_setcond_i64(TCG_COND_EQ, c2, d2, s2); + tcg_gen_and_i64(c2, c2, c1); + + /* If compare equal, write back new data, else write back old data. */ + tcg_gen_movcond_i64(TCG_COND_NE, c1, c2, zero, t1, d1); + tcg_gen_movcond_i64(TCG_COND_NE, c2, c2, zero, t2, d2); + tcg_gen_qemu_st_i64(c1, addr, memidx, MO_64 | s->be_data); + tcg_gen_qemu_st_i64(c2, a2, memidx, MO_64 | s->be_data); + tcg_temp_free_i64(a2); + tcg_temp_free_i64(c1); + tcg_temp_free_i64(c2); + tcg_temp_free_i64(zero); + + /* Write back the data from memory to Rs. */ + tcg_gen_mov_i64(s1, d1); + tcg_gen_mov_i64(s2, d2); + tcg_temp_free_i64(d1); + tcg_temp_free_i64(d2); + } +} + /* Update the Sixty-Four bit (SF) registersize. This logic is derived * from the ARMv8 specs for LDR (Shared decode for all encodings). */ @@ -2214,10 +2311,16 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, true); return; } - /* CASP / CASPL */ + if (rt2 == 31 + && ((rt | rs) & 1) == 0 + && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { + /* CASP / CASPL */ + gen_compare_and_swap_pair(s, rs, rt, rn, size | 2); + return; + } break; - case 0x6: case 0x7: /* CASP / LDXP */ + case 0x6: case 0x7: /* CASPA / LDXP */ if (size & 2) { /* LDXP / LDAXP */ if (rn == 31) { gen_check_sp_alignment(s); @@ -2230,13 +2333,23 @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) } return; } - /* CASPA / CASPAL */ + if (rt2 == 31 + && ((rt | rs) & 1) == 0 + && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { + /* CASPA / CASPAL */ + gen_compare_and_swap_pair(s, rs, rt, rn, size | 2); + return; + } break; case 0xa: /* CAS */ case 0xb: /* CASL */ case 0xe: /* CASA */ case 0xf: /* CASAL */ + if (rt2 == 31 && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { + gen_compare_and_swap(s, rs, rt, rn, size); + return; + } break; } unallocated_encoding(s); From patchwork Fri Apr 27 00:26:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 134545 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp96426lji; Thu, 26 Apr 2018 17:39:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpdLb68WG76ACs32YwQ4uLletyVXi8S1P4zFf9X7Yx5Si7SB3SYmY2RPwGcxxvYYM74J35d X-Received: by 2002:ac8:18f:: with SMTP id x15-v6mr186408qtf.413.1524789564730; Thu, 26 Apr 2018 17:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524789564; cv=none; d=google.com; s=arc-20160816; b=XmDpjwvgt49zGenI/Xr/Oq5+r7sfb6XKhC5JEnV9HSu4gy1RbGe05+LqQ7JYJdyUpm bJmZBPJKToQ4LCSN9BEWGIgIHDlHd6qGu8nRaDd9O3VNluTN0j2KOCMUEyCZOisH/Vdf ApWyPELdrELp7HcQWEekMF4vIw83B7hI7xR+ciMkWWtN5dSyFD8ilryX6EAxtakIJhbT EZ8C2aLEQL8JFeatutLL7faiYqWcd/uq+c5JVHVKFQ6laXEfJ+D0bTMAwCgrA7xZzLhg QkQBe/2Uu9H7za1dKT4uCs1IISQTrYj68HoEbqcmkjCZjzg1SkNwAkJSLGIS/tfcNQIY QVZA== 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=+R0iLjuVp6A0iOuDys7qIxZPntnoAwMRWHbaH0zAWr0=; b=ZQIZYwe/O4OXa9EFy6y1/6A+7Wn7OsWkrpLqoRembEDR0n4pLLVUrCisrPFfCpVm2Q HA8VMcWq3TS839M+5PSmQ8+hf61IWvAwA2zNkWFldYzEhjIhl5NHtBc5HIEbygrwRk0A 47btCPiJAM5B4X2Xzy6kPzvbmvhVmHA3xDD2Ve4phxARAv+IhHaTnQdNtbABXlKP4uBW 7YkocyN9A7tuknegRgx3bqmo1xEl271MTUzfeHYObCKdzTgzjLi7N3mou67Cz7X+hoqK xzolYf2nzkqNPoWG4Brwvha+WsCgzpUflgLjGLpKY4n/A17JZLjwExZsf4dJXEeGTyh3 vf3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=g3vHKA5v; 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 e44-v6si119588qvd.129.2018.04.26.17.39.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 17:39:24 -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=g3vHKA5v; 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]:45165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrQ4-00039V-4H for patch@linaro.org; Thu, 26 Apr 2018 20:39:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBrEM-0002DM-7w for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBrEL-0004hC-HW for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:18 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:39971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBrEL-0004gp-C7 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 20:27:17 -0400 Received: by mail-pg0-x241.google.com with SMTP id l2-v6so146678pgc.7 for ; Thu, 26 Apr 2018 17:27:17 -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=+R0iLjuVp6A0iOuDys7qIxZPntnoAwMRWHbaH0zAWr0=; b=g3vHKA5v+6uXHpg5PyjOLGg0bhLNJxeKhFu54KwYw5s6YFV2f+q+GXBLCIIg4PrK+9 MUT5QqpS6OpBBpFpqLkWy7UjUOeklWYE7nWJFdhbHNv+5P0amuJQhFQUcLXjk66igGlp wN9KJjXHn6VIR1gOmP3oCtk5CG58K37fyhsoo= 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=+R0iLjuVp6A0iOuDys7qIxZPntnoAwMRWHbaH0zAWr0=; b=Ak72ktI2xu247iUnikPGNtx5gSGAPEZDLLzIkqJx5MUVveM+oxk0Xn9TeONJfWkKfi dTL4mGZeF0BpcfyR7WNDzKSM66Hpwm68Hd+rrvqX0LQ9cDvG0/Wy0rELO4t4c/P3Zhht 4iD84d+4OJpFdG6KIb/qW7d+caQ/qa9Mn8Nrvy5ybDuOvKlDxdkrO0ePSc2A+wE3BNcs Lpf/WFK1SMDiOnhr0sZKAYFwznwdjwHM/e3im/VKA3cfaSs55XCLhe1ky0meoi4ZeB3e +T+67kYf+fMVvCjK+btqFhAcJ/X/ByiO/gu6Oc9oN5VT9LvyEgS81tmjE62Vdea6khXp YPQw== X-Gm-Message-State: ALQs6tBHs0yIYY6G+vghOQqy9mpLtPjLeYFe6uGKMgbPYFGR0+CTyRRi c+uBG0kFnjCdU/OrO335iJ5lXIe3SS0= X-Received: by 2002:a17:902:bd03:: with SMTP id p3-v6mr198619pls.236.1524788836216; Thu, 26 Apr 2018 17:27:16 -0700 (PDT) Received: from cloudburst.twiddle.net.com ([2605:e000:112b:41da:c94c:5ee7:de92:7d78]) by smtp.gmail.com with ESMTPSA id g76sm86338pfj.102.2018.04.26.17.27.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 17:27:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 14:26:51 -1000 Message-Id: <20180427002651.28356-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427002651.28356-1-richard.henderson@linaro.org> References: <20180427002651.28356-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:c05::241 Subject: [Qemu-devel] [PATCH 9/9] target/arm: Enable ARM_FEATURE_V8_ATOMICS for user-only 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-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 1 + 1 file changed, 1 insertion(+) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 991d764674..c50dcd4077 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -248,6 +248,7 @@ static void aarch64_max_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8_SM4); set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); set_feature(&cpu->env, ARM_FEATURE_CRC); + set_feature(&cpu->env, ARM_FEATURE_V8_ATOMICS); set_feature(&cpu->env, ARM_FEATURE_V8_RDM); set_feature(&cpu->env, ARM_FEATURE_V8_FP16); set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);