From patchwork Wed Mar 8 16:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 660457 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp437386wrb; Wed, 8 Mar 2023 09:09:54 -0800 (PST) X-Google-Smtp-Source: AK7set/8zYrsAj9OxHblIvm3p/lXYKmOvvJMThXEJ8JnuphMvyP3uNxVSLkbgaUEqxSTaUmks56Z X-Received: by 2002:a05:7500:6787:b0:fb:1350:ad76 with SMTP id je7-20020a057500678700b000fb1350ad76mr618134gab.0.1678295394263; Wed, 08 Mar 2023 09:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678295394; cv=none; d=google.com; s=arc-20160816; b=DhCOgUAW/di/FmPsCf7qsQ3gCYEjFAyeCh/RJCwP75GPtpb4/wQj7wTdbuabYy8NHo P0pDG1BJxsErPaMEgZ7AXctWinjzsnctoCS3jTut9yWzfuL+S5e5ScAdjzttd/F76mR4 KBSyvDEeKgKIPlfTrTwzBBQP+yr9dMZHRJlGdJvbsiVy6sFrEFaPox1Kqluq2Wc33qth 3BFs27cYHQ2+j698dDEGwC48iYVK3QuxpEfpYXwRABeHvdAykgBWt1VbVClmSlSE3KAz Yp/7TC78E9ZhcIsqMGVVq9qshYrl+44YvZny38JSV6keNaW9G1EvW/CTRWHHu3vy2h6z g05Q== 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; bh=MANDDFEM3qq+VO4SNvb5gE2IiVSjN8LnA1pHlzfI32I=; b=RFdfvqrjNKI9OSDKI9cGeSAjUxYgkscLxHEdwqi1FFRZud39iCrIw9gKFvtemedKjn mjLwTyY3jNBZaB6spfo/mrzNovgpmB/TMrrdEbs9MhPbyOYQj4jqnMiWmCBbKl5Fc7TF 2+rOXHTs2sOWJxlbQfXwoJr4laLKCf/Aw9PP3nJt22vtfJZIt/2NyZOmmBsj2OAuKwgc EiXIQhtO4kMrYdCOMl0j8rjt4TcAykk7AxlNH0vudW40XLS9sSdiQD3F7cLFWeT93vU0 GYYh8dYFesSpp7iRDX2X+xs47Z7KNg8UoF3iV//VTv37nde14S3GQCPlRIL6LykulGMT Lnyw== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i25-20020a67dd99000000b00412dea8d470si5112722vsk.543.2023.03.08.09.09.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Mar 2023 09:09:54 -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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZx86-0004NZ-G5; Wed, 08 Mar 2023 11:59:06 -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 1pZx83-0004HE-36; Wed, 08 Mar 2023 11:59:03 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZx80-000426-Ox; Wed, 08 Mar 2023 11:59:02 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 4622B40102; Wed, 8 Mar 2023 19:58:33 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 0987613A; Wed, 8 Mar 2023 19:58:32 +0300 (MSK) Received: (nullmailer pid 2098324 invoked by uid 1000); Wed, 08 Mar 2023 16:58:31 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , Paolo Bonzini , Michael Tokarev Subject: [PATCH 24/47] target/i386: Fix BZHI instruction Date: Wed, 8 Mar 2023 19:57:27 +0300 Message-Id: <20230308165815.2098148-24-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308165035.2097594-1-mjt@msgid.tls.msk.ru> References: <20230308165035.2097594-1-mjt@msgid.tls.msk.ru> MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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 From: Richard Henderson We did not correctly handle N >= operand size. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1374 Signed-off-by: Richard Henderson Message-Id: <20230114233206.3118472-1-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini (cherry picked from commit 9ad2ba6e8e7fc195d0dd0b76ab38bd2fceb1bdd4) Signed-off-by: Michael Tokarev --- target/i386/tcg/emit.c.inc | 14 +++++++------- tests/tcg/i386/test-i386-bmi2.c | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 0d7c6e80ae..7296f3952c 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1145,20 +1145,20 @@ static void gen_BLSR(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) static void gen_BZHI(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { MemOp ot = decode->op[0].ot; - TCGv bound; + TCGv bound = tcg_constant_tl(ot == MO_64 ? 63 : 31); + TCGv zero = tcg_constant_tl(0); + TCGv mone = tcg_constant_tl(-1); - tcg_gen_ext8u_tl(s->T1, cpu_regs[s->vex_v]); - bound = tcg_constant_tl(ot == MO_64 ? 63 : 31); + tcg_gen_ext8u_tl(s->T1, s->T1); /* * Note that since we're using BMILG (in order to get O * cleared) we need to store the inverse into C. */ - tcg_gen_setcond_tl(TCG_COND_LT, cpu_cc_src, s->T1, bound); - tcg_gen_movcond_tl(TCG_COND_GT, s->T1, s->T1, bound, bound, s->T1); + tcg_gen_setcond_tl(TCG_COND_LEU, cpu_cc_src, s->T1, bound); - tcg_gen_movi_tl(s->A0, -1); - tcg_gen_shl_tl(s->A0, s->A0, s->T1); + tcg_gen_shl_tl(s->A0, mone, s->T1); + tcg_gen_movcond_tl(TCG_COND_LEU, s->A0, s->T1, bound, s->A0, zero); tcg_gen_andc_tl(s->T0, s->T0, s->A0); gen_op_update1_cc(s); diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi2.c index 982d4abda4..0244df7987 100644 --- a/tests/tcg/i386/test-i386-bmi2.c +++ b/tests/tcg/i386/test-i386-bmi2.c @@ -123,6 +123,9 @@ int main(int argc, char *argv[]) { result = bzhiq(mask, 0x1f); assert(result == (mask & ~(-1 << 30))); + result = bzhiq(mask, 0x40); + assert(result == mask); + result = rorxq(0x2132435465768798, 8); assert(result == 0x9821324354657687);