aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/i386/test-i386-fxam.c
blob: ddd76ca42d202dbbd34d4c2478e1f6e7ba628f10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* Test fxam instruction.  */

#include <stdint.h>
#include <stdio.h>

union u {
    struct { uint64_t sig; uint16_t sign_exp; } s;
    long double ld;
};

volatile union u ld_pseudo_m16382 = { .s = { UINT64_C(1) << 63, 0 } };
volatile union u ld_pseudo_nm16382 = { .s = { UINT64_C(1) << 63, 0x8000 } };
volatile union u ld_invalid_1 = { .s = { 1, 1234 } };
volatile union u ld_invalid_2 = { .s = { 0, 1234 } };
volatile union u ld_invalid_3 = { .s = { 0, 0x7fff } };
volatile union u ld_invalid_4 = { .s = { (UINT64_C(1) << 63) - 1, 0x7fff } };
volatile union u ld_invalid_n1 = { .s = { 1, 0x8123 } };
volatile union u ld_invalid_n2 = { .s = { 0, 0x8123 } };
volatile union u ld_invalid_n3 = { .s = { 0, 0xffff } };
volatile union u ld_invalid_n4 = { .s = { (UINT64_C(1) << 63) - 1, 0xffff } };

#define C0 (1 << 8)
#define C1 (1 << 9)
#define C2 (1 << 10)
#define C3 (1 << 14)
#define FLAGS (C0 | C1 | C2 | C3)

int main(void)
{
    short sw;
    int ret = 0;
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (0.0L));
    if ((sw & FLAGS) != C3) {
        printf("FAIL: +0\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-0.0L));
    if ((sw & FLAGS) != (C3 | C1)) {
        printf("FAIL: -0\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (1.0L));
    if ((sw & FLAGS) != C2) {
        printf("FAIL: +normal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-1.0L));
    if ((sw & FLAGS) != (C2 | C1)) {
        printf("FAIL: -normal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (__builtin_infl()));
    if ((sw & FLAGS) != (C2 | C0)) {
        printf("FAIL: +inf\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-__builtin_infl()));
    if ((sw & FLAGS) != (C2 | C1 | C0)) {
        printf("FAIL: -inf\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (__builtin_nanl("")));
    if ((sw & FLAGS) != C0) {
        printf("FAIL: +nan\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-__builtin_nanl("")));
    if ((sw & FLAGS) != (C1 | C0)) {
        printf("FAIL: -nan\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (__builtin_nansl("")));
    if ((sw & FLAGS) != C0) {
        printf("FAIL: +snan\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-__builtin_nansl("")));
    if ((sw & FLAGS) != (C1 | C0)) {
        printf("FAIL: -snan\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (0x1p-16445L));
    if ((sw & FLAGS) != (C3 | C2)) {
        printf("FAIL: +denormal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (-0x1p-16445L));
    if ((sw & FLAGS) != (C3 | C2 | C1)) {
        printf("FAIL: -denormal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_pseudo_m16382.ld));
    if ((sw & FLAGS) != (C3 | C2)) {
        printf("FAIL: +pseudo-denormal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_pseudo_nm16382.ld));
    if ((sw & FLAGS) != (C3 | C2 | C1)) {
        printf("FAIL: -pseudo-denormal\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_1.ld));
    if ((sw & FLAGS) != 0) {
        printf("FAIL: +invalid 1\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_n1.ld));
    if ((sw & FLAGS) != C1) {
        printf("FAIL: -invalid 1\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_2.ld));
    if ((sw & FLAGS) != 0) {
        printf("FAIL: +invalid 2\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_n2.ld));
    if ((sw & FLAGS) != C1) {
        printf("FAIL: -invalid 2\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_3.ld));
    if ((sw & FLAGS) != 0) {
        printf("FAIL: +invalid 3\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_n3.ld));
    if ((sw & FLAGS) != C1) {
        printf("FAIL: -invalid 3\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_4.ld));
    if ((sw & FLAGS) != 0) {
        printf("FAIL: +invalid 4\n");
        ret = 1;
    }
    __asm__ volatile ("fxam\nfnstsw" : "=a" (sw) : "t" (ld_invalid_n4.ld));
    if ((sw & FLAGS) != C1) {
        printf("FAIL: -invalid 4\n");
        ret = 1;
    }
    return ret;
}