1799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===//
2799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//
3799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//                     The LLVM Compiler Infrastructure
4799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//
5799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar// This file is dual licensed under the MIT and the University of Illinois Open
6799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar// Source Licenses. See LICENSE.TXT for details.
7799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//
8799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//===----------------------------------------------------------------------===//
9799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//
10799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar// This file tests __fixunstfti for the compiler_rt library.
11799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//
12799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//===----------------------------------------------------------------------===//
13799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
14799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#include <stdio.h>
15799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
16799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#if __LDBL_MANT_DIG__ == 113
17799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
18799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#include "fp_test.h"
19799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#include "int_lib.h"
20799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
21799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar// Returns: convert a to a unsigned long long, rounding toward zero.
22799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//          Negative values all become zero.
23799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
24799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar// Assumption: long double is a 128 bit floating point type
25799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//             tu_int is a 128 bit integral type
26799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//             value in long double is representable in tu_int or is negative
27799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar//                 (no range checking performed)
28799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
29799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga NainarCOMPILER_RT_ABI tu_int __fixunstfti(long double a);
30799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
31799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainarint test__fixunstfti(long double a, tu_int expected)
32799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar{
33799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    tu_int x = __fixunstfti(a);
34799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (x != expected)
35799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    {
36799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        twords xt;
37799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        xt.all = x;
38799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
39799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        twords expectedt;
40799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        expectedt.all = expected;
41799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
42799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
43799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar               "expected 0x%.16llX%.16llX\n",
44799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar               a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
45799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    }
46799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    return x != expected;
47799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar}
48799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
49799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainarchar assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
50799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainarchar assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
51799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainarchar assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
52799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
53799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#endif
54799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
55799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainarint main()
56799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar{
57799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#if __LDBL_MANT_DIG__ == 113
58799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
59799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar                                               0xffffffffffffffffLL)))
60799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
61799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
62799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0.0, 0))
63799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
64799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
65799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0.5, 0))
66799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
67799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0.99, 0))
68799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
69799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(1.0, 1))
70799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
71799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(1.5, 1))
72799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
73799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(1.99, 1))
74799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
75799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(2.0, 2))
76799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
77799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(2.01, 2))
78799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
79799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(-0.01, 0))
80799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
81799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(-0.99, 0))
82799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
83799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
84799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
85799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar                                            0xffffffffffffffffLL)))
86799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
87799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
88799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
89799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
90799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
91799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
92799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
93799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar                                                  0xffffffffffffffffLL)))
94799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
95799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
96799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar                                                  0xffffffffffffffffLL)))
97799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar        return 1;
98799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar
99799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#else
100799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar    printf("skipped\n");
101799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar#endif
102799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar   return 0;
103799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar}
104