Home | History | Annotate | Download | only in Unit
      1 //===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
      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 __addvti3 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #if __x86_64
     15 
     16 #include "int_lib.h"
     17 #include <stdio.h>
     18 
     19 // Returns: a + b
     20 
     21 // Effects: aborts if a + b overflows
     22 
     23 ti_int __addvti3(ti_int a, ti_int b);
     24 
     25 int test__addvti3(ti_int a, ti_int b)
     26 {
     27     ti_int x = __addvti3(a, b);
     28     ti_int expected = a + b;
     29     if (x != expected)
     30     {
     31         twords at;
     32         at.all = a;
     33         twords bt;
     34         bt.all = b;
     35         twords xt;
     36         xt.all = x;
     37         twords expectedt;
     38         expectedt.all = expected;
     39         printf("error in test__addvti3(0x%llX%.16llX, 0x%llX%.16llX) = "
     40                "0x%llX%.16llX, expected 0x%llX%.16llX\n",
     41                 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
     42                 expectedt.s.high, expectedt.s.low);
     43     }
     44     return x != expected;
     45 }
     46 
     47 #endif
     48 
     49 int main()
     50 {
     51 #if __x86_64
     52 // should abort
     53 //     test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
     54 //                   make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
     55 // should abort
     56 //     test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
     57 //                   make_ti(0x8000000000000000LL, 0x0000000000000000LL));
     58 // should abort
     59 //     test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
     60 //                   make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL));
     61 // should abort
     62 //     test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
     63 //                   make_ti(0x0000000000000000LL, 0x0000000000000001LL));
     64 
     65     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
     66                       make_ti(0x0000000000000000LL, 0x0000000000000001LL)))
     67         return 1;
     68     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000001LL),
     69                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
     70         return 1;
     71     if (test__addvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
     72                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
     73         return 1;
     74     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
     75                       make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
     76         return 1;
     77     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
     78                       make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
     79         return 1;
     80     if (test__addvti3(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
     81                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
     82         return 1;
     83     if (test__addvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
     84                       make_ti(0x0000000000000000LL, 0x0000000000000000LL)))
     85         return 1;
     86     if (test__addvti3(make_ti(0x0000000000000000LL, 0x0000000000000000LL),
     87                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
     88         return 1;
     89 
     90 #else
     91     printf("skipped\n");
     92 #endif
     93     return 0;
     94 }
     95