hw/display/pxa2xx: Remove use of BITS in pxa2xx_template.h
[qemu/ar7.git] / tests / tcg / i386 / test-i386-fbstp.c
blob73bf56b9dc3fed01831e0b98b054993034c4298b
1 /* Test fbstp instruction. */
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <string.h>
7 union u {
8 struct { uint64_t sig; uint16_t sign_exp; } s;
9 long double ld;
12 volatile union u ld_invalid_1 = { .s = { 1, 1234 } };
13 volatile union u ld_invalid_2 = { .s = { 0, 1234 } };
14 volatile union u ld_invalid_3 = { .s = { 0, 0x7fff } };
15 volatile union u ld_invalid_4 = { .s = { (UINT64_C(1) << 63) - 1, 0x7fff } };
17 int main(void)
19 int ret = 0;
20 unsigned char out[10];
21 memset(out, 0xfe, sizeof out);
22 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-0.0L) : "st");
23 out[9] &= 0x80;
24 if (memcmp(out, "\0\0\0\0\0\0\0\0\0\x80", sizeof out) != 0) {
25 printf("FAIL: fbstp -0\n");
26 ret = 1;
28 memset(out, 0x12, sizeof out);
29 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-0.1L) : "st");
30 out[9] &= 0x80;
31 if (memcmp(out, "\0\0\0\0\0\0\0\0\0\x80", sizeof out) != 0) {
32 printf("FAIL: fbstp -0.1\n");
33 ret = 1;
35 memset(out, 0x1f, sizeof out);
36 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-987654321987654321.0L) :
37 "st");
38 out[9] &= 0x80;
39 if (memcmp(out, "\x21\x43\x65\x87\x19\x32\x54\x76\x98\x80",
40 sizeof out) != 0) {
41 printf("FAIL: fbstp -987654321987654321\n");
42 ret = 1;
44 memset(out, 0x12, sizeof out);
45 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (999999999999999999.5L) :
46 "st");
47 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
48 printf("FAIL: fbstp 999999999999999999.5\n");
49 ret = 1;
51 memset(out, 0x12, sizeof out);
52 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (1000000000000000000.0L) :
53 "st");
54 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
55 printf("FAIL: fbstp 1000000000000000000\n");
56 ret = 1;
58 memset(out, 0x12, sizeof out);
59 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (1e30L) : "st");
60 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
61 printf("FAIL: fbstp 1e30\n");
62 ret = 1;
64 memset(out, 0x12, sizeof out);
65 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-999999999999999999.5L) :
66 "st");
67 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
68 printf("FAIL: fbstp -999999999999999999.5\n");
69 ret = 1;
71 memset(out, 0x12, sizeof out);
72 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-1000000000000000000.0L) :
73 "st");
74 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
75 printf("FAIL: fbstp -1000000000000000000\n");
76 ret = 1;
78 memset(out, 0x12, sizeof out);
79 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-1e30L) : "st");
80 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
81 printf("FAIL: fbstp -1e30\n");
82 ret = 1;
84 memset(out, 0x12, sizeof out);
85 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (__builtin_infl()) : "st");
86 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
87 printf("FAIL: fbstp inf\n");
88 ret = 1;
90 memset(out, 0x12, sizeof out);
91 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-__builtin_infl()) :
92 "st");
93 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
94 printf("FAIL: fbstp -inf\n");
95 ret = 1;
97 memset(out, 0x12, sizeof out);
98 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (__builtin_nanl("")) :
99 "st");
100 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
101 printf("FAIL: fbstp nan\n");
102 ret = 1;
104 memset(out, 0x12, sizeof out);
105 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-__builtin_nanl("")) :
106 "st");
107 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
108 printf("FAIL: fbstp -nan\n");
109 ret = 1;
111 memset(out, 0x12, sizeof out);
112 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_1.ld) :
113 "st");
114 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
115 printf("FAIL: fbstp invalid 1\n");
116 ret = 1;
118 memset(out, 0x12, sizeof out);
119 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_2.ld) :
120 "st");
121 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
122 printf("FAIL: fbstp invalid 2\n");
123 ret = 1;
125 memset(out, 0x12, sizeof out);
126 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_3.ld) :
127 "st");
128 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
129 printf("FAIL: fbstp invalid 3\n");
130 ret = 1;
132 memset(out, 0x12, sizeof out);
133 __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_4.ld) :
134 "st");
135 if (memcmp(out, "\0\0\0\0\0\0\0\xc0\xff\xff", sizeof out) != 0) {
136 printf("FAIL: fbstp invalid 4\n");
137 ret = 1;
139 return ret;