xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/absvsi2_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- absvsi2_test.c - Test __absvsi2 -----------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __absvsi2 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc #include <stdlib.h>
17*4684ddb6SLionel Sambuc 
18*4684ddb6SLionel Sambuc // Returns: absolute value
19*4684ddb6SLionel Sambuc 
20*4684ddb6SLionel Sambuc // Effects: aborts if abs(x) < 0
21*4684ddb6SLionel Sambuc 
22*4684ddb6SLionel Sambuc si_int __absvsi2(si_int a);
23*4684ddb6SLionel Sambuc 
test__absvsi2(si_int a)24*4684ddb6SLionel Sambuc int test__absvsi2(si_int a)
25*4684ddb6SLionel Sambuc {
26*4684ddb6SLionel Sambuc     si_int x = __absvsi2(a);
27*4684ddb6SLionel Sambuc     si_int expected = a;
28*4684ddb6SLionel Sambuc     if (expected < 0)
29*4684ddb6SLionel Sambuc         expected = -expected;
30*4684ddb6SLionel Sambuc     if (x != expected || expected < 0)
31*4684ddb6SLionel Sambuc         printf("error in __absvsi2(0x%X) = %d, expected positive %d\n",
32*4684ddb6SLionel Sambuc                a, x, expected);
33*4684ddb6SLionel Sambuc     return x != expected;
34*4684ddb6SLionel Sambuc }
35*4684ddb6SLionel Sambuc 
main()36*4684ddb6SLionel Sambuc int main()
37*4684ddb6SLionel Sambuc {
38*4684ddb6SLionel Sambuc //     if (test__absvsi2(0x80000000))  // should abort
39*4684ddb6SLionel Sambuc //         return 1;
40*4684ddb6SLionel Sambuc     if (test__absvsi2(0x00000000))
41*4684ddb6SLionel Sambuc         return 1;
42*4684ddb6SLionel Sambuc     if (test__absvsi2(0x00000001))
43*4684ddb6SLionel Sambuc         return 1;
44*4684ddb6SLionel Sambuc     if (test__absvsi2(0x00000002))
45*4684ddb6SLionel Sambuc         return 1;
46*4684ddb6SLionel Sambuc     if (test__absvsi2(0x7FFFFFFE))
47*4684ddb6SLionel Sambuc         return 1;
48*4684ddb6SLionel Sambuc     if (test__absvsi2(0x7FFFFFFF))
49*4684ddb6SLionel Sambuc         return 1;
50*4684ddb6SLionel Sambuc     if (test__absvsi2(0x80000001))
51*4684ddb6SLionel Sambuc         return 1;
52*4684ddb6SLionel Sambuc     if (test__absvsi2(0x80000002))
53*4684ddb6SLionel Sambuc         return 1;
54*4684ddb6SLionel Sambuc     if (test__absvsi2(0xFFFFFFFE))
55*4684ddb6SLionel Sambuc         return 1;
56*4684ddb6SLionel Sambuc     if (test__absvsi2(0xFFFFFFFF))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc 
59*4684ddb6SLionel Sambuc     int i;
60*4684ddb6SLionel Sambuc     for (i = 0; i < 10000; ++i)
61*4684ddb6SLionel Sambuc         if (test__absvsi2(rand()))
62*4684ddb6SLionel Sambuc             return 1;
63*4684ddb6SLionel Sambuc 
64*4684ddb6SLionel Sambuc     return 0;
65*4684ddb6SLionel Sambuc }
66