1 //===-- fixunsxfsi_test.c - Test __fixunsxfsi -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __fixunsxfsi for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
17 #if HAS_80_BIT_LONG_DOUBLE
18 // Returns: convert a to a unsigned int, rounding toward zero.
19 // Negative values all become zero.
21 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22 // su_int is a 32 bit integral type
23 // value in long double is representable in su_int or is negative
24 // (no range checking performed)
26 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
27 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
29 su_int
__fixunsxfsi(long double a
);
31 int test__fixunsxfsi(long double a
, su_int expected
)
33 su_int x
= __fixunsxfsi(a
);
35 printf("error in __fixunsxfsi(%LA) = %X, expected %X\n", a
, x
, expected
);
39 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
40 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
45 #if HAS_80_BIT_LONG_DOUBLE
46 if (test__fixunsxfsi(0.0, 0))
49 if (test__fixunsxfsi(0.5, 0))
51 if (test__fixunsxfsi(0.99, 0))
53 if (test__fixunsxfsi(1.0, 1))
55 if (test__fixunsxfsi(1.5, 1))
57 if (test__fixunsxfsi(1.99, 1))
59 if (test__fixunsxfsi(2.0, 2))
61 if (test__fixunsxfsi(2.01, 2))
63 if (test__fixunsxfsi(-0.5, 0))
65 if (test__fixunsxfsi(-0.99, 0))
68 if (test__fixunsxfsi(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
70 if (test__fixunsxfsi(-1.5, 0))
72 if (test__fixunsxfsi(-1.99, 0))
74 if (test__fixunsxfsi(-2.0, 0))
76 if (test__fixunsxfsi(-2.01, 0))
80 if (test__fixunsxfsi(0x1.000000p
+31, 0x80000000))
82 if (test__fixunsxfsi(0x1.FFFFFEp
+31, 0xFFFFFF00))
84 if (test__fixunsxfsi(0x1.FFFFFEp
+30, 0x7FFFFF80))
86 if (test__fixunsxfsi(0x1.FFFFFCp
+30, 0x7FFFFF00))
90 if (test__fixunsxfsi(-0x1.FFFFFEp
+30, 0))
92 if (test__fixunsxfsi(-0x1.FFFFFCp
+30, 0))
96 if (test__fixunsxfsi(0x1.FFFFFFFEp
+31, 0xFFFFFFFF))
98 if (test__fixunsxfsi(0x1.FFFFFFFC00000p
+30, 0x7FFFFFFF))
100 if (test__fixunsxfsi(0x1.FFFFFFF800000p
+30, 0x7FFFFFFE))