Home | History | Annotate | Download | only in Unit
      1 //===-- negti2_test.c - Test __negti2 -------------------------------------===//
      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 __negti2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 #ifdef CRT_HAS_128BIT
     18 
     19 // Returns: -a
     20 
     21 ti_int __negti2(ti_int a);
     22 
     23 int test__negti2(ti_int a, ti_int expected)
     24 {
     25     ti_int x = __negti2(a);
     26     if (x != expected)
     27     {
     28         twords at;
     29         at.all = a;
     30         twords xt;
     31         xt.all = x;
     32         twords expectedt;
     33         expectedt.all = expected;
     34         printf("error in __negti2: -0x%.16llX%.16llX = 0x%.16llX%.16llX, "
     35                "expected 0x%.16llX%.16llX\n",
     36                at.s.high, at.s.low, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
     37     }
     38     return x != expected;
     39 }
     40 
     41 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
     42 
     43 #endif
     44 
     45 int main()
     46 {
     47 #ifdef CRT_HAS_128BIT
     48     if (test__negti2(0, 0))
     49         return 1;
     50     if (test__negti2(1, -1))
     51         return 1;
     52     if (test__negti2(-1, 1))
     53         return 1;
     54     if (test__negti2(2, -2))
     55         return 1;
     56     if (test__negti2(-2, 2))
     57         return 1;
     58     if (test__negti2(3, -3))
     59         return 1;
     60     if (test__negti2(-3, 3))
     61         return 1;
     62     if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL),
     63                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL)))
     64         return 1;
     65     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL),
     66                      make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL)))
     67         return 1;
     68     if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL),
     69                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL)))
     70         return 1;
     71     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL),
     72                      make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL)))
     73         return 1;
     74     if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
     75                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
     76         return 1;
     77     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
     78                      make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
     79         return 1;
     80     if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
     81                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
     82         return 1;
     83     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
     84                      make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
     85         return 1;
     86     if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000300000000LL),
     87                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL)))
     88         return 1;
     89     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL),
     90                      make_ti(0x0000000000000000LL, 0x0000000300000000LL)))
     91         return 1;
     92     if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
     93                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
     94         return 1;
     95     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL),
     96                      make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL)))
     97         return 1;
     98     if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
     99                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
    100         return 1;
    101     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
    102                      make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
    103         return 1;
    104     if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
    105                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
    106         return 1;
    107     if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
    108                      make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
    109         return 1;
    110     if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
    111                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
    112         return 1;
    113     if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
    114                      make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
    115         return 1;
    116     if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
    117                      make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
    118         return 1;
    119     if (test__negti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
    120                      make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
    121         return 1;
    122 
    123 #else
    124     printf("skipped\n");
    125 #endif
    126    return 0;
    127 }
    128