From 5c437f7549fc9480c1a60c8b6e3125185a4b61e6 Mon Sep 17 00:00:00 2001 From: Niles Salter Date: Wed, 3 Jan 2024 02:40:12 -0700 Subject: [PATCH] remove unnecessary & ~0x7 It is easy to prove we do not need `& ~0x7` because the maximum value it can operate on is `00001000_00000111_00000110_00000101_00000100_00000011_00000010_00000001 >> 53`. Since the byte under the most significant byte can be a 7 at most, the upper 3 bits of that second byte are always 0. Therefore we do not need to zero them out. --- popcount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popcount.h b/popcount.h index de6fc90..539261b 100644 --- a/popcount.h +++ b/popcount.h @@ -125,7 +125,7 @@ inline int select64_broadword(uint64 x, int k) { // Phase 2: compare each byte sum with the residual const uint64 residual_step_8 = residual * ONES_STEP_8; - const int place = ( LEQ_STEP_8( byte_sums, residual_step_8 ) * ONES_STEP_8 >> 53 ) & ~0x7; + const int place = ( LEQ_STEP_8( byte_sums, residual_step_8 ) * ONES_STEP_8 >> 53 ); // Phase 3: Locate the relevant byte and make 8 copies with incremental masks const int byte_rank = residual - ( ( ( byte_sums << 8 ) >> place ) & 0xFF );