1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixtfti
3 //===--------------- fixtfti_test.c - Test __fixtfti ----------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixtfti for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 #if __LDBL_MANT_DIG__ == 113
22 ti_int
__fixtfti(long double a
);
24 int test__fixtfti(long double a
, ti_int expected
)
26 ti_int x
= __fixtfti(a
);
27 int ret
= (x
!= expected
);
35 expectedt
.all
= expected
;
37 printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, "
38 "expected 0x%.16llX%.16llX\n",
39 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
44 char assumption_1
[sizeof(long double) * CHAR_BIT
== 128] = {0};
50 #if __LDBL_MANT_DIG__ == 113
51 if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL
,
52 0xffffffffffffffffLL
)))
54 if (test__fixtfti(0, make_ti(0x0LL
, 0x0LL
)))
56 if (test__fixtfti(0x1.23456789abcdefp
+5L, make_ti(0x0LL
, 0x24LL
)))
58 if (test__fixtfti(0x1.23456789abcdefp
-3L, make_ti(0x0LL
, 0x0LL
)))
60 if (test__fixtfti(0x1.23456789abcdef12345678p
+20L,
61 make_ti(0x0LL
, 0x123456LL
)))
63 if (test__fixtfti(0x1.23456789abcdef123456789abcdep
+112L,
64 make_ti(0x123456789abcdLL
, 0xef123456789abcdeLL
)))
66 if (test__fixtfti(-0x1.23456789abcdef123456789abcdep
+112L,
67 make_ti(0xFFFEDCBA98765432LL
, 0x10EDCBA987654322LL
)))
69 if (test__fixtfti(0x1.23456789abcdefp
+256L, make_ti(0x7fffffffffffffffLL
,
70 0xffffffffffffffffLL
)))
72 if (test__fixtfti(-0x1.23456789abcdefp
+20L, make_ti(0xffffffffffffffffLL
,
73 0xffffffffffedcbaaLL
)))
75 if (test__fixtfti(-0x1.23456789abcdefp
+256L, make_ti(0x8000000000000000LL
,