]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/builtins/Unit/negti2_test.c
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / builtins / Unit / negti2_test.c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- negti2_test.c - Test __negti2 -------------------------------------===//
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 __negti2 for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "int_lib.h"
16 #include <stdio.h>
17
18 #ifdef CRT_HAS_128BIT
19
20 // Returns: -a
21
22 COMPILER_RT_ABI ti_int __negti2(ti_int a);
23
24 int test__negti2(ti_int a, ti_int expected)
25 {
26 ti_int x = __negti2(a);
27 if (x != expected)
28 {
29 twords at;
30 at.all = a;
31 twords xt;
32 xt.all = x;
33 twords expectedt;
34 expectedt.all = expected;
35 printf("error in __negti2: -0x%.16llX%.16llX = 0x%.16llX%.16llX, "
36 "expected 0x%.16llX%.16llX\n",
37 at.s.high, at.s.low, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
38 }
39 return x != expected;
40 }
41
42 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
43
44 #endif
45
46 int main()
47 {
48 #ifdef CRT_HAS_128BIT
49 if (test__negti2(0, 0))
50 return 1;
51 if (test__negti2(1, -1))
52 return 1;
53 if (test__negti2(-1, 1))
54 return 1;
55 if (test__negti2(2, -2))
56 return 1;
57 if (test__negti2(-2, 2))
58 return 1;
59 if (test__negti2(3, -3))
60 return 1;
61 if (test__negti2(-3, 3))
62 return 1;
63 if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL),
64 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL)))
65 return 1;
66 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL),
67 make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL)))
68 return 1;
69 if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL),
70 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL)))
71 return 1;
72 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL),
73 make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL)))
74 return 1;
75 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
76 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
77 return 1;
78 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
79 make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
80 return 1;
81 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
82 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
83 return 1;
84 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
85 make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
86 return 1;
87 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000300000000LL),
88 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL)))
89 return 1;
90 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL),
91 make_ti(0x0000000000000000LL, 0x0000000300000000LL)))
92 return 1;
93 if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
94 make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
95 return 1;
96 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL),
97 make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL)))
98 return 1;
99 if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
100 make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
101 return 1;
102 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
103 make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
104 return 1;
105 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
106 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
107 return 1;
108 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
109 make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
110 return 1;
111 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
112 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
113 return 1;
114 if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
115 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
116 return 1;
117 if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
118 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
119 return 1;
120 if (test__negti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
121 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
122 return 1;
123
124 #else
125 printf("skipped\n");
126 #endif
127 return 0;
128 }