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