xref: /qemu/tests/tcg/ppc64/non_signalling_xscv.c (revision 37b0dba45c4e44a02000a4170f25af0110f501d5)
184ade98eSMatheus Ferst #include <stdio.h>
284ade98eSMatheus Ferst #include <stdint.h>
384ade98eSMatheus Ferst #include <inttypes.h>
484ade98eSMatheus Ferst #include <assert.h>
584ade98eSMatheus Ferst 
684ade98eSMatheus Ferst #define TEST(INSN, B_HI, B_LO, T_HI, T_LO) \
784ade98eSMatheus Ferst     do {                                                                \
884ade98eSMatheus Ferst         uint64_t th, tl, bh = B_HI, bl = B_LO;                          \
968455cf5SMatheus Ferst         asm("mtvsrd 32, %2\n\t"                                         \
1068455cf5SMatheus Ferst             "mtvsrd 33, %3\n\t"                                         \
1168455cf5SMatheus Ferst             "xxmrghd 32, 32, 33\n\t"                                    \
1268455cf5SMatheus Ferst             INSN " 32, 32\n\t"                                          \
1368455cf5SMatheus Ferst             "mfvsrd %0, 32\n\t"                                         \
1468455cf5SMatheus Ferst             "xxswapd 32, 32\n\t"                                        \
1568455cf5SMatheus Ferst             "mfvsrd %1, 32\n\t"                                         \
1684ade98eSMatheus Ferst             : "=r" (th), "=r" (tl)                                      \
1784ade98eSMatheus Ferst             : "r" (bh), "r" (bl)                                        \
1868455cf5SMatheus Ferst             : "v0", "v1");                                              \
1984ade98eSMatheus Ferst         printf(INSN "(0x%016" PRIx64 "%016" PRIx64 ") = 0x%016" PRIx64  \
2084ade98eSMatheus Ferst                "%016" PRIx64 "\n", bh, bl, th, tl);                     \
2184ade98eSMatheus Ferst         assert(th == T_HI && tl == T_LO);                               \
2284ade98eSMatheus Ferst     } while (0)
2384ade98eSMatheus Ferst 
main(void)2484ade98eSMatheus Ferst int main(void)
2584ade98eSMatheus Ferst {
2684ade98eSMatheus Ferst     /* SNaN shouldn't be silenced */
2784ade98eSMatheus Ferst     TEST("xscvspdpn", 0x7fbfffff00000000ULL, 0x0, 0x7ff7ffffe0000000ULL, 0x0);
2884ade98eSMatheus Ferst     TEST("xscvdpspn", 0x7ff7ffffffffffffULL, 0x0, 0x7fbfffff7fbfffffULL, 0x0);
2984ade98eSMatheus Ferst 
3084ade98eSMatheus Ferst     /*
3184ade98eSMatheus Ferst      * SNaN inputs having no significant bits in the upper 23 bits of the
3284ade98eSMatheus Ferst      * signifcand will return Infinity as the result.
3384ade98eSMatheus Ferst      */
3484ade98eSMatheus Ferst     TEST("xscvdpspn", 0x7ff000001fffffffULL, 0x0, 0x7f8000007f800000ULL, 0x0);
3584ade98eSMatheus Ferst 
3684ade98eSMatheus Ferst     return 0;
3784ade98eSMatheus Ferst }
38