Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- absvsi2_test.c - Test __absvsi2 -----------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 7 | // |
| 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 Sen | 8973a27 | 2009-10-28 15:46:10 +0000 | [diff] [blame] | 16 | #include <stdlib.h> |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 17 | |
| 18 | // Returns: absolute value |
| 19 | |
| 20 | // Effects: aborts if abs(x) < 0 |
| 21 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 22 | COMPILER_RT_ABI si_int __absvsi2(si_int a); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 23 | |
| 24 | int 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 | |
| 36 | int 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 | } |