iPXE
math_test.c File Reference

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.
#define ffsl_ok(value, lsb)
#define ffsll_ok(value, lsb)
#define flsl_ok(value, msb)
#define flsll_ok(value, msb)
#define lsl64_ok(value, shift, expected)
#define lsr64_ok(value, shift, expected)
#define asr64_ok(value, shift, expected)
#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()
int ffsll_var (long long value)
 Force a call to the non-constant implementation of ffsll()
int flsl_var (long value)
 Force a call to the non-constant implementation of flsl()
int flsll_var (long long value)
 Force a call to the non-constant implementation of flsll()
uint64_t lsl64_var (uint64_t value, unsigned int shift)
 Force a use of runtime 64-bit shift left.
uint64_t lsr64_var (uint64_t value, unsigned int shift)
 Force a use of runtime 64-bit logical shift right.
int64_t asr64_var (int64_t value, unsigned int shift)
 Force a use of runtime 64-bit arithmetic shift right.
static void * stack_check (void)
 Check current stack pointer.
uint64_t u64div_var (uint64_t dividend, uint64_t divisor)
 Force a use of runtime 64-bit unsigned integer division.
uint64_t u64mod_var (uint64_t dividend, uint64_t divisor)
 Force a use of runtime 64-bit unsigned integer modulus.
int64_t s64div_var (int64_t dividend, int64_t divisor)
 Force a use of runtime 64-bit signed integer division.
int64_t s64mod_var (int64_t dividend, int64_t divisor)
 Force a use of runtime 64-bit unsigned integer modulus.
static void ffsl_okx (long value, int lsb, const char *file, unsigned int line)
 Report a ffsl() test result.
static void ffsll_okx (long long value, int lsb, const char *file, unsigned int line)
 Report a ffsll() test result.
static void flsl_okx (long value, int msb, const char *file, unsigned int line)
 Report a flsl() test result.
static void flsll_okx (long long value, int msb, const char *file, unsigned int line)
 Report a flsll() test result.
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.
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.
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.
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 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.
static void math_test_exec (void)
 Perform mathematical self-tests.

Variables

struct self_test math_test __self_test
 Mathematical self-tests.

Detailed Description

Mathematical self-tests.

Definition in file math_test.c.

Macro Definition Documentation

◆ check_divmod

#define check_divmod ( dividend,
divisor,
OP )
Value:
( { \
int count = 2; \
void *check = NULL; \
\
/* Prevent compiler from unrolling the loop */ \
__asm__ ( "\n" : "=g" ( count ) : "0" ( count ) ); \
\
do { \
/* Check that stack pointer does not change between \
* loop iterations. \
*/ \
if ( check ) { \
assert ( check == stack_check() ); \
} else { \
check = stack_check(); \
} \
\
/* Perform division, preventing the compiler from \
* moving the division out of the loop. \
*/ \
__asm__ ( "\n" : "=g" ( dividend ), "=g" ( divisor ) \
: "0" ( dividend ), "1" ( divisor ) ); \
result = ( dividend OP divisor ); \
__asm__ ( "\n" : "=g" ( result ) : "0" ( result ) ); \
\
} while ( --count ); \
result; } )
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint16_t result
Definition hyperv.h:33
unsigned long long uint64_t
Definition stdint.h:13
static unsigned int count
Number of entries.
Definition dwmac.h:220
static void * stack_check(void)
Check current stack pointer.
Definition math_test.c:124

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.

154#define check_divmod( dividend, divisor, OP ) ( { \
155 uint64_t result; \
156 int count = 2; \
157 void *check = NULL; \
158 \
159 /* Prevent compiler from unrolling the loop */ \
160 __asm__ ( "\n" : "=g" ( count ) : "0" ( count ) ); \
161 \
162 do { \
163 /* Check that stack pointer does not change between \
164 * loop iterations. \
165 */ \
166 if ( check ) { \
167 assert ( check == stack_check() ); \
168 } else { \
169 check = stack_check(); \
170 } \
171 \
172 /* Perform division, preventing the compiler from \
173 * moving the division out of the loop. \
174 */ \
175 __asm__ ( "\n" : "=g" ( dividend ), "=g" ( divisor ) \
176 : "0" ( dividend ), "1" ( divisor ) ); \
177 result = ( dividend OP divisor ); \

Referenced by s64div_var(), s64mod_var(), u64div_var(), and u64mod_var().

◆ ffsl_ok

#define ffsl_ok ( value,
lsb )
Value:
ffsl_okx ( value, lsb, __FILE__, __LINE__ )
pseudo_bit_t value[0x00020]
Definition arbel.h:2
static void ffsl_okx(long value, int lsb, const char *file, unsigned int line)
Report a ffsl() test result.
Definition math_test.c:240

Definition at line 248 of file math_test.c.

Referenced by math_test_exec().

◆ ffsll_ok

#define ffsll_ok ( value,
lsb )
Value:
ffsll_okx ( value, lsb, __FILE__, __LINE__ )
static void ffsll_okx(long long value, int lsb, const char *file, unsigned int line)
Report a ffsll() test result.
Definition math_test.c:259

Definition at line 267 of file math_test.c.

Referenced by math_test_exec().

◆ flsl_ok

#define flsl_ok ( value,
msb )
Value:
flsl_okx ( value, msb, __FILE__, __LINE__ )
static void flsl_okx(long value, int msb, const char *file, unsigned int line)
Report a flsl() test result.
Definition math_test.c:278

Definition at line 286 of file math_test.c.

Referenced by math_test_exec().

◆ flsll_ok

#define flsll_ok ( value,
msb )
Value:
flsll_okx ( value, msb, __FILE__, __LINE__ )
static void flsll_okx(long long value, int msb, const char *file, unsigned int line)
Report a flsll() test result.
Definition math_test.c:297

Definition at line 305 of file math_test.c.

Referenced by math_test_exec().

◆ lsl64_ok

#define lsl64_ok ( value,
shift,
expected )
Value:
lsl64_okx ( value, shift, expected, __FILE__, __LINE__ )
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.
Definition math_test.c:317

Definition at line 326 of file math_test.c.

326
327 /* Verify as a runtime calculation */

Referenced by math_test_exec().

◆ lsr64_ok

#define lsr64_ok ( value,
shift,
expected )
Value:
lsr64_okx ( value, shift, expected, __FILE__, __LINE__ )
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.
Definition math_test.c:339

Definition at line 348 of file math_test.c.

348
349 /* Verify as a runtime calculation */

Referenced by math_test_exec().

◆ asr64_ok

#define asr64_ok ( value,
shift,
expected )
Value:
asr64_okx ( value, shift, expected, __FILE__, __LINE__ )
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.
Definition math_test.c:361

Definition at line 370 of file math_test.c.

370
371 /* Verify as a runtime calculation */

Referenced by math_test_exec().

◆ u64divmod_ok

#define u64divmod_ok ( dividend,
divisor,
quotient,
remainder )
Value:
u64divmod_okx ( dividend, divisor, quotient, remainder, \
__FILE__, __LINE__ )
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.
Definition math_test.c:383

Definition at line 396 of file math_test.c.

396
397 /* Check modulus */
398 okx ( u64mod_var ( dividend, divisor ) == remainder, file, line );
uint64_t u64mod_var(uint64_t dividend, uint64_t divisor)
Force a use of runtime 64-bit unsigned integer modulus.
Definition math_test.c:199
#define okx(success, file, line)
Report test result.
Definition test.h:44

Referenced by math_test_exec().

◆ s64divmod_ok

#define s64divmod_ok ( dividend,
divisor,
quotient,
remainder )
Value:
s64divmod_okx ( dividend, divisor, quotient, remainder, \
__FILE__, __LINE__ )
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.
Definition math_test.c:410

Definition at line 423 of file math_test.c.

423
424 /* Check modulus */
425 okx ( s64mod_var ( dividend, divisor ) == remainder, file, line );
int64_t s64mod_var(int64_t dividend, int64_t divisor)
Force a use of runtime 64-bit unsigned integer modulus.
Definition math_test.c:225

Referenced by math_test_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ ffsl_var()

int ffsl_var ( long value)

Force a call to the non-constant implementation of ffsl()

Parameters
valueValue
Return values
lsbLeast significant bit set in value (LSB=1), or zero

Definition at line 47 of file math_test.c.

47 {
48 return ffsl ( value );
49}
#define ffsl(x)
Find first (i.e.
Definition strings.h:132

References ffsl, and value.

◆ ffsll_var()

int ffsll_var ( long long value)

Force a call to the non-constant implementation of ffsll()

Parameters
valueValue
Return values
lsbLeast significant bit set in value (LSB=1), or zero

Definition at line 57 of file math_test.c.

57 {
58 return ffsll ( value );
59}
#define ffsll(x)
Find first (i.e.
Definition strings.h:123

References ffsll, and value.

◆ flsl_var()

int flsl_var ( long value)

Force a call to the non-constant implementation of flsl()

Parameters
valueValue
Return values
msbMost significant bit set in value (LSB=1), or zero

Definition at line 67 of file math_test.c.

67 {
68 return flsl ( value );
69}
#define flsl(x)
Find last (i.e.
Definition strings.h:158

References flsl, and value.

◆ flsll_var()

int flsll_var ( long long value)

Force a call to the non-constant implementation of flsll()

Parameters
valueValue
Return values
msbMost significant bit set in value (LSB=1), or zero

Definition at line 77 of file math_test.c.

77 {
78 return flsll ( value );
79}
#define flsll(x)
Find last (i.e.
Definition strings.h:149

References flsll, and value.

◆ lsl64_var()

uint64_t lsl64_var ( uint64_t value,
unsigned int shift )

Force a use of runtime 64-bit shift left.

Parameters
valueValue
shiftShift amount
Return values
valueShifted value

Definition at line 88 of file math_test.c.

89 {
90 return ( value << shift );
91}

References value.

◆ lsr64_var()

uint64_t lsr64_var ( uint64_t value,
unsigned int shift )

Force a use of runtime 64-bit logical shift right.

Parameters
valueValue
shiftShift amount
Return values
valueShifted value

Definition at line 100 of file math_test.c.

101 {
102 return ( value >> shift );
103}

References value.

◆ asr64_var()

int64_t asr64_var ( int64_t value,
unsigned int shift )

Force a use of runtime 64-bit arithmetic shift right.

Parameters
valueValue
shiftShift amount
Return values
valueShifted value

Definition at line 112 of file math_test.c.

113 {
114 return ( value >> shift );
115}

References value.

◆ stack_check()

void * stack_check ( void )
static

Check current stack pointer.

Return values
stackA value at a fixed offset from the current stack pointer

Used by check_divmod()

Definition at line 124 of file math_test.c.

124 {
125 int a;
126 void *ret;
127
128 /* Hide the fact that we are returning the address of a local
129 * variable, to prevent a compiler warning.
130 */
131 __asm__ ( "\n" : "=g" ( ret ) : "0" ( &a ) );
132
133 return ret;
134}
__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")

References __asm__().

◆ u64div_var()

uint64_t u64div_var ( uint64_t dividend,
uint64_t divisor )

Force a use of runtime 64-bit unsigned integer division.

Parameters
dividendDividend
divisorDivisor
Return values
quotientQuotient

Definition at line 186 of file math_test.c.

References check_divmod.

Referenced by u64divmod_okx().

◆ u64mod_var()

uint64_t u64mod_var ( uint64_t dividend,
uint64_t divisor )

Force a use of runtime 64-bit unsigned integer modulus.

Parameters
dividendDividend
divisorDivisor
Return values
remainderRemainder

Definition at line 199 of file math_test.c.

References check_divmod.

◆ s64div_var()

int64_t s64div_var ( int64_t dividend,
int64_t divisor )

Force a use of runtime 64-bit signed integer division.

Parameters
dividendDividend
divisorDivisor
Return values
quotientQuotient

Definition at line 212 of file math_test.c.

References check_divmod.

Referenced by s64divmod_okx().

◆ s64mod_var()

int64_t s64mod_var ( int64_t dividend,
int64_t divisor )

Force a use of runtime 64-bit unsigned integer modulus.

Parameters
dividendDividend
divisorDivisor
Return values
remainderRemainder

Definition at line 225 of file math_test.c.

References check_divmod.

◆ ffsl_okx()

void ffsl_okx ( long value,
int lsb,
const char * file,
unsigned int line )
inlinestatic

Report a ffsl() test result.

Parameters
valueValue
lsbExpected LSB
fileTest code file
lineTest code line

Definition at line 240 of file math_test.c.

244 {
245
246 /* Verify as a constant (requires to be inlined) */
247 okx ( ffsl ( value ) == lsb, file, line );

References ffsl, okx, and value.

◆ ffsll_okx()

void ffsll_okx ( long long value,
int lsb,
const char * file,
unsigned int line )
inlinestatic

Report a ffsll() test result.

Parameters
valueValue
lsbExpected LSB
fileTest code file
lineTest code line

Definition at line 259 of file math_test.c.

263 {
264
265 /* Verify as a constant (requires to be inlined) */
266 okx ( ffsll ( value ) == lsb, file, line );

References ffsll, okx, and value.

◆ flsl_okx()

void flsl_okx ( long value,
int msb,
const char * file,
unsigned int line )
inlinestatic

Report a flsl() test result.

Parameters
valueValue
msbExpected MSB
fileTest code file
lineTest code line

Definition at line 278 of file math_test.c.

282 {
283
284 /* Verify as a constant (requires to be inlined) */
285 okx ( flsl ( value ) == msb, file, line );

References flsl, okx, and value.

◆ flsll_okx()

void flsll_okx ( long long value,
int msb,
const char * file,
unsigned int line )
inlinestatic

Report a flsll() test result.

Parameters
valueValue
msbExpected MSB
fileTest code file
lineTest code line

Definition at line 297 of file math_test.c.

301 {
302
303 /* Verify as a constant (requires to be inlined) */
304 okx ( flsll ( value ) == msb, file, line );

References flsll, okx, and value.

◆ lsl64_okx()

void lsl64_okx ( uint64_t value,
unsigned int shift,
uint64_t expected,
const char * file,
unsigned int line )
inlinestatic

Report a 64-bit shift left test result.

Parameters
valueValue
shiftShift amount
expectedExpected value
fileTest code file
lineTest code line

Definition at line 317 of file math_test.c.

322 {
323
324 /* Verify as a compile-time calculation */
325 okx ( ( value << shift ) == expected, file, line );

References okx, and value.

◆ lsr64_okx()

void lsr64_okx ( uint64_t value,
unsigned int shift,
uint64_t expected,
const char * file,
unsigned int line )
inlinestatic

Report a 64-bit logical shift right test result.

Parameters
valueValue
shiftShift amount
expectedExpected value
fileTest code file
lineTest code line

Definition at line 339 of file math_test.c.

344 {
345
346 /* Verify as a compile-time calculation */
347 okx ( ( value >> shift ) == expected, file, line );

References okx, and value.

◆ asr64_okx()

void asr64_okx ( int64_t value,
unsigned int shift,
int64_t expected,
const char * file,
unsigned int line )
inlinestatic

Report a 64-bit arithmetic shift right test result.

Parameters
valueValue
shiftShift amount
expectedExpected value
fileTest code file
lineTest code line

Definition at line 361 of file math_test.c.

366 {
367
368 /* Verify as a compile-time calculation */
369 okx ( ( value >> shift ) == expected, file, line );

References okx, and value.

◆ u64divmod_okx()

void u64divmod_okx ( uint64_t dividend,
uint64_t divisor,
uint64_t quotient,
uint64_t remainder,
const char * file,
unsigned int line )
static

Report a 64-bit unsigned integer division test result.

Parameters
dividendDividend
divisorDivisor
quotientQuotient
remainderRemainder
fileTest code file
lineTest code line

Definition at line 383 of file math_test.c.

389 {
390
391 /* Sanity check */
392 okx ( ( ( divisor * quotient ) + remainder ) == dividend, file, line );
393
394 /* Check division */
395 okx ( u64div_var ( dividend, divisor ) == quotient, file, line );
uint64_t u64div_var(uint64_t dividend, uint64_t divisor)
Force a use of runtime 64-bit unsigned integer division.
Definition math_test.c:186

References okx, and u64div_var().

◆ s64divmod_okx()

void s64divmod_okx ( int64_t dividend,
int64_t divisor,
int64_t quotient,
int64_t remainder,
const char * file,
unsigned int line )
static

Report a 64-bit signed integer division test result.

Parameters
dividendDividend
divisorDivisor
quotientQuotient
remainderRemainder
fileTest code file
lineTest code line

Definition at line 410 of file math_test.c.

416 {
417
418 /* Sanity check */
419 okx ( ( ( divisor * quotient ) + remainder ) == dividend, file, line );
420
421 /* Check division */
422 okx ( s64div_var ( dividend, divisor ) == quotient, file, line );
int64_t s64div_var(int64_t dividend, int64_t divisor)
Force a use of runtime 64-bit signed integer division.
Definition math_test.c:212

References okx, and s64div_var().

◆ math_test_exec()

void math_test_exec ( void )
static

Perform mathematical self-tests.

Definition at line 431 of file math_test.c.

435 {
436
437 /* Test ffsl() */
438 ffsl_ok ( 0, 0 );
439 ffsl_ok ( 1, 1 );
440 ffsl_ok ( 255, 1 );
441 ffsl_ok ( 256, 9 );
442 ffsl_ok ( 257, 1 );
443 ffsl_ok ( 0x54850596, 2 );
444 ffsl_ok ( 0x80000000, 32 );
445
446 /* Test ffsll() */
447 ffsll_ok ( 0, 0 );
448 ffsll_ok ( 1, 1 );
449 ffsll_ok ( 0x6d63623330ULL, 5 );
450 ffsll_ok ( 0x80000000UL, 32 );
451 ffsll_ok ( 0x8000000000000000ULL, 64 );
452
453 /* Test flsl() */
454 flsl_ok ( 0, 0 );
455 flsl_ok ( 1, 1 );
456 flsl_ok ( 255, 8 );
457 flsl_ok ( 256, 9 );
458 flsl_ok ( 257, 9 );
459 flsl_ok ( 0x69505845, 31 );
460 flsl_ok ( -1U, ( 8 * sizeof ( int ) ) );
461 flsl_ok ( -1UL, ( 8 * sizeof ( long ) ) );
462
463 /* Test flsll() */
464 flsll_ok ( 0, 0 );
465 flsll_ok ( 1, 1 );
466 flsll_ok ( 0x6d63623330ULL, 39 );
467 flsll_ok ( -1U, ( 8 * sizeof ( int ) ) );
468 flsll_ok ( -1UL, ( 8 * sizeof ( long ) ) );
469 flsll_ok ( -1ULL, ( 8 * sizeof ( long long ) ) );
470
471 /* Test 64-bit arithmetic
472 *
473 * On a 64-bit machine, these tests are fairly meaningless.
474 *
475 * On a 32-bit machine, these tests verify the correct
476 * operation of our libgcc functions __udivmoddi4()
477 * etc. (including checking that the implicit calling
478 * convention assumed by gcc matches our expectations).
479 */
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 );
495 u64divmod_ok ( 0x2b90ddccf699f765ULL, 0xed9f5e73ULL,
496 0x2eef6ab4ULL, 0x0e12f089ULL );
497 s64divmod_ok ( 0x2b90ddccf699f765ULL, 0xed9f5e73ULL,
498 0x2eef6ab4ULL, 0x0e12f089ULL );
499 u64divmod_ok ( 0xc09e00dcb9e34b54ULL, 0x35968185cdc744f3ULL,
500 3, 0x1fda7c4b508d7c7bULL );
501 s64divmod_ok ( -0x3f61ff23461cb4acLL, 0x35968185cdc744f3ULL,
502 -1LL, -0x9cb7d9d78556fb9LL );
503 u64divmod_ok ( 0, 0x5b2f2737f4ffULL, 0, 0 );
504 s64divmod_ok ( 0, 0xbb00ded72766207fULL, 0, 0 );
505
506 /* Test integer square root */
507 ok ( isqrt ( 0 ) == 0 );
508 ok ( isqrt ( 1 ) == 1 );
509 ok ( isqrt ( 255 ) == 15 );
510 ok ( isqrt ( 256 ) == 16 );
511 ok ( isqrt ( 257 ) == 16 );
unsigned long isqrt(unsigned long value)
Find integer square root.
Definition isqrt.c:41
#define lsl64_ok(value, shift, expected)
Definition math_test.c:326
#define flsll_ok(value, msb)
Definition math_test.c:305
#define asr64_ok(value, shift, expected)
Definition math_test.c:370
#define u64divmod_ok(dividend, divisor, quotient, remainder)
Definition math_test.c:396
#define s64divmod_ok(dividend, divisor, quotient, remainder)
Definition math_test.c:423
#define lsr64_ok(value, shift, expected)
Definition math_test.c:348
#define flsl_ok(value, msb)
Definition math_test.c:286
#define ffsl_ok(value, lsb)
Definition math_test.c:248
#define ffsll_ok(value, lsb)
Definition math_test.c:267
#define ok(success)
Definition test.h:46

References asr64_ok, ffsl_ok, ffsll_ok, flsl_ok, flsll_ok, isqrt(), lsl64_ok, lsr64_ok, ok, s64divmod_ok, and u64divmod_ok.

Variable Documentation

◆ __self_test

struct self_test math_test __self_test
Initial value:
= {
.name = "math",
.exec = math_test_exec,
}
static void math_test_exec(void)
Perform mathematical self-tests.
Definition math_test.c:431

Mathematical self-tests.

Definition at line 514 of file math_test.c.