Skip to content

Commit 6c53ef1

Browse files
committed
Use Nativeint to avoid tagging
This reduces the generated code size for this operation.
1 parent ca2ca22 commit 6c53ef1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/kcas_data/bits.ml

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ let max_0 n =
55
n land lnot m
66

77
let ceil_pow_2_minus_1 n =
8-
let n = n lor (n lsr 1) in
9-
let n = n lor (n lsr 2) in
10-
let n = n lor (n lsr 4) in
11-
let n = n lor (n lsr 8) in
12-
let n = n lor (n lsr 16) in
13-
if Sys.int_size > 32 then n lor (n lsr 32) else n
8+
let n = Nativeint.of_int n in
9+
let n = Nativeint.logor n (Nativeint.shift_right_logical n 1) in
10+
let n = Nativeint.logor n (Nativeint.shift_right_logical n 2) in
11+
let n = Nativeint.logor n (Nativeint.shift_right_logical n 4) in
12+
let n = Nativeint.logor n (Nativeint.shift_right_logical n 8) in
13+
let n = Nativeint.logor n (Nativeint.shift_right_logical n 16) in
14+
Nativeint.to_int
15+
(if Sys.int_size > 32 then
16+
Nativeint.logor n (Nativeint.shift_right_logical n 32)
17+
else n)
1418

1519
let ceil_pow_2 n =
1620
if n <= 1 then 1

0 commit comments

Comments
 (0)