[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / absvdi2_test.c
bloba1bdbc5ef91526596ba91c9da84aaa4212e7b209
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_absvdi2
3 //===-- absvdi2_test.c - Test __absvdi2 -----------------------------------===//
4 //
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
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __absvdi2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
17 #include <stdlib.h>
19 // Returns: absolute value
21 // Effects: aborts if abs(x) < 0
23 COMPILER_RT_ABI di_int __absvdi2(di_int a);
25 int test__absvdi2(di_int a)
27 di_int x = __absvdi2(a);
28 di_int expected = a;
29 if (expected < 0)
30 expected = -expected;
31 if (x != expected || expected < 0)
32 printf("error in __absvdi2(0x%llX) = %lld, expected positive %lld\n",
33 a, x, expected);
34 return x != expected;
37 int main()
39 // if (test__absvdi2(0x8000000000000000LL)) // should abort
40 // return 1;
41 if (test__absvdi2(0x0000000000000000LL))
42 return 1;
43 if (test__absvdi2(0x0000000000000001LL))
44 return 1;
45 if (test__absvdi2(0x0000000000000002LL))
46 return 1;
47 if (test__absvdi2(0x7FFFFFFFFFFFFFFELL))
48 return 1;
49 if (test__absvdi2(0x7FFFFFFFFFFFFFFFLL))
50 return 1;
51 if (test__absvdi2(0x8000000000000001LL))
52 return 1;
53 if (test__absvdi2(0x8000000000000002LL))
54 return 1;
55 if (test__absvdi2(0xFFFFFFFFFFFFFFFELL))
56 return 1;
57 if (test__absvdi2(0xFFFFFFFFFFFFFFFFLL))
58 return 1;
60 int i;
61 for (i = 0; i < 10000; ++i)
62 if (test__absvdi2(((di_int)rand() << 32) | rand()))
63 return 1;
65 return 0;