]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/builtins/Unit/fixtfdi_test.c
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / builtins / Unit / fixtfdi_test.c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===--------------- fixtfdi_test.c - Test __fixtfdi ----------------------===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file tests __fixtfdi for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "int_lib.h"
16 #include <stdio.h>
17
18 #if __LDBL_MANT_DIG__ == 113
19
20 #include "fp_test.h"
21
22 di_int __fixtfdi(long double a);
23
24 int test__fixtfdi(long double a, di_int expected)
25 {
26 di_int x = __fixtfdi(a);
27 int ret = (x != expected);
28
29 if (ret)
30 {
31 printf("error in test__fixtfdi(%.20Lf) = %llX, "
32 "expected %llX\n", a, x, expected);
33 }
34 return ret;
35 }
36
37 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
38
39 #endif
40
41 int main()
42 {
43 #if __LDBL_MANT_DIG__ == 113
44 if (test__fixtfdi(makeInf128(), 0x7fffffffffffffffLL))
45 return 1;
46 if (test__fixtfdi(0, 0x0))
47 return 1;
48 if (test__fixtfdi(0x1.23456789abcdefp+5L, 0x24LL))
49 return 1;
50 if (test__fixtfdi(0x1.23456789abcdefp-3L, 0x0LL))
51 return 1;
52 if (test__fixtfdi(0x1.23456789abcdef12345678p+20L, 0x123456LL))
53 return 1;
54 if (test__fixtfdi(0x1.23456789abcdef12345678p+40L, 0x123456789abLL))
55 return 1;
56 if (test__fixtfdi(0x1.23456789abcdef12345678p+60L, 0x123456789abcdef1LL))
57 return 1;
58 if (test__fixtfdi(0x1.23456789abcdefp+256L, 0x7fffffffffffffffLL))
59 return 1;
60 if (test__fixtfdi(-0x1.23456789abcdefp+20L, 0xffffffffffedcbaaLL))
61 return 1;
62 if (test__fixtfdi(-0x1.23456789abcdefp+40L, 0xfffffedcba987655LL))
63 return 1;
64 if (test__fixtfdi(-0x1.23456789abcdefp+256L, 0x8000000000000000LL))
65 return 1;
66
67 #else
68 printf("skipped\n");
69
70 #endif
71 return 0;
72 }