Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 2 | //===-- absvti2_test.c - Test __absvti2 -----------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file tests __absvti2 for the compiler_rt library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | #include "int_lib.h" |
| 16 | #include <stdio.h> |
Shantonu Sen | 1467592 | 2009-10-28 15:46:10 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 18 | |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 19 | #ifdef CRT_HAS_128BIT |
| 20 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 21 | // Returns: absolute value |
| 22 | |
| 23 | // Effects: aborts if abs(x) < 0 |
| 24 | |
Derek Schuff | eb0ebc3 | 2015-04-24 15:45:57 +0000 | [diff] [blame] | 25 | COMPILER_RT_ABI ti_int __absvti2(ti_int a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 26 | |
| 27 | int test__absvti2(ti_int a) |
| 28 | { |
| 29 | ti_int x = __absvti2(a); |
| 30 | ti_int expected = a; |
| 31 | if (expected < 0) |
| 32 | expected = -expected; |
| 33 | if (x != expected || expected < 0) |
| 34 | { |
| 35 | twords at; |
| 36 | at.all = a; |
| 37 | twords xt; |
| 38 | xt.all = x; |
| 39 | twords expectedt; |
| 40 | expectedt.all = expected; |
| 41 | printf("error in __absvti2(0x%llX%.16llX) = " |
| 42 | "0x%llX%.16llX, expected positive 0x%llX%.16llX\n", |
Daniel Dunbar | 6485720 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 43 | at.s.high, at.s.low, xt.s.high, xt.s.low, |
| 44 | expectedt.s.high, expectedt.s.low); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 45 | } |
| 46 | return x != expected; |
| 47 | } |
| 48 | |
| 49 | #endif |
| 50 | |
| 51 | int main() |
| 52 | { |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 53 | #ifdef CRT_HAS_128BIT |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 54 | |
| 55 | // if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort |
| 56 | // return 1; |
| 57 | if (test__absvti2(0x0000000000000000LL)) |
| 58 | return 1; |
| 59 | if (test__absvti2(0x0000000000000001LL)) |
| 60 | return 1; |
| 61 | if (test__absvti2(0x0000000000000002LL)) |
| 62 | return 1; |
| 63 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 64 | return 1; |
| 65 | if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 66 | return 1; |
| 67 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL))) |
| 68 | return 1; |
| 69 | if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL))) |
| 70 | return 1; |
| 71 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL))) |
| 72 | return 1; |
| 73 | if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) |
| 74 | return 1; |
| 75 | |
| 76 | int i; |
| 77 | for (i = 0; i < 10000; ++i) |
| 78 | if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(), |
| 79 | ((ti_int)rand() << 32) | rand()))) |
| 80 | return 1; |
Joerg Sonnenberger | d9bcddd | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 81 | #else |
| 82 | printf("skipped\n"); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 83 | #endif |
| 84 | return 0; |
| 85 | } |