1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_negdi2
3 //===-- negdi2_test.c - Test __negdi2 -------------------------------------===//
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 __negdi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
20 COMPILER_RT_ABI di_int
__negdi2(di_int a
);
22 int test__negdi2(di_int a
, di_int expected
)
24 di_int x
= __negdi2(a
);
26 printf("error in __negdi2: -0x%llX = 0x%llX, expected 0x%llX\n",
31 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
35 if (test__negdi2(0, 0))
37 if (test__negdi2(1, -1))
39 if (test__negdi2(-1, 1))
41 if (test__negdi2(2, -2))
43 if (test__negdi2(-2, 2))
45 if (test__negdi2(3, -3))
47 if (test__negdi2(-3, 3))
49 if (test__negdi2(0x00000000FFFFFFFELL
, 0xFFFFFFFF00000002LL
))
51 if (test__negdi2(0xFFFFFFFF00000002LL
, 0x00000000FFFFFFFELL
))
53 if (test__negdi2(0x00000000FFFFFFFFLL
, 0xFFFFFFFF00000001LL
))
55 if (test__negdi2(0xFFFFFFFF00000001LL
, 0x00000000FFFFFFFFLL
))
57 if (test__negdi2(0x0000000100000000LL
, 0xFFFFFFFF00000000LL
))
59 if (test__negdi2(0xFFFFFFFF00000000LL
, 0x0000000100000000LL
))
61 if (test__negdi2(0x0000000200000000LL
, 0xFFFFFFFE00000000LL
))
63 if (test__negdi2(0xFFFFFFFE00000000LL
, 0x0000000200000000LL
))
65 if (test__negdi2(0x0000000300000000LL
, 0xFFFFFFFD00000000LL
))
67 if (test__negdi2(0xFFFFFFFD00000000LL
, 0x0000000300000000LL
))
69 if (test__negdi2(0x8000000000000000LL
, 0x8000000000000000LL
))
71 if (test__negdi2(0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
))
73 if (test__negdi2(0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
))
75 if (test__negdi2(0xFFFFFFFE00000000LL
, 0x0000000200000000LL
))
77 if (test__negdi2(0x0000000200000000LL
, 0xFFFFFFFE00000000LL
))
79 if (test__negdi2(0xFFFFFFFF00000000LL
, 0x0000000100000000LL
))
81 if (test__negdi2(0x0000000100000000LL
, 0xFFFFFFFF00000000LL
))