1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_negdi2
3 
4 #include "int_lib.h"
5 #include <stdio.h>
6 
7 // Returns: -a
8 
9 COMPILER_RT_ABI di_int __negdi2(di_int a);
10 
test__negdi2(di_int a,di_int expected)11 int test__negdi2(di_int a, di_int expected)
12 {
13     di_int x = __negdi2(a);
14     if (x != expected)
15         printf("error in __negdi2: -0x%llX = 0x%llX, expected 0x%llX\n",
16                a, x, expected);
17     return x != expected;
18 }
19 
20 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
21 
main()22 int main()
23 {
24     if (test__negdi2(0, 0))
25         return 1;
26     if (test__negdi2(1, -1))
27         return 1;
28     if (test__negdi2(-1, 1))
29         return 1;
30     if (test__negdi2(2, -2))
31         return 1;
32     if (test__negdi2(-2, 2))
33         return 1;
34     if (test__negdi2(3, -3))
35         return 1;
36     if (test__negdi2(-3, 3))
37         return 1;
38     if (test__negdi2(0x00000000FFFFFFFELL, 0xFFFFFFFF00000002LL))
39         return 1;
40     if (test__negdi2(0xFFFFFFFF00000002LL, 0x00000000FFFFFFFELL))
41         return 1;
42     if (test__negdi2(0x00000000FFFFFFFFLL, 0xFFFFFFFF00000001LL))
43         return 1;
44     if (test__negdi2(0xFFFFFFFF00000001LL, 0x00000000FFFFFFFFLL))
45         return 1;
46     if (test__negdi2(0x0000000100000000LL, 0xFFFFFFFF00000000LL))
47         return 1;
48     if (test__negdi2(0xFFFFFFFF00000000LL, 0x0000000100000000LL))
49         return 1;
50     if (test__negdi2(0x0000000200000000LL, 0xFFFFFFFE00000000LL))
51         return 1;
52     if (test__negdi2(0xFFFFFFFE00000000LL, 0x0000000200000000LL))
53         return 1;
54     if (test__negdi2(0x0000000300000000LL, 0xFFFFFFFD00000000LL))
55         return 1;
56     if (test__negdi2(0xFFFFFFFD00000000LL, 0x0000000300000000LL))
57         return 1;
58     if (test__negdi2(0x8000000000000000LL, 0x8000000000000000LL))
59         return 1;
60     if (test__negdi2(0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL))
61         return 1;
62     if (test__negdi2(0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL))
63         return 1;
64     if (test__negdi2(0xFFFFFFFE00000000LL, 0x0000000200000000LL))
65         return 1;
66     if (test__negdi2(0x0000000200000000LL, 0xFFFFFFFE00000000LL))
67         return 1;
68     if (test__negdi2(0xFFFFFFFF00000000LL, 0x0000000100000000LL))
69         return 1;
70     if (test__negdi2(0x0000000100000000LL, 0xFFFFFFFF00000000LL))
71         return 1;
72 
73    return 0;
74 }
75