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