1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
---|---|
2 | // REQUIRES: librt_has_absvsi2 |
3 | |
4 | #include "int_lib.h" |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | |
8 | // Returns: absolute value |
9 | |
10 | // Effects: aborts if abs(x) < 0 |
11 | |
12 | COMPILER_RT_ABI si_int __absvsi2(si_int a); |
13 | |
14 | int test__absvsi2(si_int a) |
15 | { |
16 | si_int x = __absvsi2(a); |
17 | si_int expected = a; |
18 | if (expected < 0) |
19 | expected = -expected; |
20 | if (x != expected || expected < 0) |
21 | printf(format: "error in __absvsi2(0x%X) = %d, expected positive %d\n", |
22 | a, x, expected); |
23 | return x != expected; |
24 | } |
25 | |
26 | int main() |
27 | { |
28 | // if (test__absvsi2(0x80000000)) // should abort |
29 | // return 1; |
30 | if (test__absvsi2(a: 0x00000000)) |
31 | return 1; |
32 | if (test__absvsi2(a: 0x00000001)) |
33 | return 1; |
34 | if (test__absvsi2(a: 0x00000002)) |
35 | return 1; |
36 | if (test__absvsi2(a: 0x7FFFFFFE)) |
37 | return 1; |
38 | if (test__absvsi2(a: 0x7FFFFFFF)) |
39 | return 1; |
40 | if (test__absvsi2(a: 0x80000001)) |
41 | return 1; |
42 | if (test__absvsi2(a: 0x80000002)) |
43 | return 1; |
44 | if (test__absvsi2(a: 0xFFFFFFFE)) |
45 | return 1; |
46 | if (test__absvsi2(a: 0xFFFFFFFF)) |
47 | return 1; |
48 | |
49 | int i; |
50 | for (i = 0; i < 10000; ++i) |
51 | if (test__absvsi2(a: rand())) |
52 | return 1; |
53 | |
54 | return 0; |
55 | } |
56 |