Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit bd0f5af

Browse files
authored
Fix SIMD bitmask (#335)
Bitmask was confused about endianness. The text format for v128.const is little endian, so the lowest lane set translates to the least significant bit set.
1 parent ab14709 commit bd0f5af

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

interpreter/exec/simd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ struct
310310
let bitmask x =
311311
let xs = Convert.to_shape x in
312312
let negs = List.map (fun x -> if Int.(lt_s x zero) then Int32.one else Int32.zero) xs in
313-
List.fold_left (fun a b -> Int32.(logor b (shift_left a 1))) Int32.zero negs
313+
List.fold_right (fun a b -> Int32.(logor a (shift_left b 1))) negs Int32.zero
314314
let shl v s =
315315
let shift = Int.of_int_u (Int32.to_int s) in
316316
unop (fun a -> Int.shl a shift) v

test/core/simd/simd_boolean.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
(assert_return (invoke "i8x16.bitmask" (v128.const i8x16 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF))
5555
(i32.const 0x0000FFFF))
5656
(assert_return (invoke "i8x16.bitmask" (v128.const i8x16 -1 0 1 2 3 4 5 6 7 8 9 0xA 0xB 0xC 0xD 0xF))
57-
(i32.const 0x00008000))
57+
(i32.const 0x00000001))
5858

5959
;; i16x8
6060
(assert_return (invoke "i16x8.any_true" (v128.const i16x8 0 0 0 0 0 0 0 0))
@@ -104,7 +104,7 @@
104104
(assert_return (invoke "i16x8.bitmask" (v128.const i16x8 0xFFFF 0xFFFF 0xFFFF 0xFFFF 0xFFFF 0xFFFF 0xFFFF 0xFFFF))
105105
(i32.const 0x000000FF))
106106
(assert_return (invoke "i16x8.bitmask" (v128.const i16x8 -1 0 1 2 0xB 0xC 0xD 0xF))
107-
(i32.const 0x00000080))
107+
(i32.const 0x00000001))
108108

109109
;; i32x4
110110
(assert_return (invoke "i32x4.any_true" (v128.const i32x4 0 0 0 0))
@@ -154,7 +154,7 @@
154154
(assert_return (invoke "i32x4.bitmask" (v128.const i32x4 0xFFFFFFFF 0xFFFFFFFF 0xFFFFFFFF 0xFFFFFFFF))
155155
(i32.const 0x0000000F))
156156
(assert_return (invoke "i32x4.bitmask" (v128.const i32x4 -1 0 1 0xF))
157-
(i32.const 0x00000008))
157+
(i32.const 0x00000001))
158158

159159
;; Combination
160160

0 commit comments

Comments
 (0)