Skip to content

Commit

Permalink
[interpreter] Update {memory,table}.copy to match spec text (#1666)
Browse files Browse the repository at this point in the history
Change the interpreter implementation of backward copying in the evaluation of
memory.copy and table.copy to match the implementation given in the spec. This
does not change any behavior.
  • Loading branch information
tlively authored and rossberg committed Oct 6, 2023
1 parent e5435b2 commit ef9c157
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,16 @@ let rec step (c : config) : config =
Plain (TableCopy (x, y));
]
else (* d > s *)
let n' = I32.sub n 1l in
vs', List.map (Lib.Fun.flip (@@) e.at) [
Plain (Const (I32 (I32.add d 1l) @@ e.at));
Plain (Const (I32 (I32.add s 1l) @@ e.at));
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
Plain (TableCopy (x, y));
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 (I32.add d n') @@ e.at));
Plain (Const (I32 (I32.add s n') @@ e.at));
Plain (TableGet y);
Plain (TableSet x);
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 n' @@ e.at));
Plain (TableCopy (x, y));
]

| TableInit (x, y), Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->
Expand Down Expand Up @@ -513,17 +514,18 @@ let rec step (c : config) : config =
Plain (MemoryCopy);
]
else (* d > s *)
let n' = I32.sub n 1l in
vs', List.map (Lib.Fun.flip (@@) e.at) [
Plain (Const (I32 (I32.add d 1l) @@ e.at));
Plain (Const (I32 (I32.add s 1l) @@ e.at));
Plain (Const (I32 (I32.sub n 1l) @@ e.at));
Plain (MemoryCopy);
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 (I32.add d n') @@ e.at));
Plain (Const (I32 (I32.add s n') @@ e.at));
Plain (Load
{ty = Types.I32T; align = 0; offset = 0l; pack = Some (Pack8, ZX)});
Plain (Store
{ty = Types.I32T; align = 0; offset = 0l; pack = Some Pack8});
Plain (Const (I32 d @@ e.at));
Plain (Const (I32 s @@ e.at));
Plain (Const (I32 n' @@ e.at));
Plain (MemoryCopy);
]

| MemoryInit x, Num (I32 n) :: Num (I32 s) :: Num (I32 d) :: vs' ->
Expand Down

0 comments on commit ef9c157

Please sign in to comment.