[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 004/101] test/tcg/ppc64le: test mtfsf
From: |
Cédric Le Goater |
Subject: |
[PULL 004/101] test/tcg/ppc64le: test mtfsf |
Date: |
Thu, 16 Dec 2021 21:24:37 +0100 |
From: "Lucas Mateus Castro (alqotel)" <lucas.araujo@eldorado.org.br>
Added tests for the mtfsf to check if FI bit of FPSCR is being set
and if exception calls are being made correctly.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Message-Id: <20211201163808.440385-3-lucas.araujo@eldorado.org.br>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
tests/tcg/ppc64le/mtfsf.c | 61 +++++++++++++++++++++++++++++++
tests/tcg/ppc64/Makefile.target | 1 +
tests/tcg/ppc64le/Makefile.target | 1 +
3 files changed, 63 insertions(+)
create mode 100644 tests/tcg/ppc64le/mtfsf.c
diff --git a/tests/tcg/ppc64le/mtfsf.c b/tests/tcg/ppc64le/mtfsf.c
new file mode 100644
index 000000000000..b3d31f3637d9
--- /dev/null
+++ b/tests/tcg/ppc64le/mtfsf.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <signal.h>
+#include <sys/prctl.h>
+
+#define FPSCR_VE 7 /* Floating-point invalid operation exception enable */
+#define FPSCR_VXSOFT 10 /* Floating-point invalid operation exception (soft) */
+#define FPSCR_FI 17 /* Floating-point fraction inexact */
+
+#define FP_VE (1ull << FPSCR_VE)
+#define FP_VXSOFT (1ull << FPSCR_VXSOFT)
+#define FP_FI (1ull << FPSCR_FI)
+
+void sigfpe_handler(int sig, siginfo_t *si, void *ucontext)
+{
+ if (si->si_code == FPE_FLTINV) {
+ exit(0);
+ }
+ exit(1);
+}
+
+int main(void)
+{
+ union {
+ double d;
+ long long ll;
+ } fpscr;
+
+ struct sigaction sa = {
+ .sa_sigaction = sigfpe_handler,
+ .sa_flags = SA_SIGINFO
+ };
+
+ /*
+ * Enable the MSR bits F0 and F1 to enable exceptions.
+ * This shouldn't be needed in linux-user as these bits are enabled by
+ * default, but this allows to execute either in a VM or a real machine
+ * to compare the behaviors.
+ */
+ prctl(PR_SET_FPEXC, PR_FP_EXC_PRECISE);
+
+ /* First test if the FI bit is being set correctly */
+ fpscr.ll = FP_FI;
+ __builtin_mtfsf(0b11111111, fpscr.d);
+ fpscr.d = __builtin_mffs();
+ assert((fpscr.ll & FP_FI) != 0);
+
+ /* Then test if the deferred exception is being called correctly */
+ sigaction(SIGFPE, &sa, NULL);
+
+ /*
+ * Although the VXSOFT exception has been chosen, based on test in a Power9
+ * any combination of exception bit + its enabling bit should work.
+ * But if a different exception is chosen si_code check should
+ * change accordingly.
+ */
+ fpscr.ll = FP_VE | FP_VXSOFT;
+ __builtin_mtfsf(0b11111111, fpscr.d);
+
+ return 1;
+}
diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target
index 6ab7934fdff9..8f4c7ac4ed7d 100644
--- a/tests/tcg/ppc64/Makefile.target
+++ b/tests/tcg/ppc64/Makefile.target
@@ -11,6 +11,7 @@ endif
bcdsub: CFLAGS += -mpower8-vector
PPC64_TESTS += byte_reverse
+PPC64_TESTS += mtfsf
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_POWER10),)
run-byte_reverse: QEMU_OPTS+=-cpu POWER10
run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10
diff --git a/tests/tcg/ppc64le/Makefile.target
b/tests/tcg/ppc64le/Makefile.target
index ba2fde5ff1c3..e031f65adcb3 100644
--- a/tests/tcg/ppc64le/Makefile.target
+++ b/tests/tcg/ppc64le/Makefile.target
@@ -16,6 +16,7 @@ byte_reverse: CFLAGS += -mcpu=power10
run-byte_reverse: QEMU_OPTS+=-cpu POWER10
run-plugin-byte_reverse-with-%: QEMU_OPTS+=-cpu POWER10
+PPC64LE_TESTS += mtfsf
PPC64LE_TESTS += signal_save_restore_xer
TESTS += $(PPC64LE_TESTS)
--
2.31.1
- [PULL v2 000/101] ppc queue, Cédric Le Goater, 2021/12/16
- [PULL 003/101] target/ppc: Fixed call to deferred exception, Cédric Le Goater, 2021/12/16
- [PULL 001/101] pseries: Update SLOF firmware image, Cédric Le Goater, 2021/12/16
- [PULL 010/101] ivshmem-test.c: enable test_ivshmem_server for ppc64 arch, Cédric Le Goater, 2021/12/16
- [PULL 002/101] hw/ppc/mac.h: Remove MAX_CPUS macro, Cédric Le Goater, 2021/12/16
- [PULL 004/101] test/tcg/ppc64le: test mtfsf,
Cédric Le Goater <=
- [PULL 005/101] target/ppc: ppc_store_fpscr doesn't update bits 0 to 28 and 52, Cédric Le Goater, 2021/12/16
- [PULL 009/101] ivshmem.c: change endianness to LITTLE_ENDIAN, Cédric Le Goater, 2021/12/16
- [PULL 027/101] target/ppc: Update float_invalid_op_addsub for new flags, Cédric Le Goater, 2021/12/16
- [PULL 026/101] softfloat: Add flag specific to signaling nans, Cédric Le Goater, 2021/12/16
- [PULL 012/101] docs: Minor updates on the powernv documentation., Cédric Le Goater, 2021/12/16
- [PULL 007/101] target/ppc: Implement Vector Extract Mask, Cédric Le Goater, 2021/12/16
- [PULL 011/101] pci-host: Allow extended config space access for PowerNV PHB4 model, Cédric Le Goater, 2021/12/16
- [PULL 006/101] target/ppc: Implement Vector Expand Mask, Cédric Le Goater, 2021/12/16
- [PULL 023/101] softfloat: Add flags specific to Inf / Inf and 0 / 0, Cédric Le Goater, 2021/12/16
- [PULL 025/101] softfloat: Add flag specific to convert non-nan to int, Cédric Le Goater, 2021/12/16