1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsxfsi
7 #if HAS_80_BIT_LONG_DOUBLE
8 // Returns: convert a to a unsigned int, rounding toward zero.
9 // Negative values all become zero.
11 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
12 // su_int is a 32 bit integral type
13 // value in long double is representable in su_int or is negative
14 // (no range checking performed)
16 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
17 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
19 COMPILER_RT_ABI su_int
__fixunsxfsi(long double a
);
21 int test__fixunsxfsi(long double a
, su_int expected
)
23 su_int x
= __fixunsxfsi(a
);
25 printf("error in __fixunsxfsi(%LA) = %X, expected %X\n", a
, x
, expected
);
29 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
30 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
35 #if HAS_80_BIT_LONG_DOUBLE
36 if (test__fixunsxfsi(0.0, 0))
39 if (test__fixunsxfsi(0.5, 0))
41 if (test__fixunsxfsi(0.99, 0))
43 if (test__fixunsxfsi(1.0, 1))
45 if (test__fixunsxfsi(1.5, 1))
47 if (test__fixunsxfsi(1.99, 1))
49 if (test__fixunsxfsi(2.0, 2))
51 if (test__fixunsxfsi(2.01, 2))
53 if (test__fixunsxfsi(-0.5, 0))
55 if (test__fixunsxfsi(-0.99, 0))
58 if (test__fixunsxfsi(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
60 if (test__fixunsxfsi(-1.5, 0))
62 if (test__fixunsxfsi(-1.99, 0))
64 if (test__fixunsxfsi(-2.0, 0))
66 if (test__fixunsxfsi(-2.01, 0))
70 if (test__fixunsxfsi(0x1.000000p
+31, 0x80000000))
72 if (test__fixunsxfsi(0x1.FFFFFEp
+31, 0xFFFFFF00))
74 if (test__fixunsxfsi(0x1.FFFFFEp
+30, 0x7FFFFF80))
76 if (test__fixunsxfsi(0x1.FFFFFCp
+30, 0x7FFFFF00))
80 if (test__fixunsxfsi(-0x1.FFFFFEp
+30, 0))
82 if (test__fixunsxfsi(-0x1.FFFFFCp
+30, 0))
86 if (test__fixunsxfsi(0x1.FFFFFFFEp
+31, 0xFFFFFFFF))
88 if (test__fixunsxfsi(0x1.FFFFFFFC00000p
+30, 0x7FFFFFFF))
90 if (test__fixunsxfsi(0x1.FFFFFFF800000p
+30, 0x7FFFFFFE))