Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- absvti2_test.c - Test __absvti2 -----------------------------------===// |
| 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 __absvti2 for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #if __x86_64 |
| 15 | |
| 16 | #include "int_lib.h" |
| 17 | #include <stdio.h> |
Shantonu Sen | 8973a27 | 2009-10-28 15:46:10 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 19 | |
| 20 | // Returns: absolute value |
| 21 | |
| 22 | // Effects: aborts if abs(x) < 0 |
| 23 | |
| 24 | ti_int __absvti2(ti_int a); |
| 25 | |
| 26 | int test__absvti2(ti_int a) |
| 27 | { |
| 28 | ti_int x = __absvti2(a); |
| 29 | ti_int expected = a; |
| 30 | if (expected < 0) |
| 31 | expected = -expected; |
| 32 | if (x != expected || expected < 0) |
| 33 | { |
| 34 | twords at; |
| 35 | at.all = a; |
| 36 | twords xt; |
| 37 | xt.all = x; |
| 38 | twords expectedt; |
| 39 | expectedt.all = expected; |
| 40 | printf("error in __absvti2(0x%llX%.16llX) = " |
| 41 | "0x%llX%.16llX, expected positive 0x%llX%.16llX\n", |
Daniel Dunbar | cff5248 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 42 | at.s.high, at.s.low, xt.s.high, xt.s.low, |
| 43 | expectedt.s.high, expectedt.s.low); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 44 | } |
| 45 | return x != expected; |
| 46 | } |
| 47 | |
| 48 | #endif |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | #if __x86_64 |
| 53 | |
| 54 | // if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort |
| 55 | // return 1; |
| 56 | if (test__absvti2(0x0000000000000000LL)) |
| 57 | return 1; |
| 58 | if (test__absvti2(0x0000000000000001LL)) |
| 59 | return 1; |
| 60 | if (test__absvti2(0x0000000000000002LL)) |
| 61 | return 1; |
| 62 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 63 | return 1; |
| 64 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 65 | return 1; |
| 66 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL))) |
| 67 | return 1; |
| 68 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL))) |
| 69 | return 1; |
| 70 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 71 | return 1; |
| 72 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 73 | return 1; |
| 74 | |
| 75 | int i; |
| 76 | for (i = 0; i < 10000; ++i) |
| 77 | if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(), |
| 78 | ((ti_int)rand() << 32) | rand()))) |
| 79 | return 1; |
Joerg Sonnenberger | 7482815 | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 80 | #else |
| 81 | printf("skipped\n"); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 82 | #endif |
| 83 | return 0; |
| 84 | } |