From nobody Sat Nov 15 07:32:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1755628146; cv=none; d=zohomail.com; s=zohoarc; b=axP4WYpT44W3RccDhfpubWhzcaQJikwzr1EvAld9X2ki5o3ohSktHXm4wSMoJuzzweiCcQJULnme+xqrBvEQAe7YlHr/pDtPoQGVJc4Cuulrb5VFW4XThnk7YCc6YN4LgqJ5NVXZ001dGThRrNlbLgaNMc9/AhgIjv4/sA5aTUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755628146; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i6f7sVT4bGYsPhkhxxnC/Q6xqoXFxbpoICuYkhSX10A=; b=j1EFlZSSOdBc/PX0NojFrQm0qo7VdmzHfL/vdN210lY460A2oKZSBJwfsmEoIDbfTqAheOjNZgs/u+AXZoZd8YyXHhm7hkp1z/B1/YiyNi9lz96uupkoQVfg87CY1mWZBSQrSd6lXkBam0ITUYTH1gJHv/EBPm0dUkYi8EA3X0c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755628146903237.62675045904473; Tue, 19 Aug 2025 11:29:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uoR0n-000860-Re; Tue, 19 Aug 2025 14:24:46 -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 1uoR0g-0007HH-1t; Tue, 19 Aug 2025 14:24:38 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uoR0d-0003yG-8Y; Tue, 19 Aug 2025 14:24:37 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-b471756592cso3862706a12.3; Tue, 19 Aug 2025 11:24:34 -0700 (PDT) Received: from ktock.. ([240d:1a:3b6:8b00:29ce:ef58:c2c9:e52f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-245ed33b4c2sm3725125ad.25.2025.08.19.11.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Aug 2025 11:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755627873; x=1756232673; 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=i6f7sVT4bGYsPhkhxxnC/Q6xqoXFxbpoICuYkhSX10A=; b=gZ5yFs+tcZky0TEOki1x7JUBNTlj/MzKlh07yY7agJjvCRMcilp/ibeiZzy1KnIRpa /8wswvDqIOpX3vBEF1rDlkxVy1VhpElGIzGug3EMF8lZL1wRJ09+R6SfVHjsAM0fg4iI yEv2camTtcvACMNcuL9VnkPp8wYYN8H6KbUNnfzSjk0VesTHs2MFXL24kg/92lxwmhr6 O5ttXwKWS5C75ESobj50kt9SmV7OZGbRxJvtvtQ1R+2X3iGZh5iZxw8+Yh7yJKiM2ro+ p70LAUkwY4FW2qadWjYDZiXGi4DcR7Y0ii4VjidmWSCSTz80BKy/K/i6jDg5vGL/bZjR oG/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755627873; x=1756232673; 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=i6f7sVT4bGYsPhkhxxnC/Q6xqoXFxbpoICuYkhSX10A=; b=teS4X7HWUfeRH4MwkTGmQkqOByvZOgd3CuqFqGTBWbbUhBCXdkrvih0fWgKtEOLBWf dUhcaz7fGCctx5dgMwCBxrrQxDdp4H/vS54qBozWSvJU69bYRjYVnS16b99+qoHgnmje b0oyubTOhDsl+pZPFMD3y+QgyA1M/wLNv4y74uOzalp1OBBZQNWdrSV274sXhriLUxjF ZiW4gWlM43qtqDr6h2nti/N5FMROwn+Sx8oFIDjtbgFzIn9gWBvBY/jcj/gi0nQw5XJl ynk+3WlLlhVW2DhK68lj04XRj0CkFHdm5S/MZsQVMoGLEmp2bI1W+v/qUJuufb6bwccb VUkA== X-Forwarded-Encrypted: i=1; AJvYcCVHTtytr6mYfnsJRCuSAABRNN2EpRKq4a85YrI627KxhuoI1xKlwjC0X112ihDqBPSzWAokNCDA+fTz3w==@nongnu.org, AJvYcCX4WCWtZdAPjB5U1+WJ9lpRx2a96hgkIFfvZAKVhACTkw0PTHXmcZH2xG2HYPBbyTPTHn/S6FbxkQ==@nongnu.org X-Gm-Message-State: AOJu0Yyy0nQNTyTBqxUHn4Drc3t6yeBPidiXi4yPDBTebtJ8hyb8RiV7 Erv3IWYGQSDZhZRDMqUfwBRf89niUJAoqI/bdbZLAzFk7omSQXLTMR+xQsfWvHML X-Gm-Gg: ASbGncsmogQLXU90zelXckRmVEYdwCsKj85z7m8DNH3SS1iELaWRXsS03w4i4WWSptt tztG98RDDahgsqtxkpsclLR/G63p/3io6FkmLzC7jYoQBtSBPS/kyz1z0ilGoPNoScajiFc0ovp fHd+XWv/DusuCZy8chmLpx9U3e3yj3ePslE5PN5ahTJ1sPrxs6pnTQqbcUeJ7388CNeSOFi9g9Q jjMI+ZdczZND6r8XjIiske5EdpUWbSkBD04BnP+SFno3ifz5fib3tB8Zz/ZCBtUKmwqAbZzxliH Ty37lYOs+2Q74k11ArK+FKyfspyXlzgcdMqH/UVZB3HA9nMI3ByHwBLXye6WfV6mieb7jnul5UK FPQyxgwHmYdFRwauL5pPvxplklE/Nqnob X-Google-Smtp-Source: AGHT+IEy/0Agp5IS6C8/NwyH610FoMQVkjWxGkrobBfEBNSM11Dp8E1r/XXFQWWpYkW0NCusONsDQQ== X-Received: by 2002:a17:902:f64d:b0:240:8ce5:f514 with SMTP id d9443c01a7336-245e0470413mr49560815ad.34.1755627872830; Tue, 19 Aug 2025 11:24:32 -0700 (PDT) From: Kohei Tokunaga To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Paolo Bonzini , Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , WANG Xuerui , Aurelien Jarno , Huacai Chen , Jiaxun Yang , Aleksandar Rikalo , Palmer Dabbelt , Alistair Francis , Stefan Weil , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Stefan Hajnoczi , Pierrick Bouvier , ktokunaga.mail@gmail.com Subject: [PATCH 21/35] tcg/wasm: Add neg/not/ctpop instructions Date: Wed, 20 Aug 2025 03:21:50 +0900 Message-ID: <0eb3445353ddde2f34bac187bf8d3ecf02f106b4.1755623522.git.ktokunaga.mail@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=ktokunaga.mail@gmail.com; helo=mail-pg1-x52c.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, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1755628148805116600 Content-Type: text/plain; charset="utf-8" The Wasm backend implements only TCG_TARGET_REG_BITS=3D64 so the ctpop instruction is generated only for 64bit operations, as declared in cset_ctpop. Therefore, this commit adds only the 64bit version of ctpop implementation. The tgen_neg function was used by several functions and intended to emit TCI code. So it have been renamed to tgen_neg_tci. Signed-off-by: Kohei Tokunaga --- tcg/wasm/tcg-target.c.inc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tcg/wasm/tcg-target.c.inc b/tcg/wasm/tcg-target.c.inc index 3c0374cd01..0ba16e8dce 100644 --- a/tcg/wasm/tcg-target.c.inc +++ b/tcg/wasm/tcg-target.c.inc @@ -180,6 +180,7 @@ typedef enum { OPC_I32_SHR_U =3D 0x76, OPC_I32_ROTR =3D 0x78, =20 + OPC_I64_POPCNT =3D 0x7b, OPC_I64_ADD =3D 0x7c, OPC_I64_SUB =3D 0x7d, OPC_I64_MUL =3D 0x7e, @@ -499,6 +500,29 @@ static void tcg_wasm_out_nor( tcg_wasm_out_op_idx(s, OPC_GLOBAL_SET, REG_IDX(ret)); } =20 +static void tcg_wasm_out_neg(TCGContext *s, TCGReg ret, TCGReg arg) +{ + tcg_wasm_out_op_idx(s, OPC_GLOBAL_GET, REG_IDX(arg)); + tcg_wasm_out_op_not(s); + tcg_wasm_out_op_const(s, OPC_I64_CONST, 1); + tcg_wasm_out_op(s, OPC_I64_ADD); + tcg_wasm_out_op_idx(s, OPC_GLOBAL_SET, REG_IDX(ret)); +} + +static void tcg_wasm_out_not(TCGContext *s, TCGReg ret, TCGReg arg) +{ + tcg_wasm_out_op_idx(s, OPC_GLOBAL_GET, REG_IDX(arg)); + tcg_wasm_out_op_not(s); + tcg_wasm_out_op_idx(s, OPC_GLOBAL_SET, REG_IDX(ret)); +} + +static void tcg_wasm_out_ctpop64(TCGContext *s, TCGReg ret, TCGReg arg) +{ + tcg_wasm_out_op_idx(s, OPC_GLOBAL_GET, REG_IDX(arg)); + tcg_wasm_out_op(s, OPC_I64_POPCNT); + tcg_wasm_out_op_idx(s, OPC_GLOBAL_SET, REG_IDX(ret)); +} + static void tcg_wasm_out_setcond(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg1, TCGReg arg2, TCGCond cond) { @@ -1609,6 +1633,7 @@ static const TCGOutOpBinary outop_xor =3D { static void tgen_ctpop(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) { tcg_out_op_rr(s, INDEX_op_ctpop, a0, a1); + tcg_wasm_out_ctpop64(s, a0, a1); } =20 static TCGConstraintSetIndex cset_ctpop(TCGType type, unsigned flags) @@ -1665,9 +1690,15 @@ static const TCGOutOpUnary outop_bswap64 =3D { }; #endif =20 -static void tgen_neg(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) +static void tgen_neg_tci(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) { tcg_out_op_rr(s, INDEX_op_neg, a0, a1); + } + +static void tgen_neg(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) +{ + tgen_neg_tci(s, type, a0, a1); + tcg_wasm_out_neg(s, a0, a1); } =20 static const TCGOutOpUnary outop_neg =3D { @@ -1678,6 +1709,7 @@ static const TCGOutOpUnary outop_neg =3D { static void tgen_not(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) { tcg_out_op_rr(s, INDEX_op_not, a0, a1); + tcg_wasm_out_not(s, a0, a1); } =20 static const TCGOutOpUnary outop_not =3D { @@ -1710,7 +1742,7 @@ static void tgen_negsetcond(TCGContext *s, TCGType ty= pe, TCGCond cond, TCGReg dest, TCGReg arg1, TCGReg arg2) { tgen_setcond_tci(s, type, cond, dest, arg1, arg2); - tgen_neg(s, type, dest, dest); + tgen_neg_tci(s, type, dest, dest); tcg_wasm_out_negsetcond(s, type, dest, arg1, arg2, cond); } =20 --=20 2.43.0