From 9a32b1ecb28e18ff494ffef39ddb6bea5201b908 Mon Sep 17 00:00:00 2001 From: Rutam Kathale Date: Mon, 18 Mar 2024 18:51:14 +0530 Subject: [PATCH 01/27] feat: add C implementation for math/base/special/fast/uint32-log2 This commit if applied adds the native C implementation to @stdlib/math/base/special/fast/uint32-log2 --- .../base/special/fast/uint32-log2/README.md | 91 ++++++++++ .../uint32-log2/benchmark/benchmark.native.js | 58 ++++++ .../uint32-log2/benchmark/c/native/Makefile | 146 +++++++++++++++ .../benchmark/c/native/benchmark.c | 137 ++++++++++++++ .../base/special/fast/uint32-log2/binding.gyp | 170 ++++++++++++++++++ .../fast/uint32-log2/examples/c/Makefile | 146 +++++++++++++++ .../fast/uint32-log2/examples/c/example.c | 32 ++++ .../special/fast/uint32-log2/include.gypi | 53 ++++++ .../math/base/special/fast/uint32_log2.h | 43 +++++ .../special/fast/uint32-log2/lib/native.js | 55 ++++++ .../special/fast/uint32-log2/manifest.json | 65 +++++++ .../special/fast/uint32-log2/src/Makefile | 70 ++++++++ .../base/special/fast/uint32-log2/src/addon.c | 90 ++++++++++ .../base/special/fast/uint32-log2/src/main.c | 73 ++++++++ .../fast/uint32-log2/test/test.native.js | 74 ++++++++ 15 files changed, 1303 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/include/stdlib/math/base/special/fast/uint32_log2.h create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md index 76eaa5e2cc86..ac78e8f3928e 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md @@ -88,6 +88,97 @@ for ( i = 1; i < 101; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/fast/uint32_log2.h" +``` + +#### stdlib_base_fast_uint32_log2( x ) + +Compute an integer [binary logarithm][binary-logarithm]. + +```c +#include + +uint32_t out = stdlib_base_fast_uint32_log2( 4 ); +// returns 2 + +out = stdlib_base_uint32_is_pow2( 9 ); +// returns 3 +``` + +The function accepts the following arguments: + +- **x**: `[in] uint32_t` input value. + +```c +uint32_t stdlib_base_uint32_is_pow2( const uint32_t x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/fast/uint32_log2.h" +#include +#include + +int main( void ) { + const uint32_t x[] = { 5, 7, 10, 22, 98 }; + + uint32_t y; + int i; + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_fast_uint32_log2( x[ i ] ); + printf( "uint32_log2(%u) ≈ %u\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + + From f1a05d3da038c73dde75c6929cf055bbf0fbe616 Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:19:32 +0530 Subject: [PATCH 04/27] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../base/special/fast/uint32-log2/src/main.c | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c index 1b2abe3ee60a..07735a23858b 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c @@ -40,33 +40,36 @@ static const uint32_t S0 = 1u; * uint32_t out = stdlib_base_fast_uint32_log2( 8 ); * // returns 3 */ -uint32_t stdlib_base_fast_uint32_log2( uint32_t x ) { - uint32_t out = 0u; - - // `x >= 65536`: - if ( x & B4 ) { - x >>= S4; - out |= S4; - } - // `x >= 256`: - if ( x & B3 ) { - x >>= S3; - out |= S3; - } - // `x >= 16`: - if ( x & B2 ) { - x >>= S2; - out |= S2; - } - // `x >= 4`: - if ( x & B1 ) { - x >>= S1; - out |= S1; - } - // `x >= 2`: - if ( x & B0 ) { - x >>= S0; - out |= S0; - } - return out; +uint32_t stdlib_base_fast_uint32_log2( const uint32_t x ) { + uint32_t out; + uint32_t xc; + + xc = x; + out = 0; + // `xc >= 65536`: + if ( xc & B4 ) { + xc >>= S4; + out |= S4; + } + // `xc >= 256`: + if ( xc & B3 ) { + xc >>= S3; + out |= S3; + } + // `xc >= 16`: + if ( xc & B2 ) { + xc >>= S2; + out |= S2; + } + // `xc >= 4`: + if ( xc & B1 ) { + xc >>= S1; + out |= S1; + } + // `xc >= 2`: + if ( xc & B0 ) { + x >>= S0; + out |= S0; + } + return out; } From fc31378eac381375a5764c4397081b5d9a3f60dc Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:21:23 +0530 Subject: [PATCH 05/27] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index c0acb849e771..7222f5c6315b 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "stdlib/math/base/assert/uint32_log2.h" +#include "stdlib/math/base/special/fast/uint32_log2.h" #include #include #include From 822707a910f4824c92ffcb30078349a5034367cd Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:22:58 +0530 Subject: [PATCH 06/27] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c index 07735a23858b..ee950c12b35d 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c @@ -68,7 +68,7 @@ uint32_t stdlib_base_fast_uint32_log2( const uint32_t x ) { } // `xc >= 2`: if ( xc & B0 ) { - x >>= S0; + xc >>= S0; out |= S0; } return out; From e7bd52027536fac4d65a6e625189179c24f2b5fe Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:24:46 +0530 Subject: [PATCH 07/27] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/README.md | 2 +- .../math/base/special/fast/uint32-log2/examples/c/example.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md index 1ba03d218757..3dc3f6b457bc 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md @@ -166,7 +166,7 @@ int main( void ) { int i; for ( i = 0; i < 5; i++ ) { y = stdlib_base_fast_uint32_log2( x[ i ] ); - printf( "uint32_log2(%u) ≈ %u\n", x[ i ], y ); + printf( "uint32_log2(%u) = %u\n", x[ i ], y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/example.c index 42c037717766..8dbbf2598b4d 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/examples/c/example.c @@ -27,6 +27,6 @@ int main( void ) { int i; for ( i = 0; i < 5; i++ ) { y = stdlib_base_fast_uint32_log2( x[ i ] ); - printf( "uint32_log2(%u) ≈ %u\n", x[ i ], y ); + printf( "uint32_log2(%u) = %u\n", x[ i ], y ); } } From f097ea788f8bd015b775dacd92bf637709881a71 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:33:10 +0530 Subject: [PATCH 08/27] Update native.js - fix return type Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js index eef0cc3145cc..64114a833028 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js @@ -46,7 +46,7 @@ var addon = require( './../src/addon.node' ); * // returns 3 */ function log2Uint32( x ) { - return Boolean( addon( x ) ); + return addon( x ); } From 4bc339aad78a1943b2a2dd29eb2fef4d2adf4e94 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:56:28 +0530 Subject: [PATCH 09/27] Update native.js - remove import Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/lib/native.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js index 64114a833028..8a39704f6ab9 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/lib/native.js @@ -20,7 +20,6 @@ // MODULES // -var Boolean = require( '@stdlib/boolean/ctor' ); var addon = require( './../src/addon.node' ); From ed2ac1e9487a9648091836932d8db29490ccadca Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:26:26 +0530 Subject: [PATCH 10/27] Update main.c Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c index ee950c12b35d..40dce0fd60d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c @@ -68,7 +68,6 @@ uint32_t stdlib_base_fast_uint32_log2( const uint32_t x ) { } // `xc >= 2`: if ( xc & B0 ) { - xc >>= S0; out |= S0; } return out; From c8c1cde4d2361340c574bef86f24c88a817320ce Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 22 Mar 2024 20:35:39 -0700 Subject: [PATCH 11/27] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/fast/uint32-log2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md index 3dc3f6b457bc..20c5b974447e 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/README.md @@ -116,7 +116,7 @@ for ( i = 1; i < 101; i++ ) { #### stdlib_base_fast_uint32_log2( x ) -Compute an integer [binary logarithm][binary-logarithm]. +Returns an **approximate** [binary logarithm][binary-logarithm] of an unsigned 32-bit integer `x`. ```c #include From a6891ef18e9e26308ede73b8eac81aad19157c89 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 22 Mar 2024 20:41:26 -0700 Subject: [PATCH 12/27] Apply suggestions from code review Signed-off-by: Athan --- .../fast/uint32-log2/benchmark/c/native/benchmark.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/benchmark.c index 137884a53721..fd96b3ad721a 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/benchmark/c/native/benchmark.c @@ -104,14 +104,14 @@ double benchmark() { for ( i = 0; i < ITERATIONS; i++ ) { x = (uint32_t)rand(); y = stdlib_base_fast_uint32_log2( x ); - if ( y != y ) { - printf( "should not return NaN\n" ); + if ( y > x ) { + printf( "unexpected result\n" ); break; } } elapsed = tic() - t; - if ( y != y ) { - printf( "should not return NaN\n" ); + if ( y > x ) { + printf( "unexpected result\n" ); } return elapsed; } From a3cabbc30d0c50466c3581fc1216009527aa48ee Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 22 Mar 2024 20:46:46 -0700 Subject: [PATCH 13/27] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 7222f5c6315b..b3dab79df4a5 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -66,7 +66,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { uint32_t result = stdlib_base_fast_uint32_log2( x ); napi_value v; - status = napi_create_int32( env, (int32_t)result, &v ); + status = napi_create_uint32( env, result, &v ); assert( status == napi_ok ); return v; From 1c7b05d16bc28de99a1fdee65f73541df284f0b6 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:03:23 +0530 Subject: [PATCH 14/27] Update addon.c Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../base/special/fast/uint32-log2/src/addon.c | 38 +++---------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index b3dab79df4a5..23da78b7bdf6 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/math/base/special/fast/uint32_log2.h" +#include "stdlib/napi/argv_uint32.h" #include #include #include @@ -30,40 +31,13 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; + // Retrieve add-on callback arguments: + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); - // Get callback arguments: - size_t argc = 1; - napi_value argv[ 1 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - // Check whether we were provided the correct number of arguments: - if ( argc < 1 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 1 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - uint32_t x; - status = napi_get_value_uint32( env, argv[ 0 ], &x ); - assert( status == napi_ok ); + // Convert the first argument to a C type: + STDLIB_NAPI_ARGV_UINT32( env, value, argv, 0 ); - uint32_t result = stdlib_base_fast_uint32_log2( x ); + uint32_t result = stdlib_base_fast_uint32_log2( value ); napi_value v; status = napi_create_uint32( env, result, &v ); From 1b9885560a9f59bb25a6e68647e0538cfb4edb8a Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:04:12 +0530 Subject: [PATCH 15/27] Update addon.c - spacing Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 23da78b7bdf6..d408168f0d2a 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -31,7 +31,7 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - // Retrieve add-on callback arguments: + // Retrieve add-on callback arguments: STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); // Convert the first argument to a C type: From bd11bb5ad4f02ff390cfb130a17c589ac6e5e201 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:06:14 +0530 Subject: [PATCH 16/27] Update addon.c - spacing and initialization Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../math/base/special/fast/uint32-log2/src/addon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index d408168f0d2a..a4e0171f9b34 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -31,19 +31,20 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { + napi_status status; // Retrieve add-on callback arguments: STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); // Convert the first argument to a C type: STDLIB_NAPI_ARGV_UINT32( env, value, argv, 0 ); - uint32_t result = stdlib_base_fast_uint32_log2( value ); + uint32_t result = stdlib_base_fast_uint32_log2( value ); - napi_value v; - status = napi_create_uint32( env, result, &v ); - assert( status == napi_ok ); + napi_value v; + status = napi_create_uint32( env, result, &v ); + assert( status == napi_ok ); - return v; + return v; } /** From d6da18a7bb6f7e3b3437325480bb618d0c534dde Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:11:50 +0530 Subject: [PATCH 17/27] Update manifest.json Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json index 70f9e562772c..9cf6b2992c9f 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json @@ -35,7 +35,9 @@ ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/napi/argv_uint32" + ] }, { "task": "benchmark", From a16920c635b6f4a2b49f2accf490599ed9e7e238 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:22:30 +0530 Subject: [PATCH 18/27] Update manifest.json Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json index 9cf6b2992c9f..52ac58cc197d 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json @@ -36,7 +36,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/napi/argv_uint32" + "@stdlib/napi/argv-uint32" ] }, { From e5dd306d37d972930f5d58114b3700635b89dbb5 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:30:16 +0530 Subject: [PATCH 19/27] Update main.c - add extended comment string Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../base/special/fast/uint32-log2/src/main.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c index 40dce0fd60d1..cfb921de376e 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c @@ -33,6 +33,26 @@ static const uint32_t S0 = 1u; /** * Computes an integer binary logarithm (base two). * +* ## Method +* +* 1. Note that the largest unsigned 32-bit integer is `4294967295`, which is `2^{32}-1`. Hence, the integer binary logarithm cannot exceed `31` (i.e., `16 + 8 + 4 + 2 + 1`), which corresponds to the bit sequence +* +* ```binarystring +* 00000000000000000000000000011111 +* ``` +* +* 2. Initialize a return variable with the value zero. +* +* 3. If at least one of the first sixteen most significant bits of the input 32-bit integer `x` is turned on, we know that the power to which the number `2` must be raised to obtain `x` is at least `16` (i.e., `x > 65536`). Hence, activate the corresponding bit of the return variable. Mutate `x` by shifting sixteen bits to the right, discarding the bits shifted off. +* +* 4. Carry out the following steps with `B` in `[ 8, 4, 2, 1 ]`: +* +* - If at least one of the next `B` most significant bits of the current `x` is turned on, we know that the power to which the number `2` must be raised to obtain `x` has to be increased by `B`. +* - Activate the bit of the return variable that corresponds to `B`. +* - Mutate `x` by shifting `B` bits to the right, discarding the bits shifted off. +* +* 5. The final value of the return variable is the integer binary logarithm of `x`. +* * @param x number * @returns integer binary logarithm * From 85ebd4bb066ffc4718766daa9db478e205b1cd3e Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:30:56 +0530 Subject: [PATCH 20/27] Update addon.c Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index a4e0171f9b34..16723d29c02b 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -31,7 +31,8 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; + napi_status status; + // Retrieve add-on callback arguments: STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); From 304366f8785fa75b782e879d9e4a32cc5f17ebe6 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:35:23 +0530 Subject: [PATCH 21/27] Update lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c Co-authored-by: Athan Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c index cfb921de376e..d280a62e3f2a 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/main.c @@ -54,7 +54,7 @@ static const uint32_t S0 = 1u; * 5. The final value of the return variable is the integer binary logarithm of `x`. * * @param x number -* @returns integer binary logarithm +* @return integer binary logarithm * * @example * uint32_t out = stdlib_base_fast_uint32_log2( 8 ); From 31c5b304d90875c1ee91a5253ecfa19074f258a0 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 23 Mar 2024 00:45:04 -0700 Subject: [PATCH 22/27] Apply suggestions from code review Signed-off-by: Athan --- .../math/base/special/fast/uint32-log2/src/addon.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 16723d29c02b..e5ea055f450d 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -31,18 +31,11 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Retrieve add-on callback arguments: - STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); - - // Convert the first argument to a C type: - STDLIB_NAPI_ARGV_UINT32( env, value, argv, 0 ); - - uint32_t result = stdlib_base_fast_uint32_log2( value ); + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + STDLIB_NAPI_ARGV_UINT32( env, value, argv, 0 ); napi_value v; - status = napi_create_uint32( env, result, &v ); + napi_status status = napi_create_uint32( env, stdlib_base_fast_uint32_log2( value ), &v ); assert( status == napi_ok ); return v; From 4b3f66989c9ba7f69d54193f14b802df043126ca Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 23 Mar 2024 00:45:29 -0700 Subject: [PATCH 23/27] Apply suggestions from code review Signed-off-by: Athan --- .../math/base/special/fast/uint32-log2/src/addon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index e5ea055f450d..12dc2e22b751 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -34,11 +34,11 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); STDLIB_NAPI_ARGV_UINT32( env, value, argv, 0 ); - napi_value v; - napi_status status = napi_create_uint32( env, stdlib_base_fast_uint32_log2( value ), &v ); - assert( status == napi_ok ); + napi_value v; + napi_status status = napi_create_uint32( env, stdlib_base_fast_uint32_log2( value ), &v ); + assert( status == napi_ok ); - return v; + return v; } /** From b67dd0570d5ef209c881e9026c8b59516ae5d67d Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:24:42 +0530 Subject: [PATCH 24/27] Update addon.c Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../base/special/fast/uint32-log2/src/addon.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 12dc2e22b751..5228fabafb57 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -18,6 +18,7 @@ #include "stdlib/math/base/special/fast/uint32_log2.h" #include "stdlib/napi/argv_uint32.h" +#include "stdlib/napi/export.h" #include #include #include @@ -41,19 +42,5 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return v; } -/** -* Initializes a Node-API module. -* -* @private -* @param env environment under which the function is invoked -* @param exports exports object -* @return main export -*/ -static napi_value init( napi_env env, napi_value exports ) { - napi_value fcn; - napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; -} - -NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) +// Register a Node-API module: +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) From 85a450da92a39cd1bcd75ebf36810ecb0e9d56e8 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:25:39 +0530 Subject: [PATCH 25/27] Update manifest.json Signed-off-by: Rutam <138517416+performant23@users.noreply.github.com> --- .../@stdlib/math/base/special/fast/uint32-log2/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json index 52ac58cc197d..710288ade820 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/manifest.json @@ -36,7 +36,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/napi/argv-uint32" + "@stdlib/napi/argv-uint32", + "@stdlib/napi/export" ] }, { From 77e65d589595ac53d0623e0e3eef85d327f02358 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 23 Mar 2024 00:57:14 -0700 Subject: [PATCH 26/27] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 5228fabafb57..79d6d2abd077 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -42,5 +42,4 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return v; } -// Register a Node-API module: STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) From e4248da40d7c941bfdf26cb0fab1cf7f04728ec4 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 23 Mar 2024 00:57:35 -0700 Subject: [PATCH 27/27] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/fast/uint32-log2/src/addon.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c index 79d6d2abd077..6f27f1455582 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-log2/src/addon.c @@ -20,7 +20,6 @@ #include "stdlib/napi/argv_uint32.h" #include "stdlib/napi/export.h" #include -#include #include /**