Skip to content

Commit

Permalink
LIB: fast_log2: make this a little faster by assuming positive input
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Westerfeld <[email protected]>
  • Loading branch information
swesterfeld committed Jun 9, 2024
1 parent 83c10aa commit 586de6d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/smmath.hh
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fast_log2 (float *values, int n_values)
for (int k = 0; k < todo; k++)
{
const int EXPONENT_MASK = 0x7F800000;
fexp[k] = ((values_i[k] & EXPONENT_MASK) >> 23) - FloatIEEE754::BIAS; // extract exponent without bias
fexp[k] = (values_i[k] >> 23) - FloatIEEE754::BIAS; // extract exponent without bias (rely on sign bit == 0)
values_i[k] = (values_i[k] & ~EXPONENT_MASK) | FloatIEEE754::BIAS << 23; // reset exponent to 2^0 so v_float is mantissa in [1..2]
}
for (int k = 0; k < todo; k++)
Expand Down

0 comments on commit 586de6d

Please sign in to comment.