xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/fixtfti_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===--------------- fixtfti_test.c - Test __fixtfti ----------------------===//
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 __fixtfti 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 #if __LDBL_MANT_DIG__ == 113
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot #include "fp_test.h"
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot ti_int __fixtfti(long double a);
22*7c3d14c8STreehugger Robot 
test__fixtfti(long double a,ti_int expected)23*7c3d14c8STreehugger Robot int test__fixtfti(long double a, ti_int expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot     ti_int x = __fixtfti(a);
26*7c3d14c8STreehugger Robot     int ret = (x != expected);
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot     if (ret)
29*7c3d14c8STreehugger Robot     {
30*7c3d14c8STreehugger Robot         twords xt;
31*7c3d14c8STreehugger Robot         xt.all = x;
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot         twords expectedt;
34*7c3d14c8STreehugger Robot         expectedt.all = expected;
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot         printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, "
37*7c3d14c8STreehugger Robot                "expected 0x%.16llX%.16llX\n",
38*7c3d14c8STreehugger Robot                a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
39*7c3d14c8STreehugger Robot     }
40*7c3d14c8STreehugger Robot     return ret;
41*7c3d14c8STreehugger Robot }
42*7c3d14c8STreehugger Robot 
43*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
44*7c3d14c8STreehugger Robot 
45*7c3d14c8STreehugger Robot #endif
46*7c3d14c8STreehugger Robot 
main()47*7c3d14c8STreehugger Robot int main()
48*7c3d14c8STreehugger Robot {
49*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
50*7c3d14c8STreehugger Robot     if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL,
51*7c3d14c8STreehugger Robot                                             0xffffffffffffffffLL)))
52*7c3d14c8STreehugger Robot         return 1;
53*7c3d14c8STreehugger Robot     if (test__fixtfti(0, make_ti(0x0LL, 0x0LL)))
54*7c3d14c8STreehugger Robot         return 1;
55*7c3d14c8STreehugger Robot     if (test__fixtfti(0x1.23456789abcdefp+5L, make_ti(0x0LL, 0x24LL)))
56*7c3d14c8STreehugger Robot         return 1;
57*7c3d14c8STreehugger Robot     if (test__fixtfti(0x1.23456789abcdefp-3L, make_ti(0x0LL, 0x0LL)))
58*7c3d14c8STreehugger Robot         return 1;
59*7c3d14c8STreehugger Robot     if (test__fixtfti(0x1.23456789abcdef12345678p+20L,
60*7c3d14c8STreehugger Robot                       make_ti(0x0LL, 0x123456LL)))
61*7c3d14c8STreehugger Robot         return 1;
62*7c3d14c8STreehugger Robot     if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112L,
63*7c3d14c8STreehugger Robot                       make_ti(0x123456789abcdLL, 0xef123456789abcdeLL)))
64*7c3d14c8STreehugger Robot         return 1;
65*7c3d14c8STreehugger Robot     if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112L,
66*7c3d14c8STreehugger Robot                       make_ti(0xFFFEDCBA98765432LL, 0x10EDCBA987654322LL)))
67*7c3d14c8STreehugger Robot         return 1;
68*7c3d14c8STreehugger Robot     if (test__fixtfti(0x1.23456789abcdefp+256L, make_ti(0x7fffffffffffffffLL,
69*7c3d14c8STreehugger Robot                                                         0xffffffffffffffffLL)))
70*7c3d14c8STreehugger Robot         return 1;
71*7c3d14c8STreehugger Robot     if (test__fixtfti(-0x1.23456789abcdefp+20L, make_ti(0xffffffffffffffffLL,
72*7c3d14c8STreehugger Robot                                                         0xffffffffffedcbaaLL)))
73*7c3d14c8STreehugger Robot         return 1;
74*7c3d14c8STreehugger Robot     if (test__fixtfti(-0x1.23456789abcdefp+256L, make_ti(0x8000000000000000LL,
75*7c3d14c8STreehugger Robot                                                          0x0)))
76*7c3d14c8STreehugger Robot         return 1;
77*7c3d14c8STreehugger Robot 
78*7c3d14c8STreehugger Robot #else
79*7c3d14c8STreehugger Robot     printf("skipped\n");
80*7c3d14c8STreehugger Robot 
81*7c3d14c8STreehugger Robot #endif
82*7c3d14c8STreehugger Robot     return 0;
83*7c3d14c8STreehugger Robot }
84