Skip to content

Commit 6bcd5ea

Browse files
committed
Bigarrays: make it explicit when we are reading multiple bytes from a byte array
1 parent 01f381c commit 6bcd5ea

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

runtime/wasm/bigarray.wat

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@
120120
(func $dv_set_i16 (param externref i32 i32 i32)))
121121
(import "bindings" "dv_set_i8"
122122
(func $dv_set_i8 (param externref i32 i32)))
123+
(import "bindings" "dv_get_i64"
124+
(func $dv_get_i64_unaligned (param externref i32 i32) (result i64)))
125+
(import "bindings" "dv_get_i32"
126+
(func $dv_get_i32_unaligned (param externref i32 i32) (result i32)))
127+
(import "bindings" "dv_get_ui16"
128+
(func $dv_get_ui16_unaligned (param externref i32 i32) (result i32)))
129+
(import "bindings" "dv_set_i64"
130+
(func $dv_set_i64_unaligned (param externref i32 i64 i32)))
131+
(import "bindings" "dv_set_i32"
132+
(func $dv_set_i32_unaligned (param externref i32 i32 i32)))
133+
(import "bindings" "dv_set_i16"
134+
(func $dv_set_i16_unaligned (param externref i32 i32 i32)))
123135
(import "bindings" "littleEndian" (global $littleEndian i32))
124136

125137
(type $block (array (mut (ref eq))))
@@ -2018,7 +2030,8 @@
20182030
(i32.const 0)))
20192031
(then (call $caml_bound_error)))
20202032
(ref.i31
2021-
(call $dv_get_ui16 (local.get $view) (local.get $p) (i32.const 1))))
2033+
(call $dv_get_ui16_unaligned
2034+
(local.get $view) (local.get $p) (i32.const 1))))
20222035

20232036
(func (export "caml_ba_uint8_get32")
20242037
(param $vba (ref eq)) (param $i (ref eq)) (result i32)
@@ -2035,7 +2048,8 @@
20352048
(struct.get $bigarray $ba_dim (local.get $ba))
20362049
(i32.const 0)))
20372050
(then (call $caml_bound_error)))
2038-
(return_call $dv_get_i32 (local.get $view) (local.get $p) (i32.const 1)))
2051+
(return_call $dv_get_i32_unaligned
2052+
(local.get $view) (local.get $p) (i32.const 1)))
20392053

20402054
(func (export "caml_ba_uint8_get64")
20412055
(param $vba (ref eq)) (param $i (ref eq)) (result i64)
@@ -2052,7 +2066,7 @@
20522066
(struct.get $bigarray $ba_dim (local.get $ba))
20532067
(i32.const 0)))
20542068
(then (call $caml_bound_error)))
2055-
(call $dv_get_i64
2069+
(call $dv_get_i64_unaligned
20562070
(local.get $view) (local.get $p) (i32.const 1)))
20572071

20582072
(func (export "caml_ba_uint8_set16")
@@ -2072,7 +2086,7 @@
20722086
(struct.get $bigarray $ba_dim (local.get $ba))
20732087
(i32.const 0)))
20742088
(then (call $caml_bound_error)))
2075-
(call $dv_set_i16
2089+
(call $dv_set_i16_unaligned
20762090
(local.get $view) (local.get $p) (local.get $d) (i32.const 1))
20772091
(ref.i31 (i32.const 0)))
20782092

@@ -2092,7 +2106,7 @@
20922106
(struct.get $bigarray $ba_dim (local.get $ba))
20932107
(i32.const 0)))
20942108
(then (call $caml_bound_error)))
2095-
(call $dv_set_i32
2109+
(call $dv_set_i32_unaligned
20962110
(local.get $view) (local.get $p) (local.get $d) (i32.const 1))
20972111
(ref.i31 (i32.const 0)))
20982112

@@ -2112,7 +2126,7 @@
21122126
(struct.get $bigarray $ba_dim (local.get $ba))
21132127
(i32.const 0)))
21142128
(then (call $caml_bound_error)))
2115-
(call $dv_set_i64
2129+
(call $dv_set_i64_unaligned
21162130
(local.get $view) (local.get $p) (local.get $d) (i32.const 1))
21172131
(ref.i31 (i32.const 0)))
21182132

runtime/wasm/bigstring.wat

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
(import "bindings" "ta_create"
3939
(func $ta_create (param i32) (param anyref) (result anyref)))
4040
(import "bindings" "dv_get_i32"
41-
(func $dv_get_i32 (param externref i32 i32) (result i32)))
41+
(func $dv_get_i32_unaligned (param externref i32 i32) (result i32)))
4242
(import "bindings" "dv_get_ui8"
4343
(func $dv_get_ui8 (param externref i32) (result i32)))
4444
(import "bindings" "dv_set_i8"
@@ -77,7 +77,8 @@
7777
(local.set $h
7878
(call $caml_hash_mix_int
7979
(local.get $h)
80-
(call $dv_get_i32 (local.get $view) (local.get $i)
80+
(call $dv_get_i32_unaligned
81+
(local.get $view) (local.get $i)
8182
(i32.const 1))))
8283
(local.set $i (i32.add (local.get $i) (i32.const 4)))
8384
(br $loop))))

0 commit comments

Comments
 (0)