From patchwork Sun Jan 15 01:21:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 642942 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp478011pvb; Sat, 14 Jan 2023 17:21:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXtwBY9skSKLkseAk7HQ+iZp1ZvcXx3LOBS85nNweR90YveHg4gCOkxIXk8P1a3Hzm1az+D8 X-Received: by 2002:a05:6214:188e:b0:4c6:eca0:4870 with SMTP id cx14-20020a056214188e00b004c6eca04870mr20994582qvb.30.1673745714363; Sat, 14 Jan 2023 17:21:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673745714; cv=none; d=google.com; s=arc-20160816; b=0E4NoRxJmTZVOyZGuRJ6JOGbqjPMwlKBFBC8MAEOIcPIYpOihdtQOFICn/7EVN5ruu 7J7TgVLrOK7j42oo3+7WczYh8JZQYj1Afw68XIcfgRxHO9TGpPD11Lu7LYqlEvi3BIHw i6pNPHqeVdZiChlX/+JcF/aSF7t8q/Hf2DLAENz1pewgGATuFsUGtut0QB5E1+zBJVtt SKX3kTCtM4jYzc34iPiA/CJUeM2VhtSxGKHgZKj0fzOnQ9b7R6CUJxtIE6RlXCOACrfC aWDK4VdfUuXm6vyfNUTfwt6aotKKWPa4ek/pie7sOcZQx33zHzvBtimav94vZ0Rv66Ms mlMw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=+4lg7eradCYPVsrMRZCCKNQC6F+FnSFuqVVZBIJoIWA=; b=LOHcTqIWRfGupxPZB7LuH/ctzhv3LtQNEgd3Oq9mz86XJzWP7wQt7/MlRgAlSy9Apk KC8pWalxoixuxzrXvHnoBZlZ4n5V8DjiVL2WxveES6OoTkxCb6Uum/q5CYJteywD/yYP xHNvMcy0fRFX31BRsYQGh4KFTXfG59pjCbLOfDgqoCAtw5hNbmBJSmhtpghIgyhhccwV H4YCziBRxBtA3eljyPfuEdZl9b3eYhKLvNhsSohu1oTMdpVl19TyLMx/5bazIBttoawi o5QmicYr9FfEMyDyh4nDHaG07CGSyfQnzhL/4svWJ+TRVTRAVlEK6mj1CWdTytoPN7Z/ kwCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mM1JOI5L; 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 m2-20020a05620a220200b007049d89b123si13999793qkh.364.2023.01.14.17.21.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 14 Jan 2023 17:21: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; dkim=pass header.i=@linaro.org header.s=google header.b=mM1JOI5L; 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 1pGrhx-0007Dq-Dh; Sat, 14 Jan 2023 20:21:13 -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 1pGrhw-0007D7-Kx for qemu-devel@nongnu.org; Sat, 14 Jan 2023 20:21:12 -0500 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGrht-0002Ct-5H for qemu-devel@nongnu.org; Sat, 14 Jan 2023 20:21:12 -0500 Received: by mail-pg1-x534.google.com with SMTP id s67so17376385pgs.3 for ; Sat, 14 Jan 2023 17:21:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+4lg7eradCYPVsrMRZCCKNQC6F+FnSFuqVVZBIJoIWA=; b=mM1JOI5LcPOEfxkTxe7m/P4llx7yijlwQ+MkuUwtWgZmqYHxVR80VaEGkBsQ0N90kr WL4LHpMX0Su2QlSJfNV9vZGoifJ73S0SumVhiL1M1eXWLr9fD+kuMMG6SxMuhL/SV437 Byc0zk3r7raqwhi63324c5/3q3qe7g6Sdl77dlCqfPtrkAViQKQntDqPWvPYxNtspYAC VI/D1jlSfVs74vuFBwFPMJQYLgztTJh2PdSO9GtZD7/6q0pwXdIXptc0Bo50z+mF7aHn M8cA+ulGRAY9o15gJJ27qwqAwBhGld2FUhgcoN5Oeivywi+6clYH1+iDVEsw0xdCB6B4 Xb8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+4lg7eradCYPVsrMRZCCKNQC6F+FnSFuqVVZBIJoIWA=; b=ze5+SIMb+bzCAb6waNwpG3W/UGomNVD9EdEvLpOg6Dws+54ZdCGGWCHQm5V+dXjGLg aW8Pi/Gd8NWEkEoWBaGjEChubXx5bKqpBPZi5I6pv5Ve7Dze7KLT6cvWWEOlW7wQT0w6 jW7DE0Avl2DHo1qCAM0bl2VeOimZg/asqSzUH2vBIyZSccCG/NT4VYp9gdFkpZnnjzgi NZztEr0r75u35iQBpLavCAfKYip9LL/DtSY23rHyEt18UPaEDlIQBjvyKutFqaGoRvca gIcWFKRRid5Er7Zqo/vXu6rzVv4II+4jsWzhDda9h469nNjJr6sNB5vr1VUVe3EUV7Cm aXyQ== X-Gm-Message-State: AFqh2kojxXVx0tRTuXiusamZdh1I7t1yAe7/tgB1Kx2jh6vNk84ZQtdD GIUPuxt7mnd4i8B/heyW/SGrymwmnztYmX7R X-Received: by 2002:a62:870f:0:b0:582:bb80:58d7 with SMTP id i15-20020a62870f000000b00582bb8058d7mr16247883pfe.26.1673745667023; Sat, 14 Jan 2023 17:21:07 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id 5-20020a621505000000b005772d55df03sm15704260pfv.35.2023.01.14.17.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 17:21:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH] target/i386: Fix 32-bit AD[CO]X insns in 64-bit mode Date: Sat, 14 Jan 2023 15:21:03 -1000 Message-Id: <20230115012103.3131796-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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 Failure to truncate the inputs results in garbage for the carry-out. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1373 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tests/tcg/x86_64/adox.c | 69 ++++++++++++++++++++++++++++++++ target/i386/tcg/emit.c.inc | 2 + tests/tcg/x86_64/Makefile.target | 3 ++ 3 files changed, 74 insertions(+) create mode 100644 tests/tcg/x86_64/adox.c diff --git a/tests/tcg/x86_64/adox.c b/tests/tcg/x86_64/adox.c new file mode 100644 index 0000000000..36be644c8b --- /dev/null +++ b/tests/tcg/x86_64/adox.c @@ -0,0 +1,69 @@ +/* See if ADOX give expected results */ + +#include +#include +#include + +static uint64_t adoxq(bool *c_out, uint64_t a, uint64_t b, bool c) +{ + asm ("addl $0x7fffffff, %k1\n\t" + "adoxq %2, %0\n\t" + "seto %b1" + : "+r"(a), "=&r"(c) : "r"(b), "1"((int)c)); + *c_out = c; + return a; +} + +static uint64_t adoxl(bool *c_out, uint64_t a, uint64_t b, bool c) +{ + asm ("addl $0x7fffffff, %k1\n\t" + "adoxl %k2, %k0\n\t" + "seto %b1" + : "+r"(a), "=&r"(c) : "r"(b), "1"((int)c)); + *c_out = c; + return a; +} + +int main() +{ + uint64_t r; + bool c; + + r = adoxq(&c, 0, 0, 0); + assert(r == 0); + assert(c == 0); + + r = adoxl(&c, 0, 0, 0); + assert(r == 0); + assert(c == 0); + + r = adoxl(&c, 0x100000000, 0, 0); + assert(r == 0); + assert(c == 0); + + r = adoxq(&c, 0, 0, 1); + assert(r == 1); + assert(c == 0); + + r = adoxl(&c, 0, 0, 1); + assert(r == 1); + assert(c == 0); + + r = adoxq(&c, -1, -1, 0); + assert(r == -2); + assert(c == 1); + + r = adoxl(&c, -1, -1, 0); + assert(r == 0xfffffffe); + assert(c == 1); + + r = adoxq(&c, -1, -1, 1); + assert(r == -1); + assert(c == 1); + + r = adoxl(&c, -1, -1, 1); + assert(r == 0xffffffff); + assert(c == 1); + + return 0; +} diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 1eace1231a..d44c51209d 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1042,6 +1042,8 @@ static void gen_ADCOX(DisasContext *s, CPUX86State *env, MemOp ot, int cc_op) #ifdef TARGET_X86_64 case MO_32: /* If TL is 64-bit just do everything in 64-bit arithmetic. */ + tcg_gen_ext32u_tl(s->T0, s->T0); + tcg_gen_ext32u_tl(s->T1, s->T1); tcg_gen_add_i64(s->T0, s->T0, s->T1); tcg_gen_add_i64(s->T0, s->T0, carry_in); tcg_gen_shri_i64(carry_out, s->T0, 32); diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target index 4eac78293f..e64aab1b81 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -12,11 +12,14 @@ ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) X86_64_TESTS += vsyscall X86_64_TESTS += noexec X86_64_TESTS += cmpxchg +X86_64_TESTS += adox TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=$(MULTIARCH_TESTS) endif +adox: CFLAGS=-O2 + run-test-i386-ssse3: QEMU_OPTS += -cpu max run-plugin-test-i386-ssse3-%: QEMU_OPTS += -cpu max