xref: /openbmc/qemu/tests/tcg/i386/test-i386-fisttp.c (revision f0984d40)
1 /* Test fisttpl and fisttpll instructions.  */
2 
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 union u {
8     struct { uint64_t sig; uint16_t sign_exp; } s;
9     long double ld;
10 };
11 
12 volatile union u ld_invalid_1 = { .s = { 1, 1234 } };
13 
14 int main(void)
15 {
16     int ret = 0;
17     int32_t res_32;
18     int64_t res_64;
19     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (0x1p100L) : "st");
20     if (res_32 != INT32_MIN) {
21         printf("FAIL: fisttpl 0x1p100\n");
22         ret = 1;
23     }
24     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-0x1p100L) : "st");
25     if (res_32 != INT32_MIN) {
26         printf("FAIL: fisttpl -0x1p100\n");
27         ret = 1;
28     }
29     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (__builtin_infl()) :
30                       "st");
31     if (res_32 != INT32_MIN) {
32         printf("FAIL: fisttpl inf\n");
33         ret = 1;
34     }
35     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-__builtin_infl()) :
36                       "st");
37     if (res_32 != INT32_MIN) {
38         printf("FAIL: fisttpl -inf\n");
39         ret = 1;
40     }
41     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (__builtin_nanl("")) :
42                       "st");
43     if (res_32 != INT32_MIN) {
44         printf("FAIL: fisttpl nan\n");
45         ret = 1;
46     }
47     __asm__ volatile ("fisttpl %0" : "=m" (res_32) :
48                       "t" (-__builtin_nanl("")) : "st");
49     if (res_32 != INT32_MIN) {
50         printf("FAIL: fisttpl -nan\n");
51         ret = 1;
52     }
53     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) :
54                       "st");
55     if (res_32 != INT32_MIN) {
56         printf("FAIL: fisttpl invalid\n");
57         ret = 1;
58     }
59     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (0x1p100L) : "st");
60     if (res_64 != INT64_MIN) {
61         printf("FAIL: fisttpll 0x1p100\n");
62         ret = 1;
63     }
64     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-0x1p100L) : "st");
65     if (res_64 != INT64_MIN) {
66         printf("FAIL: fisttpll -0x1p100\n");
67         ret = 1;
68     }
69     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (__builtin_infl()) :
70                       "st");
71     if (res_64 != INT64_MIN) {
72         printf("FAIL: fisttpll inf\n");
73         ret = 1;
74     }
75     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-__builtin_infl()) :
76                       "st");
77     if (res_64 != INT64_MIN) {
78         printf("FAIL: fisttpll -inf\n");
79         ret = 1;
80     }
81     __asm__ volatile ("fisttpll %0" : "=m" (res_64) :
82                       "t" (__builtin_nanl("")) : "st");
83     if (res_64 != INT64_MIN) {
84         printf("FAIL: fisttpll nan\n");
85         ret = 1;
86     }
87     __asm__ volatile ("fisttpll %0" : "=m" (res_64) :
88                       "t" (-__builtin_nanl("")) : "st");
89     if (res_64 != INT64_MIN) {
90         printf("FAIL: fisttpll -nan\n");
91         ret = 1;
92     }
93     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) :
94                       "st");
95     if (res_64 != INT64_MIN) {
96         printf("FAIL: fisttpll invalid\n");
97         ret = 1;
98     }
99     return ret;
100 }
101