Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
      2  1.1  joerg //
      3  1.1  joerg //                     The LLVM Compiler Infrastructure
      4  1.1  joerg //
      5  1.1  joerg // This file is dual licensed under the MIT and the University of Illinois Open
      6  1.1  joerg // Source Licenses. See LICENSE.TXT for details.
      7  1.1  joerg //
      8  1.1  joerg //===----------------------------------------------------------------------===//
      9  1.1  joerg //
     10  1.1  joerg // This file tests __absvti2 for the compiler_rt library.
     11  1.1  joerg //
     12  1.1  joerg //===----------------------------------------------------------------------===//
     13  1.1  joerg 
     14  1.1  joerg #if __x86_64
     15  1.1  joerg 
     16  1.1  joerg #include "int_lib.h"
     17  1.1  joerg #include <stdio.h>
     18  1.1  joerg #include <stdlib.h>
     19  1.1  joerg 
     20  1.1  joerg // Returns: absolute value
     21  1.1  joerg 
     22  1.1  joerg // Effects: aborts if abs(x) < 0
     23  1.1  joerg 
     24  1.1  joerg ti_int __absvti2(ti_int a);
     25  1.1  joerg 
     26  1.1  joerg int test__absvti2(ti_int a)
     27  1.1  joerg {
     28  1.1  joerg     ti_int x = __absvti2(a);
     29  1.1  joerg     ti_int expected = a;
     30  1.1  joerg     if (expected < 0)
     31  1.1  joerg         expected = -expected;
     32  1.1  joerg     if (x != expected || expected < 0)
     33  1.1  joerg     {
     34  1.1  joerg         twords at;
     35  1.1  joerg         at.all = a;
     36  1.1  joerg         twords xt;
     37  1.1  joerg         xt.all = x;
     38  1.1  joerg         twords expectedt;
     39  1.1  joerg         expectedt.all = expected;
     40  1.1  joerg         printf("error in __absvti2(0x%llX%.16llX) = "
     41  1.1  joerg                "0x%llX%.16llX, expected positive 0x%llX%.16llX\n",
     42  1.1  joerg                at.s.high, at.s.low, xt.s.high, xt.s.low,
     43  1.1  joerg                expectedt.s.high, expectedt.s.low);
     44  1.1  joerg     }
     45  1.1  joerg     return x != expected;
     46  1.1  joerg }
     47  1.1  joerg 
     48  1.1  joerg #endif
     49  1.1  joerg 
     50  1.1  joerg int main()
     51  1.1  joerg {
     52  1.1  joerg #if __x86_64
     53  1.1  joerg 
     54  1.1  joerg //     if (test__absvti2(make_ti(0x8000000000000000LL, 0)))  // should abort
     55  1.1  joerg //         return 1;
     56  1.1  joerg     if (test__absvti2(0x0000000000000000LL))
     57  1.1  joerg         return 1;
     58  1.1  joerg     if (test__absvti2(0x0000000000000001LL))
     59  1.1  joerg         return 1;
     60  1.1  joerg     if (test__absvti2(0x0000000000000002LL))
     61  1.1  joerg         return 1;
     62  1.1  joerg     if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
     63  1.1  joerg         return 1;
     64  1.1  joerg     if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
     65  1.1  joerg         return 1;
     66  1.1  joerg     if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
     67  1.1  joerg         return 1;
     68  1.1  joerg     if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL)))
     69  1.1  joerg         return 1;
     70  1.1  joerg     if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
     71  1.1  joerg         return 1;
     72  1.1  joerg     if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
     73  1.1  joerg         return 1;
     74  1.1  joerg 
     75  1.1  joerg     int i;
     76  1.1  joerg     for (i = 0; i < 10000; ++i)
     77  1.1  joerg         if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(),
     78  1.1  joerg                                   ((ti_int)rand() << 32) | rand())))
     79  1.1  joerg             return 1;
     80  1.1  joerg #else
     81  1.1  joerg     printf("skipped\n");
     82  1.1  joerg #endif
     83  1.1  joerg     return 0;
     84  1.1  joerg }
     85