Skip to content

Commit a0647a8

Browse files
PR updates
1 parent 86d0760 commit a0647a8

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

interpreter/valid/valid.ml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,22 @@ let check_vec_binop binop at =
189189
error at "invalid lane index"
190190
| _ -> ()
191191

192-
let check_memop (c : context) (memop : ('t, 's) memop) ty_size get_sz at ~(isAtomic : bool) =
192+
type mem_mode = NonAtomic | Atomic
193+
194+
let check_memop (mode : mem_mode) (c : context) (memop : ('t, 's) memop) ty_size get_sz at =
193195
let _mt = memory c (0l @@ at) in
194196
let size =
195197
match get_sz memop.pack with
196198
| None -> ty_size memop.ty
197199
| Some sz ->
198200
check_pack sz (ty_size memop.ty) at;
199201
packed_size sz
200-
in
201-
require (1 lsl memop.align <= size) at
202-
"alignment must not be larger than natural";
203-
if isAtomic then
204-
require (1 lsl memop.align == size) at "atomic memory instruction's alignment must equal the instruction's natural alignment"
202+
in match mode with
203+
| NonAtomic ->
204+
require (1 lsl memop.align <= size) at
205+
"alignment must not be larger than natural";
206+
| Atomic ->
207+
require (1 lsl memop.align == size) at "atomic memory instruction's alignment must equal the instruction's natural alignment"
205208

206209

207210
(*
@@ -356,29 +359,29 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : op_type
356359
[] --> []
357360

358361
| Load memop ->
359-
check_memop ~isAtomic:false c memop num_size (Lib.Option.map fst) e.at;
362+
check_memop NonAtomic c memop num_size (Lib.Option.map fst) e.at;
360363
[NumType I32Type] --> [NumType memop.ty]
361364

362365
| Store memop ->
363-
check_memop ~isAtomic:false c memop num_size (fun sz -> sz) e.at;
366+
check_memop NonAtomic c memop num_size (fun sz -> sz) e.at;
364367
[NumType I32Type; NumType memop.ty] --> []
365368

366369
| VecLoad memop ->
367-
check_memop ~isAtomic:false c memop vec_size (Lib.Option.map fst) e.at;
370+
check_memop NonAtomic c memop vec_size (Lib.Option.map fst) e.at;
368371
[NumType I32Type] --> [VecType memop.ty]
369372

370373
| VecStore memop ->
371-
check_memop ~isAtomic:false c memop vec_size (fun _ -> None) e.at;
374+
check_memop NonAtomic c memop vec_size (fun _ -> None) e.at;
372375
[NumType I32Type; VecType memop.ty] --> []
373376

374377
| VecLoadLane (memop, i) ->
375-
check_memop ~isAtomic:false c memop vec_size (fun sz -> Some sz) e.at;
378+
check_memop NonAtomic c memop vec_size (fun sz -> Some sz) e.at;
376379
require (i < vec_size memop.ty / packed_size memop.pack) e.at
377380
"invalid lane index";
378381
[NumType I32Type; VecType memop.ty] --> [VecType memop.ty]
379382

380383
| VecStoreLane (memop, i) ->
381-
check_memop ~isAtomic:false c memop vec_size (fun sz -> Some sz) e.at;
384+
check_memop NonAtomic c memop vec_size (fun sz -> Some sz) e.at;
382385
require (i < vec_size memop.ty / packed_size memop.pack) e.at
383386
"invalid lane index";
384387
[NumType I32Type; VecType memop.ty] --> []
@@ -516,23 +519,23 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : op_type
516519
"invalid lane index";
517520
[t; NumType t2] --> [t]
518521
| MemoryAtomicWait atomicop ->
519-
check_memop ~isAtomic:true c atomicop num_size (fun sz -> sz) e.at;
522+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
520523
[NumType I32Type; NumType atomicop.ty; NumType I64Type] --> [NumType I32Type]
521524
| MemoryAtomicNotify atomicop ->
522-
check_memop ~isAtomic:true c atomicop num_size (fun sz -> sz) e.at;
525+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
523526
[NumType I32Type; NumType I32Type] --> [NumType I32Type]
524527
| AtomicFence -> [] --> []
525528
| AtomicLoad atomicop ->
526-
check_memop ~isAtomic:true c atomicop num_size (fun sz -> sz) e.at;
529+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
527530
[NumType I32Type] --> [NumType atomicop.ty]
528531
| AtomicStore atomicop ->
529-
check_memop ~isAtomic:true c atomicop num_size (fun sz -> sz) e.at;
532+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
530533
[NumType I32Type; NumType atomicop.ty] --> []
531534
| AtomicRmw (rmwop, atomicop) ->
532-
check_memop ~isAtomic:true c atomicop num_size (fun sz -> sz) e.at;
535+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
533536
[NumType I32Type; NumType atomicop.ty] --> [NumType atomicop.ty]
534537
| AtomicRmwCmpXchg atomicop ->
535-
check_memop ~isAtomic: true c atomicop num_size (fun sz -> sz) e.at;
538+
check_memop Atomic c atomicop num_size (fun sz -> sz) e.at;
536539
[NumType I32Type; NumType atomicop.ty; NumType atomicop.ty] --> [NumType atomicop.ty]
537540

538541
and check_seq (c : context) (s : infer_result_type) (es : instr list)

0 commit comments

Comments
 (0)