Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/math/test_div64: add some edge cases relevant to __div64_const32()

Be sure to test the extreme cases with and without bias.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Nicolas Pitre and committed by
Arnd Bergmann
1dc82675 3e25d5a4

+83 -2
+83 -2
lib/math/test_div64.c
··· 26 26 0x0072db27380dd689, 27 27 0x0842f488162e2284, 28 28 0xf66745411d8ab063, 29 + 0xfffffffffffffffb, 30 + 0xfffffffffffffffc, 31 + 0xffffffffffffffff, 29 32 }; 30 33 #define SIZE_DIV64_DIVIDENDS ARRAY_SIZE(test_div64_dividends) 31 34 ··· 40 37 #define TEST_DIV64_DIVISOR_5 0x0008a880 41 38 #define TEST_DIV64_DIVISOR_6 0x003fd3ae 42 39 #define TEST_DIV64_DIVISOR_7 0x0b658fac 43 - #define TEST_DIV64_DIVISOR_8 0xdc08b349 40 + #define TEST_DIV64_DIVISOR_8 0x80000001 41 + #define TEST_DIV64_DIVISOR_9 0xdc08b349 42 + #define TEST_DIV64_DIVISOR_A 0xfffffffe 43 + #define TEST_DIV64_DIVISOR_B 0xffffffff 44 44 45 45 static const u32 test_div64_divisors[] = { 46 46 TEST_DIV64_DIVISOR_0, ··· 55 49 TEST_DIV64_DIVISOR_6, 56 50 TEST_DIV64_DIVISOR_7, 57 51 TEST_DIV64_DIVISOR_8, 52 + TEST_DIV64_DIVISOR_9, 53 + TEST_DIV64_DIVISOR_A, 54 + TEST_DIV64_DIVISOR_B, 58 55 }; 59 56 #define SIZE_DIV64_DIVISORS ARRAY_SIZE(test_div64_divisors) 60 57 61 58 static const struct { 62 59 u64 quotient; 63 60 u32 remainder; 64 - } test_div64_results[SIZE_DIV64_DIVISORS][SIZE_DIV64_DIVIDENDS] = { 61 + } test_div64_results[SIZE_DIV64_DIVIDENDS][SIZE_DIV64_DIVISORS] = { 65 62 { 66 63 { 0x0000000013045e47, 0x00000001 }, 67 64 { 0x000000000161596c, 0x00000030 }, ··· 74 65 { 0x00000000000013c4, 0x0004ce80 }, 75 66 { 0x00000000000002ae, 0x001e143c }, 76 67 { 0x000000000000000f, 0x0033e56c }, 68 + { 0x0000000000000001, 0x2b27507f }, 69 + { 0x0000000000000000, 0xab275080 }, 70 + { 0x0000000000000000, 0xab275080 }, 77 71 { 0x0000000000000000, 0xab275080 }, 78 72 }, { 79 73 { 0x00000001c45c02d1, 0x00000000 }, ··· 87 75 { 0x000000000001d637, 0x0004e5d9 }, 88 76 { 0x0000000000003fc9, 0x000713bb }, 89 77 { 0x0000000000000165, 0x029abe7d }, 78 + { 0x000000000000001f, 0x673c193a }, 90 79 { 0x0000000000000012, 0x6e9f7e37 }, 80 + { 0x000000000000000f, 0xe73c1977 }, 81 + { 0x000000000000000f, 0xe73c1968 }, 91 82 }, { 92 83 { 0x000000197a3a0cf7, 0x00000002 }, 93 84 { 0x00000001d9632e5c, 0x00000021 }, ··· 100 85 { 0x00000000001a7bb3, 0x00072331 }, 101 86 { 0x00000000000397ad, 0x0002c61b }, 102 87 { 0x000000000000141e, 0x06ea2e89 }, 88 + { 0x00000000000001ca, 0x4c0a72e7 }, 103 89 { 0x000000000000010a, 0xab002ad7 }, 90 + { 0x00000000000000e5, 0x4c0a767b }, 91 + { 0x00000000000000e5, 0x4c0a7596 }, 104 92 }, { 105 93 { 0x0000017949e37538, 0x00000001 }, 106 94 { 0x0000001b62441f37, 0x00000055 }, ··· 113 95 { 0x0000000001882ec6, 0x0005cbf9 }, 114 96 { 0x000000000035333b, 0x0017abdf }, 115 97 { 0x00000000000129f1, 0x0ab4520d }, 98 + { 0x0000000000001a87, 0x18ff0472 }, 116 99 { 0x0000000000000f6e, 0x8ac0ce9b }, 100 + { 0x0000000000000d43, 0x98ff397f }, 101 + { 0x0000000000000d43, 0x98ff2c3c }, 117 102 }, { 118 103 { 0x000011f321a74e49, 0x00000006 }, 119 104 { 0x0000014d8481d211, 0x0000005b }, ··· 126 105 { 0x0000000012a88828, 0x00036c97 }, 127 106 { 0x000000000287f16f, 0x002c2a25 }, 128 107 { 0x00000000000e2cc7, 0x02d581e3 }, 108 + { 0x0000000000014318, 0x2ee07d7f }, 129 109 { 0x000000000000bbf4, 0x1ba08c03 }, 110 + { 0x000000000000a18c, 0x2ee303af }, 111 + { 0x000000000000a18c, 0x2ee26223 }, 130 112 }, { 131 113 { 0x0000d8db8f72935d, 0x00000005 }, 132 114 { 0x00000fbd5aed7a2e, 0x00000002 }, ··· 139 115 { 0x00000000e16b20fa, 0x0002a14a }, 140 116 { 0x000000001e940d22, 0x00353b2e }, 141 117 { 0x0000000000ab40ac, 0x06fba6ba }, 118 + { 0x00000000000f3f70, 0x0af7eeda }, 142 119 { 0x000000000008debd, 0x72d98365 }, 120 + { 0x0000000000079fb8, 0x0b166dba }, 121 + { 0x0000000000079fb8, 0x0b0ece02 }, 143 122 }, { 144 123 { 0x000cc3045b8fc281, 0x00000000 }, 145 124 { 0x0000ed1f48b5c9fc, 0x00000079 }, ··· 152 125 { 0x0000000d43fce827, 0x00082b09 }, 153 126 { 0x00000001ccaba11a, 0x0037e8dd }, 154 127 { 0x000000000a13f729, 0x0566dffd }, 128 + { 0x0000000000e5b64e, 0x3728203b }, 155 129 { 0x000000000085a14b, 0x23d36726 }, 130 + { 0x000000000072db27, 0x38f38cd7 }, 131 + { 0x000000000072db27, 0x3880b1b0 }, 156 132 }, { 157 133 { 0x00eafeb9c993592b, 0x00000001 }, 158 134 { 0x00110e5befa9a991, 0x00000048 }, ··· 165 135 { 0x000000f4459740fc, 0x00084484 }, 166 136 { 0x0000002122c47bf9, 0x002ca446 }, 167 137 { 0x00000000b9936290, 0x004979c4 }, 138 + { 0x000000001085e910, 0x05a83974 }, 168 139 { 0x00000000099ca89d, 0x9db446bf }, 140 + { 0x000000000842f488, 0x26b40b94 }, 141 + { 0x000000000842f488, 0x1e71170c }, 169 142 }, { 170 143 { 0x1b60cece589da1d2, 0x00000001 }, 171 144 { 0x01fcb42be1453f5b, 0x0000004f }, ··· 178 145 { 0x00001c757dfab350, 0x00048863 }, 179 146 { 0x000003dc4979c652, 0x00224ea7 }, 180 147 { 0x000000159edc3144, 0x06409ab3 }, 148 + { 0x00000001ecce8a7e, 0x30bc25e5 }, 181 149 { 0x000000011eadfee3, 0xa99c48a8 }, 150 + { 0x00000000f6674543, 0x0a593ae9 }, 151 + { 0x00000000f6674542, 0x13f1f5a5 }, 152 + }, { 153 + { 0x1c71c71c71c71c71, 0x00000002 }, 154 + { 0x0210842108421084, 0x0000000b }, 155 + { 0x007f01fc07f01fc0, 0x000000fb }, 156 + { 0x00014245eabf1f9a, 0x0000a63d }, 157 + { 0x0000ffffffffffff, 0x0000fffb }, 158 + { 0x00001d913cecc509, 0x0007937b }, 159 + { 0x00000402c70c678f, 0x0005bfc9 }, 160 + { 0x00000016766cb70b, 0x045edf97 }, 161 + { 0x00000001fffffffb, 0x80000000 }, 162 + { 0x0000000129d84b3a, 0xa2e8fe71 }, 163 + { 0x0000000100000001, 0xfffffffd }, 164 + { 0x0000000100000000, 0xfffffffb }, 165 + }, { 166 + { 0x1c71c71c71c71c71, 0x00000003 }, 167 + { 0x0210842108421084, 0x0000000c }, 168 + { 0x007f01fc07f01fc0, 0x000000fc }, 169 + { 0x00014245eabf1f9a, 0x0000a63e }, 170 + { 0x0000ffffffffffff, 0x0000fffc }, 171 + { 0x00001d913cecc509, 0x0007937c }, 172 + { 0x00000402c70c678f, 0x0005bfca }, 173 + { 0x00000016766cb70b, 0x045edf98 }, 174 + { 0x00000001fffffffc, 0x00000000 }, 175 + { 0x0000000129d84b3a, 0xa2e8fe72 }, 176 + { 0x0000000100000002, 0x00000000 }, 177 + { 0x0000000100000000, 0xfffffffc }, 178 + }, { 179 + { 0x1c71c71c71c71c71, 0x00000006 }, 180 + { 0x0210842108421084, 0x0000000f }, 181 + { 0x007f01fc07f01fc0, 0x000000ff }, 182 + { 0x00014245eabf1f9a, 0x0000a641 }, 183 + { 0x0000ffffffffffff, 0x0000ffff }, 184 + { 0x00001d913cecc509, 0x0007937f }, 185 + { 0x00000402c70c678f, 0x0005bfcd }, 186 + { 0x00000016766cb70b, 0x045edf9b }, 187 + { 0x00000001fffffffc, 0x00000003 }, 188 + { 0x0000000129d84b3a, 0xa2e8fe75 }, 189 + { 0x0000000100000002, 0x00000003 }, 190 + { 0x0000000100000001, 0x00000000 }, 182 191 }, 183 192 }; 184 193 ··· 282 207 if (!test_div64_one(dividend, TEST_DIV64_DIVISOR_7, i, 7)) 283 208 return false; 284 209 if (!test_div64_one(dividend, TEST_DIV64_DIVISOR_8, i, 8)) 210 + return false; 211 + if (!test_div64_one(dividend, TEST_DIV64_DIVISOR_9, i, 9)) 212 + return false; 213 + if (!test_div64_one(dividend, TEST_DIV64_DIVISOR_A, i, 10)) 214 + return false; 215 + if (!test_div64_one(dividend, TEST_DIV64_DIVISOR_B, i, 11)) 285 216 return false; 286 217 for (j = 0; j < SIZE_DIV64_DIVISORS; j++) { 287 218 if (!test_div64_one(dividend, test_div64_divisors[j],