From 2d37bd91ae9f0477112a595bb688dd42d99daf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Colombo?= Date: Wed, 19 Jan 2022 16:36:03 -0300 Subject: [PATCH] tests/tcg/ppc64[le]: add test for xvtlsbb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: VĂ­ctor Colombo --- tests/tcg/ppc64/Makefile.target | 12 +++++++ tests/tcg/ppc64le/Makefile.target | 6 +++- tests/tcg/ppc64le/xvtlsbb.c | 54 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/ppc64le/xvtlsbb.c diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target index 0368007028c9a..1e26567f80bad 100644 --- a/tests/tcg/ppc64/Makefile.target +++ b/tests/tcg/ppc64/Makefile.target @@ -12,9 +12,14 @@ $(PPC64_TESTS): CFLAGS += -mpower8-vector PPC64_TESTS += byte_reverse PPC64_TESTS += mtfsf +PPC64_TESTS += xvtlsbb ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_POWER10),) run-byte_reverse: QEMU_OPTS+=-cpu POWER10 run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10 + +xvtlsbb: CFLAGS += -mcpu=power10 +run-xvtlsbb: QEMU_OPTS += -cpu POWER10 +run-plugin-xvtlsbb-with-%: QEMU_OPTS += -cpu POWER10 else byte_reverse: $(call skip-test, "BUILD of $@", "missing compiler support") @@ -22,6 +27,13 @@ run-byte_reverse: $(call skip-test, "RUN of byte_reverse", "not built") run-plugin-byte_reverse-with-%: $(call skip-test, "RUN of byte_reverse ($*)", "not built") + +xvtlsbb: + $(call skip-test, "BUILD of $@", "missing compiler support") +run-xvtlsbb: + $(call skip-test, "RUN of xvtlsbb", "not built") +run-plugin-xvtlsbb-with-%: + $(call skip-test, "RUN of xvtlsbb ($*)", "not built") endif PPC64_TESTS += signal_save_restore_xer diff --git a/tests/tcg/ppc64le/Makefile.target b/tests/tcg/ppc64le/Makefile.target index 480ff0898d7ea..4f47d3e0601f5 100644 --- a/tests/tcg/ppc64le/Makefile.target +++ b/tests/tcg/ppc64le/Makefile.target @@ -10,12 +10,16 @@ endif $(PPC64LE_TESTS): CFLAGS += -mpower8-vector ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_POWER10),) -PPC64LE_TESTS += byte_reverse +PPC64LE_TESTS += byte_reverse xvtlsbb endif byte_reverse: CFLAGS += -mcpu=power10 run-byte_reverse: QEMU_OPTS+=-cpu POWER10 run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10 +xvtlsbb: CFLAGS += -mcpu=power10 +run-xvtlsbb: QEMU_OPTS += -cpu POWER10 +run-plugin-xvtlsbb-with-%: QEMU_OPTS += -cpu POWER10 + PPC64LE_TESTS += mtfsf PPC64LE_TESTS += signal_save_restore_xer diff --git a/tests/tcg/ppc64le/xvtlsbb.c b/tests/tcg/ppc64le/xvtlsbb.c new file mode 100644 index 0000000000000..47306d59599db --- /dev/null +++ b/tests/tcg/ppc64le/xvtlsbb.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#define XSTR(x) #x +#define STR(x) XSTR(x) +#define I128(a, b) ((__int128)(a) << 64 | (b)) + +#define TEST(H, L, BF, EXP) \ + do { \ + uint32_t cr; \ + __uint128_t xb = I128(H, L); \ + \ + asm("xvtlsbb %1, %x2\n\t" \ + "mfcr %0\n\t" \ + : "=r"(cr) \ + : "i"(BF), "wa"(xb) \ + : "cr" STR(BF)); \ + \ + cr = (cr >> (4 * (7 - BF))) & 0xf; \ + assert(cr == EXP); \ + } while (0) + +#define TESTN(H, L, EXP) \ + do { \ + TEST(H, L, 0, EXP); \ + TEST(H, L, 1, EXP); \ + TEST(H, L, 2, EXP); \ + TEST(H, L, 3, EXP); \ + TEST(H, L, 4, EXP); \ + TEST(H, L, 5, EXP); \ + TEST(H, L, 6, EXP); \ + TEST(H, L, 7, EXP); \ + } while (0) + +int main(void) +{ + struct sigaction action; + + action.sa_handler = _exit; + sigaction(SIGABRT, &action, NULL); + + TESTN(0x0000000000000000ULL, 0x0000000000000000ULL, 0b0010); + TESTN(0xFFFFFFFFFFFFFFFFULL, 0xFFFFFFFFFFFFFFFFULL, 0b1000); + TESTN(0xEEEEEEEEEEEEEEEEULL, 0xEEEEEEEEEEEEEEEEULL, 0b0010); + TESTN(0x7777777777777777ULL, 0x7777777777777777ULL, 0b1000); + TESTN(0x0000000000000000ULL, 0xFFFFFFFFFFFFFFFFULL, 0b0000); + TESTN(0xFFFFFFFFFFFFFFFFULL, 0x0000000000000000ULL, 0b0000); + TESTN(0x000000000000FFFFULL, 0x000000000000FFFFULL, 0b0000); + + return 0; +}