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 | 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... | |
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 | 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 118 of file math_test.c.
Definition at line 216 of file math_test.c.
Definition at line 235 of file math_test.c.
Definition at line 254 of file math_test.c.
Definition at line 273 of file math_test.c.
#define u64divmod_ok | ( | dividend, | |
divisor, | |||
quotient, | |||
remainder | |||
) |
Definition at line 298 of file math_test.c.
#define s64divmod_ok | ( | dividend, | |
divisor, | |||
quotient, | |||
remainder | |||
) |
Definition at line 325 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().
|
static |
Check current stack pointer.
stack | A value at a fixed offset from the current stack pointer |
Used by check_divmod()
Definition at line 88 of file math_test.c.
Force a use of runtime 64-bit unsigned integer division.
dividend | Dividend |
divisor | Divisor |
quotient | Quotient |
Definition at line 154 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 167 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 180 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 193 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 208 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 227 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 246 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 265 of file math_test.c.
References flsll, flsll_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 285 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 312 of file math_test.c.
References okx, s64div_var(), and s64mod_var().
|
static |
Perform mathematical self-tests.
Definition at line 333 of file math_test.c.
References ffsl_ok, ffsll_ok, flsl_ok, flsll_ok, isqrt(), ok, s64divmod_ok, and u64divmod_ok.
struct self_test math_test __self_test |
Mathematical self-tests.
Definition at line 401 of file math_test.c.