1 //===-- mulodi4_test.c - Test __mulodi4 -----------------------------------===// 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 __mulodi4 for the compiler_rt library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "int_lib.h" 15 #include <stdio.h> 16 17 extern di_int __mulodi4(di_int a, di_int b, int* overflow); 18 19 int test__mulodi4(di_int a, di_int b, di_int expected, int expected_overflow) 20 { 21 int ov; 22 di_int x = __mulodi4(a, b, &ov); 23 if (ov != expected_overflow) 24 printf("error in __mulodi4: overflow=%d expected=%d\n", 25 ov, expected_overflow); 26 else if (!expected_overflow && x != expected) { 27 printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), " 28 "expected 0x%llX (overflow=%d)\n", 29 a, b, x, ov, expected, expected_overflow); 30 return 1; 31 } 32 return 0; 33 } 34 35 int main() 36 { 37 if (test__mulodi4(0, 0, 0, 0)) 38 return 1; 39 if (test__mulodi4(0, 1, 0, 0)) 40 return 1; 41 if (test__mulodi4(1, 0, 0, 0)) 42 return 1; 43 if (test__mulodi4(0, 10, 0, 0)) 44 return 1; 45 if (test__mulodi4(10, 0, 0, 0)) 46 return 1; 47 if (test__mulodi4(0, 81985529216486895LL, 0, 0)) 48 return 1; 49 if (test__mulodi4(81985529216486895LL, 0, 0, 0)) 50 return 1; 51 52 if (test__mulodi4(0, -1, 0, 0)) 53 return 1; 54 if (test__mulodi4(-1, 0, 0, 0)) 55 return 1; 56 if (test__mulodi4(0, -10, 0, 0)) 57 return 1; 58 if (test__mulodi4(-10, 0, 0, 0)) 59 return 1; 60 if (test__mulodi4(0, -81985529216486895LL, 0, 0)) 61 return 1; 62 if (test__mulodi4(-81985529216486895LL, 0, 0, 0)) 63 return 1; 64 65 if (test__mulodi4(1, 1, 1, 0)) 66 return 1; 67 if (test__mulodi4(1, 10, 10, 0)) 68 return 1; 69 if (test__mulodi4(10, 1, 10, 0)) 70 return 1; 71 if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0)) 72 return 1; 73 if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0)) 74 return 1; 75 76 if (test__mulodi4(1, -1, -1, 0)) 77 return 1; 78 if (test__mulodi4(1, -10, -10, 0)) 79 return 1; 80 if (test__mulodi4(-10, 1, -10, 0)) 81 return 1; 82 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0)) 83 return 1; 84 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0)) 85 return 1; 86 87 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0)) 88 return 1; 89 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0)) 90 return 1; 91 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0)) 92 return 1; 93 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0)) 94 return 1; 95 96 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0)) 97 return 1; 98 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0)) 99 return 1; 100 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0)) 101 return 1; 102 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0)) 103 return 1; 104 105 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0)) 106 return 1; 107 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0)) 108 return 1; 109 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0)) 110 return 1; 111 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0)) 112 return 1; 113 114 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -2, 2, 1)) 115 return 1; 116 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL, 2, 1)) 117 return 1; 118 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -1, 0x8000000000000001LL, 0)) 119 return 1; 120 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 0)) 121 return 1; 122 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 0, 0, 0)) 123 return 1; 124 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL, 0, 0)) 125 return 1; 126 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 1, 0x7FFFFFFFFFFFFFFFLL, 0)) 127 return 1; 128 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL, 0)) 129 return 1; 130 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL, 1)) 131 return 1; 132 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 1)) 133 return 1; 134 135 if (test__mulodi4(0x8000000000000000LL, -2, 0x8000000000000000LL, 1)) 136 return 1; 137 if (test__mulodi4(-2, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 138 return 1; 139 if (test__mulodi4(0x8000000000000000LL, -1, 0x8000000000000000LL, 1)) 140 return 1; 141 if (test__mulodi4(-1, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 142 return 1; 143 if (test__mulodi4(0x8000000000000000LL, 0, 0, 0)) 144 return 1; 145 if (test__mulodi4(0, 0x8000000000000000LL, 0, 0)) 146 return 1; 147 if (test__mulodi4(0x8000000000000000LL, 1, 0x8000000000000000LL, 0)) 148 return 1; 149 if (test__mulodi4(1, 0x8000000000000000LL, 0x8000000000000000LL, 0)) 150 return 1; 151 if (test__mulodi4(0x8000000000000000LL, 2, 0x8000000000000000LL, 1)) 152 return 1; 153 if (test__mulodi4(2, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 154 return 1; 155 156 if (test__mulodi4(0x8000000000000001LL, -2, 0x8000000000000001LL, 1)) 157 return 1; 158 if (test__mulodi4(-2, 0x8000000000000001LL, 0x8000000000000001LL, 1)) 159 return 1; 160 if (test__mulodi4(0x8000000000000001LL, -1, 0x7FFFFFFFFFFFFFFFLL, 0)) 161 return 1; 162 if (test__mulodi4(-1, 0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL, 0)) 163 return 1; 164 if (test__mulodi4(0x8000000000000001LL, 0, 0, 0)) 165 return 1; 166 if (test__mulodi4(0, 0x8000000000000001LL, 0, 0)) 167 return 1; 168 if (test__mulodi4(0x8000000000000001LL, 1, 0x8000000000000001LL, 0)) 169 return 1; 170 if (test__mulodi4(1, 0x8000000000000001LL, 0x8000000000000001LL, 0)) 171 return 1; 172 if (test__mulodi4(0x8000000000000001LL, 2, 0x8000000000000000LL, 1)) 173 return 1; 174 if (test__mulodi4(2, 0x8000000000000001LL, 0x8000000000000000LL, 1)) 175 return 1; 176 177 return 0; 178 } 179