From patchwork Sat Apr 20 07:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 162566 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp304523jan; Sat, 20 Apr 2019 00:46:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLUsOBQFkvBT8ca0EIPgcV+dbA9I6Nh+Za0ZT96uxnR8XYlYH5GJYsUwo9o4LWePqHHw+0 X-Received: by 2002:a05:600c:291:: with SMTP id 17mr5465562wmk.17.1555746396861; Sat, 20 Apr 2019 00:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555746396; cv=none; d=google.com; s=arc-20160816; b=c3p9Fj4JD3i+W9lZAdStGdrEJwto7ykRVGd7YV4uHuTU4M7hDrIpfI9PxIhu87NTFO 1H8iN41EKdq7+ycofUtUugsCOT9aqLGQ332rq3OkscXaV3cKnNniUloel7v2zch/MgzV WUv7QRw1CQ4UBH26Jz4hVE04AYR0/3TIPAUilDEO5QiO9AovYG5ZPumMnhnGRa1y6Nfq ov1HtWpm5f90XTinFQ9pZ9AvI+Licn1V3SXROX9pR5JSrfzSlbZNZqttqM/aVM5QA4on Xe4jf9KMPRF7dCHt0QSWcWyb5Op6Of+oJtfeoiD6HzTJU2VEBjDYy2qhBjeIAsRVVX5n K4Ug== 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; bh=4wzV6OFZGlF90Lzl5pNsHL4DyaHrlHsg3fnJ58nfXjc=; b=rr9HD/JS8oXknTh0u7c56NOy/z0itpeakR0J1EjuvjOl9dL7evZew9jcEJEkoTtw3g Z8j9sC9BI3DkcdRq4hYrQeuPS66GJO/UnKmfHIY17JWjFqQ1PbFPgErL5lmf/0ILf08s qnYcGyUPgDHOwG4PhvFTh4q7jsvWvGmmLqNE3TU2LP8cUWp1fB88H3THVqifDhInhV2q DO7kWz8RX70bUWhNutzDG5YS5olPZCq2z3fVFtErXdFGEbuQQsSKPHL+c12soxa3SGEr Bc6jA+xPxmxr1dviy7UKOpz6VMBEkjq8intUrIAtSM9I9bgw/bUwSR3dK87IArpy1WeX qaaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mhEfVSiF; 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 n7si4890337wrj.34.2019.04.20.00.46.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 20 Apr 2019 00:46:36 -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=mhEfVSiF; 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]:38231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHkhn-0001lq-PA for patch@linaro.org; Sat, 20 Apr 2019 03:46:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHkWt-0000Es-Tg for qemu-devel@nongnu.org; Sat, 20 Apr 2019 03:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHkWs-0008PV-H3 for qemu-devel@nongnu.org; Sat, 20 Apr 2019 03:35:19 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:36383) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hHkWs-0008OZ-B5 for qemu-devel@nongnu.org; Sat, 20 Apr 2019 03:35:18 -0400 Received: by mail-pg1-x541.google.com with SMTP id 85so3602807pgc.3 for ; Sat, 20 Apr 2019 00:35:18 -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=4wzV6OFZGlF90Lzl5pNsHL4DyaHrlHsg3fnJ58nfXjc=; b=mhEfVSiF1e0kyBao6RH+J09n3EDKdVTvtKnA4cJZQ7Q966kmY3L6wQ2SPOe/emq8Aw Ew728XxBgwAhKFisVtLLjAkKBw1/WniOaRq6T1zMCTxcmJOpPHPyVi8C72YTAe4W5hsc Owxw8tQs+uQpMtqpSdKM6Sh1N8DK/fThtBPiqfJkr/Ce8+FwkY9KoJ4RQUPyJBWGwyPN 6bPQv7IHw2cKYtLdMYBthFlWWdKEn71+xPRzYbwPMMfY1hEdFA1zZ/RrsVJcnZbbOoz9 4W5qPAEsk8i6G2rh9sQvjB7vLgh0KjTCxZZEix1VvnbcTowQXVDwGP56fXvYhk+RG8Bl zkyw== 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=4wzV6OFZGlF90Lzl5pNsHL4DyaHrlHsg3fnJ58nfXjc=; b=WlGtOYDv3sgqhRqp3nnU0ijG+YG7iJ6/Cg3qCAJSkV2WLpJ9UU4CZD8EKA30cQYl7F Tbgzk7U6Cib+wCaOVHBvakiDzmFQGo6SM2XgsckuuWEwPE5nCvcrZegme/VQulgG0Toa tvXz5D6cHhClvuC4Ru8S36fp/eNbAtAjNDHG7c3yWtAu/zPA2QEgN6JdIGWolJvtDB1z rKNF/0c8xBexgpWJHGEO8vjkunWIzJCUvJxeh9J8KA0oHsIGoFQrMl0xLJouq4KeeQJx Z/yBI8kCBeBQoT7uO+qm5EKJ3QkoYFRcmdUmImnJe5xt8u8jIVnLN0cFi8xI9bLjeYRb t0Yg== X-Gm-Message-State: APjAAAUzz9HIRv+/XZ3LKkcuYHWFWfAgNX4/vYyseqpUq8zbg+dstoUD 03InwYGw09Gvlp5NEfLWyWXyixAKbwg= X-Received: by 2002:a63:e818:: with SMTP id s24mr8150779pgh.190.1555745717133; Sat, 20 Apr 2019 00:35:17 -0700 (PDT) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id z22sm7025492pgv.23.2019.04.20.00.35.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Apr 2019 00:35:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 19 Apr 2019 21:34:23 -1000 Message-Id: <20190420073442.7488-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190420073442.7488-1-richard.henderson@linaro.org> References: <20190420073442.7488-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH 19/38] 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: , Cc: david@redhat.com 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 that gcc uses for x86. 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: Philippe Mathieu-Daudé Reviewed-by: David Hildenbrand 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 83a008e945..721171794d 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -603,16 +603,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)