Verified Commit a5f3654a authored by Camil Staps's avatar Camil Staps 🚀

Remove unused first word from prelinked bytecode (was used to store the length...

Remove unused first word from prelinked bytecode (was used to store the length of the preamble before we used variable-width encoding)
parent 676c388c
Pipeline #26275 passed with stages
in 13 minutes and 56 seconds
......@@ -290,8 +290,8 @@
(then
(if
(i32.or
(i32.eq (local.get $d) (i32.const 210)) ;; INT+2
(i32.eq (local.get $d) (i32.const 170)) ;; REAL+2
(i32.eq (local.get $d) (i32.const 202)) ;; INT+2
(i32.eq (local.get $d) (i32.const 162)) ;; REAL+2
;; BOOL and CHAR are always static so cannot occur here
)
(then
......@@ -301,7 +301,7 @@
)
(if
;; _STRING_+2
(i32.eq (local.get $d) (i32.const 50))
(i32.eq (local.get $d) (i32.const 42))
(then
(local.set $size (i32.load offset=8 (local.get $n))) ;; size
(local.set $size (i32.shr_u (i32.add (local.get $size) (i32.const 7)) (i32.const 3)))
......@@ -311,14 +311,14 @@
)
(if
;; _ARRAY_+2
(i32.eq (local.get $d) (i32.const 10))
(i32.eq (local.get $d) (i32.const 2))
(then
(local.set $size (i32.load offset=8 (local.get $n))) ;; size
(local.set $d (i32.load offset=16 (local.get $n))) ;; child descriptor
(if
(i32.or ;; unboxed INT/REAL
(i32.eq (local.get $d) (i32.const 170))
(i32.eq (local.get $d) (i32.const 210))
(i32.eq (local.get $d) (i32.const 162))
(i32.eq (local.get $d) (i32.const 202))
)
(then
(local.set $n (i32.add (local.get $n) (i32.add (i32.const 24)
......@@ -327,7 +327,7 @@
)
)
(if ;; unboxed BOOL
(i32.eq (local.get $d) (i32.const 90))
(i32.eq (local.get $d) (i32.const 82))
(then
(local.set $n (i32.add (local.get $n) (i32.add (i32.const 24)
(i32.shl (local.get $size) (i32.const 6))))) ;; 3+3
......@@ -520,12 +520,12 @@
;; hnf
(then
(if
(i32.eq (local.get $d) (i32.const 210)) ;; INT+2
(i32.eq (local.get $d) (i32.const 202)) ;; INT+2
(then
(if
(i64.lt_u (i64.load offset=8 (local.get $n)) (i64.const 33))
(then
(local.set $d (i32.add (i32.const 248) (i32.shl (i32.load offset=8 (local.get $n)) (i32.const 4)))) ;; small integer
(local.set $d (i32.add (i32.const 240) (i32.shl (i32.load offset=8 (local.get $n)) (i32.const 4)))) ;; small integer
(i64.store (local.get $ref) (i64.extend_i32_u (local.get $d)))
(i64.store (local.get $n) (i64.extend_i32_u (i32.add (local.get $d) (i32.const 1))))
(return (local.get $hp))
......@@ -540,18 +540,18 @@
)
)
(if
(i32.eq (local.get $d) (i32.const 90)) ;; BOOL+2
(i32.eq (local.get $d) (i32.const 82)) ;; BOOL+2
(then
(local.set $d (select (i32.const 5304) (i32.const 5288) (i32.load offset=8 (local.get $n)))) ;; static FALSE/TRUE
(local.set $d (select (i32.const 5296) (i32.const 5280) (i32.load offset=8 (local.get $n)))) ;; static FALSE/TRUE
(i64.store (local.get $ref) (i64.extend_i32_u (local.get $d)))
(i64.store (local.get $n) (i64.extend_i32_u (i32.add (local.get $d) (i32.const 1))))
(return (local.get $hp))
)
)
(if
(i32.eq (local.get $d) (i32.const 130)) ;; CHAR+2
(i32.eq (local.get $d) (i32.const 122)) ;; CHAR+2
(then
(local.set $d (i32.add (i32.const 1176) (i32.shl
(local.set $d (i32.add (i32.const 1168) (i32.shl
(i32.and (i32.load8_u offset=8 (local.get $n)) (i32.const 0xff)) (i32.const 4)))) ;; static character
(i64.store (local.get $ref) (i64.extend_i32_u (local.get $d)))
(i64.store (local.get $n) (i64.extend_i32_u (i32.add (local.get $d) (i32.const 1))))
......@@ -559,7 +559,7 @@
)
)
(if
(i32.eq (local.get $d) (i32.const 170)) ;; REAL+2
(i32.eq (local.get $d) (i32.const 162)) ;; REAL+2
(then
(i64.store (local.get $hp) (i64.extend_i32_u (local.get $d)))
(i64.store offset=8 (local.get $hp) (i64.load offset=8 (local.get $n)))
......@@ -569,7 +569,7 @@
)
(if
;; _STRING_+2
(i32.eq (local.get $d) (i32.const 50))
(i32.eq (local.get $d) (i32.const 42))
(then
(i64.store (local.get $hp) (i64.extend_i32_u (local.get $d)))
(i64.store (local.get $n) (i64.extend_i32_u (i32.add (local.get $hp) (i32.const 1))))
......@@ -594,7 +594,7 @@
)
(if
;; _ARRAY_+2
(i32.eq (local.get $d) (i32.const 10))
(i32.eq (local.get $d) (i32.const 2))
(then
(i64.store (local.get $hp) (i64.extend_i32_u (local.get $d)))
(i64.store (local.get $n) (i64.extend_i32_u (i32.add (local.get $hp) (i32.const 1))))
......@@ -612,14 +612,14 @@
(i32.or
(i32.eqz (local.get $d)) ;; boxed
(i32.or ;; unboxed INT/REAL
(i32.eq (i32.const 170) (local.get $d))
(i32.eq (local.get $d) (i32.const 210))
(i32.eq (i32.const 162) (local.get $d))
(i32.eq (i32.const 202) (local.get $d))
)
)
)
(then
(if
(i32.eq (local.get $d) (i32.const 90))
(i32.eq (local.get $d) (i32.const 82))
(then ;; BOOL
(local.set $size (i32.shr_u (i32.add (local.get $size) (i32.const 7)) (i32.const 3)))
)
......@@ -814,7 +814,7 @@
(if ;; BOOL
(i32.eq (local.get $desc) (i32.const -22))
(then
(i64.store (local.get $hp) (i64.const 90))
(i64.store (local.get $hp) (i64.const 82))
(i64.store offset=8 (local.get $hp) (i64.load offset=8 (i32.add (local.get $s) (local.get $i))))
(br $predefined-constructor)
)
......@@ -822,7 +822,7 @@
(if ;; CHAR
(i32.eq (local.get $desc) (i32.const -30))
(then
(i64.store (local.get $hp) (i64.const 130))
(i64.store (local.get $hp) (i64.const 122))
(i64.store offset=8 (local.get $hp) (i64.load offset=8 (i32.add (local.get $s) (local.get $i))))
(br $predefined-constructor)
)
......@@ -830,7 +830,7 @@
(if ;; REAL
(i32.eq (local.get $desc) (i32.const -38))
(then
(i64.store (local.get $hp) (i64.const 170))
(i64.store (local.get $hp) (i64.const 162))
(i64.store offset=8 (local.get $hp) (i64.load offset=8 (i32.add (local.get $s) (local.get $i))))
(br $predefined-constructor)
)
......@@ -838,7 +838,7 @@
(if ;; INT
(i32.eq (local.get $desc) (i32.const -46))
(then
(i64.store (local.get $hp) (i64.const 210))
(i64.store (local.get $hp) (i64.const 202))
(i64.store offset=8 (local.get $hp) (i64.load offset=8 (i32.add (local.get $s) (local.get $i))))
(br $predefined-constructor)
)
......@@ -862,7 +862,7 @@
(i64.store (i32.load (local.get $ptr-stack)) (i64.extend_i32_u (local.get $hp)))
(local.set $ptr-stack (i32.sub (local.get $ptr-stack) (i32.const 4)))
(i64.store (local.get $hp) (i64.const 50))
(i64.store (local.get $hp) (i64.const 42))
(local.set $a (i32.load offset=8 (i32.add (local.get $s) (local.get $i))))
(i64.store offset=8 (local.get $hp) (i64.extend_i32_u (local.get $a)))
(local.set $a (i32.shr_u (i32.add (local.get $a) (i32.const 7)) (i32.const 3)))
......@@ -886,13 +886,13 @@
(local.set $a (i32.load offset=8 (i32.add (local.get $s) (local.get $i))))
(local.set $desc (i32.load offset=16 (i32.add (local.get $s) (local.get $i))))
(i64.store (local.get $hp) (i64.const 10))
(i64.store (local.get $hp) (i64.const 2))
(i64.store offset=8 (local.get $hp) (i64.extend_i32_u (local.get $a)))
(if ;; INT elements
(i32.eq (local.get $desc) (i32.const -46))
(then
(i64.store offset=16 (local.get $hp) (i64.const 210))
(i64.store offset=16 (local.get $hp) (i64.const 202))
(call $copy
(i32.add (local.get $hp) (i32.const 24))
(i32.add (local.get $s) (i32.add (local.get $i) (i32.const 24)))
......@@ -906,7 +906,7 @@
(if ;; REAL elements
(i32.eq (local.get $desc) (i32.const -38))
(then
(i64.store offset=16 (local.get $hp) (i64.const 170))
(i64.store offset=16 (local.get $hp) (i64.const 162))
(call $copy
(i32.add (local.get $hp) (i32.const 24))
(i32.add (local.get $s) (i32.add (local.get $i) (i32.const 24)))
......@@ -920,7 +920,7 @@
(if ;; BOOL elements
(i32.eq (local.get $desc) (i32.const -22))
(then
(i64.store offset=16 (local.get $hp) (i64.const 90))
(i64.store offset=16 (local.get $hp) (i64.const 82))
(local.set $a (i32.shr_u (i32.add (local.get $a) (i32.const 7)) (i32.const 3)))
(call $copy
(i32.add (local.get $hp) (i32.const 24))
......
......@@ -207,7 +207,7 @@ class ABCInterpreter {
this.memory_array[hp/4+3]=0;
hp+=16;
hp_free-=2;
this.memory_array[hp/4]=6*8+2; // _STRING_
this.memory_array[hp/4]=5*8+2; // _STRING_
this.memory_array[hp/4+1]=0;
this.memory_array[hp/4+2]=values[i].length;
this.memory_array[hp/4+3]=0;
......@@ -231,7 +231,7 @@ class ABCInterpreter {
this.memory_array[hp/4+3]=0;
hp+=16;
hp_free-=2;
this.memory_array[hp/4]=1*8+2; // _ARRAY_
this.memory_array[hp/4]=0*8+2; // _ARRAY_
this.memory_array[hp/4+1]=0;
this.memory_array[hp/4+2]=values[i].length;
this.memory_array[hp/4+3]=0;
......@@ -586,7 +586,7 @@ class ABCInterpreter {
},
RtoAC: function (dest, v) {
v=Number(0+v).toPrecision(15).replace(/\.?0*$/,'');
me.memory_array[dest/4]=6*8+2; // __STRING__
me.memory_array[dest/4]=5*8+2; // __STRING__
me.memory_array[dest/4+1]=0;
me.memory_array[dest/4+2]=v.length;
me.memory_array[dest/4+3]=0;
......@@ -611,7 +611,7 @@ class ABCInterpreter {
const csp=asp+me.stack_size/2;
const hp=bsp+8;
me.util.instance.exports.setup_gc(hp, me.heap_size, asp, 97*8);
me.util.instance.exports.setup_gc(hp, me.heap_size, asp, 96*8);
me.interpreter.instance.exports.set_asp(asp);
me.interpreter.instance.exports.set_bsp(bsp);
......@@ -630,7 +630,7 @@ class ABCInterpreter {
* collection, so do that first, then set the rest of the arguments and
* update asp. */
const copied=me.copy_js_to_clean(args, asp+8);
me.memory_array[asp/4]=(31+17*2)*8; // JSWorld: INT 17
me.memory_array[asp/4]=(30+17*2)*8; // JSWorld: INT 17
me.memory_array[asp/4+4]=me.shared_clean_values[f.shared_clean_value_index].ref;
me.interpreter.instance.exports.set_asp(asp+16);
......@@ -638,11 +638,11 @@ class ABCInterpreter {
hp_free=copied.hp_free;
var csp=me.interpreter.instance.exports.get_csp();
me.memory_array[csp/4]=659*8; // instruction 0; to return
me.memory_array[csp/4]=658*8; // instruction 0; to return
csp+=8;
const old_pc=me.interpreter.instance.exports.get_pc();
me.interpreter.instance.exports.set_pc(100*8); // jmp_ap2
me.interpreter.instance.exports.set_pc(99*8); // jmp_ap2
me.interpreter.instance.exports.set_csp(csp);
me.interpreter.instance.exports.set_hp(hp);
me.interpreter.instance.exports.set_hp_free(hp_free);
......
......@@ -20,8 +20,7 @@ enum section_type {
#define _4chars2int(a,b,c,d) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)))
#define _7chars2int(a,b,c,d,e,f,g) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)))
#define _8chars2int(a,b,c,d,e,f,g,h) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)+((uint64_t)h<<56)))
uint64_t prelinker_preamble[665] = {
0, /* reserved */
uint64_t prelinker_preamble[664] = {
/* 0 */ 0, 0, 0, 7, _7chars2int('_','A','R','R','A','Y','_'),
/* 5 */ 0, 0, 0, 8, _8chars2int('_','S','T','R','I','N','G','_'),
/* 10 */ 0, 0, 0, 4, _4chars2int('B','O','O','L'),
......@@ -32,7 +31,7 @@ uint64_t prelinker_preamble[665] = {
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,
/* 96 */ 0, 98*8, /* caf list */
/* 96 */ 0, 97*8, /* caf list */
/* 98 */
Cjmp_ap1, Cjmp_ap2, Cjmp_ap3, Cjmp_ap4, Cjmp_ap5,
Cjmp_ap6, Cjmp_ap7, Cjmp_ap8, Cjmp_ap9, Cjmp_ap10,
......@@ -43,8 +42,8 @@ uint64_t prelinker_preamble[665] = {
Cjmp_ap31, Cjmp_ap32,
/* 130 */ Chalt, /* cycle in spine */
/* 131 */ Cjsr_eval0, Cfill_a01_pop_rtn, Chalt, Chalt, -2, /* indirection */
Cpush_node1, (131+1+5)*8, Cjsr_eval0, Cfill_a01_pop_rtn,
/* 140 */ (141+1)*8+2, 0, 0, 0, 4, /* Nil */
Cpush_node1, (131+5)*8, Cjsr_eval0, Cfill_a01_pop_rtn,
/* 140 */ 141*8+2, 0, 0, 0, 4, /* Nil */
_4chars2int('_','N','i','l'),
/* 146 static characters*/
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
......@@ -65,19 +64,19 @@ uint64_t prelinker_preamble[665] = {
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 658 */ Cinstruction, 0, /* to return to JavaScript */
/* 660 static booleans */
(10+1)*8+2,0, (10+1)*8+2,1,
10*8+2,0, 10*8+2,1,
/* 664 */
};
void prepare_preamble(void) {
for (int i=0; i<=32; i++) {
prelinker_preamble[31+i*2]=26*8+2; /* INT+2 */
prelinker_preamble[31+i*2+1]=i;
prelinker_preamble[30+i*2]=25*8+2; /* INT+2 */
prelinker_preamble[30+i*2+1]=i;
}
for (int i=0; i<256; i++) {
prelinker_preamble[147+i*2]=16*8+2; /* CHAR+2 */
prelinker_preamble[147+i*2+1]=i;
prelinker_preamble[146+i*2]=15*8+2; /* CHAR+2 */
prelinker_preamble[146+i*2+1]=i;
}
}
......
#pragma once
extern uint64_t prelinker_preamble[665];
extern uint64_t prelinker_preamble[664];
......@@ -500,20 +500,20 @@ int parse_program(struct parser *state, struct char_provider *cp) {
# define INTERPRETER_OR_PRELINKER(i,u) (u*8)
# endif
if (!strcmp(state->program->symbol_table[state->ptr].name, "__ARRAY__")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__ARRAY__,1);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__ARRAY__,0);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "__STRING__")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__STRING__,6);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__STRING__,5);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "INT") ||
!strcmp(state->program->symbol_table[state->ptr].name, "dINT")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&INT,26);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&INT,25);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "BOOL")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&BOOL,11);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&BOOL,10);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "CHAR")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&CHAR,16);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&CHAR,15);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "REAL")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&REAL,21);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&REAL,20);
} else if (!strcmp(state->program->symbol_table[state->ptr].name, "e__system__nind")) {
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__interpreter_indirection[5], 137);
state->program->symbol_table[state->ptr].offset = (BC_WORD) INTERPRETER_OR_PRELINKER(&__interpreter_indirection[5], 136);
} else if (state->program->symbol_table[state->ptr].offset == -1) {
# ifdef DEBUG_CLEAN_LINKS
EPRINTF("Warning: symbol '%s' is not defined.\n",state->program->symbol_table[state->ptr].name);
......
......@@ -690,51 +690,51 @@ Hp_free :: Expr TPtrOffset
Hp_free = Ivar (rt_var "hp-free")
BOOL_ptr :: Expr TWord
BOOL_ptr = Econst I64 (11*8)
BOOL_ptr = Econst I64 (10*8)
CHAR_ptr :: Expr TWord
CHAR_ptr = Econst I64 (16*8)
CHAR_ptr = Econst I64 (15*8)
INT_ptr :: Expr TWord
INT_ptr = Econst I64 (26*8)
INT_ptr = Econst I64 (25*8)
REAL_ptr :: Expr TWord
REAL_ptr = Econst I64 (21*8)
REAL_ptr = Econst I64 (20*8)
ARRAY__ptr :: Expr TWord
ARRAY__ptr = Econst I64 (1*8)
ARRAY__ptr = Econst I64 (0*8)
STRING__ptr :: Expr TWord
STRING__ptr = Econst I64 (6*8)
STRING__ptr = Econst I64 (5*8)
jmp_ap_ptr :: !Int -> Expr (TPtr TWord)
jmp_ap_ptr i = Econst I32 ((99+i)*8)
jmp_ap_ptr i = Econst I32 ((98+i)*8)
cycle_ptr :: Expr TWord
cycle_ptr = Econst I64 (131*8)
cycle_ptr = Econst I64 (130*8)
indirection_ptr :: Expr TWord
indirection_ptr = Econst I64 ((131+1+5)*8)
indirection_ptr = Econst I64 ((131+5)*8)
dNil_ptr :: Expr TWord
dNil_ptr = Econst I64 ((141+1)*8)
dNil_ptr = Econst I64 (141*8)
small_integer :: !(Expr TInt) -> Expr TWord
small_integer i = Eadd I64 (Econst I64 (8*31)) (Eshl I64 i (Econst I64 4))
small_integer i = Eadd I64 (Econst I64 (8*30)) (Eshl I64 i (Econst I64 4))
static_character :: !(Expr TChar) -> Expr TWord
static_character c = Eadd I64 (Econst I64 (8*147)) (Eshl I64 c (Econst I64 4))
static_character c = Eadd I64 (Econst I64 (8*146)) (Eshl I64 c (Econst I64 4))
static_boolean :: !(Expr TWord) -> Expr TWord
static_boolean b = case b of
Econst _ i -> if (is_zero i) FALSE TRUE
b -> if_expr (Ewrap I32 I64 b) TRUE FALSE
where
TRUE = Econst I64 (8*663)
FALSE = Econst I64 (8*661)
TRUE = Econst I64 (8*662)
FALSE = Econst I64 (8*660)
caf_list :: Expr (TPtr TWord)
caf_list = Econst I32 (97*8)
caf_list = Econst I32 (96*8)
fast_ap_descriptor :: Expr TWord
fast_ap_descriptor = Ivar (Global "g-fast-ap-descriptor")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment