summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorMichael Brown2014-04-27 17:11:44 +0200
committerMichael Brown2014-04-27 17:56:09 +0200
commitd36e814b8aad0dc15386180245efb3f5cb8b8386 (patch)
tree9c3c633f01a1703a8c85524a4393f8f45539f459 /src/tests
parent[libc] Add isqrt() function to find integer square roots (diff)
downloadipxe-d36e814b8aad0dc15386180245efb3f5cb8b8386.tar.gz
ipxe-d36e814b8aad0dc15386180245efb3f5cb8b8386.tar.xz
ipxe-d36e814b8aad0dc15386180245efb3f5cb8b8386.zip
[libc] Add flsll()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/math_test.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/tests/math_test.c b/src/tests/math_test.c
index 96cf050b..e12b7939 100644
--- a/src/tests/math_test.c
+++ b/src/tests/math_test.c
@@ -45,6 +45,16 @@ __attribute__ (( noinline )) int flsl_var ( long value ) {
}
/**
+ * Force a call to the non-constant implementation of flsll()
+ *
+ * @v value Value
+ * @ret msb Most significant bit set in value (LSB=1), or zero
+ */
+__attribute__ (( noinline )) int flsll_var ( long long value ) {
+ return flsll ( value );
+}
+
+/**
* Check current stack pointer
*
* @ret stack A value at a fixed offset from the current stack pointer
@@ -182,6 +192,25 @@ flsl_okx ( long value, int msb, const char *file, unsigned int line ) {
#define flsl_ok( value, msb ) flsl_okx ( value, msb, __FILE__, __LINE__ )
/**
+ * Report a flsll() test result
+ *
+ * @v value Value
+ * @v msb Expected MSB
+ * @v file Test code file
+ * @v line Test code line
+ */
+static inline __attribute__ (( always_inline )) void
+flsll_okx ( long long value, int msb, const char *file, unsigned int line ) {
+
+ /* Verify as a constant (requires to be inlined) */
+ okx ( flsll ( value ) == msb, file, line );
+
+ /* Verify as a non-constant */
+ okx ( flsll_var ( value ) == msb, file, line );
+}
+#define flsll_ok( value, msb ) flsll_okx ( value, msb, __FILE__, __LINE__ )
+
+/**
* Report a 64-bit unsigned integer division test result
*
* @v dividend Dividend
@@ -251,6 +280,14 @@ static void math_test_exec ( void ) {
flsl_ok ( -1U, ( 8 * sizeof ( int ) ) );
flsl_ok ( -1UL, ( 8 * sizeof ( long ) ) );
+ /* Test flsll() */
+ flsll_ok ( 0, 0 );
+ flsll_ok ( 1, 1 );
+ flsll_ok ( 0x6d63623330ULL, 39 );
+ flsll_ok ( -1U, ( 8 * sizeof ( int ) ) );
+ flsll_ok ( -1UL, ( 8 * sizeof ( long ) ) );
+ flsll_ok ( -1ULL, ( 8 * sizeof ( long long ) ) );
+
/* Test 64-bit arithmetic
*
* On a 64-bit machine, these tests are fairly meaningless.