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