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

lib: test_mul_u64_u64_div_u64(): test the 32bit code on 64bit

There are slight differences in the mul_u64_add_u64_div_u64() code between
32bit and 64bit systems.

Compile and test the 32bit version on 64bit hosts for better test
coverage.

Link: https://lkml.kernel.org/r/20251105201035.64043-10-david.laight.linux@gmail.com
Signed-off-by: David Laight <david.laight.linux@gmail.com>
Reviewed-by: Nicolas Pitre <npitre@baylibre.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Li RongQing <lirongqing@baidu.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Laight and committed by
Andrew Morton
1d1ef8c1 d10bb374

+29
+29
lib/math/test_mul_u64_u64_div_u64.c
··· 74 74 */ 75 75 76 76 static u64 test_mul_u64_add_u64_div_u64(u64 a, u64 b, u64 c, u64 d); 77 + #if __LONG_WIDTH__ >= 64 78 + #define TEST_32BIT_DIV 79 + static u64 test_mul_u64_add_u64_div_u64_32bit(u64 a, u64 b, u64 c, u64 d); 80 + #endif 77 81 78 82 static int __init test_run(unsigned int fn_no, const char *fn_name) 79 83 { ··· 104 100 result = test_mul_u64_add_u64_div_u64(a, b, 0, d); 105 101 result_up = test_mul_u64_add_u64_div_u64(a, b, d - 1, d); 106 102 break; 103 + #ifdef TEST_32BIT_DIV 104 + case 2: 105 + result = test_mul_u64_add_u64_div_u64_32bit(a, b, 0, d); 106 + result_up = test_mul_u64_add_u64_div_u64_32bit(a, b, d - 1, d); 107 + break; 108 + #endif 107 109 } 108 110 109 111 tests += 2; ··· 141 131 return -EINVAL; 142 132 if (test_run(1, "test_mul_u64_u64_div_u64")) 143 133 return -EINVAL; 134 + #ifdef TEST_32BIT_DIV 135 + if (test_run(2, "test_mul_u64_u64_div_u64_32bit")) 136 + return -EINVAL; 137 + #endif 144 138 return 0; 145 139 } 146 140 ··· 166 152 #define test_mul_u64_add_u64_div_u64 test_mul_u64_add_u64_div_u64 167 153 168 154 #include "div64.c" 155 + 156 + #ifdef TEST_32BIT_DIV 157 + /* Recompile the generic code for 32bit long */ 158 + #undef test_mul_u64_add_u64_div_u64 159 + #define test_mul_u64_add_u64_div_u64 test_mul_u64_add_u64_div_u64_32bit 160 + #undef BITS_PER_ITER 161 + #define BITS_PER_ITER 16 162 + 163 + #define mul_u64_u64_add_u64 mul_u64_u64_add_u64_32bit 164 + #undef mul_u64_long_add_u64 165 + #undef add_u64_long 166 + #undef mul_add 167 + 168 + #include "div64.c" 169 + #endif 169 170 170 171 module_init(test_init); 171 172 module_exit(test_exit);