Home | History | Annotate | Download | only in Unit
      1 //===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __absvti2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 
     18 #ifdef CRT_HAS_128BIT
     19 
     20 // Returns: absolute value
     21 
     22 // Effects: aborts if abs(x) < 0
     23 
     24 COMPILER_RT_ABI 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",
     42                at.s.high, at.s.low, xt.s.high, xt.s.low,
     43                expectedt.s.high, expectedt.s.low);
     44     }
     45     return x != expected;
     46 }
     47 
     48 #endif
     49 
     50 int main()
     51 {
     52 #ifdef CRT_HAS_128BIT
     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;
     80 #else
     81     printf("skipped\n");
     82 #endif
     83     return 0;
     84 }
     85