Skip to content

Commit

Permalink
Change the OFFSETCLOSURE bytecode instructions to use an offset of 3 …
Browse files Browse the repository at this point in the history
…instead of 2 (ocaml#10050)

Replace (PUSH)OFFSETCLOSURE(2|M2) by (PUSH)OFFSETCLOSURE(3|M3) to match the change of representation of closures.
  • Loading branch information
Ekdohibs authored and dbuenzli committed Mar 25, 2021
1 parent bc07ac4 commit 9735471
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -207,6 +207,10 @@ OCaml 4.12.0
in the same thread the allocation takes place
(Jacques-Henri Jourdan, review by Stephen Dolan)

- #10050: update {PUSH,}OFFSETCLOSURE* bytecode instructions to match new
representation for closures
(Nathanaël Courant, review by Xavier Leroy)

### Code generation and optimizations:

- #9551: ocamlc no longer loads DLLs at link time to check that
Expand Down
8 changes: 4 additions & 4 deletions bytecomp/emitcode.ml
Expand Up @@ -226,8 +226,8 @@ let emit_instr = function
let org = !out_position in
List.iter (out_label_with_orig org) lbls
| Koffsetclosure ofs ->
if ofs = -2 || ofs = 0 || ofs = 2
then out (opOFFSETCLOSURE0 + ofs / 2)
if ofs = -3 || ofs = 0 || ofs = 3
then out (opOFFSETCLOSURE0 + ofs / 3)
else (out opOFFSETCLOSURE; out_int ofs)
| Kgetglobal q -> out opGETGLOBAL; slot_for_getglobal q
| Ksetglobal q -> out opSETGLOBAL; slot_for_setglobal q
Expand Down Expand Up @@ -351,8 +351,8 @@ let rec emit = function
else (out opPUSHENVACC; out_int n);
emit c
| Kpush :: Koffsetclosure ofs :: c ->
if ofs = -2 || ofs = 0 || ofs = 2
then out(opPUSHOFFSETCLOSURE0 + ofs / 2)
if ofs = -3 || ofs = 0 || ofs = 3
then out(opPUSHOFFSETCLOSURE0 + ofs / 3)
else (out opPUSHOFFSETCLOSURE; out_int ofs);
emit c
| Kpush :: Kgetglobal id :: Kgetfield n :: c ->
Expand Down
6 changes: 3 additions & 3 deletions runtime/caml/instruct.h
Expand Up @@ -32,9 +32,9 @@ enum instructions {
APPTERM, APPTERM1, APPTERM2, APPTERM3,
RETURN, RESTART, GRAB,
CLOSURE, CLOSUREREC,
OFFSETCLOSUREM2, OFFSETCLOSURE0, OFFSETCLOSURE2, OFFSETCLOSURE,
PUSHOFFSETCLOSUREM2, PUSHOFFSETCLOSURE0,
PUSHOFFSETCLOSURE2, PUSHOFFSETCLOSURE,
OFFSETCLOSUREM3, OFFSETCLOSURE0, OFFSETCLOSURE3, OFFSETCLOSURE,
PUSHOFFSETCLOSUREM3, PUSHOFFSETCLOSURE0,
PUSHOFFSETCLOSURE3, PUSHOFFSETCLOSURE,
GETGLOBAL, PUSHGETGLOBAL, GETGLOBALFIELD, PUSHGETGLOBALFIELD, SETGLOBAL,
ATOM0, ATOM, PUSHATOM0, PUSHATOM,
MAKEBLOCK, MAKEBLOCK1, MAKEBLOCK2, MAKEBLOCK3, MAKEFLOATBLOCK,
Expand Down
12 changes: 6 additions & 6 deletions runtime/interp.c
Expand Up @@ -616,18 +616,18 @@ value caml_interprete(code_t prog, asize_t prog_size)
Instruct(OFFSETCLOSURE):
accu = env + *pc++ * sizeof(value); Next;

Instruct(PUSHOFFSETCLOSUREM2):
Instruct(PUSHOFFSETCLOSUREM3):
*--sp = accu; /* fallthrough */
Instruct(OFFSETCLOSUREM2):
accu = env - 2 * sizeof(value); Next;
Instruct(OFFSETCLOSUREM3):
accu = env - 3 * sizeof(value); Next;
Instruct(PUSHOFFSETCLOSURE0):
*--sp = accu; /* fallthrough */
Instruct(OFFSETCLOSURE0):
accu = env; Next;
Instruct(PUSHOFFSETCLOSURE2):
Instruct(PUSHOFFSETCLOSURE3):
*--sp = accu; /* fallthrough */
Instruct(OFFSETCLOSURE2):
accu = env + 2 * sizeof(value); Next;
Instruct(OFFSETCLOSURE3):
accu = env + 3 * sizeof(value); Next;


/* Access to global variables */
Expand Down
8 changes: 4 additions & 4 deletions tools/dumpobj.ml
Expand Up @@ -296,13 +296,13 @@ let op_shapes = [
opGRAB, Uint;
opCLOSURE, Uint_Disp;
opCLOSUREREC, Closurerec;
opOFFSETCLOSUREM2, Nothing;
opOFFSETCLOSUREM3, Nothing;
opOFFSETCLOSURE0, Nothing;
opOFFSETCLOSURE2, Nothing;
opOFFSETCLOSURE3, Nothing;
opOFFSETCLOSURE, Sint; (* was Uint *)
opPUSHOFFSETCLOSUREM2, Nothing;
opPUSHOFFSETCLOSUREM3, Nothing;
opPUSHOFFSETCLOSURE0, Nothing;
opPUSHOFFSETCLOSURE2, Nothing;
opPUSHOFFSETCLOSURE3, Nothing;
opPUSHOFFSETCLOSURE, Sint; (* was Nothing *)
opGETGLOBAL, Getglobal;
opPUSHGETGLOBAL, Getglobal;
Expand Down

0 comments on commit 9735471

Please sign in to comment.