From patchwork Tue May 14 00:05:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164102 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2194373ili; Mon, 13 May 2019 22:24:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0QRSLXYsM35uKGmM/3AY/0zHwqhk0HOCGvhbGYCcDC/IFCf39EeeQzxL5gTAWjdV+5JzE X-Received: by 2002:a50:97ed:: with SMTP id f42mr33899075edb.141.1557811456726; Mon, 13 May 2019 22:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557811456; cv=none; d=google.com; s=arc-20160816; b=w8GWq9kjTS8uqpPKj20wfdLyj9p201D4g5nlfzInXcIBwaCek/es3v3IGBo7RsVzqZ sD5+UmGLsdtegJwyPHMBJGfcPlrHos6dk4bfcE9MFSm4IaXhbe8w/7ldS0JRF6kRWtGN 5tMBjEhzFg19qYKLUztTDuEHVcR+Z/fNQUGm1YnK4WRFi65EmKrh+G14fC3nkPBrLcnb S8ZeQRAodQXcwQ/K+hxlNAQcCKHzoMKZoPbw2PebH+Vhx1WXrBy28Ko95Ue0MEbMdblr LvgOSMwv0Oz3adHdoHJqpjKxbalLTfkhD3yCVCSmgPE9vPOuN+YbmfDq83PoHrk/DsRl cf4A== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=oB7VP5ATUZChOLMjOlpdWPN1IctJhwYBQQIlaCDVjkw=; b=Qoi6vV5MlVW4QN/nGfIzZcjW6WTVMCzreC0+RU4RwZVoirsHG2edkc8IWVtRCI3/bl TimSSc3L4Ss3IfW3NQzSVGvq+XE76lrEdEEmzr1bVch8tTxBSPiZjHvJMgGmqn9zsLvZ nXs6ewAF8h9uVjoWfCPWJsRDpDIaTuDihe2xf9sgDpy0aNFTBhGI6yuCRdJ2NBJPuxN+ PPQ0ER64/v3mvddnMdpHtBhERq+g40fPTA6X/IFTrGJYaubZwhY+7mzozwoAPaW9y07v aa5p/90aKEwrOClpcR3lUuHPUwoMy9/zZrgsRIyxobSy9g1d36S4QfRatY+o/DadGYo0 AwsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="leTqu8/D"; 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 p59si11860060edb.126.2019.05.13.22.24.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 13 May 2019 22:24:16 -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="leTqu8/D"; 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]:39454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQPvD-0005VV-JR for patch@linaro.org; Tue, 14 May 2019 01:24:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQPty-0004qr-Gc for qemu-devel@nongnu.org; Tue, 14 May 2019 01:22:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQPtx-0004gS-CO for qemu-devel@nongnu.org; Tue, 14 May 2019 01:22:58 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:45078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQKxP-0003Sy-Pj for qemu-devel@nongnu.org; Mon, 13 May 2019 20:06:11 -0400 Received: by mail-pl1-x62a.google.com with SMTP id a5so7254651pls.12 for ; Mon, 13 May 2019 17:06: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 :mime-version:content-transfer-encoding; bh=oB7VP5ATUZChOLMjOlpdWPN1IctJhwYBQQIlaCDVjkw=; b=leTqu8/DI8MzpUWoAYnCi1Qr4rR0BtDqbXChthla/WcLLjap3YjbdF7QbYqfwoH8mf OCpU21DvuZ4xwPpdaQ/828EJApuw5wCc24hYWqBVyGt7CzTIs1j+aexFQw1mi7zSzrrJ WrkBSpMNrEtXHbKRVwZvxHJ/QpvKSJazzGrMd9yTHNUQMaA6e+5oc1/3C63NaGY99z6s Gy1zHDznTt+2ZUwE6s047lMidadP5Ub1DEMwK/hFLfzmXIk14YEYhRlXTtHXqVsh6lML gBKZjeEIfbL4tc3yiwk6WiSJtcqkJShKrdLrwa2giPTtetY6W8S4DAfowveoF3cjXMZV U+nw== 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:mime-version:content-transfer-encoding; bh=oB7VP5ATUZChOLMjOlpdWPN1IctJhwYBQQIlaCDVjkw=; b=LmNfyC63gaR117mb/xxd1goLICmA92PJE/zLK+/Oo9hqir8nRjq3oL9gp4XFeQl0u/ GGm/jAwIcRPIu5eB4wfdmEhwnTZ9C6gXlIkHiJEuerdLMWsBxxYCrS5+HX8vwbJ89t55 5/2uGYLEvew2Ly+itK+KO7y9fZB76zrmk7BSptfRorMQyyEiIcbLrxmSrw6WDOl6w/Lj iCn/F8mUw4TpYLGK2uElCHZSDPEh/T4vHQ83vuYb3SQNORiZH7ua9lgbXa4/gpRxxyXF 8+9TxLnOQ4tNRa5kWD0PnfhaJPKYLHDDwmagKjhddJH4D49OP+cqjQmxrl9xPw2S5o6Y 4vgg== X-Gm-Message-State: APjAAAUPxFz/G+80Q8T4uZwu1IpzSe4+RI7bOhe57a+6ProCuA6gkRWb ZLdwBk1orz1wFPRdju1dU3pmip0iqak= X-Received: by 2002:a17:902:e785:: with SMTP id cp5mr15743115plb.167.1557792369502; Mon, 13 May 2019 17:06:09 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id u3sm238151pfn.29.2019.05.13.17.06.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 17:06:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 13 May 2019 17:05:29 -0700 Message-Id: <20190514000540.4313-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514000540.4313-1-richard.henderson@linaro.org> References: <20190514000540.4313-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::62a Subject: [Qemu-devel] [PULL 20/31] 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: peter.maydell@linux.org 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: Alex Bennée 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 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)