From patchwork Sat Jan 7 07:51:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 640082 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1179903pvb; Sat, 7 Jan 2023 00:12:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXs2iCKiY5oitZ7K6U0EG9jStBizeyABLm2SUBAAqwc+cFTmjBuC9+DVLtrlfJNAGjmYnZ0w X-Received: by 2002:ac8:7082:0:b0:3a8:1593:f15b with SMTP id y2-20020ac87082000000b003a81593f15bmr94275718qto.50.1673079128050; Sat, 07 Jan 2023 00:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673079128; cv=none; d=google.com; s=arc-20160816; b=tPw5B6AZFSFQRDSdJ3F60Wux9i8Jo9tal86dPZ5T8pPXOfMBk1AbqydNxSXpWcO7EV s5oU5uth3+jR6R1sRf22W4tl6O8EeABcoSzcLeAPbXTVnqZtQpM1HVQoq7qSGiLFAlXg Z6dKw+0WDyU5G392U5Wz6cU2ISi0ZTFAXFH7+bZaJM+TRKgugowjg0hsV4geMVEz7WJf SJDu4BGhAQLLY3EsGy/+wXrxfhy7vCvB18wBFr9oXBUC/d3u3zmXcLSP3VqK0IEOp/jJ X8PZP6JwkuHw5483DlwVlb7x3RqYYRLdmtVGrV+27bA+ymxU3vQLCAMWzrImPnk6aB9e Ljng== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7jUA9/ifCEteEPBnCrvu2FZgUNzc6y0gw3a24gfdjs4=; b=pYEAqtQpm/x7s6qXNwi0QxRU8U9KdcPIz0g9IF0q4iFggiFL2v/FXid5flL5veMQpJ +2c4HVVWI7JJJA84eZ9jqqeTbNjXxMsKGfTI2DqpTkJoRUDQ0fz5OysaN+JV1/YaqFxC nVgUESHloloV8d6nUSar4grMRWwksEt/Nnr4pccC0+qBsdxmYrW+7F9vHZBJL28K08O2 NSnik+StyVaPwDWS/FufFipX96xHO5Xmycr0eoN0t5lLSNXFKTZRncro4WQIcnAM5z4n lMhktz6k3OFQ9Q9zbvCcbLKglfk493NkMGgsKST7iIRO5vkZCWEegKqm+NZi3lZOzXBO kvNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uW4Ldb5C; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fz18-20020a05622a5a9200b003a50df01c3dsi2097598qtb.390.2023.01.07.00.12.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Jan 2023 00:12:08 -0800 (PST) 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=uW4Ldb5C; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pE3zZ-0003p0-B9; Sat, 07 Jan 2023 02:51:49 -0500 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 1pE3zU-0003lH-R7 for qemu-devel@nongnu.org; Sat, 07 Jan 2023 02:51:44 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pE3zT-0004Eo-4v for qemu-devel@nongnu.org; Sat, 07 Jan 2023 02:51:44 -0500 Received: by mail-pj1-x1029.google.com with SMTP id z9-20020a17090a468900b00226b6e7aeeaso4148429pjf.1 for ; Fri, 06 Jan 2023 23:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=7jUA9/ifCEteEPBnCrvu2FZgUNzc6y0gw3a24gfdjs4=; b=uW4Ldb5C9Xn+WLwPsP6sLC/FBnVvOM4ORbX1CzcvrYXb4YDYa+ydg35fiHKVuuIbuK XojcN1fwVrVNUyEOjOEoOD7/u2/DHAE/OqjBHgHqDzkTUoWhEneMzt/4Tun8/iIdx3y+ J2fHu9JR0pWPmn0uEtoUCFlXBfKMGkNieYeyfA/eF9k05UkkeuR0lzG07qg3sNnHmbMO pDJQtRQGrW0OLFIdZKZiICKPu2rrnVH56tkb+nqrqF1Wpi57zF60wRDpA4VgEwY9tNO+ lj7R2yjT8CrxkvGj20yCtoxPE4yvTt4hAhv7WBmeChzDYCwulPjJxen4bEK6ceC2qa/J 38lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7jUA9/ifCEteEPBnCrvu2FZgUNzc6y0gw3a24gfdjs4=; b=Xs8/5YLaJSNfKmFITSo+pdmjy3dx42FgCY2/qafpX4f1lqG4w4Qyx3Zv8v59aeuygB R+yVbTVL8mCmjXqG4gMpqhL/ureZFetnmJSynKNnmSZ2PLx3ZfPPBedrqMRkoctO4dei mhL1Irhdt6oocZWhXKB19bZxzeaD0b4jd1VOjSmo5GffOmid1r8rKCWus3ormtdiExIm vN115BG9VkSBi4z167D+Sf+pgYmEk6SBWrZ61VDCEsx28U4dfhyuaHYyBb6hkatrWOSm Vk2T70hthru/L0sdUMtzu398HTvek4o8wFCeiItvpF/osXJypojiu3J0RugHwZB7ohBY mbvQ== X-Gm-Message-State: AFqh2kqYIyFdlxpR9hQQhexzyH7aFmnQikpoimvPpRNtpdGpATYWAVXG ++KKUNGX29CT9wZ7WmL6102YEdepmyFmJKtH X-Received: by 2002:a17:90a:e616:b0:226:62bb:3257 with SMTP id j22-20020a17090ae61600b0022662bb3257mr22550188pjy.10.1673077902189; Fri, 06 Jan 2023 23:51:42 -0800 (PST) Received: from stoup.. ([2602:47:d48c:8101:9d81:5b04:51d7:acae]) by smtp.gmail.com with ESMTPSA id bj5-20020a17090b088500b00212e5068e17sm1945119pjb.40.2023.01.06.23.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 23:51:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 24/27] tcg/s390x: Implement ctpop operation Date: Fri, 6 Jan 2023 23:51:15 -0800 Message-Id: <20230107075118.1814503-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107075118.1814503-1-richard.henderson@linaro.org> References: <20230107075118.1814503-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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 There is an older form that produces per-byte results, and a newer form that produces per-register results. Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- tcg/s390x/tcg-target.h | 4 ++-- tcg/s390x/tcg-target.c.inc | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tcg/s390x/tcg-target.h b/tcg/s390x/tcg-target.h index dabdae1e84..68dcbc6645 100644 --- a/tcg/s390x/tcg-target.h +++ b/tcg/s390x/tcg-target.h @@ -91,7 +91,7 @@ extern uint64_t s390_facilities[3]; #define TCG_TARGET_HAS_nor_i32 HAVE_FACILITY(MISC_INSN_EXT3) #define TCG_TARGET_HAS_clz_i32 0 #define TCG_TARGET_HAS_ctz_i32 0 -#define TCG_TARGET_HAS_ctpop_i32 0 +#define TCG_TARGET_HAS_ctpop_i32 1 #define TCG_TARGET_HAS_deposit_i32 1 #define TCG_TARGET_HAS_extract_i32 1 #define TCG_TARGET_HAS_sextract_i32 0 @@ -128,7 +128,7 @@ extern uint64_t s390_facilities[3]; #define TCG_TARGET_HAS_nor_i64 HAVE_FACILITY(MISC_INSN_EXT3) #define TCG_TARGET_HAS_clz_i64 1 #define TCG_TARGET_HAS_ctz_i64 0 -#define TCG_TARGET_HAS_ctpop_i64 0 +#define TCG_TARGET_HAS_ctpop_i64 1 #define TCG_TARGET_HAS_deposit_i64 1 #define TCG_TARGET_HAS_extract_i64 1 #define TCG_TARGET_HAS_sextract_i64 0 diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc index 8254f9f650..c0434fa2f8 100644 --- a/tcg/s390x/tcg-target.c.inc +++ b/tcg/s390x/tcg-target.c.inc @@ -206,6 +206,7 @@ typedef enum S390Opcode { RRFc_LOCR = 0xb9f2, RRFc_LOCGR = 0xb9e2, + RRFc_POPCNT = 0xb9e1, RR_AR = 0x1a, RR_ALR = 0x1e, @@ -1435,6 +1436,32 @@ static void tgen_clz(TCGContext *s, TCGReg dest, TCGReg a1, tgen_movcond_int(s, TCG_TYPE_I64, dest, a2, a2const, TCG_REG_R0, 8, 2); } +static void tgen_ctpop(TCGContext *s, TCGType type, TCGReg dest, TCGReg src) +{ + /* With MIE3, and bit 0 of m4 set, we get the complete result. */ + if (HAVE_FACILITY(MISC_INSN_EXT3)) { + if (type == TCG_TYPE_I32) { + tgen_ext32u(s, dest, src); + src = dest; + } + tcg_out_insn(s, RRFc, POPCNT, dest, src, 8); + return; + } + + /* Without MIE3, each byte gets the count of bits for the byte. */ + tcg_out_insn(s, RRFc, POPCNT, dest, src, 0); + + /* Multiply to sum each byte at the top of the word. */ + if (type == TCG_TYPE_I32) { + tcg_out_insn(s, RIL, MSFI, dest, 0x01010101); + tcg_out_sh32(s, RS_SRL, dest, TCG_REG_NONE, 24); + } else { + tcg_out_movi(s, TCG_TYPE_I64, TCG_TMP0, 0x0101010101010101ull); + tcg_out_insn(s, RRE, MSGR, dest, TCG_TMP0); + tcg_out_sh64(s, RSY_SRLG, dest, dest, TCG_REG_NONE, 56); + } +} + static void tgen_deposit(TCGContext *s, TCGReg dest, TCGReg src, int ofs, int len, int z) { @@ -2584,6 +2611,13 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, tgen_clz(s, args[0], args[1], args[2], const_args[2]); break; + case INDEX_op_ctpop_i32: + tgen_ctpop(s, TCG_TYPE_I32, args[0], args[1]); + break; + case INDEX_op_ctpop_i64: + tgen_ctpop(s, TCG_TYPE_I64, args[0], args[1]); + break; + case INDEX_op_mb: /* The host memory model is quite strong, we simply need to serialize the instruction stream. */ @@ -3146,6 +3180,8 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_extu_i32_i64: case INDEX_op_extract_i32: case INDEX_op_extract_i64: + case INDEX_op_ctpop_i32: + case INDEX_op_ctpop_i64: return C_O1_I1(r, r); case INDEX_op_qemu_ld_i32: