1 //===--------------- fixtfti_test.c - Test __fixtfti ----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __fixtfti for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "int_lib.h"
15 #include <stdio.h>
16 
17 #if __LDBL_MANT_DIG__ == 113
18 
19 #include "fp_test.h"
20 
21 ti_int __fixtfti(long double a);
22 
test__fixtfti(long double a,ti_int expected)23 int test__fixtfti(long double a, ti_int expected)
24 {
25     ti_int x = __fixtfti(a);
26     int ret = (x != expected);
27 
28     if (ret)
29     {
30         twords xt;
31         xt.all = x;
32 
33         twords expectedt;
34         expectedt.all = expected;
35 
36         printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, "
37                "expected 0x%.16llX%.16llX\n",
38                a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
39     }
40     return ret;
41 }
42 
43 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
44 
45 #endif
46 
main()47 int main()
48 {
49 #if __LDBL_MANT_DIG__ == 113
50     if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL,
51                                             0xffffffffffffffffLL)))
52         return 1;
53     if (test__fixtfti(0, make_ti(0x0LL, 0x0LL)))
54         return 1;
55     if (test__fixtfti(0x1.23456789abcdefp+5L, make_ti(0x0LL, 0x24LL)))
56         return 1;
57     if (test__fixtfti(0x1.23456789abcdefp-3L, make_ti(0x0LL, 0x0LL)))
58         return 1;
59     if (test__fixtfti(0x1.23456789abcdef12345678p+20L,
60                       make_ti(0x0LL, 0x123456LL)))
61         return 1;
62     if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112L,
63                       make_ti(0x123456789abcdLL, 0xef123456789abcdeLL)))
64         return 1;
65     if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112L,
66                       make_ti(0xFFFEDCBA98765432LL, 0x10EDCBA987654322LL)))
67         return 1;
68     if (test__fixtfti(0x1.23456789abcdefp+256L, make_ti(0x7fffffffffffffffLL,
69                                                         0xffffffffffffffffLL)))
70         return 1;
71     if (test__fixtfti(-0x1.23456789abcdefp+20L, make_ti(0xffffffffffffffffLL,
72                                                         0xffffffffffedcbaaLL)))
73         return 1;
74     if (test__fixtfti(-0x1.23456789abcdefp+256L, make_ti(0x8000000000000000LL,
75                                                          0x0)))
76         return 1;
77 
78 #else
79     printf("skipped\n");
80 
81 #endif
82     return 0;
83 }
84