Home | History | Annotate | Download | only in Unit
      1 //===-- absvdi2_test.c - Test __absvdi2 -----------------------------------===//
      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 __absvdi2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 
     18 // Returns: absolute value
     19 
     20 // Effects: aborts if abs(x) < 0
     21 
     22 COMPILER_RT_ABI di_int __absvdi2(di_int a);
     23 
     24 int test__absvdi2(di_int a)
     25 {
     26     di_int x = __absvdi2(a);
     27     di_int expected = a;
     28     if (expected < 0)
     29         expected = -expected;
     30     if (x != expected || expected < 0)
     31         printf("error in __absvdi2(0x%llX) = %lld, expected positive %lld\n",
     32                a, x, expected);
     33     return x != expected;
     34 }
     35 
     36 int main()
     37 {
     38 //     if (test__absvdi2(0x8000000000000000LL))  // should abort
     39 //         return 1;
     40     if (test__absvdi2(0x0000000000000000LL))
     41         return 1;
     42     if (test__absvdi2(0x0000000000000001LL))
     43         return 1;
     44     if (test__absvdi2(0x0000000000000002LL))
     45         return 1;
     46     if (test__absvdi2(0x7FFFFFFFFFFFFFFELL))
     47         return 1;
     48     if (test__absvdi2(0x7FFFFFFFFFFFFFFFLL))
     49         return 1;
     50     if (test__absvdi2(0x8000000000000001LL))
     51         return 1;
     52     if (test__absvdi2(0x8000000000000002LL))
     53         return 1;
     54     if (test__absvdi2(0xFFFFFFFFFFFFFFFELL))
     55         return 1;
     56     if (test__absvdi2(0xFFFFFFFFFFFFFFFFLL))
     57         return 1;
     58 
     59     int i;
     60     for (i = 0; i < 10000; ++i)
     61         if (test__absvdi2(((di_int)rand() << 32) | rand()))
     62             return 1;
     63 
     64     return 0;
     65 }
     66