1 //===-- subvti3_test.c - Test __subvti3 -----------------------------------===// 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 __subvti3 for the compiler_rt library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "int_lib.h" 15 #include <stdio.h> 16 #include <stdlib.h> 17 18 #ifdef CRT_HAS_128BIT 19 20 // Returns: a - b 21 22 // Effects: aborts if a - b overflows 23 24 COMPILER_RT_ABI ti_int __subvti3(ti_int a, ti_int b); 25 26 int test__subvti3(ti_int a, ti_int b) 27 { 28 ti_int x = __subvti3(a, b); 29 ti_int expected = a - b; 30 if (x != expected) 31 { 32 twords at; 33 at.all = a; 34 twords bt; 35 bt.all = b; 36 twords xt; 37 xt.all = x; 38 twords expectedt; 39 expectedt.all = expected; 40 printf("error in test__subvsi3(0x%.16llX%.16llX, 0x%.16llX%.16llX) = " 41 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", 42 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low, 43 expectedt.s.high, expectedt.s.low); 44 } 45 return x != expected; 46 } 47 48 #endif 49 50 int main() 51 { 52 #ifdef CRT_HAS_128BIT 53 // test__subvti3(make_ti(0x8000000000000000LL, 0), 1); // should abort 54 // test__subvti3(0, make_ti(0x8000000000000000LL, 0)); // should abort 55 // test__subvti3(1, make_ti(0x8000000000000000LL, 0)); // should abort 56 // test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), -1); // should abort 57 // test__subvti3(-2, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)); // should abort 58 59 if (test__subvti3(make_ti(0x8000000000000000LL, 0), -1)) 60 return 1; 61 if (test__subvti3(make_ti(0x8000000000000000LL, 0), 0)) 62 return 1; 63 if (test__subvti3(-1, make_ti(0x8000000000000000LL, 0))) 64 return 1; 65 if (test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 1)) 66 return 1; 67 if (test__subvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0)) 68 return 1; 69 if (test__subvti3(1, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) 70 return 1; 71 if (test__subvti3(0, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) 72 return 1; 73 if (test__subvti3(-1, make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL))) 74 return 1; 75 76 #else 77 printf("skipped\n"); 78 #endif 79 return 0; 80 } 81