From patchwork Tue Jun 1 15:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 451414 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp1883629jao; Tue, 1 Jun 2021 08:21:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwS4xznuU/5D1L3Pep1yphhsZjeDuRaU6wFgg0qrxbY+jGuDorF9nYZ8tu/Hh6vwrKnvFZ X-Received: by 2002:a05:6512:3ba5:: with SMTP id g37mr19518703lfv.453.1622560894682; Tue, 01 Jun 2021 08:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622560894; cv=none; d=google.com; s=arc-20160816; b=KE7s9sOTRSDQm6fd6LxweDAS4F88JKtMuqdlXrFlnhOzWg7w/i6VMBkBiuHvdlb629 9+/I5ptF7IA4mtQzNqmhzHVqMpgoFL1MEZ6DtRQG5drrmICZEKOfQcJ+7xdIbAqkIrDk P7GAPjPH6Ls3waomJE5Fvjw58SvZO4pRnHeIPDqA9uOpj/JOjuWMR9bl0hu+fwXUiTMT VyvbUyiw2EToDz/bexBQvlScu5qRjsqgUBwfg43uAGSQSM6II2OmRvW4q+eUeobiVKwT tlQ0yEVlrfLbV5LjBuLX0JPY2fsmSFAzkiNnzPMOGj1JIIFQdzz1U+Gzzx+Y/Qsf7oca v51A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=oEIZYcilzhqc0TqsSnNTanV1QNHzejDQCs/zffIYgHI=; b=hyeK7MtjD06vLrp8FQ/hSvS839yt1E4dcth2Eva6lrs0s/OKSY7U75+GM3N0SRuz+h 9YYviRoqpGEV/0CKYT4o0nCYSd5lsh0wBPczHTuPJ64atUVzVTV9pmeaM/jJffYoN721 S9IYIHkA2ifbGXsYJBxxHgyjiJd/UeU3ckwe9dszdpb9fI0p85qr3jjGudANnh04Fypl CFU+ZMTRaB0vfQdn9MB1WP3QABbGHTInqEyMsrxIP4jaddAJRMtssKoDbX5LzrCxr2PQ wkJm9KiumeGxAVvsBdLuau+Czu6tGQoMLsmMhoWQofllCbRdq8WlsjDOQavH6pwMmygI P3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xfbqGM/R"; 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 m9si8674992lfu.52.2021.06.01.08.21.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Jun 2021 08:21:34 -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="xfbqGM/R"; 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]:41398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lo6Cz-0002ey-Bz for patch@linaro.org; Tue, 01 Jun 2021 11:21:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lo5tx-0002bF-Ch for qemu-devel@nongnu.org; Tue, 01 Jun 2021 11:01:54 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:33772) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lo5tk-0002h5-RY for qemu-devel@nongnu.org; Tue, 01 Jun 2021 11:01:53 -0400 Received: by mail-io1-xd30.google.com with SMTP id a6so15685443ioe.0 for ; Tue, 01 Jun 2021 08:01:36 -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=oEIZYcilzhqc0TqsSnNTanV1QNHzejDQCs/zffIYgHI=; b=xfbqGM/Rvk2HdbTcMnIrfiD6amZJ4dLQ/xvp7JGWiJyFQDvg1/rjWVGBKd/yu6Bwfc RLNKEPL8SVQ3ZJWBDhpi4Gorcnes0sBLvqDTMb68OwM4VSLvvvtd7odIMFgPY7BiEYfs k4kUWDcNm83sybmblRQn6R9g9y3r2u32FI1tK02tCg8i7CUZnzqdCagADKFrqlVnu/1W YUczgaXojNpQd4LX5m+2X6OZurb6jZjdETH8UUdVnG4I2x+QZxmaLVo8UOBTvNiTuyPj hBToEfi9unfARhK050qUJNNNBxyTDx30a5JR28LBgVo04rEH2qu6iu6FcgAGNuNHMQIR 2q0A== 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=oEIZYcilzhqc0TqsSnNTanV1QNHzejDQCs/zffIYgHI=; b=QsWbdk8kOW5gATktiuBQtCQHlUZL2Xas8GAobsuLXMG4UWh5xtpbS36zEscfKIPJqC l8zgApoZ2j8n3K+bLNhqIGQzUkuFpobSn44Wx/S4t1JGHWfVeCuS/Us4l3+2QQLxnPfs U6YN59XeShCyiWNg5BuqpFlHTZuQOhE+/4Zz12ZA088WyAZQTLiFY4qMzWPX+67R2L0h I1/ZjrZlVH7OxQk5o/I3EciZOMYvjVRP03RNdfJ+AWPFaw6AOfOUAHRNsTkg2MQEviUY do0QoQ4VpUv4Igoh2rhEV3g27iQGWjhAc9D0ixHyi4+LwRG10rg1pS/zYtKiCTf3FUBH 0T0g== X-Gm-Message-State: AOAM530eUsqNHsabRE8f0b1LxLyele98GIpBckZCq7OGdkvasxYN9VaG vJi0PgVq6PEsJ70i/zwkQXOhvSZWdF91DQmS X-Received: by 2002:a05:6638:258c:: with SMTP id s12mr25343696jat.92.1622559696214; Tue, 01 Jun 2021 08:01:36 -0700 (PDT) Received: from localhost.localdomain ([2607:fb90:806c:3e8a:9cf0:b3be:5e07:b99f]) by smtp.gmail.com with ESMTPSA id f8sm4109909ilj.37.2021.06.01.08.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 08:01:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 20/27] tcg/tci: Implement clz, ctz, ctpop Date: Tue, 1 Jun 2021 08:00:59 -0700 Message-Id: <20210601150106.12761-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210601150106.12761-1-richard.henderson@linaro.org> References: <20210601150106.12761-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d30; envelope-from=richard.henderson@linaro.org; helo=mail-io1-xd30.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Tested-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/tci/tcg-target.h | 12 +++++------ tcg/tci.c | 44 ++++++++++++++++++++++++++++++++++++++++ tcg/tci/tcg-target.c.inc | 9 ++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index 60b67b196b..59859bd8a6 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -75,9 +75,9 @@ #define TCG_TARGET_HAS_eqv_i32 1 #define TCG_TARGET_HAS_nand_i32 1 #define TCG_TARGET_HAS_nor_i32 1 -#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_clz_i32 1 +#define TCG_TARGET_HAS_ctz_i32 1 +#define TCG_TARGET_HAS_ctpop_i32 1 #define TCG_TARGET_HAS_neg_i32 1 #define TCG_TARGET_HAS_not_i32 1 #define TCG_TARGET_HAS_orc_i32 1 @@ -112,9 +112,9 @@ #define TCG_TARGET_HAS_eqv_i64 1 #define TCG_TARGET_HAS_nand_i64 1 #define TCG_TARGET_HAS_nor_i64 1 -#define TCG_TARGET_HAS_clz_i64 0 -#define TCG_TARGET_HAS_ctz_i64 0 -#define TCG_TARGET_HAS_ctpop_i64 0 +#define TCG_TARGET_HAS_clz_i64 1 +#define TCG_TARGET_HAS_ctz_i64 1 +#define TCG_TARGET_HAS_ctpop_i64 1 #define TCG_TARGET_HAS_neg_i64 1 #define TCG_TARGET_HAS_not_i64 1 #define TCG_TARGET_HAS_orc_i64 1 diff --git a/tcg/tci.c b/tcg/tci.c index 22ee32bc24..1e2737e079 100644 --- a/tcg/tci.c +++ b/tcg/tci.c @@ -587,6 +587,26 @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, tci_args_rrr(insn, &r0, &r1, &r2); regs[r0] = (uint32_t)regs[r1] % (uint32_t)regs[r2]; break; +#if TCG_TARGET_HAS_clz_i32 + case INDEX_op_clz_i32: + tci_args_rrr(insn, &r0, &r1, &r2); + tmp32 = regs[r1]; + regs[r0] = tmp32 ? clz32(tmp32) : regs[r2]; + break; +#endif +#if TCG_TARGET_HAS_ctz_i32 + case INDEX_op_ctz_i32: + tci_args_rrr(insn, &r0, &r1, &r2); + tmp32 = regs[r1]; + regs[r0] = tmp32 ? ctz32(tmp32) : regs[r2]; + break; +#endif +#if TCG_TARGET_HAS_ctpop_i32 + case INDEX_op_ctpop_i32: + tci_args_rr(insn, &r0, &r1); + regs[r0] = ctpop32(regs[r1]); + break; +#endif /* Shift/rotate operations (32 bit). */ @@ -739,6 +759,24 @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, tci_args_rrr(insn, &r0, &r1, &r2); regs[r0] = (uint64_t)regs[r1] % (uint64_t)regs[r2]; break; +#if TCG_TARGET_HAS_clz_i64 + case INDEX_op_clz_i64: + tci_args_rrr(insn, &r0, &r1, &r2); + regs[r0] = regs[r1] ? clz64(regs[r1]) : regs[r2]; + break; +#endif +#if TCG_TARGET_HAS_ctz_i64 + case INDEX_op_ctz_i64: + tci_args_rrr(insn, &r0, &r1, &r2); + regs[r0] = regs[r1] ? ctz64(regs[r1]) : regs[r2]; + break; +#endif +#if TCG_TARGET_HAS_ctpop_i64 + case INDEX_op_ctpop_i64: + tci_args_rr(insn, &r0, &r1); + regs[r0] = ctpop64(regs[r1]); + break; +#endif /* Shift/rotate operations (64 bit). */ @@ -1165,6 +1203,8 @@ int print_insn_tci(bfd_vma addr, disassemble_info *info) case INDEX_op_not_i64: case INDEX_op_neg_i32: case INDEX_op_neg_i64: + case INDEX_op_ctpop_i32: + case INDEX_op_ctpop_i64: tci_args_rr(insn, &r0, &r1); info->fprintf_func(info->stream, "%-12s %s, %s", op_name, str_r(r0), str_r(r1)); @@ -1210,6 +1250,10 @@ int print_insn_tci(bfd_vma addr, disassemble_info *info) case INDEX_op_rotl_i64: case INDEX_op_rotr_i32: case INDEX_op_rotr_i64: + case INDEX_op_clz_i32: + case INDEX_op_clz_i64: + case INDEX_op_ctz_i32: + case INDEX_op_ctz_i64: tci_args_rrr(insn, &r0, &r1, &r2); info->fprintf_func(info->stream, "%-12s %s, %s, %s", op_name, str_r(r0), str_r(r1), str_r(r2)); diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc index 677ae2dceb..748bc13d4e 100644 --- a/tcg/tci/tcg-target.c.inc +++ b/tcg/tci/tcg-target.c.inc @@ -67,6 +67,8 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_extract_i64: case INDEX_op_sextract_i32: case INDEX_op_sextract_i64: + case INDEX_op_ctpop_i32: + case INDEX_op_ctpop_i64: return C_O1_I1(r, r); case INDEX_op_st8_i32: @@ -122,6 +124,10 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_setcond_i64: case INDEX_op_deposit_i32: case INDEX_op_deposit_i64: + case INDEX_op_clz_i32: + case INDEX_op_clz_i64: + case INDEX_op_ctz_i32: + case INDEX_op_ctz_i64: return C_O1_I2(r, r, r); case INDEX_op_brcond_i32: @@ -655,6 +661,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, CASE_32_64(divu) /* Optional (TCG_TARGET_HAS_div_*). */ CASE_32_64(rem) /* Optional (TCG_TARGET_HAS_div_*). */ CASE_32_64(remu) /* Optional (TCG_TARGET_HAS_div_*). */ + CASE_32_64(clz) /* Optional (TCG_TARGET_HAS_clz_*). */ + CASE_32_64(ctz) /* Optional (TCG_TARGET_HAS_ctz_*). */ tcg_out_op_rrr(s, opc, args[0], args[1], args[2]); break; @@ -703,6 +711,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, CASE_32_64(bswap16) /* Optional (TCG_TARGET_HAS_bswap16_*). */ CASE_32_64(bswap32) /* Optional (TCG_TARGET_HAS_bswap32_*). */ CASE_64(bswap64) /* Optional (TCG_TARGET_HAS_bswap64_i64). */ + CASE_32_64(ctpop) /* Optional (TCG_TARGET_HAS_ctpop_*). */ tcg_out_op_rr(s, opc, args[0], args[1]); break;