From nobody Fri Mar 29 15:00:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634150650539311.65943575662595; Wed, 13 Oct 2021 11:44:10 -0700 (PDT) Received: from localhost ([::1]:55244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1majEX-0005ok-6Y for importer@patchew.org; Wed, 13 Oct 2021 14:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1majCQ-000474-FE for qemu-devel@nongnu.org; Wed, 13 Oct 2021 14:41:58 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:45043) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1majCO-0000xE-6E for qemu-devel@nongnu.org; Wed, 13 Oct 2021 14:41:58 -0400 Received: by mail-lf1-x12c.google.com with SMTP id y26so15936644lfa.11 for ; Wed, 13 Oct 2021 11:41:52 -0700 (PDT) Received: from localhost.localdomain ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id j18sm22095lfg.255.2021.10.13.11.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 11:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jVEww1lzp0MjFUAYOIjx49odZWcfEctNMccayO6Ru3s=; b=DXZeAE/Jum7NFs11Eiqke40nX0dVUBNRm1Xr4o9xMzyVgYZGyOlzsoEpFWcZMYY4G1 QcrHL2vpCrqzmuRl74ZMqGMjtQgCfZHrqAb8c+KOFp9QNaOlca55QtHbmcBRdvDi3wsn bNdEb5zbSCJeWJrwAYM38pJNaenJw9VpGyhWiVkZqVniAUr1npGgFQZs/v/JWCDJuB6G QEIBLEliZHVR2gbr5v9fs7ts5zIJ2By9S1tz2g2Kl1isE9QeFAxSETZdXemJEjKyCCMC CP28MXvcKwEXXEsVu8hNbV88hLblbKsl6AcHAOfPjQzmhOzd+dN9+Ixt9PKjpKznt4sh 0sUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jVEww1lzp0MjFUAYOIjx49odZWcfEctNMccayO6Ru3s=; b=13qm+73w5QloEsokvi45O+nPytT3ae1pBQYCo88yCeAjpztS+OU8CsvyVynx9Go7H/ fL4BtUgrRolfIz9gyEwXcw5s7N9NoAwSdkvrgmtu2pzowZz522rr20WjwEhbHNUnEBWU zjVKbN+4BZoVMD1YiQk2aZ+UWYtL1/QwAAYqWOJi3vysdkXzEVNf/+hPYHPstdVH6YYP LrETfTzLciJR7Oj4wRsCHUbu+e2/giN43T5kv0lnOQ1h3sKUWEUFF7Y6Or+oU1GbKLgE Yx5VewNmLprNcs58aeI84b0H5ERIsWj0OaygFCfGGhbUmali73PUkdTtCOtKw7PZYkHh ATOg== X-Gm-Message-State: AOAM5317WKj46wcHK+ajy/3wtMuGwRazkYrTiJKZ3Y8M1CWFsBeIfQv2 tqfz+tc3oCz7ZaiSYXjW2ZAYAm4Zyj/7PQ== X-Google-Smtp-Source: ABdhPJwcBYn/BHNNics1n0i0zTrvjgj2yzn+U5LUskZvHasQemaiRw8EnCPbxvlhIhvISqQEirH9JA== X-Received: by 2002:a05:651c:617:: with SMTP id k23mr1114672lje.402.1634150511104; Wed, 13 Oct 2021 11:41:51 -0700 (PDT) From: Philipp Tomsich To: qemu-devel@nongnu.org Subject: [PATCH] target/riscv: Fix orc.b implementation Date: Wed, 13 Oct 2021 20:41:25 +0200 Message-Id: <20211013184125.2010897-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.25.1 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=2a00:1450:4864:20::12c; envelope-from=philipp.tomsich@vrull.eu; helo=mail-lf1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-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: Alistair Francis , Richard Henderson , Philipp Tomsich , Vincent Palatin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1634150651442100001 Content-Type: text/plain; charset="utf-8" The earlier implementation fell into a corner case for bytes that were 0x01, giving a wrong result (but not affecting our application test cases for strings, as an ASCII value 0x01 is rare in those...). This changes the algorithm to: 1. Mask out the high-bit of each bytes (so that each byte is <=3D 127). 2. Add 127 to each byte (i.e. if the low 7 bits are not 0, this will overf= low into the highest bit of each byte). 3. Bitwise-or the original value back in (to cover those cases where the source byte was exactly 128) to saturate the high-bit. 4. Shift-and-mask (implemented as a mask-and-shift) to extract the MSB of each byte into its LSB. 5. Multiply with 0xff to fan out the LSB to all bits of each byte. Fixes: d7a4fcb034 ("target/riscv: Add orc.b instruction for Zbb, removing g= orc/gorci") Signed-off-by: Philipp Tomsich Reported-by: Vincent Palatin Reviewed-by: Richard Henderson Tested-by: Vincent Palatin --- target/riscv/insn_trans/trans_rvb.c.inc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_tr= ans/trans_rvb.c.inc index 185c3e9a60..3095624f32 100644 --- a/target/riscv/insn_trans/trans_rvb.c.inc +++ b/target/riscv/insn_trans/trans_rvb.c.inc @@ -249,13 +249,16 @@ static bool trans_rev8_64(DisasContext *ctx, arg_rev8= _64 *a) static void gen_orc_b(TCGv ret, TCGv source1) { TCGv tmp =3D tcg_temp_new(); - TCGv ones =3D tcg_constant_tl(dup_const_tl(MO_8, 0x01)); + TCGv low7 =3D tcg_constant_tl(dup_const_tl(MO_8, 0x7f)); =20 - /* Set lsb in each byte if the byte was zero. */ - tcg_gen_sub_tl(tmp, source1, ones); - tcg_gen_andc_tl(tmp, tmp, source1); + /* Set msb in each byte if the byte was non-zero. */ + tcg_gen_and_tl(tmp, source1, low7); + tcg_gen_add_tl(tmp, tmp, low7); + tcg_gen_or_tl(tmp, tmp, source1); + + /* Extract the msb to the lsb in each byte */ + tcg_gen_andc_tl(tmp, tmp, low7); tcg_gen_shri_tl(tmp, tmp, 7); - tcg_gen_andc_tl(tmp, ones, tmp); =20 /* Replicate the lsb of each byte across the byte. */ tcg_gen_muli_tl(ret, tmp, 0xff); --=20 2.25.1