From patchwork Wed Sep 11 16:50:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 827463 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp891616wrc; Wed, 11 Sep 2024 09:53:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXSua4CAo72jUU3pBfMVBlFZ4TbTaNfFhc5lOwTgaN6RAJQzcGOIEAYhJLULwsHfhwsaJ/d1A==@linaro.org X-Google-Smtp-Source: AGHT+IEj/41X4aGcC0YSWG981TbjvML23v8Caf6+6+1S04JH+lNwGiOfjUTG5ETX9N0oQNnFGmlG X-Received: by 2002:a05:620a:24c4:b0:7a9:c0f2:81a5 with SMTP id af79cd13be357-7a9e5f1d3demr3174685a.36.1726073580090; Wed, 11 Sep 2024 09:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726073580; cv=none; d=google.com; s=arc-20240605; b=QWprebU34TySPdnUWGb6kZBHteTSXEc3d2LI2BlGGUogpB2bJ5oTu/g1/20UzGKUBo SLyNs1In1vf2/e5pkh+ajcttXqUKPxhoR1dZb1UnuQ7SWMB5A9Dl99LNmA7QgYdKtOJR 2Jk1Uwne56Lvu6+XFRyRtIMKx61oE48xxENAwOB6xZ3MSgGJ8/9lAw6AlCX4d2Piwrzu Ifgr/5HlZhDv0AmR6hjYKyr66OvcCzoPmDIAFyY6EimEn84ahXGPuyrEmfSBg8a4vSxJ ACSX+M+d0Ss50OqJhmFPxva0ZFlOiLmpXEb9fal+Jdtv1vefVfbpDrDrA/fKWCBAOB6T 3MoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nf2KKD8gpkfqLcprZUwSXAhZF2kW47U2PBUtTXC4uSQ=; fh=gW8xxqNJ+GKzLr7OBpcms3Apqae8iNJSKgK4r5swIT4=; b=NhKCRtR9fhG/4KxFGbRAORE3PFweYeIYmUkd52qsARO2s3TKmvrnelsAL4pudl71z6 tBbG0Q/ZpD5Z+U3l1UI1VlVHUsuZgzeR64J7aipauZ1LmHXe6mBvhQOn6vr6E/u2Qj8y EIzvbcUJGxPUY1prqe/FInMNpf36ey2rzSYHKy8VEV4rjn25Bulb678Z7h+8ECf8xPLh oELiS+xOV01Xk+miFdU+ltqtttQ3lDhrzJ8QaAHPqTyT14Kcz0kvn4ucqIJ4VlKV9JjE xUJn91uwqRWk1/izoX/ZnIkY+18CVjpQNcjorE3kWlOXHwxqOdQp6qr5ZAUnkAvtBp6W yplQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xa8rkY1X; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a9a79c63e0si1029077785a.155.2024.09.11.09.52.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2024 09:53:00 -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=pass header.i=@linaro.org header.s=google header.b=xa8rkY1X; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soQYw-0003lo-2n; Wed, 11 Sep 2024 12:51:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soQYf-0002nB-B4 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 12:51:10 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1soQYd-0003hS-9x for qemu-devel@nongnu.org; Wed, 11 Sep 2024 12:51:09 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-717934728adso5173278b3a.2 for ; Wed, 11 Sep 2024 09:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726073466; x=1726678266; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nf2KKD8gpkfqLcprZUwSXAhZF2kW47U2PBUtTXC4uSQ=; b=xa8rkY1XmNjHsqmS+m3G3AzgZ5EatdbBlQe3gtSqGvfVD/Fz9UrfdmE/b6dqDFSYSp iLlLuGvy0BDC+azWKALjXdol510ZJaIl3/SUnJDDl3qzSWHH1IVqqnKKrZ8h8b5RaVZj uf2wBZNPD+ZkUYFDycNcawa/RQp12Z5bexDGxztIjaFhX/AXyrmavEddJpTdQMPj5fll 1UIEa8OS6N144KG0NrAwCaGL2grO6lE5J9vWImJT44XJmoKwRrCUpJX/YTXnDLQoVtQd yZ8PZy7XFB5J4nSiJazJnx0+3XCEBtgGug92mZHuF2cWdbAgW7Z4IUXQZr31RHf/6qcM aJQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726073466; x=1726678266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nf2KKD8gpkfqLcprZUwSXAhZF2kW47U2PBUtTXC4uSQ=; b=p9IQj/UcDt69eHtzfhR0uSkVeQU2hAYf0xGFVBZkydKovdyEdkGZ1Tq+/Uc2+8V9eC h3PZl9ahdSccyaoeBw1f2AOF1rMPNfgnafMULLJFWf4bnv+PEMNum6LeG9eMZlOzYQOQ 5wWe2KitngVl5mtRX3hTyeS7b+3obwXf0XCgk8igTvUEhuXR3njYhJkX/QXnhvufVqhx l1OkefFxl6jwbYietk9607/+tmU4yHdbu1XEbNYbz9iB3/RfGSHxZUGhLHrEK2v8Xa2T izgDqgkZZBVcTmDzvHt4D7Eq4XCdTGwXjlsTnkNII9NjahNbGItN+zsdfkwKSGqWbJ3u mgKw== X-Gm-Message-State: AOJu0YxKgVEBcNP+f5CpxoHWA3BlYHa6MzQ4XifpgpdmfKIq8xvVNdb1 zhNTV0zHQhou4F+KBxg6Oh5IxT76UnUMdB+/PvqyG0SOnKBBvP5K4cSboAueYrjith9WpFypz8o o X-Received: by 2002:a05:6a00:4f90:b0:717:97ac:ef46 with SMTP id d2e1a72fcca58-7192609615amr16010b3a.15.1726073465714; Wed, 11 Sep 2024 09:51:05 -0700 (PDT) Received: from stoup.. (174-21-81-121.tukw.qwest.net. [174.21.81.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm3186947b3a.80.2024.09.11.09.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 09:51:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: zhiwei_liu@linux.alibaba.com, tangtiancheng.ttc@alibaba-inc.com, philmd@linaro.org Subject: [PATCH v2 18/18] tcg/s390x: Optimize cmpsel with constant 0/-1 arguments Date: Wed, 11 Sep 2024 09:50:47 -0700 Message-ID: <20240911165047.1035764-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240911165047.1035764-1-richard.henderson@linaro.org> References: <20240911165047.1035764-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org These can be simplified to and/or/andc/orc, avoiding the load of the constantinto a register. Signed-off-by: Richard Henderson --- tcg/s390x/tcg-target-con-set.h | 3 ++- tcg/s390x/tcg-target-con-str.h | 1 + tcg/s390x/tcg-target.c.inc | 40 ++++++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tcg/s390x/tcg-target-con-set.h b/tcg/s390x/tcg-target-con-set.h index 670089086d..370e4b1295 100644 --- a/tcg/s390x/tcg-target-con-set.h +++ b/tcg/s390x/tcg-target-con-set.h @@ -38,7 +38,8 @@ C_O1_I2(r, rZ, r) C_O1_I2(v, v, r) C_O1_I2(v, v, v) C_O1_I3(v, v, v, v) -C_O1_I4(v, v, v, v, v) +C_O1_I4(v, v, v, vZ, v) +C_O1_I4(v, v, v, vZM, v) C_O1_I4(r, r, ri, rI, r) C_O1_I4(r, r, rC, rI, r) C_O2_I1(o, m, r) diff --git a/tcg/s390x/tcg-target-con-str.h b/tcg/s390x/tcg-target-con-str.h index 745f6c0df5..3e574e0662 100644 --- a/tcg/s390x/tcg-target-con-str.h +++ b/tcg/s390x/tcg-target-con-str.h @@ -20,6 +20,7 @@ CONST('C', TCG_CT_CONST_CMP) CONST('I', TCG_CT_CONST_S16) CONST('J', TCG_CT_CONST_S32) CONST('K', TCG_CT_CONST_P32) +CONST('M', TCG_CT_CONST_M1) CONST('N', TCG_CT_CONST_INV) CONST('R', TCG_CT_CONST_INVRISBG) CONST('U', TCG_CT_CONST_U32) diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc index e044168826..a5d57197a4 100644 --- a/tcg/s390x/tcg-target.c.inc +++ b/tcg/s390x/tcg-target.c.inc @@ -36,6 +36,7 @@ #define TCG_CT_CONST_INV (1 << 13) #define TCG_CT_CONST_INVRISBG (1 << 14) #define TCG_CT_CONST_CMP (1 << 15) +#define TCG_CT_CONST_M1 (1 << 16) #define ALL_GENERAL_REGS MAKE_64BIT_MASK(0, 16) #define ALL_VECTOR_REGS MAKE_64BIT_MASK(32, 32) @@ -607,6 +608,9 @@ static bool tcg_target_const_match(int64_t val, int ct, if ((ct & TCG_CT_CONST_ZERO) && val == 0) { return true; } + if ((ct & TCG_CT_CONST_M1) && val == -1) { + return true; + } if (ct & TCG_CT_CONST_INV) { val = ~val; @@ -2904,15 +2908,30 @@ static void tcg_out_cmp_vec(TCGContext *s, unsigned vece, TCGReg a0, } static void tcg_out_cmpsel_vec(TCGContext *s, unsigned vece, TCGReg a0, - TCGReg c1, TCGReg c2, - TCGReg v3, TCGReg v4, TCGCond cond) + TCGReg c1, TCGReg c2, TCGArg v3, + int const_v3, TCGReg v4, TCGCond cond) { - if (tcg_out_cmp_vec_noinv(s, vece, TCG_VEC_TMP0, c1, c2, cond)) { - TCGReg swap = v3; - v3 = v4; - v4 = swap; + bool inv = tcg_out_cmp_vec_noinv(s, vece, TCG_VEC_TMP0, c1, c2, cond); + + if (!const_v3) { + if (inv) { + tcg_out_insn(s, VRRe, VSEL, a0, v4, v3, TCG_VEC_TMP0); + } else { + tcg_out_insn(s, VRRe, VSEL, a0, v3, v4, TCG_VEC_TMP0); + } + } else if (v3) { + if (inv) { + tcg_out_insn(s, VRRc, VOC, a0, v4, TCG_VEC_TMP0, 0); + } else { + tcg_out_insn(s, VRRc, VO, a0, v4, TCG_VEC_TMP0, 0); + } + } else { + if (inv) { + tcg_out_insn(s, VRRc, VN, a0, v4, TCG_VEC_TMP0, 0); + } else { + tcg_out_insn(s, VRRc, VNC, a0, v4, TCG_VEC_TMP0, 0); + } } - tcg_out_insn(s, VRRe, VSEL, a0, v3, v4, TCG_VEC_TMP0); } static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, @@ -3036,7 +3055,8 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, tcg_out_cmp_vec(s, vece, a0, a1, a2, args[3]); break; case INDEX_op_cmpsel_vec: - tcg_out_cmpsel_vec(s, vece, a0, a1, a2, args[3], args[4], args[5]); + tcg_out_cmpsel_vec(s, vece, a0, a1, a2, args[3], const_args[3], + args[4], args[5]); break; case INDEX_op_s390_vuph_vec: @@ -3388,7 +3408,9 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_bitsel_vec: return C_O1_I3(v, v, v, v); case INDEX_op_cmpsel_vec: - return C_O1_I4(v, v, v, v, v); + return (TCG_TARGET_HAS_orc_vec + ? C_O1_I4(v, v, v, vZM, v) + : C_O1_I4(v, v, v, vZ, v)); default: g_assert_not_reached();