89 unsigned int shift ) {
90 return (
value << shift );
101 unsigned int shift ) {
102 return (
value >> shift );
113 unsigned int shift ) {
114 return (
value >> shift );
131 __asm__ (
"\n" :
"=g" ( ret ) :
"0" ( &a ) );
154 #define check_divmod( dividend, divisor, OP ) ( { \ 157 void *check = NULL; \ 160 __asm__ ( "\n" : "=g" ( count ) : "0" ( count ) ); \ 167 assert ( check == stack_check() ); \ 169 check = stack_check(); \ 175 __asm__ ( "\n" : "=g" ( dividend ), "=g" ( divisor ) \ 176 : "0" ( dividend ), "1" ( divisor ) ); \ 177 result = ( dividend OP divisor ); \ 178 __asm__ ( "\n" : "=g" ( result ) : "0" ( result ) ); \ 180 } while ( --count ); \ 252 #define ffsl_ok( value, lsb ) ffsl_okx ( value, lsb, __FILE__, __LINE__ ) 271 #define ffsll_ok( value, lsb ) ffsll_okx ( value, lsb, __FILE__, __LINE__ ) 290 #define flsl_ok( value, msb ) flsl_okx ( value, msb, __FILE__, __LINE__ ) 309 #define flsll_ok( value, msb ) flsll_okx ( value, msb, __FILE__, __LINE__ ) 322 const char *file,
unsigned int line ) {
325 okx ( (
value << shift ) == expected, file, line );
330 #define lsl64_ok( value, shift, expected ) \ 331 lsl64_okx ( value, shift, expected, __FILE__, __LINE__ ) 344 const char *file,
unsigned int line ) {
347 okx ( (
value >> shift ) == expected, file, line );
352 #define lsr64_ok( value, shift, expected ) \ 353 lsr64_okx ( value, shift, expected, __FILE__, __LINE__ ) 366 const char *file,
unsigned int line ) {
369 okx ( (
value >> shift ) == expected, file, line );
374 #define asr64_ok( value, shift, expected ) \ 375 asr64_okx ( value, shift, expected, __FILE__, __LINE__ ) 389 const char *file,
unsigned int line ) {
392 okx ( ( ( divisor * quotient ) + remainder ) == dividend, file, line );
395 okx (
u64div_var ( dividend, divisor ) == quotient, file, line );
398 okx (
u64mod_var ( dividend, divisor ) == remainder, file, line );
400 #define u64divmod_ok( dividend, divisor, quotient, remainder ) \ 401 u64divmod_okx ( dividend, divisor, quotient, remainder, \ 416 const char *file,
unsigned int line ) {
419 okx ( ( ( divisor * quotient ) + remainder ) == dividend, file, line );
422 okx (
s64div_var ( dividend, divisor ) == quotient, file, line );
425 okx (
s64mod_var ( dividend, divisor ) == remainder, file, line );
427 #define s64divmod_ok( dividend, divisor, quotient, remainder ) \ 428 s64divmod_okx ( dividend, divisor, quotient, remainder, \ 451 ffsll_ok ( 0x8000000000000000ULL, 64 );
460 flsl_ok ( -1U, ( 8 *
sizeof (
int ) ) );
461 flsl_ok ( -1UL, ( 8 *
sizeof (
long ) ) );
467 flsll_ok ( -1U, ( 8 *
sizeof (
int ) ) );
468 flsll_ok ( -1UL, ( 8 *
sizeof (
long ) ) );
469 flsll_ok ( -1ULL, ( 8 *
sizeof (
long long ) ) );
480 lsl64_ok ( 0x06760c14710540c2ULL, 0, 0x06760c14710540c2ULL );
481 lsr64_ok ( 0x06760c14710540c2ULL, 0, 0x06760c14710540c2ULL );
482 asr64_ok ( 0x06760c14710540c2ULL, 0, 0x06760c14710540c2ULL );
483 lsl64_ok ( 0xccafd1a8cb724c13ULL, 20, 0x1a8cb724c1300000ULL );
484 lsr64_ok ( 0xccafd1a8cb724c13ULL, 20, 0x00000ccafd1a8cb7ULL );
485 asr64_ok ( 0xccafd1a8cb724c13ULL, 20, 0xfffffccafd1a8cb7ULL );
486 lsl64_ok ( 0x83567264b1234518ULL, 32, 0xb123451800000000ULL );
487 lsr64_ok ( 0x83567264b1234518ULL, 32, 0x0000000083567264ULL );
488 asr64_ok ( 0x83567264b1234518ULL, 32, 0xffffffff83567264ULL );
489 lsl64_ok ( 0x69ee42fcbf1a4ea4ULL, 47, 0x2752000000000000ULL );
490 lsr64_ok ( 0x69ee42fcbf1a4ea4ULL, 47, 0x000000000000d3dcULL );
491 asr64_ok ( 0x69ee42fcbf1a4ea4ULL, 47, 0x000000000000d3dcULL );
492 lsl64_ok ( 0xaa20b8caddee4269ULL, 63, 0x8000000000000000ULL );
493 lsr64_ok ( 0xaa20b8caddee4269ULL, 63, 0x0000000000000001ULL );
494 asr64_ok ( 0xaa20b8caddee4269ULL, 63, 0xffffffffffffffffULL );
496 0x2eef6ab4ULL, 0x0e12f089ULL );
498 0x2eef6ab4ULL, 0x0e12f089ULL );
499 u64divmod_ok ( 0xc09e00dcb9e34b54ULL, 0x35968185cdc744f3ULL,
500 3, 0x1fda7c4b508d7c7bULL );
501 s64divmod_ok ( -0x3f61ff23461cb4acLL, 0x35968185cdc744f3ULL,
502 -1LL, -0x9cb7d9d78556fb9LL );
512 ok (
isqrt ( 0xa53df2adUL ) == 52652 );
513 ok (
isqrt ( 0x123793c6UL ) == 17482 );
514 ok (
isqrt ( -1UL ) == ( -1UL >> ( 8 *
sizeof (
unsigned long ) / 2 )));
#define s64divmod_ok(dividend, divisor, quotient, remainder)
#define ffsl(x)
Find first (i.e.
#define ffsl_ok(value, lsb)
#define lsl64_ok(value, shift, expected)
unsigned long isqrt(unsigned long value)
Find integer square root.
unsigned long long uint64_t
Self-test infrastructure.
const char * name
Test set name.
static void ffsl_okx(long value, int lsb, const char *file, unsigned int line)
Report a ffsl() test result.
#define flsll(x)
Find last (i.e.
int ffsll_var(long long value)
Force a call to the non-constant implementation of ffsll()
int64_t s64div_var(int64_t dividend, int64_t divisor)
Force a use of runtime 64-bit signed integer division.
static void lsr64_okx(uint64_t value, unsigned int shift, uint64_t expected, const char *file, unsigned int line)
Report a 64-bit logical shift right test result.
#define u64divmod_ok(dividend, divisor, quotient, remainder)
uint64_t u64div_var(uint64_t dividend, uint64_t divisor)
Force a use of runtime 64-bit unsigned integer division.
struct self_test math_test __self_test
Mathematical self-tests.
#define okx(success, file, line)
Report test result.
#define ffsll(x)
Find first (i.e.
#define ffsll_ok(value, lsb)
static void math_test_exec(void)
Perform mathematical self-tests.
static void asr64_okx(int64_t value, unsigned int shift, int64_t expected, const char *file, unsigned int line)
Report a 64-bit arithmetic shift right test result.
pseudo_bit_t value[0x00020]
static void u64divmod_okx(uint64_t dividend, uint64_t divisor, uint64_t quotient, uint64_t remainder, const char *file, unsigned int line)
Report a 64-bit unsigned integer division test result.
static void ffsll_okx(long long value, int lsb, const char *file, unsigned int line)
Report a ffsll() test result.
static void * stack_check(void)
Check current stack pointer.
static void s64divmod_okx(int64_t dividend, int64_t divisor, int64_t quotient, int64_t remainder, const char *file, unsigned int line)
Report a 64-bit signed integer division test result.
int64_t s64mod_var(int64_t dividend, int64_t divisor)
Force a use of runtime 64-bit unsigned integer modulus.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int64_t asr64_var(int64_t value, unsigned int shift)
Force a use of runtime 64-bit arithmetic shift right.
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint64_t u64mod_var(uint64_t dividend, uint64_t divisor)
Force a use of runtime 64-bit unsigned integer modulus.
#define flsll_ok(value, msb)
uint64_t lsl64_var(uint64_t value, unsigned int shift)
Force a use of runtime 64-bit shift left.
#define asr64_ok(value, shift, expected)
static void flsl_okx(long value, int msb, const char *file, unsigned int line)
Report a flsl() test result.
int flsll_var(long long value)
Force a call to the non-constant implementation of flsll()
static void flsll_okx(long long value, int msb, const char *file, unsigned int line)
Report a flsll() test result.
#define check_divmod(dividend, divisor, OP)
Check division/modulus operation.
int ffsl_var(long value)
Force a call to the non-constant implementation of ffsl()
#define flsl(x)
Find last (i.e.
#define lsr64_ok(value, shift, expected)
static void lsl64_okx(uint64_t value, unsigned int shift, uint64_t expected, const char *file, unsigned int line)
Report a 64-bit shift left test result.
int flsl_var(long value)
Force a call to the non-constant implementation of flsl()
uint64_t lsr64_var(uint64_t value, unsigned int shift)
Force a use of runtime 64-bit logical shift right.
#define flsl_ok(value, msb)