• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- negdi2_test.c - Test __negdi2 -------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __negdi2 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "int_lib.h"
15 #include <stdio.h>
16 
17 // Returns: -a
18 
19 COMPILER_RT_ABI di_int __negdi2(di_int a);
20 
test__negdi2(di_int a,di_int expected)21 int test__negdi2(di_int a, di_int expected)
22 {
23     di_int x = __negdi2(a);
24     if (x != expected)
25         printf("error in __negdi2: -0x%llX = 0x%llX, expected 0x%llX\n",
26                a, x, expected);
27     return x != expected;
28 }
29 
30 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
31 
main()32 int main()
33 {
34     if (test__negdi2(0, 0))
35         return 1;
36     if (test__negdi2(1, -1))
37         return 1;
38     if (test__negdi2(-1, 1))
39         return 1;
40     if (test__negdi2(2, -2))
41         return 1;
42     if (test__negdi2(-2, 2))
43         return 1;
44     if (test__negdi2(3, -3))
45         return 1;
46     if (test__negdi2(-3, 3))
47         return 1;
48     if (test__negdi2(0x00000000FFFFFFFELL, 0xFFFFFFFF00000002LL))
49         return 1;
50     if (test__negdi2(0xFFFFFFFF00000002LL, 0x00000000FFFFFFFELL))
51         return 1;
52     if (test__negdi2(0x00000000FFFFFFFFLL, 0xFFFFFFFF00000001LL))
53         return 1;
54     if (test__negdi2(0xFFFFFFFF00000001LL, 0x00000000FFFFFFFFLL))
55         return 1;
56     if (test__negdi2(0x0000000100000000LL, 0xFFFFFFFF00000000LL))
57         return 1;
58     if (test__negdi2(0xFFFFFFFF00000000LL, 0x0000000100000000LL))
59         return 1;
60     if (test__negdi2(0x0000000200000000LL, 0xFFFFFFFE00000000LL))
61         return 1;
62     if (test__negdi2(0xFFFFFFFE00000000LL, 0x0000000200000000LL))
63         return 1;
64     if (test__negdi2(0x0000000300000000LL, 0xFFFFFFFD00000000LL))
65         return 1;
66     if (test__negdi2(0xFFFFFFFD00000000LL, 0x0000000300000000LL))
67         return 1;
68     if (test__negdi2(0x8000000000000000LL, 0x8000000000000000LL))
69         return 1;
70     if (test__negdi2(0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL))
71         return 1;
72     if (test__negdi2(0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL))
73         return 1;
74     if (test__negdi2(0xFFFFFFFE00000000LL, 0x0000000200000000LL))
75         return 1;
76     if (test__negdi2(0x0000000200000000LL, 0xFFFFFFFE00000000LL))
77         return 1;
78     if (test__negdi2(0xFFFFFFFF00000000LL, 0x0000000100000000LL))
79         return 1;
80     if (test__negdi2(0x0000000100000000LL, 0xFFFFFFFF00000000LL))
81         return 1;
82 
83    return 0;
84 }
85