| 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 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 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> |
| 18 | |
| 19 | // Returns: absolute value |
| 20 | |
| 21 | // Effects: aborts if abs(x) < 0 |
| 22 | |
| 23 | ti_int __absvti2(ti_int a); |
| 24 | |
| 25 | int test__absvti2(ti_int a) |
| 26 | { |
| 27 | ti_int x = __absvti2(a); |
| 28 | ti_int expected = a; |
| 29 | if (expected < 0) |
| 30 | expected = -expected; |
| 31 | if (x != expected || expected < 0) |
| 32 | { |
| 33 | twords at; |
| 34 | at.all = a; |
| 35 | twords xt; |
| 36 | xt.all = x; |
| 37 | twords expectedt; |
| 38 | expectedt.all = expected; |
| 39 | printf("error in __absvti2(0x%llX%.16llX) = " |
| 40 | "0x%llX%.16llX, expected positive 0x%llX%.16llX\n", |
| 41 | at.high, at.low, xt.high, xt.low, expectedt.high, expectedt.low); |
| 42 | } |
| 43 | return x != expected; |
| 44 | } |
| 45 | |
| 46 | #endif |
| 47 | |
| 48 | int main() |
| 49 | { |
| 50 | #if __x86_64 |
| 51 | |
| 52 | // if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort |
| 53 | // return 1; |
| 54 | if (test__absvti2(0x0000000000000000LL)) |
| 55 | return 1; |
| 56 | if (test__absvti2(0x0000000000000001LL)) |
| 57 | return 1; |
| 58 | if (test__absvti2(0x0000000000000002LL)) |
| 59 | return 1; |
| 60 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 61 | return 1; |
| 62 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 63 | return 1; |
| 64 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL))) |
| 65 | return 1; |
| 66 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL))) |
| 67 | return 1; |
| 68 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 69 | return 1; |
| 70 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 71 | return 1; |
| 72 | |
| 73 | int i; |
| 74 | for (i = 0; i < 10000; ++i) |
| 75 | if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(), |
| 76 | ((ti_int)rand() << 32) | rand()))) |
| 77 | return 1; |
| 78 | #endif |
| 79 | return 0; |
| 80 | } |