From patchwork Wed May 1 05:05:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163195 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp4130091ill; Tue, 30 Apr 2019 22:20:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNmg7Vtq+ynosetqgW+eFKHlg4KW88ZVvfvtmLB/Hw+4vCWPAL55iqxqp5A4qmXJYwFtJh X-Received: by 2002:adf:f1cb:: with SMTP id z11mr20304985wro.209.1556688023966; Tue, 30 Apr 2019 22:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556688023; cv=none; d=google.com; s=arc-20160816; b=Hyo5UJ3ZJegdSrI+i997AL5D3DhmbCwW96qUKzoNAV1gPidW1isdC0+Jbz0u8ngrn8 PmZfDL7AlHgYr5qycvy4ubBk2Y4ieQDt69oUV4nvu/QbNA++07KViVr8Do+VF1dGwn4U 32OsNPl3H21dW7tNhP4aHFrUSApIN+m36NIA/EsFlTm8kneIeEBA+M3RJPUsOkDlj+kV uyulQ2hyJdRDInQHCcB0oYOYg+rQI/nkHBTM39GxtSlHQrBcvGCS/c6uCTR19ZjwsH4Z URb4P4DYsgCmmBZd55SZOVhYTTHKawcRsbTbnioBJzJqBHspN26qdUF25NjkLuGDPPau bdMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=yFRiQL+bz58cWGz6Ig2AM72yMnp/aPGg7D5yMyvGces=; b=rjkykjUWYs4YDp8CQTfg6zf59V2NTrS4wEnUSEQ+KQjMXUnlNLJWhC8MzprFEh0QLB YEz0Sw+pUiAsW629Dx7eVPpJ5PNE4RpUmmWgR0sk0Hh0Mv0MdcNVMq9yKoxXnaSAs1iR n+picOWiQN3TWc7eUWutmqufr19wvPpKiMEtG+LPZlASyLa6w5PP/vppSAb/VbFus+C7 r0J8kNzcTDkN1W4eH/dAaJwDTZEnTLVy8M0MkHH2OPM7z4EBsCR0IRO4pRjhvf/AyH9t FXft/SsXttWUENM9qO+K4q6VErE8uv/2ZhAE4/qY5581Re6wvh+rejDB4EaCosdUAOkp uAtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=b0mCOOGo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id c16si23839679wrs.240.2019.04.30.22.20.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 30 Apr 2019 22:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=b0mCOOGo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:36426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhfK-0001vl-Pz for patch@linaro.org; Wed, 01 May 2019 01:20:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhRf-0006de-1s for qemu-devel@nongnu.org; Wed, 01 May 2019 01:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLhRb-00030j-Cz for qemu-devel@nongnu.org; Wed, 01 May 2019 01:06:14 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:38308) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLhRZ-0002xi-Bc for qemu-devel@nongnu.org; Wed, 01 May 2019 01:06:10 -0400 Received: by mail-pg1-x542.google.com with SMTP id j26so7869534pgl.5 for ; Tue, 30 Apr 2019 22:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yFRiQL+bz58cWGz6Ig2AM72yMnp/aPGg7D5yMyvGces=; b=b0mCOOGoVldLR9CZSwIEn9gACKL8H8NKGSMp0Qijtww4FOFR1XWnobJGn5tHM/YwbT kGnQ32Hzb5wXRyVffiQIE2jvZuenjyGjKsWHDt43SaqpthiAl2xgqx2UYkET7FUygtgS 3kK2DM1mCnDe8THYeRJ/k0mTBDP647lM4FKKKuuXeHvND6IIPEBd34eel+9ho5FCa1yN NvYAO4cj2TcVi68tKvmnheWiTYRgnr6HZeT6pvBuSjylPGjunUlLvOTrfeqeeB1Ah2xQ FwypiQqrFNavZ1zvIhlmbEGP8I7Sdm2FVXMT5t5Eup6gUOxV+p8LWe+WM1Z8Zx2G1850 s9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yFRiQL+bz58cWGz6Ig2AM72yMnp/aPGg7D5yMyvGces=; b=HEJqwLsN8JZRI9Aq6F0WnnyhR8whpO79KGRwS5PzBLQx8OzRlYa/MKTve1p7lYVaZP 1N/COitZRbUa+eYmoG9DJmoq78/ZBmwCxJIsYovw9PPfHP+BJAUvmttieYKjKdKaSlVt LQydPyorJFiW6NikiYs2eXv6ZyP+1RyDkr3jz9Jj41GtRReeFpzW+mLGDNbcmnEbHMWM x5oOZpY8RA3NpGHtfOUBrCQo4g2Cg7V2H7fF5/58qn17GqGxLWhCWFZFo76PZU0FwY+W cjSaLeQtL8j/OQoBA6grWWH3lLUBYAk8DAZLtqZUd71btaVeN2uX1DElyX9nw2356r7c w+eQ== X-Gm-Message-State: APjAAAW2Zmi1AN0ZoGhmZgKhOzJjEf9mAs0pNDcY3/QwEwOgk4qngWix 101GhX8hEX4SPwQd/EkW0l4HKPExn+g= X-Received: by 2002:a63:4f1c:: with SMTP id d28mr70620861pgb.144.1556687166937; Tue, 30 Apr 2019 22:06:06 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id t127sm9687251pfb.106.2019.04.30.22.06.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 22:06:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 30 Apr 2019 22:05:26 -0700 Message-Id: <20190501050536.15580-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190501050536.15580-1-richard.henderson@linaro.org> References: <20190501050536.15580-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v2 19/29] tcg: Add support for integer absolute value 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Remove a function of the same name from target/arm/. Use a branchless implementation of abs gleaned from gcc. Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/tcg-op.h | 5 +++++ target/arm/translate.c | 10 ---------- tcg/tcg-op.c | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 472b73cb38..660fe205d0 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -335,6 +335,7 @@ 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); +void tcg_gen_abs_i32(TCGv_i32, TCGv_i32); static inline void tcg_gen_discard_i32(TCGv_i32 arg) { @@ -534,6 +535,7 @@ 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); +void tcg_gen_abs_i64(TCGv_i64, TCGv_i64); #if TCG_TARGET_REG_BITS == 64 static inline void tcg_gen_discard_i64(TCGv_i64 arg) @@ -973,6 +975,7 @@ void tcg_gen_nor_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_eqv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_not_vec(unsigned vece, TCGv_vec r, TCGv_vec a); void tcg_gen_neg_vec(unsigned vece, TCGv_vec r, TCGv_vec a); +void tcg_gen_abs_vec(unsigned vece, TCGv_vec r, TCGv_vec a); void tcg_gen_ssadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_usadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_sssub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); @@ -1019,6 +1022,7 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_addi_tl tcg_gen_addi_i64 #define tcg_gen_sub_tl tcg_gen_sub_i64 #define tcg_gen_neg_tl tcg_gen_neg_i64 +#define tcg_gen_abs_tl tcg_gen_abs_i64 #define tcg_gen_subfi_tl tcg_gen_subfi_i64 #define tcg_gen_subi_tl tcg_gen_subi_i64 #define tcg_gen_and_tl tcg_gen_and_i64 @@ -1131,6 +1135,7 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); #define tcg_gen_addi_tl tcg_gen_addi_i32 #define tcg_gen_sub_tl tcg_gen_sub_i32 #define tcg_gen_neg_tl tcg_gen_neg_i32 +#define tcg_gen_abs_tl tcg_gen_abs_i32 #define tcg_gen_subfi_tl tcg_gen_subfi_i32 #define tcg_gen_subi_tl tcg_gen_subi_i32 #define tcg_gen_and_tl tcg_gen_and_i32 diff --git a/target/arm/translate.c b/target/arm/translate.c index 35bd426a3d..b25781554f 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -604,16 +604,6 @@ static void gen_sar(TCGv_i32 dest, TCGv_i32 t0, TCGv_i32 t1) tcg_temp_free_i32(tmp1); } -static void tcg_gen_abs_i32(TCGv_i32 dest, TCGv_i32 src) -{ - TCGv_i32 c0 = tcg_const_i32(0); - TCGv_i32 tmp = tcg_temp_new_i32(); - tcg_gen_neg_i32(tmp, src); - tcg_gen_movcond_i32(TCG_COND_GT, dest, src, c0, src, tmp); - tcg_temp_free_i32(c0); - tcg_temp_free_i32(tmp); -} - static void shifter_out_im(TCGv_i32 var, int shift) { if (shift == 0) { diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index a00d1df37e..0ac291f1c4 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -1091,6 +1091,16 @@ 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); } +void tcg_gen_abs_i32(TCGv_i32 ret, TCGv_i32 a) +{ + TCGv_i32 t = tcg_temp_new_i32(); + + tcg_gen_sari_i32(t, a, 31); + tcg_gen_xor_i32(ret, a, t); + tcg_gen_sub_i32(ret, ret, t); + tcg_temp_free_i32(t); +} + /* 64-bit ops */ #if TCG_TARGET_REG_BITS == 32 @@ -2548,6 +2558,16 @@ 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); } +void tcg_gen_abs_i64(TCGv_i64 ret, TCGv_i64 a) +{ + TCGv_i64 t = tcg_temp_new_i64(); + + tcg_gen_sari_i64(t, a, 63); + tcg_gen_xor_i64(ret, a, t); + tcg_gen_sub_i64(ret, ret, t); + tcg_temp_free_i64(t); +} + /* Size changing operations. */ void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)