1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_fixunssfti |
3 | // REQUIRES: int128 |
4 | |
5 | #include "int_lib.h" |
6 | #include <stdio.h> |
7 | |
8 | #ifdef CRT_HAS_128BIT |
9 | |
10 | // Returns: convert a to a unsigned long long, rounding toward zero. |
11 | // Negative values all become zero. |
12 | |
13 | // Assumption: float is a IEEE 32 bit floating point type |
14 | // tu_int is a 64 bit integral type |
15 | // value in float is representable in tu_int or is negative |
16 | // (no range checking performed) |
17 | |
18 | // seee eeee emmm mmmm mmmm mmmm mmmm mmmm |
19 | |
20 | COMPILER_RT_ABI tu_int __fixunssfti(float a); |
21 | |
22 | int test__fixunssfti(float a, tu_int expected) |
23 | { |
24 | tu_int x = __fixunssfti(a); |
25 | if (x != expected) |
26 | { |
27 | utwords xt; |
28 | xt.all = x; |
29 | utwords expectedt; |
30 | expectedt.all = expected; |
31 | printf(format: "error in __fixunssfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n" , |
32 | a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); |
33 | } |
34 | return x != expected; |
35 | } |
36 | |
37 | char assumption_1[sizeof(tu_int) == 2*sizeof(di_int)] = {0}; |
38 | char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; |
39 | char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; |
40 | |
41 | #endif |
42 | |
43 | int main() |
44 | { |
45 | #ifdef CRT_HAS_128BIT |
46 | if (test__fixunssfti(a: 0.0F, expected: 0)) |
47 | return 1; |
48 | |
49 | if (test__fixunssfti(a: 0.5F, expected: 0)) |
50 | return 1; |
51 | if (test__fixunssfti(a: 0.99F, expected: 0)) |
52 | return 1; |
53 | if (test__fixunssfti(a: 1.0F, expected: 1)) |
54 | return 1; |
55 | if (test__fixunssfti(a: 1.5F, expected: 1)) |
56 | return 1; |
57 | if (test__fixunssfti(a: 1.99F, expected: 1)) |
58 | return 1; |
59 | if (test__fixunssfti(a: 2.0F, expected: 2)) |
60 | return 1; |
61 | if (test__fixunssfti(a: 2.01F, expected: 2)) |
62 | return 1; |
63 | if (test__fixunssfti(a: -0.5F, expected: 0)) |
64 | return 1; |
65 | if (test__fixunssfti(a: -0.99F, expected: 0)) |
66 | return 1; |
67 | #if !TARGET_LIBGCC |
68 | if (test__fixunssfti(a: -1.0F, expected: 0)) // libgcc ignores "returns 0 for negative input" spec |
69 | return 1; |
70 | if (test__fixunssfti(a: -1.5F, expected: 0)) |
71 | return 1; |
72 | if (test__fixunssfti(a: -1.99F, expected: 0)) |
73 | return 1; |
74 | if (test__fixunssfti(a: -2.0F, expected: 0)) |
75 | return 1; |
76 | if (test__fixunssfti(a: -2.01F, expected: 0)) |
77 | return 1; |
78 | #endif |
79 | |
80 | if (test__fixunssfti(a: 0x1.FFFFFEp+63F, expected: 0xFFFFFF0000000000ULL)) |
81 | return 1; |
82 | if (test__fixunssfti(a: 0x1.000000p+63F, expected: 0x8000000000000000ULL)) |
83 | return 1; |
84 | if (test__fixunssfti(a: 0x1.FFFFFEp+62F, expected: 0x7FFFFF8000000000LL)) |
85 | return 1; |
86 | if (test__fixunssfti(a: 0x1.FFFFFCp+62F, expected: 0x7FFFFF0000000000LL)) |
87 | return 1; |
88 | |
89 | if (test__fixunssfti(a: 0x1.FFFFFEp+127F, expected: make_ti(h: 0xFFFFFF0000000000ULL, l: 0))) |
90 | return 1; |
91 | if (test__fixunssfti(a: 0x1.000000p+127F, expected: make_ti(h: 0x8000000000000000ULL, l: 0))) |
92 | return 1; |
93 | if (test__fixunssfti(a: 0x1.FFFFFEp+126F, expected: make_ti(h: 0x7FFFFF8000000000LL, l: 0))) |
94 | return 1; |
95 | if (test__fixunssfti(a: 0x1.FFFFFCp+126F, expected: make_ti(h: 0x7FFFFF0000000000LL, l: 0))) |
96 | return 1; |
97 | |
98 | #if !TARGET_LIBGCC |
99 | if (test__fixunssfti(a: -0x1.FFFFFEp+62F, expected: 0x0000000000000000LL)) |
100 | return 1; |
101 | if (test__fixunssfti(a: -0x1.FFFFFCp+62F, expected: 0x0000000000000000LL)) |
102 | return 1; |
103 | if (test__fixunssfti(a: -0x1.FFFFFEp+126F, expected: 0x0000000000000000LL)) |
104 | return 1; |
105 | if (test__fixunssfti(a: -0x1.FFFFFCp+126F, expected: 0x0000000000000000LL)) |
106 | return 1; |
107 | #endif |
108 | |
109 | #endif |
110 | return 0; |
111 | } |
112 | |