|
|
ed5979 |
From 120db3dfeb88c447f0e115c19b7ede704f8f80cb Mon Sep 17 00:00:00 2001
|
|
|
ed5979 |
From: Richard Henderson <richard.henderson@linaro.org>
|
|
|
ed5979 |
Date: Sat, 14 Jan 2023 13:05:41 -1000
|
|
|
ed5979 |
Subject: [PATCH 2/8] tests/tcg/i386: Introduce and use reg_t consistently
|
|
|
ed5979 |
MIME-Version: 1.0
|
|
|
ed5979 |
Content-Type: text/plain; charset=UTF-8
|
|
|
ed5979 |
Content-Transfer-Encoding: 8bit
|
|
|
ed5979 |
|
|
|
ed5979 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
ed5979 |
RH-MergeRequest: 154: target/i386: fix bugs in emulation of BMI instructions
|
|
|
ed5979 |
RH-Bugzilla: 2173590
|
|
|
ed5979 |
RH-Acked-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
|
|
|
ed5979 |
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
|
ed5979 |
RH-Acked-by: Bandan Das <None>
|
|
|
ed5979 |
RH-Commit: [2/7] 843a677555414170392db21c828bef3dc3c29300 (bonzini/rhel-qemu-kvm)
|
|
|
ed5979 |
|
|
|
ed5979 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2173590
|
|
|
ed5979 |
Upstream-Status: merged
|
|
|
ed5979 |
|
|
|
ed5979 |
Define reg_t based on the actual register width.
|
|
|
ed5979 |
Define the inlines using that type. This will allow
|
|
|
ed5979 |
input registers to 32-bit insns to be set to 64-bit
|
|
|
ed5979 |
values on x86-64, which allows testing various edge cases.
|
|
|
ed5979 |
|
|
|
ed5979 |
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
|
|
|
ed5979 |
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
|
|
|
ed5979 |
Message-Id: <20230114230542.3116013-2-richard.henderson@linaro.org>
|
|
|
ed5979 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
ed5979 |
(cherry picked from commit 5d62d6649cd367b5b4a3676e7514d2f9ca86cb03)
|
|
|
ed5979 |
---
|
|
|
ed5979 |
tests/tcg/i386/test-i386-bmi2.c | 182 ++++++++++++++++----------------
|
|
|
ed5979 |
1 file changed, 93 insertions(+), 89 deletions(-)
|
|
|
ed5979 |
|
|
|
ed5979 |
diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi2.c
|
|
|
ed5979 |
index 5fadf47510..3c3ef85513 100644
|
|
|
ed5979 |
--- a/tests/tcg/i386/test-i386-bmi2.c
|
|
|
ed5979 |
+++ b/tests/tcg/i386/test-i386-bmi2.c
|
|
|
ed5979 |
@@ -3,34 +3,40 @@
|
|
|
ed5979 |
#include <stdint.h>
|
|
|
ed5979 |
#include <stdio.h>
|
|
|
ed5979 |
|
|
|
ed5979 |
+#ifdef __x86_64
|
|
|
ed5979 |
+typedef uint64_t reg_t;
|
|
|
ed5979 |
+#else
|
|
|
ed5979 |
+typedef uint32_t reg_t;
|
|
|
ed5979 |
+#endif
|
|
|
ed5979 |
+
|
|
|
ed5979 |
#define insn1q(name, arg0) \
|
|
|
ed5979 |
-static inline uint64_t name##q(uint64_t arg0) \
|
|
|
ed5979 |
+static inline reg_t name##q(reg_t arg0) \
|
|
|
ed5979 |
{ \
|
|
|
ed5979 |
- uint64_t result64; \
|
|
|
ed5979 |
+ reg_t result64; \
|
|
|
ed5979 |
asm volatile (#name "q %1, %0" : "=r"(result64) : "rm"(arg0)); \
|
|
|
ed5979 |
return result64; \
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
#define insn1l(name, arg0) \
|
|
|
ed5979 |
-static inline uint32_t name##l(uint32_t arg0) \
|
|
|
ed5979 |
+static inline reg_t name##l(reg_t arg0) \
|
|
|
ed5979 |
{ \
|
|
|
ed5979 |
- uint32_t result32; \
|
|
|
ed5979 |
+ reg_t result32; \
|
|
|
ed5979 |
asm volatile (#name "l %k1, %k0" : "=r"(result32) : "rm"(arg0)); \
|
|
|
ed5979 |
return result32; \
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
#define insn2q(name, arg0, c0, arg1, c1) \
|
|
|
ed5979 |
-static inline uint64_t name##q(uint64_t arg0, uint64_t arg1) \
|
|
|
ed5979 |
+static inline reg_t name##q(reg_t arg0, reg_t arg1) \
|
|
|
ed5979 |
{ \
|
|
|
ed5979 |
- uint64_t result64; \
|
|
|
ed5979 |
+ reg_t result64; \
|
|
|
ed5979 |
asm volatile (#name "q %2, %1, %0" : "=r"(result64) : c0(arg0), c1(arg1)); \
|
|
|
ed5979 |
return result64; \
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
#define insn2l(name, arg0, c0, arg1, c1) \
|
|
|
ed5979 |
-static inline uint32_t name##l(uint32_t arg0, uint32_t arg1) \
|
|
|
ed5979 |
+static inline reg_t name##l(reg_t arg0, reg_t arg1) \
|
|
|
ed5979 |
{ \
|
|
|
ed5979 |
- uint32_t result32; \
|
|
|
ed5979 |
+ reg_t result32; \
|
|
|
ed5979 |
asm volatile (#name "l %k2, %k1, %k0" : "=r"(result32) : c0(arg0), c1(arg1)); \
|
|
|
ed5979 |
return result32; \
|
|
|
ed5979 |
}
|
|
|
ed5979 |
@@ -65,130 +71,128 @@ insn1l(blsr, src)
|
|
|
ed5979 |
int main(int argc, char *argv[]) {
|
|
|
ed5979 |
uint64_t ehlo = 0x202020204f4c4845ull;
|
|
|
ed5979 |
uint64_t mask = 0xa080800302020001ull;
|
|
|
ed5979 |
- uint32_t result32;
|
|
|
ed5979 |
+ reg_t result;
|
|
|
ed5979 |
|
|
|
ed5979 |
#ifdef __x86_64
|
|
|
ed5979 |
- uint64_t result64;
|
|
|
ed5979 |
-
|
|
|
ed5979 |
/* 64 bits */
|
|
|
ed5979 |
- result64 = andnq(mask, ehlo);
|
|
|
ed5979 |
- assert(result64 == 0x002020204d4c4844);
|
|
|
ed5979 |
+ result = andnq(mask, ehlo);
|
|
|
ed5979 |
+ assert(result == 0x002020204d4c4844);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = pextq(ehlo, mask);
|
|
|
ed5979 |
- assert(result64 == 133);
|
|
|
ed5979 |
+ result = pextq(ehlo, mask);
|
|
|
ed5979 |
+ assert(result == 133);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = pdepq(result64, mask);
|
|
|
ed5979 |
- assert(result64 == (ehlo & mask));
|
|
|
ed5979 |
+ result = pdepq(result, mask);
|
|
|
ed5979 |
+ assert(result == (ehlo & mask));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = pextq(-1ull, mask);
|
|
|
ed5979 |
- assert(result64 == 511); /* mask has 9 bits set */
|
|
|
ed5979 |
+ result = pextq(-1ull, mask);
|
|
|
ed5979 |
+ assert(result == 511); /* mask has 9 bits set */
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = pdepq(-1ull, mask);
|
|
|
ed5979 |
- assert(result64 == mask);
|
|
|
ed5979 |
+ result = pdepq(-1ull, mask);
|
|
|
ed5979 |
+ assert(result == mask);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = bextrq(mask, 0x3f00);
|
|
|
ed5979 |
- assert(result64 == (mask & ~INT64_MIN));
|
|
|
ed5979 |
+ result = bextrq(mask, 0x3f00);
|
|
|
ed5979 |
+ assert(result == (mask & ~INT64_MIN));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = bextrq(mask, 0x1038);
|
|
|
ed5979 |
- assert(result64 == 0xa0);
|
|
|
ed5979 |
+ result = bextrq(mask, 0x1038);
|
|
|
ed5979 |
+ assert(result == 0xa0);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = bextrq(mask, 0x10f8);
|
|
|
ed5979 |
- assert(result64 == 0);
|
|
|
ed5979 |
+ result = bextrq(mask, 0x10f8);
|
|
|
ed5979 |
+ assert(result == 0);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = blsiq(0x30);
|
|
|
ed5979 |
- assert(result64 == 0x10);
|
|
|
ed5979 |
+ result = blsiq(0x30);
|
|
|
ed5979 |
+ assert(result == 0x10);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = blsiq(0x30ull << 32);
|
|
|
ed5979 |
- assert(result64 == 0x10ull << 32);
|
|
|
ed5979 |
+ result = blsiq(0x30ull << 32);
|
|
|
ed5979 |
+ assert(result == 0x10ull << 32);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = blsmskq(0x30);
|
|
|
ed5979 |
- assert(result64 == 0x1f);
|
|
|
ed5979 |
+ result = blsmskq(0x30);
|
|
|
ed5979 |
+ assert(result == 0x1f);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = blsrq(0x30);
|
|
|
ed5979 |
- assert(result64 == 0x20);
|
|
|
ed5979 |
+ result = blsrq(0x30);
|
|
|
ed5979 |
+ assert(result == 0x20);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = blsrq(0x30ull << 32);
|
|
|
ed5979 |
- assert(result64 == 0x20ull << 32);
|
|
|
ed5979 |
+ result = blsrq(0x30ull << 32);
|
|
|
ed5979 |
+ assert(result == 0x20ull << 32);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = bzhiq(mask, 0x3f);
|
|
|
ed5979 |
- assert(result64 == (mask & ~INT64_MIN));
|
|
|
ed5979 |
+ result = bzhiq(mask, 0x3f);
|
|
|
ed5979 |
+ assert(result == (mask & ~INT64_MIN));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = bzhiq(mask, 0x1f);
|
|
|
ed5979 |
- assert(result64 == (mask & ~(-1 << 30)));
|
|
|
ed5979 |
+ result = bzhiq(mask, 0x1f);
|
|
|
ed5979 |
+ assert(result == (mask & ~(-1 << 30)));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = rorxq(0x2132435465768798, 8);
|
|
|
ed5979 |
- assert(result64 == 0x9821324354657687);
|
|
|
ed5979 |
+ result = rorxq(0x2132435465768798, 8);
|
|
|
ed5979 |
+ assert(result == 0x9821324354657687);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = sarxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
- assert(result64 == 0xffffeeddccbbaa99);
|
|
|
ed5979 |
+ result = sarxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
+ assert(result == 0xffffeeddccbbaa99);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = sarxq(0x77eeddccbbaa9988, 8 | 64);
|
|
|
ed5979 |
- assert(result64 == 0x0077eeddccbbaa99);
|
|
|
ed5979 |
+ result = sarxq(0x77eeddccbbaa9988, 8 | 64);
|
|
|
ed5979 |
+ assert(result == 0x0077eeddccbbaa99);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = shrxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
- assert(result64 == 0x00ffeeddccbbaa99);
|
|
|
ed5979 |
+ result = shrxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
+ assert(result == 0x00ffeeddccbbaa99);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = shrxq(0x77eeddccbbaa9988, 8 | 192);
|
|
|
ed5979 |
- assert(result64 == 0x0077eeddccbbaa99);
|
|
|
ed5979 |
+ result = shrxq(0x77eeddccbbaa9988, 8 | 192);
|
|
|
ed5979 |
+ assert(result == 0x0077eeddccbbaa99);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result64 = shlxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
- assert(result64 == 0xeeddccbbaa998800);
|
|
|
ed5979 |
+ result = shlxq(0xffeeddccbbaa9988, 8);
|
|
|
ed5979 |
+ assert(result == 0xeeddccbbaa998800);
|
|
|
ed5979 |
#endif
|
|
|
ed5979 |
|
|
|
ed5979 |
/* 32 bits */
|
|
|
ed5979 |
- result32 = andnl(mask, ehlo);
|
|
|
ed5979 |
- assert(result32 == 0x04d4c4844);
|
|
|
ed5979 |
+ result = andnl(mask, ehlo);
|
|
|
ed5979 |
+ assert(result == 0x04d4c4844);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = pextl((uint32_t) ehlo, mask);
|
|
|
ed5979 |
- assert(result32 == 5);
|
|
|
ed5979 |
+ result = pextl((uint32_t) ehlo, mask);
|
|
|
ed5979 |
+ assert(result == 5);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = pdepl(result32, mask);
|
|
|
ed5979 |
- assert(result32 == (uint32_t)(ehlo & mask));
|
|
|
ed5979 |
+ result = pdepl(result, mask);
|
|
|
ed5979 |
+ assert(result == (uint32_t)(ehlo & mask));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = pextl(-1u, mask);
|
|
|
ed5979 |
- assert(result32 == 7); /* mask has 3 bits set */
|
|
|
ed5979 |
+ result = pextl(-1u, mask);
|
|
|
ed5979 |
+ assert(result == 7); /* mask has 3 bits set */
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = pdepl(-1u, mask);
|
|
|
ed5979 |
- assert(result32 == (uint32_t)mask);
|
|
|
ed5979 |
+ result = pdepl(-1u, mask);
|
|
|
ed5979 |
+ assert(result == (uint32_t)mask);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = bextrl(mask, 0x1f00);
|
|
|
ed5979 |
- assert(result32 == (mask & ~INT32_MIN));
|
|
|
ed5979 |
+ result = bextrl(mask, 0x1f00);
|
|
|
ed5979 |
+ assert(result == (mask & ~INT32_MIN));
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = bextrl(ehlo, 0x1018);
|
|
|
ed5979 |
- assert(result32 == 0x4f);
|
|
|
ed5979 |
+ result = bextrl(ehlo, 0x1018);
|
|
|
ed5979 |
+ assert(result == 0x4f);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = bextrl(mask, 0x1038);
|
|
|
ed5979 |
- assert(result32 == 0);
|
|
|
ed5979 |
+ result = bextrl(mask, 0x1038);
|
|
|
ed5979 |
+ assert(result == 0);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = blsil(0xffff);
|
|
|
ed5979 |
- assert(result32 == 1);
|
|
|
ed5979 |
+ result = blsil(0xffff);
|
|
|
ed5979 |
+ assert(result == 1);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = blsmskl(0x300);
|
|
|
ed5979 |
- assert(result32 == 0x1ff);
|
|
|
ed5979 |
+ result = blsmskl(0x300);
|
|
|
ed5979 |
+ assert(result == 0x1ff);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = blsrl(0xffc);
|
|
|
ed5979 |
- assert(result32 == 0xff8);
|
|
|
ed5979 |
+ result = blsrl(0xffc);
|
|
|
ed5979 |
+ assert(result == 0xff8);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = bzhil(mask, 0xf);
|
|
|
ed5979 |
- assert(result32 == 1);
|
|
|
ed5979 |
+ result = bzhil(mask, 0xf);
|
|
|
ed5979 |
+ assert(result == 1);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = rorxl(0x65768798, 8);
|
|
|
ed5979 |
- assert(result32 == 0x98657687);
|
|
|
ed5979 |
+ result = rorxl(0x65768798, 8);
|
|
|
ed5979 |
+ assert(result == 0x98657687);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = sarxl(0xffeeddcc, 8);
|
|
|
ed5979 |
- assert(result32 == 0xffffeedd);
|
|
|
ed5979 |
+ result = sarxl(0xffeeddcc, 8);
|
|
|
ed5979 |
+ assert(result == 0xffffeedd);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = sarxl(0x77eeddcc, 8 | 32);
|
|
|
ed5979 |
- assert(result32 == 0x0077eedd);
|
|
|
ed5979 |
+ result = sarxl(0x77eeddcc, 8 | 32);
|
|
|
ed5979 |
+ assert(result == 0x0077eedd);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = shrxl(0xffeeddcc, 8);
|
|
|
ed5979 |
- assert(result32 == 0x00ffeedd);
|
|
|
ed5979 |
+ result = shrxl(0xffeeddcc, 8);
|
|
|
ed5979 |
+ assert(result == 0x00ffeedd);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = shrxl(0x77eeddcc, 8 | 128);
|
|
|
ed5979 |
- assert(result32 == 0x0077eedd);
|
|
|
ed5979 |
+ result = shrxl(0x77eeddcc, 8 | 128);
|
|
|
ed5979 |
+ assert(result == 0x0077eedd);
|
|
|
ed5979 |
|
|
|
ed5979 |
- result32 = shlxl(0xffeeddcc, 8);
|
|
|
ed5979 |
- assert(result32 == 0xeeddcc00);
|
|
|
ed5979 |
+ result = shlxl(0xffeeddcc, 8);
|
|
|
ed5979 |
+ assert(result == 0xeeddcc00);
|
|
|
ed5979 |
|
|
|
ed5979 |
return 0;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
--
|
|
|
ed5979 |
2.39.1
|
|
|
ed5979 |
|