blob: c395cca7adc8acb73bb4ed84e5722a85adcbf79c [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- absvsi2_test.c - Test __absvsi2 -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarb3a69012009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __absvsi2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15#include <stdio.h>
Shantonu Sen8973a272009-10-28 15:46:10 +000016#include <stdlib.h>
Daniel Dunbarb3a69012009-06-26 16:47:03 +000017
18// Returns: absolute value
19
20// Effects: aborts if abs(x) < 0
21
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070022COMPILER_RT_ABI si_int __absvsi2(si_int a);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023
24int test__absvsi2(si_int a)
25{
26 si_int x = __absvsi2(a);
27 si_int expected = a;
28 if (expected < 0)
29 expected = -expected;
30 if (x != expected || expected < 0)
31 printf("error in __absvsi2(0x%X) = %d, expected positive %d\n",
32 a, x, expected);
33 return x != expected;
34}
35
36int main()
37{
38// if (test__absvsi2(0x80000000)) // should abort
39// return 1;
40 if (test__absvsi2(0x00000000))
41 return 1;
42 if (test__absvsi2(0x00000001))
43 return 1;
44 if (test__absvsi2(0x00000002))
45 return 1;
46 if (test__absvsi2(0x7FFFFFFE))
47 return 1;
48 if (test__absvsi2(0x7FFFFFFF))
49 return 1;
50 if (test__absvsi2(0x80000001))
51 return 1;
52 if (test__absvsi2(0x80000002))
53 return 1;
54 if (test__absvsi2(0xFFFFFFFE))
55 return 1;
56 if (test__absvsi2(0xFFFFFFFF))
57 return 1;
58
59 int i;
60 for (i = 0; i < 10000; ++i)
61 if (test__absvsi2(rand()))
62 return 1;
63
64 return 0;
65}