Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- subvdi3_test.c - Test __subvdi3 -----------------------------------===//
      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 __subvdi3 for the compiler_rt library.
     11  1.1  joerg //
     12  1.1  joerg //===----------------------------------------------------------------------===//
     13  1.1  joerg 
     14  1.1  joerg #include "int_lib.h"
     15  1.1  joerg #include <stdio.h>
     16  1.1  joerg #include <stdlib.h>
     17  1.1  joerg 
     18  1.1  joerg // Returns: a - b
     19  1.1  joerg 
     20  1.1  joerg // Effects: aborts if a - b overflows
     21  1.1  joerg 
     22  1.1  joerg di_int __subvdi3(di_int a, di_int b);
     23  1.1  joerg 
     24  1.1  joerg int test__subvdi3(di_int a, di_int b)
     25  1.1  joerg {
     26  1.1  joerg     di_int x = __subvdi3(a, b);
     27  1.1  joerg     di_int expected = a - b;
     28  1.1  joerg     if (x != expected)
     29  1.1  joerg         printf("error in test__subvsi3(0x%llX, 0x%llX) = %lld, expected %lld\n",
     30  1.1  joerg                a, b, x, expected);
     31  1.1  joerg     return x != expected;
     32  1.1  joerg }
     33  1.1  joerg 
     34  1.1  joerg int main()
     35  1.1  joerg {
     36  1.1  joerg //     test__subvdi3(0x8000000000000000LL, 1);  // should abort
     37  1.1  joerg //     test__subvdi3(0, 0x8000000000000000LL);  // should abort
     38  1.1  joerg //     test__subvdi3(1, 0x8000000000000000LL);  // should abort
     39  1.1  joerg //     test__subvdi3(0x7FFFFFFFFFFFFFFFLL, -1);  // should abort
     40  1.1  joerg //     test__subvdi3(-2, 0x7FFFFFFFFFFFFFFFLL);  // should abort
     41  1.1  joerg 
     42  1.1  joerg     if (test__subvdi3(0x8000000000000000LL, -1))
     43  1.1  joerg         return 1;
     44  1.1  joerg     if (test__subvdi3(0x8000000000000000LL, 0))
     45  1.1  joerg         return 1;
     46  1.1  joerg     if (test__subvdi3(-1, 0x8000000000000000LL))
     47  1.1  joerg         return 1;
     48  1.1  joerg     if (test__subvdi3(0x7FFFFFFFFFFFFFFLL, 1))
     49  1.1  joerg         return 1;
     50  1.1  joerg     if (test__subvdi3(0x7FFFFFFFFFFFFFFFLL, 0))
     51  1.1  joerg         return 1;
     52  1.1  joerg     if (test__subvdi3(1, 0x7FFFFFFFFFFFFFFLL))
     53  1.1  joerg         return 1;
     54  1.1  joerg     if (test__subvdi3(0, 0x7FFFFFFFFFFFFFFFLL))
     55  1.1  joerg         return 1;
     56  1.1  joerg     if (test__subvdi3(-1, 0x7FFFFFFFFFFFFFFFLL))
     57  1.1  joerg         return 1;
     58  1.1  joerg 
     59  1.1  joerg     return 0;
     60  1.1  joerg }
     61