aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/i386/test-i386-fisttp.c
blob: 16af59a7749f6dfa3f149b73b390dc4a39351a0b (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
/* Test fisttpl and fisttpll instructions.  */

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

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

volatile union u ld_invalid_1 = { .s = { 1, 1234 } };

int main(void)
{
    int ret = 0;
    int32_t res_32;
    int64_t res_64;
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (0x1p100L) : "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl 0x1p100\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-0x1p100L) : "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl -0x1p100\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (__builtin_infl()) :
                      "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl inf\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-__builtin_infl()) :
                      "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl -inf\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (__builtin_nanl("")) :
                      "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl nan\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) :
                      "t" (-__builtin_nanl("")) : "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl -nan\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) :
                      "st");
    if (res_32 != INT32_MIN) {
        printf("FAIL: fisttpl invalid\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (0x1p100L) : "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll 0x1p100\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-0x1p100L) : "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll -0x1p100\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (__builtin_infl()) :
                      "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll inf\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-__builtin_infl()) :
                      "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll -inf\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) :
                      "t" (__builtin_nanl("")) : "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll nan\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) :
                      "t" (-__builtin_nanl("")) : "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll -nan\n");
        ret = 1;
    }
    __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) :
                      "st");
    if (res_64 != INT64_MIN) {
        printf("FAIL: fisttpll invalid\n");
        ret = 1;
    }
    return ret;
}