1 //===-- udivsi3_test.c - Test __udivsi3 -----------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file tests __udivsi3 for the compiler_rt library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "int_lib.h" 15 #include <stdio.h> 16 17 // Returns: a / b 18 19 su_int __udivsi3(su_int a, su_int b); 20 21 int test__udivsi3(su_int a, su_int b, su_int expected_q) 22 { 23 su_int q = __udivsi3(a, b); 24 if (q != expected_q) 25 printf("error in __udivsi3: %X / %X = %X, expected %X\n", 26 a, b, q, expected_q); 27 return q != expected_q; 28 } 29 30 su_int tests[][4] = 31 { 32 {0x00000000, 0x00000001, 0x00000000}, 33 {0x00000000, 0x00000002, 0x00000000}, 34 {0x00000000, 0x00000003, 0x00000000}, 35 {0x00000000, 0x00000010, 0x00000000}, 36 {0x00000000, 0x078644FA, 0x00000000}, 37 {0x00000000, 0x0747AE14, 0x00000000}, 38 {0x00000000, 0x7FFFFFFF, 0x00000000}, 39 {0x00000000, 0x80000000, 0x00000000}, 40 {0x00000000, 0xFFFFFFFD, 0x00000000}, 41 {0x00000000, 0xFFFFFFFE, 0x00000000}, 42 {0x00000000, 0xFFFFFFFF, 0x00000000}, 43 {0x00000001, 0x00000001, 0x00000001}, 44 {0x00000001, 0x00000002, 0x00000000}, 45 {0x00000001, 0x00000003, 0x00000000}, 46 {0x00000001, 0x00000010, 0x00000000}, 47 {0x00000001, 0x078644FA, 0x00000000}, 48 {0x00000001, 0x0747AE14, 0x00000000}, 49 {0x00000001, 0x7FFFFFFF, 0x00000000}, 50 {0x00000001, 0x80000000, 0x00000000}, 51 {0x00000001, 0xFFFFFFFD, 0x00000000}, 52 {0x00000001, 0xFFFFFFFE, 0x00000000}, 53 {0x00000001, 0xFFFFFFFF, 0x00000000}, 54 {0x00000002, 0x00000001, 0x00000002}, 55 {0x00000002, 0x00000002, 0x00000001}, 56 {0x00000002, 0x00000003, 0x00000000}, 57 {0x00000002, 0x00000010, 0x00000000}, 58 {0x00000002, 0x078644FA, 0x00000000}, 59 {0x00000002, 0x0747AE14, 0x00000000}, 60 {0x00000002, 0x7FFFFFFF, 0x00000000}, 61 {0x00000002, 0x80000000, 0x00000000}, 62 {0x00000002, 0xFFFFFFFD, 0x00000000}, 63 {0x00000002, 0xFFFFFFFE, 0x00000000}, 64 {0x00000002, 0xFFFFFFFF, 0x00000000}, 65 {0x00000003, 0x00000001, 0x00000003}, 66 {0x00000003, 0x00000002, 0x00000001}, 67 {0x00000003, 0x00000003, 0x00000001}, 68 {0x00000003, 0x00000010, 0x00000000}, 69 {0x00000003, 0x078644FA, 0x00000000}, 70 {0x00000003, 0x0747AE14, 0x00000000}, 71 {0x00000003, 0x7FFFFFFF, 0x00000000}, 72 {0x00000003, 0x80000000, 0x00000000}, 73 {0x00000003, 0xFFFFFFFD, 0x00000000}, 74 {0x00000003, 0xFFFFFFFE, 0x00000000}, 75 {0x00000003, 0xFFFFFFFF, 0x00000000}, 76 {0x00000010, 0x00000001, 0x00000010}, 77 {0x00000010, 0x00000002, 0x00000008}, 78 {0x00000010, 0x00000003, 0x00000005}, 79 {0x00000010, 0x00000010, 0x00000001}, 80 {0x00000010, 0x078644FA, 0x00000000}, 81 {0x00000010, 0x0747AE14, 0x00000000}, 82 {0x00000010, 0x7FFFFFFF, 0x00000000}, 83 {0x00000010, 0x80000000, 0x00000000}, 84 {0x00000010, 0xFFFFFFFD, 0x00000000}, 85 {0x00000010, 0xFFFFFFFE, 0x00000000}, 86 {0x00000010, 0xFFFFFFFF, 0x00000000}, 87 {0x078644FA, 0x00000001, 0x078644FA}, 88 {0x078644FA, 0x00000002, 0x03C3227D}, 89 {0x078644FA, 0x00000003, 0x028216FE}, 90 {0x078644FA, 0x00000010, 0x0078644F}, 91 {0x078644FA, 0x078644FA, 0x00000001}, 92 {0x078644FA, 0x0747AE14, 0x00000001}, 93 {0x078644FA, 0x7FFFFFFF, 0x00000000}, 94 {0x078644FA, 0x80000000, 0x00000000}, 95 {0x078644FA, 0xFFFFFFFD, 0x00000000}, 96 {0x078644FA, 0xFFFFFFFE, 0x00000000}, 97 {0x078644FA, 0xFFFFFFFF, 0x00000000}, 98 {0x0747AE14, 0x00000001, 0x0747AE14}, 99 {0x0747AE14, 0x00000002, 0x03A3D70A}, 100 {0x0747AE14, 0x00000003, 0x026D3A06}, 101 {0x0747AE14, 0x00000010, 0x00747AE1}, 102 {0x0747AE14, 0x078644FA, 0x00000000}, 103 {0x0747AE14, 0x0747AE14, 0x00000001}, 104 {0x0747AE14, 0x7FFFFFFF, 0x00000000}, 105 {0x0747AE14, 0x80000000, 0x00000000}, 106 {0x0747AE14, 0xFFFFFFFD, 0x00000000}, 107 {0x0747AE14, 0xFFFFFFFE, 0x00000000}, 108 {0x0747AE14, 0xFFFFFFFF, 0x00000000}, 109 {0x7FFFFFFF, 0x00000001, 0x7FFFFFFF}, 110 {0x7FFFFFFF, 0x00000002, 0x3FFFFFFF}, 111 {0x7FFFFFFF, 0x00000003, 0x2AAAAAAA}, 112 {0x7FFFFFFF, 0x00000010, 0x07FFFFFF}, 113 {0x7FFFFFFF, 0x078644FA, 0x00000011}, 114 {0x7FFFFFFF, 0x0747AE14, 0x00000011}, 115 {0x7FFFFFFF, 0x7FFFFFFF, 0x00000001}, 116 {0x7FFFFFFF, 0x80000000, 0x00000000}, 117 {0x7FFFFFFF, 0xFFFFFFFD, 0x00000000}, 118 {0x7FFFFFFF, 0xFFFFFFFE, 0x00000000}, 119 {0x7FFFFFFF, 0xFFFFFFFF, 0x00000000}, 120 {0x80000000, 0x00000001, 0x80000000}, 121 {0x80000000, 0x00000002, 0x40000000}, 122 {0x80000000, 0x00000003, 0x2AAAAAAA}, 123 {0x80000000, 0x00000010, 0x08000000}, 124 {0x80000000, 0x078644FA, 0x00000011}, 125 {0x80000000, 0x0747AE14, 0x00000011}, 126 {0x80000000, 0x7FFFFFFF, 0x00000001}, 127 {0x80000000, 0x80000000, 0x00000001}, 128 {0x80000000, 0xFFFFFFFD, 0x00000000}, 129 {0x80000000, 0xFFFFFFFE, 0x00000000}, 130 {0x80000000, 0xFFFFFFFF, 0x00000000}, 131 {0xFFFFFFFD, 0x00000001, 0xFFFFFFFD}, 132 {0xFFFFFFFD, 0x00000002, 0x7FFFFFFE}, 133 {0xFFFFFFFD, 0x00000003, 0x55555554}, 134 {0xFFFFFFFD, 0x00000010, 0x0FFFFFFF}, 135 {0xFFFFFFFD, 0x078644FA, 0x00000022}, 136 {0xFFFFFFFD, 0x0747AE14, 0x00000023}, 137 {0xFFFFFFFD, 0x7FFFFFFF, 0x00000001}, 138 {0xFFFFFFFD, 0x80000000, 0x00000001}, 139 {0xFFFFFFFD, 0xFFFFFFFD, 0x00000001}, 140 {0xFFFFFFFD, 0xFFFFFFFE, 0x00000000}, 141 {0xFFFFFFFD, 0xFFFFFFFF, 0x00000000}, 142 {0xFFFFFFFE, 0x00000001, 0xFFFFFFFE}, 143 {0xFFFFFFFE, 0x00000002, 0x7FFFFFFF}, 144 {0xFFFFFFFE, 0x00000003, 0x55555554}, 145 {0xFFFFFFFE, 0x00000010, 0x0FFFFFFF}, 146 {0xFFFFFFFE, 0x078644FA, 0x00000022}, 147 {0xFFFFFFFE, 0x0747AE14, 0x00000023}, 148 {0xFFFFFFFE, 0x7FFFFFFF, 0x00000002}, 149 {0xFFFFFFFE, 0x80000000, 0x00000001}, 150 {0xFFFFFFFE, 0xFFFFFFFD, 0x00000001}, 151 {0xFFFFFFFE, 0xFFFFFFFE, 0x00000001}, 152 {0xFFFFFFFE, 0xFFFFFFFF, 0x00000000}, 153 {0xFFFFFFFF, 0x00000001, 0xFFFFFFFF}, 154 {0xFFFFFFFF, 0x00000002, 0x7FFFFFFF}, 155 {0xFFFFFFFF, 0x00000003, 0x55555555}, 156 {0xFFFFFFFF, 0x00000010, 0x0FFFFFFF}, 157 {0xFFFFFFFF, 0x078644FA, 0x00000022}, 158 {0xFFFFFFFF, 0x0747AE14, 0x00000023}, 159 {0xFFFFFFFF, 0x7FFFFFFF, 0x00000002}, 160 {0xFFFFFFFF, 0x80000000, 0x00000001}, 161 {0xFFFFFFFF, 0xFFFFFFFD, 0x00000001}, 162 {0xFFFFFFFF, 0xFFFFFFFE, 0x00000001}, 163 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000001} 164 }; 165 166 int main() 167 { 168 const unsigned N = sizeof(tests) / sizeof(tests[0]); 169 unsigned i; 170 for (i = 0; i < N; ++i) 171 if (test__udivsi3(tests[i][0], tests[i][1], tests[i][2])) 172 return 1; 173 174 return 0; 175 } 176