xref: /qemu/tests/tcg/i386/test-i386-fscale.c (revision 0d48b436327955c69e2eb53f88aba9aa1e0dbaa0)
1 /* Test fscale instruction.  */
2 
3 #include <stdint.h>
4 #include <stdio.h>
5 
6 union u {
7     struct { uint64_t sig; uint16_t sign_exp; } s;
8     long double ld;
9 };
10 
11 volatile long double ld_res;
12 
13 int isnan_ld(long double x)
14 {
15   union u tmp = { .ld = x };
16   return ((tmp.s.sign_exp & 0x7fff) == 0x7fff &&
17           (tmp.s.sig >> 63) != 0 &&
18           (tmp.s.sig << 1) != 0);
19 }
20 
21 int issignaling_ld(long double x)
22 {
23     union u tmp = { .ld = x };
24     return isnan_ld(x) && (tmp.s.sig & UINT64_C(0x4000000000000000)) == 0;
25 }
26 
27 int main(void)
28 {
29     int ret = 0;
30     __asm__ volatile ("fscale" : "=t" (ld_res) :
31                       "0" (2.5L), "u" (__builtin_nansl("")));
32     if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
33         printf("FAIL: fscale snan\n");
34         ret = 1;
35     }
36     return ret;
37 }
38