Skip to content

Commit

Permalink
Use Nativeint to avoid tagging
Browse files Browse the repository at this point in the history
This reduces the generated code size for this operation.
  • Loading branch information
polytypic committed Nov 10, 2024
1 parent ca2ca22 commit 6c53ef1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/kcas_data/bits.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ let max_0 n =
n land lnot m

let ceil_pow_2_minus_1 n =
let n = n lor (n lsr 1) in
let n = n lor (n lsr 2) in
let n = n lor (n lsr 4) in
let n = n lor (n lsr 8) in
let n = n lor (n lsr 16) in
if Sys.int_size > 32 then n lor (n lsr 32) else n
let n = Nativeint.of_int n in
let n = Nativeint.logor n (Nativeint.shift_right_logical n 1) in
let n = Nativeint.logor n (Nativeint.shift_right_logical n 2) in
let n = Nativeint.logor n (Nativeint.shift_right_logical n 4) in
let n = Nativeint.logor n (Nativeint.shift_right_logical n 8) in
let n = Nativeint.logor n (Nativeint.shift_right_logical n 16) in
Nativeint.to_int
(if Sys.int_size > 32 then
Nativeint.logor n (Nativeint.shift_right_logical n 32)
else n)

let ceil_pow_2 n =
if n <= 1 then 1
Expand Down

0 comments on commit 6c53ef1

Please sign in to comment.