iPXE
|
Mathematical self-tests. More...
#include <string.h>
#include <strings.h>
#include <assert.h>
#include <ipxe/test.h>
#include <ipxe/isqrt.h>
Go to the source code of this file.
Macros | |
#define | check_divmod(dividend, divisor, OP) |
Check division/modulus operation. More... | |
#define | ffsl_ok(value, lsb) ffsl_okx ( value, lsb, __FILE__, __LINE__ ) |
#define | ffsll_ok(value, lsb) ffsll_okx ( value, lsb, __FILE__, __LINE__ ) |
#define | flsl_ok(value, msb) flsl_okx ( value, msb, __FILE__, __LINE__ ) |
#define | flsll_ok(value, msb) flsll_okx ( value, msb, __FILE__, __LINE__ ) |
#define | lsl64_ok(value, shift, expected) lsl64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
#define | lsr64_ok(value, shift, expected) lsr64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
#define | asr64_ok(value, shift, expected) asr64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
#define | u64divmod_ok(dividend, divisor, quotient, remainder) |
#define | s64divmod_ok(dividend, divisor, quotient, remainder) |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
int | ffsl_var (long value) |
Force a call to the non-constant implementation of ffsl() More... | |
int | ffsll_var (long long value) |
Force a call to the non-constant implementation of ffsll() More... | |
int | flsl_var (long value) |
Force a call to the non-constant implementation of flsl() More... | |
int | flsll_var (long long value) |
Force a call to the non-constant implementation of flsll() More... | |
uint64_t | lsl64_var (uint64_t value, unsigned int shift) |
Force a use of runtime 64-bit shift left. More... | |
uint64_t | lsr64_var (uint64_t value, unsigned int shift) |
Force a use of runtime 64-bit logical shift right. More... | |
int64_t | asr64_var (int64_t value, unsigned int shift) |
Force a use of runtime 64-bit arithmetic shift right. More... | |
static void * | stack_check (void) |
Check current stack pointer. More... | |
uint64_t | u64div_var (uint64_t dividend, uint64_t divisor) |
Force a use of runtime 64-bit unsigned integer division. More... | |
uint64_t | u64mod_var (uint64_t dividend, uint64_t divisor) |
Force a use of runtime 64-bit unsigned integer modulus. More... | |
int64_t | s64div_var (int64_t dividend, int64_t divisor) |
Force a use of runtime 64-bit signed integer division. More... | |
int64_t | s64mod_var (int64_t dividend, int64_t divisor) |
Force a use of runtime 64-bit unsigned integer modulus. More... | |
static void | ffsl_okx (long value, int lsb, const char *file, unsigned int line) |
Report a ffsl() test result. More... | |
static void | ffsll_okx (long long value, int lsb, const char *file, unsigned int line) |
Report a ffsll() test result. More... | |
static void | flsl_okx (long value, int msb, const char *file, unsigned int line) |
Report a flsl() test result. More... | |
static void | flsll_okx (long long value, int msb, const char *file, unsigned int line) |
Report a flsll() test result. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static void | math_test_exec (void) |
Perform mathematical self-tests. More... | |
Variables | |
struct self_test math_test | __self_test |
Mathematical self-tests. More... | |
Mathematical self-tests.
Definition in file math_test.c.
#define check_divmod | ( | dividend, | |
divisor, | |||
OP | |||
) |
Check division/modulus operation.
One aspect of the calling convention for the implicit arithmetic functions (__udivmoddi4() etc) is whether the caller or the callee is expected to pop any stack-based arguments. This distinction can be masked if the compiler chooses to uses a frame pointer in the caller, since the caller will then reload the stack pointer from the frame pointer and so can mask an error in the value of the stack pointer.
We run the division operation in a loop, and check that the stack pointer does not change value on the second iteration. To prevent the compiler from performing various optimisations which might invalidate our intended test (such as unrolling the loop, or moving the division operation outside the loop), we include some dummy inline assembly code.
Definition at line 154 of file math_test.c.
Definition at line 252 of file math_test.c.
Definition at line 271 of file math_test.c.
Definition at line 290 of file math_test.c.
Definition at line 309 of file math_test.c.
#define lsl64_ok | ( | value, | |
shift, | |||
expected | |||
) | lsl64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
Definition at line 330 of file math_test.c.
#define lsr64_ok | ( | value, | |
shift, | |||
expected | |||
) | lsr64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
Definition at line 352 of file math_test.c.
#define asr64_ok | ( | value, | |
shift, | |||
expected | |||
) | asr64_okx ( value, shift, expected, __FILE__, __LINE__ ) |
Definition at line 374 of file math_test.c.
#define u64divmod_ok | ( | dividend, | |
divisor, | |||
quotient, | |||
remainder | |||
) |
Definition at line 400 of file math_test.c.
#define s64divmod_ok | ( | dividend, | |
divisor, | |||
quotient, | |||
remainder | |||
) |
Definition at line 427 of file math_test.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
int ffsl_var | ( | long | value | ) |
Force a call to the non-constant implementation of ffsl()
value | Value |
lsb | Least significant bit set in value (LSB=1), or zero |
Definition at line 47 of file math_test.c.
Referenced by ffsl_okx().
int ffsll_var | ( | long long | value | ) |
Force a call to the non-constant implementation of ffsll()
value | Value |
lsb | Least significant bit set in value (LSB=1), or zero |
Definition at line 57 of file math_test.c.
Referenced by ffsll_okx().
int flsl_var | ( | long | value | ) |
Force a call to the non-constant implementation of flsl()
value | Value |
msb | Most significant bit set in value (LSB=1), or zero |
Definition at line 67 of file math_test.c.
Referenced by flsl_okx().
int flsll_var | ( | long long | value | ) |
Force a call to the non-constant implementation of flsll()
value | Value |
msb | Most significant bit set in value (LSB=1), or zero |
Definition at line 77 of file math_test.c.
Referenced by flsll_okx().
Force a use of runtime 64-bit shift left.
value | Value |
shift | Shift amount |
value | Shifted value |
Definition at line 88 of file math_test.c.
References value.
Referenced by lsl64_okx().
Force a use of runtime 64-bit logical shift right.
value | Value |
shift | Shift amount |
value | Shifted value |
Definition at line 100 of file math_test.c.
References value.
Referenced by lsr64_okx().
Force a use of runtime 64-bit arithmetic shift right.
value | Value |
shift | Shift amount |
value | Shifted value |
Definition at line 112 of file math_test.c.
References value.
Referenced by asr64_okx().
|
static |
Check current stack pointer.
stack | A value at a fixed offset from the current stack pointer |
Used by check_divmod()
Definition at line 124 of file math_test.c.
References __asm__().
Force a use of runtime 64-bit unsigned integer division.
dividend | Dividend |
divisor | Divisor |
quotient | Quotient |
Definition at line 190 of file math_test.c.
References check_divmod.
Referenced by u64divmod_okx().
Force a use of runtime 64-bit unsigned integer modulus.
dividend | Dividend |
divisor | Divisor |
remainder | Remainder |
Definition at line 203 of file math_test.c.
References check_divmod.
Referenced by u64divmod_okx().
Force a use of runtime 64-bit signed integer division.
dividend | Dividend |
divisor | Divisor |
quotient | Quotient |
Definition at line 216 of file math_test.c.
References check_divmod.
Referenced by s64divmod_okx().
Force a use of runtime 64-bit unsigned integer modulus.
dividend | Dividend |
divisor | Divisor |
remainder | Remainder |
Definition at line 229 of file math_test.c.
References check_divmod.
Referenced by s64divmod_okx().
|
inlinestatic |
Report a ffsl() test result.
value | Value |
lsb | Expected LSB |
file | Test code file |
line | Test code line |
Definition at line 244 of file math_test.c.
References ffsl, ffsl_var(), okx, and value.
|
inlinestatic |
Report a ffsll() test result.
value | Value |
lsb | Expected LSB |
file | Test code file |
line | Test code line |
Definition at line 263 of file math_test.c.
References ffsll, ffsll_var(), okx, and value.
|
inlinestatic |
Report a flsl() test result.
value | Value |
msb | Expected MSB |
file | Test code file |
line | Test code line |
Definition at line 282 of file math_test.c.
References flsl, flsl_var(), okx, and value.
|
inlinestatic |
Report a flsll() test result.
value | Value |
msb | Expected MSB |
file | Test code file |
line | Test code line |
Definition at line 301 of file math_test.c.
References flsll, flsll_var(), okx, and value.
|
inlinestatic |
Report a 64-bit shift left test result.
value | Value |
shift | Shift amount |
expected | Expected value |
file | Test code file |
line | Test code line |
Definition at line 321 of file math_test.c.
References lsl64_var(), okx, and value.
|
inlinestatic |
Report a 64-bit logical shift right test result.
value | Value |
shift | Shift amount |
expected | Expected value |
file | Test code file |
line | Test code line |
Definition at line 343 of file math_test.c.
References lsr64_var(), okx, and value.
|
inlinestatic |
Report a 64-bit arithmetic shift right test result.
value | Value |
shift | Shift amount |
expected | Expected value |
file | Test code file |
line | Test code line |
Definition at line 365 of file math_test.c.
References asr64_var(), okx, and value.
|
static |
Report a 64-bit unsigned integer division test result.
dividend | Dividend |
divisor | Divisor |
quotient | Quotient |
remainder | Remainder |
file | Test code file |
line | Test code line |
Definition at line 387 of file math_test.c.
References okx, u64div_var(), and u64mod_var().
|
static |
Report a 64-bit signed integer division test result.
dividend | Dividend |
divisor | Divisor |
quotient | Quotient |
remainder | Remainder |
file | Test code file |
line | Test code line |
Definition at line 414 of file math_test.c.
References okx, s64div_var(), and s64mod_var().
|
static |
Perform mathematical self-tests.
Definition at line 435 of file math_test.c.
References asr64_ok, ffsl_ok, ffsll_ok, flsl_ok, flsll_ok, isqrt(), lsl64_ok, lsr64_ok, ok, s64divmod_ok, and u64divmod_ok.
struct self_test math_test __self_test |
Mathematical self-tests.
Definition at line 518 of file math_test.c.