Skip to content

tests/tcg/ppc64[le]: add tests for xs{max,min}cqp and xs{max,min}[cj]dp #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: ppc-isa31-2112-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions target/ppc/fpu_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ VSX_MAX_MIN(xvminsp, minnum, 4, float32, VsrW(i))
void helper_##name(CPUPPCState *env, \
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
{ \
ppc_vsr_t t = *xt; \
ppc_vsr_t t = { }; \
bool vxsnan_flag = false, vex_flag = false; \
\
if (unlikely(tp##_is_any_nan(xa->fld) || \
Expand Down Expand Up @@ -2572,7 +2572,7 @@ VSX_MAX_MINC(XSMINCQP, minnum, float128, f128);
void helper_##name(CPUPPCState *env, \
ppc_vsr_t *xt, ppc_vsr_t *xa, ppc_vsr_t *xb) \
{ \
ppc_vsr_t t = *xt; \
ppc_vsr_t t = { }; \
bool vxsnan_flag = false, vex_flag = false; \
\
if (unlikely(float64_is_any_nan(xa->VsrD(0)))) { \
Expand Down
18 changes: 16 additions & 2 deletions tests/tcg/ppc64/Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ PPC64_TESTS=bcdsub non_signalling_xscv
endif
$(PPC64_TESTS): CFLAGS += -mpower8-vector

PPC64_TESTS += byte_reverse
PPC64_TESTS += mtfsf
PPC64_TESTS += byte_reverse mtfsf xsmaxmincqp xsmaxmincjdp
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_POWER10),)
xsmaxmincqp: CFLAGS += -mcpu=power10
run-xsmaxmincqp: QEMU_OPTS += -cpu POWER10
run-plugin-xsmaxmincqp-with-%: QEMU_OPTS += -cpu POWER10

xsmaxmincjdp: CFLAGS += -mcpu=power10
run-xsmaxmincjdp: QEMU_OPTS += -cpu POWER10
run-plugin-xsmaxmincjdp-with-%: QEMU_OPTS += -cpu POWER10

run-byte_reverse: QEMU_OPTS+=-cpu POWER10
run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10
else
xsmaxmincqp:
$(call skip-test, "BUILD of $@", "missing compiler support")
run-xsmaxmincqp:
$(call skip-test, "RUN of xsmaxmincqp", "not built")
run-plugin-xsmaxmincqp-with-%:
$(call skip-test, "RUN of xsmaxmincqp ($*)", "not built")

byte_reverse:
$(call skip-test, "BUILD of $@", "missing compiler support")
run-byte_reverse:
Expand Down
10 changes: 9 additions & 1 deletion tests/tcg/ppc64le/Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ endif
$(PPC64LE_TESTS): CFLAGS += -mpower8-vector

ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_POWER10),)
PPC64LE_TESTS += byte_reverse
PPC64LE_TESTS += byte_reverse xsmaxmincqp xsmaxmincjdp
endif
byte_reverse: CFLAGS += -mcpu=power10
run-byte_reverse: QEMU_OPTS+=-cpu POWER10
run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10

xsmaxmincjdp: CFLAGS += -mcpu=power10
run-xsmaxmincjdp: QEMU_OPTS += -cpu POWER10
run-plugin-xsmaxmincjdp-with-%: QEMU_OPTS += -cpu POWER10

xsmaxmincqp: CFLAGS += -mcpu=power10
run-xsmaxmincqp: QEMU_OPTS += -cpu POWER10
run-plugin-xsmaxmincqp-with-%: QEMU_OPTS += -cpu POWER10

PPC64LE_TESTS += mtfsf
PPC64LE_TESTS += signal_save_restore_xer

Expand Down
83 changes: 83 additions & 0 deletions tests/tcg/ppc64le/xsmaxmincjdp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <assert.h>
#include <limits.h>
#include <unistd.h>
#include <signal.h>
#include <stdint.h>

#define XSTR(x) #x
#define STR(x) XSTR(x)
#define I128(a, b) ((__int128)(a) << 64 | (b))

#define TEST(INSN, A, B, EXP) \
do { \
__uint128_t a = I128(A, 0); \
__uint128_t b = I128(B, 0); \
__uint128_t t; \
\
asm(INSN " %0, %1, %2\n\t" : "=wa"(t) : "wa"(a), "wa"(b)); \
\
assert(t == I128(EXP, 0)); \
} while (0)

static inline void test_nan()
{
TEST("xsmaxcdp", 0x42ULL, 0x7FF0000000000001ULL, 0x7FF0000000000001ULL);
TEST("xsmaxcdp", 0x7FF0000000000001ULL, 0x42ULL, 0x42ULL);

TEST("xsmaxcdp", 0x42ULL, 0x7FFF000000000000ULL, 0x7FFF000000000000ULL);
TEST("xsmaxcdp", 0x7FFF000000000000ULL, 0x42ULL, 0x42ULL);

TEST("xsmaxcdp", 0x42ULL, 0x7FF8000000000000ULL, 0x7FF8000000000000ULL);
TEST("xsmaxcdp", 0x7FF8000000000000ULL, 0x42ULL, 0x42ULL);

TEST("xsmincdp", 0x42ULL, 0x7FF0000000000001ULL, 0x7FF0000000000001ULL);
TEST("xsmincdp", 0x7FF0000000000001ULL, 0x42ULL, 0x42ULL);

TEST("xsmincdp", 0x42ULL, 0x7FFF000000000000ULL, 0x7FFF000000000000ULL);
TEST("xsmincdp", 0x7FFF000000000000ULL, 0x42ULL, 0x42ULL);

TEST("xsmincdp", 0x42ULL, 0x7FF8000000000000ULL, 0x7FF8000000000000ULL);
TEST("xsmincdp", 0x7FF8000000000000ULL, 0x42ULL, 0x42ULL);

TEST("xsmaxjdp", 0x42ULL, 0x7FF0000000000001ULL, 0x7FF0000000000001ULL);
TEST("xsmaxjdp", 0x7FF0000000000001ULL, 0x42ULL, 0x7FF0000000000001ULL);
TEST("xsmaxjdp", 0x7FF8000000000000ULL, 0x7FF0000000000001ULL,
0x7FF8000000000000ULL);
TEST("xsmaxjdp", 0x7FF0000000000001ULL, 0x7FF8000000000000ULL,
0x7FF0000000000001ULL);

TEST("xsminjdp", 0x42ULL, 0x7FF0000000000001ULL, 0x7FF0000000000001ULL);
TEST("xsminjdp", 0x7FF0000000000001ULL, 0x42ULL, 0x7FF0000000000001ULL);
TEST("xsminjdp", 0x7FF8000000000000ULL, 0x7FF0000000000001ULL,
0x7FF8000000000000ULL);
TEST("xsminjdp", 0x7FF0000000000001ULL, 0x7FF8000000000000ULL,
0x7FF0000000000001ULL);
}

static inline void test_general_case()
{
TEST("xsmaxcdp", 0xad53f789, 0xbeaab9c5, 0xbeaab9c5);
TEST("xsmaxcdp", 0x8600dd9ea0, 0x4b9f8cffd7, 0x8600dd9ea0);

TEST("xsmincdp", 0xad53f789, 0xbeaab9c5, 0xad53f789);
TEST("xsmincdp", 0x8600dd9ea0, 0x4b9f8cffd7, 0x4b9f8cffd7);

TEST("xsmaxjdp", 0xad53f789, 0xbeaab9c5, 0xbeaab9c5);
TEST("xsmaxjdp", 0x8600dd9ea0, 0x4b9f8cffd7, 0x8600dd9ea0);

TEST("xsminjdp", 0xad53f789, 0xbeaab9c5, 0xad53f789);
TEST("xsminjdp", 0x8600dd9ea0, 0x4b9f8cffd7, 0x4b9f8cffd7);
}

int main(void)
{
struct sigaction action;

action.sa_handler = _exit;
sigaction(SIGABRT, &action, NULL);

test_nan();
test_general_case();

return 0;
}
59 changes: 59 additions & 0 deletions tests/tcg/ppc64le/xsmaxmincqp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <assert.h>
#include <limits.h>
#include <unistd.h>
#include <signal.h>
#include <stdint.h>

#define XSTR(x) #x
#define STR(x) XSTR(x)
#define I128(a, b) ((__int128)(a) << 64 | (b))
#define MAX128(a, b) (a > b ? a : b)
#define MIN128(a, b) (a < b ? a : b)

#define TEST(INSN, H1, L1, H2, L2, EXP) \
do { \
__uint128_t a = I128(H1, L1); \
__uint128_t b = I128(H2, L2); \
__uint128_t t; \
\
asm(INSN " %0, %1, %2\n\t" : "=v"(t) : "v"(a), "v"(b)); \
\
assert(t == EXP); \
} while (0)

#define TEST_NAN(H1, L1, H2, L2) \
do { \
/* If any of the input is NaN, VRT <- VRB */ \
TEST("xsmaxcqp", H1, L1, H2, L2, I128(H2, L2)); \
TEST("xsmaxcqp", H2, L2, H1, L1, I128(H1, L1)); \
TEST("xsmincqp", H1, L1, H2, L2, I128(H2, L2)); \
TEST("xsmincqp", H2, L2, H1, L1, I128(H1, L1)); \
} while (0)

#define TEST_GENERAL_CASE(H1, L1, H2, L2) \
do { \
TEST("xsmaxcqp", H1, L1, H2, L2, MAX128(I128(H1, L1), I128(H2, L2))); \
TEST("xsmaxcqp", H1, L1, H2, L2, MAX128(I128(H1, L1), I128(H2, L2))); \
TEST("xsmincqp", H2, L2, H1, L1, MIN128(I128(H1, L1), I128(H2, L2))); \
TEST("xsmincqp", H2, L2, H1, L1, MIN128(I128(H1, L1), I128(H2, L2))); \
} while (0)

int main(void)
{
struct sigaction action;

action.sa_handler = _exit;
sigaction(SIGABRT, &action, NULL);

TEST_NAN(0xFFFFFFFFFFFFFFFFULL, 0xFFFFFFFFFFFFFFFFULL, 0x0ULL, 0X0ULL);
TEST_NAN(0xDEADC0DEULL, 0x0ULL, 0x7FFF000000000000ULL, 0x1ULL);

TEST_GENERAL_CASE(0x000087810000E078ULL, 0x0006E3C8000438F5ULL,
0x000B48600003780FULL, 0x00C304E00069660ULL);
TEST_GENERAL_CASE(0x0ULL, 0xF3C0C1FC8F3230ULL, 0x0ULL, 0xBEAAB9C5ULL);
TEST_GENERAL_CASE(0xC0583916EA04ULL, 0xB11DCFB3C40C58E9ULL,
0x32BB5C6435F8ULL, 0x3CDABBEC03DD171BULL);
TEST_GENERAL_CASE(0xDEADC0DEULL, 0x0ULL, 0x7FF8000000000000ULL, 0x1ULL);

return 0;
}