Eric Christopher | 1ace405 | 2011-06-17 20:17:05 +0000 | [diff] [blame] | 1 | //===-- mulosi4_test.c - Test __mulosi4 -----------------------------------===// |
| 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 __mulosi4 for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "int_lib.h" |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | // Returns: a * b |
| 18 | |
| 19 | // Effects: aborts if a * b overflows |
| 20 | |
| 21 | si_int __mulosi4(si_int a, si_int b, int *overflow); |
| 22 | |
| 23 | int test__mulosi4(si_int a, si_int b, si_int expected, int expected_overflow) |
| 24 | { |
| 25 | int ov; |
| 26 | si_int x = __mulosi4(a, b, &ov); |
| 27 | if (ov != expected_overflow) |
| 28 | printf("error in __mulosi4: overflow=%d expected=%d\n", |
| 29 | ov, expected_overflow); |
| 30 | else if (!expected_overflow && x != expected) { |
| 31 | printf("error in __mulosi4: 0x%X * 0x%X = 0x%X (overflow=%d), " |
| 32 | "expected 0x%X (overflow=%d)\n", |
| 33 | a, b, x, ov, expected, expected_overflow); |
| 34 | return 1; |
| 35 | } |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | if (test__mulosi4(0, 0, 0, 0)) |
| 43 | return 1; |
| 44 | if (test__mulosi4(0, 1, 0, 0)) |
| 45 | return 1; |
| 46 | if (test__mulosi4(1, 0, 0, 0)) |
| 47 | return 1; |
| 48 | if (test__mulosi4(0, 10, 0, 0)) |
| 49 | return 1; |
| 50 | if (test__mulosi4(10, 0, 0, 0)) |
| 51 | return 1; |
| 52 | if (test__mulosi4(0, 0x1234567, 0, 0)) |
| 53 | return 1; |
| 54 | if (test__mulosi4(0x1234567, 0, 0, 0)) |
| 55 | return 1; |
| 56 | |
| 57 | if (test__mulosi4(0, -1, 0, 0)) |
| 58 | return 1; |
| 59 | if (test__mulosi4(-1, 0, 0, 0)) |
| 60 | return 1; |
| 61 | if (test__mulosi4(0, -10, 0, 0)) |
| 62 | return 1; |
| 63 | if (test__mulosi4(-10, 0, 0, 0)) |
| 64 | return 1; |
| 65 | if (test__mulosi4(0, -0x1234567, 0, 0)) |
| 66 | return 1; |
| 67 | if (test__mulosi4(-0x1234567, 0, 0, 0)) |
| 68 | return 1; |
| 69 | |
| 70 | if (test__mulosi4(1, 1, 1, 0)) |
| 71 | return 1; |
| 72 | if (test__mulosi4(1, 10, 10, 0)) |
| 73 | return 1; |
| 74 | if (test__mulosi4(10, 1, 10, 0)) |
| 75 | return 1; |
| 76 | if (test__mulosi4(1, 0x1234567, 0x1234567, 0)) |
| 77 | return 1; |
| 78 | if (test__mulosi4(0x1234567, 1, 0x1234567, 0)) |
| 79 | return 1; |
| 80 | |
| 81 | if (test__mulosi4(1, -1, -1, 0)) |
| 82 | return 1; |
| 83 | if (test__mulosi4(1, -10, -10, 0)) |
| 84 | return 1; |
| 85 | if (test__mulosi4(-10, 1, -10, 0)) |
| 86 | return 1; |
| 87 | if (test__mulosi4(1, -0x1234567, -0x1234567, 0)) |
| 88 | return 1; |
| 89 | if (test__mulosi4(-0x1234567, 1, -0x1234567, 0)) |
| 90 | return 1; |
| 91 | |
| 92 | if (test__mulosi4(0x7FFFFFFF, -2, 0x80000001, 1)) |
| 93 | return 1; |
| 94 | if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1)) |
| 95 | return 1; |
| 96 | if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0)) |
| 97 | return 1; |
| 98 | if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0)) |
| 99 | return 1; |
| 100 | if (test__mulosi4(0x7FFFFFFF, 0, 0, 0)) |
| 101 | return 1; |
| 102 | if (test__mulosi4(0, 0x7FFFFFFF, 0, 0)) |
| 103 | return 1; |
| 104 | if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0)) |
| 105 | return 1; |
| 106 | if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0)) |
| 107 | return 1; |
| 108 | if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1)) |
| 109 | return 1; |
| 110 | if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1)) |
| 111 | return 1; |
| 112 | |
| 113 | if (test__mulosi4(0x80000000, -2, 0x80000000, 1)) |
| 114 | return 1; |
| 115 | if (test__mulosi4(-2, 0x80000000, 0x80000000, 1)) |
| 116 | return 1; |
| 117 | if (test__mulosi4(0x80000000, -1, 0x80000000, 1)) |
| 118 | return 1; |
| 119 | if (test__mulosi4(-1, 0x80000000, 0x80000000, 1)) |
| 120 | return 1; |
| 121 | if (test__mulosi4(0x80000000, 0, 0, 0)) |
| 122 | return 1; |
| 123 | if (test__mulosi4(0, 0x80000000, 0, 0)) |
| 124 | return 1; |
| 125 | if (test__mulosi4(0x80000000, 1, 0x80000000, 0)) |
| 126 | return 1; |
| 127 | if (test__mulosi4(1, 0x80000000, 0x80000000, 0)) |
| 128 | return 1; |
| 129 | if (test__mulosi4(0x80000000, 2, 0x80000000, 1)) |
| 130 | return 1; |
| 131 | if (test__mulosi4(2, 0x80000000, 0x80000000, 1)) |
| 132 | return 1; |
| 133 | |
| 134 | if (test__mulosi4(0x80000001, -2, 0x80000001, 1)) |
| 135 | return 1; |
| 136 | if (test__mulosi4(-2, 0x80000001, 0x80000001, 1)) |
| 137 | return 1; |
| 138 | if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0)) |
| 139 | return 1; |
| 140 | if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0)) |
| 141 | return 1; |
| 142 | if (test__mulosi4(0x80000001, 0, 0, 0)) |
| 143 | return 1; |
| 144 | if (test__mulosi4(0, 0x80000001, 0, 0)) |
| 145 | return 1; |
| 146 | if (test__mulosi4(0x80000001, 1, 0x80000001, 0)) |
| 147 | return 1; |
| 148 | if (test__mulosi4(1, 0x80000001, 0x80000001, 0)) |
| 149 | return 1; |
| 150 | if (test__mulosi4(0x80000001, 2, 0x80000000, 1)) |
| 151 | return 1; |
| 152 | if (test__mulosi4(2, 0x80000001, 0x80000000, 1)) |
| 153 | return 1; |
| 154 | |
| 155 | return 0; |
| 156 | } |