1*7c3d14c8STreehugger Robot //===-- fixsfti_test.c - Test __fixsfti -----------------------------------===//
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 __fixsfti 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 signed long long, rounding toward zero.
20*7c3d14c8STreehugger Robot
21*7c3d14c8STreehugger Robot // Assumption: float is a IEEE 32 bit floating point type
22*7c3d14c8STreehugger Robot // su_int is a 32 bit integral type
23*7c3d14c8STreehugger Robot // value in float is representable in ti_int (no range checking performed)
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robot // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
26*7c3d14c8STreehugger Robot
27*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __fixsfti(float a);
28*7c3d14c8STreehugger Robot
test__fixsfti(float a,ti_int expected)29*7c3d14c8STreehugger Robot int test__fixsfti(float a, ti_int expected)
30*7c3d14c8STreehugger Robot {
31*7c3d14c8STreehugger Robot ti_int x = __fixsfti(a);
32*7c3d14c8STreehugger Robot if (x != expected)
33*7c3d14c8STreehugger Robot {
34*7c3d14c8STreehugger Robot twords xt;
35*7c3d14c8STreehugger Robot xt.all = x;
36*7c3d14c8STreehugger Robot twords expectedt;
37*7c3d14c8STreehugger Robot expectedt.all = expected;
38*7c3d14c8STreehugger Robot printf("error in __fixsfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
39*7c3d14c8STreehugger Robot a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
40*7c3d14c8STreehugger Robot }
41*7c3d14c8STreehugger Robot return x != expected;
42*7c3d14c8STreehugger Robot }
43*7c3d14c8STreehugger Robot
44*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
45*7c3d14c8STreehugger Robot char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
46*7c3d14c8STreehugger Robot char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
47*7c3d14c8STreehugger Robot
48*7c3d14c8STreehugger Robot #endif
49*7c3d14c8STreehugger Robot
main()50*7c3d14c8STreehugger Robot int main()
51*7c3d14c8STreehugger Robot {
52*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
53*7c3d14c8STreehugger Robot if (test__fixsfti(0.0F, 0))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot
56*7c3d14c8STreehugger Robot if (test__fixsfti(0.5F, 0))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot if (test__fixsfti(0.99F, 0))
59*7c3d14c8STreehugger Robot return 1;
60*7c3d14c8STreehugger Robot if (test__fixsfti(1.0F, 1))
61*7c3d14c8STreehugger Robot return 1;
62*7c3d14c8STreehugger Robot if (test__fixsfti(1.5F, 1))
63*7c3d14c8STreehugger Robot return 1;
64*7c3d14c8STreehugger Robot if (test__fixsfti(1.99F, 1))
65*7c3d14c8STreehugger Robot return 1;
66*7c3d14c8STreehugger Robot if (test__fixsfti(2.0F, 2))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot if (test__fixsfti(2.01F, 2))
69*7c3d14c8STreehugger Robot return 1;
70*7c3d14c8STreehugger Robot if (test__fixsfti(-0.5F, 0))
71*7c3d14c8STreehugger Robot return 1;
72*7c3d14c8STreehugger Robot if (test__fixsfti(-0.99F, 0))
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot if (test__fixsfti(-1.0F, -1))
75*7c3d14c8STreehugger Robot return 1;
76*7c3d14c8STreehugger Robot if (test__fixsfti(-1.5F, -1))
77*7c3d14c8STreehugger Robot return 1;
78*7c3d14c8STreehugger Robot if (test__fixsfti(-1.99F, -1))
79*7c3d14c8STreehugger Robot return 1;
80*7c3d14c8STreehugger Robot if (test__fixsfti(-2.0F, -2))
81*7c3d14c8STreehugger Robot return 1;
82*7c3d14c8STreehugger Robot if (test__fixsfti(-2.01F, -2))
83*7c3d14c8STreehugger Robot return 1;
84*7c3d14c8STreehugger Robot
85*7c3d14c8STreehugger Robot if (test__fixsfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
86*7c3d14c8STreehugger Robot return 1;
87*7c3d14c8STreehugger Robot if (test__fixsfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
88*7c3d14c8STreehugger Robot return 1;
89*7c3d14c8STreehugger Robot
90*7c3d14c8STreehugger Robot if (test__fixsfti(-0x1.FFFFFEp+62F, make_ti(0xFFFFFFFFFFFFFFFFLL,
91*7c3d14c8STreehugger Robot 0x8000008000000000LL)))
92*7c3d14c8STreehugger Robot return 1;
93*7c3d14c8STreehugger Robot if (test__fixsfti(-0x1.FFFFFCp+62F, make_ti(0xFFFFFFFFFFFFFFFFLL,
94*7c3d14c8STreehugger Robot 0x8000010000000000LL)))
95*7c3d14c8STreehugger Robot return 1;
96*7c3d14c8STreehugger Robot
97*7c3d14c8STreehugger Robot if (test__fixsfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0)))
98*7c3d14c8STreehugger Robot return 1;
99*7c3d14c8STreehugger Robot if (test__fixsfti(0x1.FFFFFCp+126F, make_ti(0x7FFFFF0000000000LL, 0)))
100*7c3d14c8STreehugger Robot return 1;
101*7c3d14c8STreehugger Robot
102*7c3d14c8STreehugger Robot if (test__fixsfti(-0x1.FFFFFEp+126F, make_ti(0x8000008000000000LL, 0)))
103*7c3d14c8STreehugger Robot return 1;
104*7c3d14c8STreehugger Robot if (test__fixsfti(-0x1.FFFFFCp+126F, make_ti(0x8000010000000000LL, 0)))
105*7c3d14c8STreehugger Robot return 1;
106*7c3d14c8STreehugger Robot
107*7c3d14c8STreehugger Robot #else
108*7c3d14c8STreehugger Robot printf("skipped\n");
109*7c3d14c8STreehugger Robot #endif
110*7c3d14c8STreehugger Robot return 0;
111*7c3d14c8STreehugger Robot }
112