Skip to content

Commit

Permalink
Switch vector tag
Browse files Browse the repository at this point in the history
  • Loading branch information
djwatson committed Oct 6, 2023
1 parent a6eb4e8 commit 93f4745
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 91 deletions.
8 changes: 4 additions & 4 deletions doc/benchmark_results2.org
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
| triangl | .8 | 1.184 | -48. | *WIN* | | x |
| destruc | 1.08 | 1.28 | -18.518519 | *WIN* | | x |
| gcbench | .59 | .556 | 5.7627119 | | letrec define opt | |
| puzzle | 1.7 | 1.55 | 8.8235294 | | loop opt | x |
| puzzle | 1.32 | 1.55 | -13.970588 | *WIN* | loop opt | x |
| paraffins | 3.24 | 4.270 | -31.790123 | *WIN* | | x |
| maze | .437 | .845 | -93.363844 | *WIN* | | x |
| mazefun | 1.79 | 1.731 | 3.2960894 | | | x |
| lattice | 2.7 | 2.7 | 0. | *WIN* | closure sinking, sccp | x |
| browse | .92 | .987 | -7.2826087 | *WIN* | | |
| graphs | 1.9 | 1.3 | 31.578947 | | LOOP, closure analysis , closure sinking | nested |
| conform | 1.97 | 1.422 | 27.817259 | | | |
| graphs | 1.75 | 1.3 | 26.966292 | | LOOP, closure analysis , closure sinking | nested |
| conform | 1.89 | 1.422 | 24.761905 | | | |
| sboyer | .87 | .731 | 15.977011 | | ?? typecheck | |
| nboyer | 1.42 | 1.483 | -4.4366197 | *WIN* | ?? | |
| array1 | 2.0 | 4.5 | -125. | *WIN* | | x |
Expand All @@ -42,6 +42,6 @@
| compiler | 2.19 | 2.004 | 8.4931507 | | loop catching | |
| matrix | 1.2 | .899 | 25.083333 | | loop catching?? opt_loop | |
| dynamic | 1.88 | 1.447 | 23.031915 | | read | |
| TOTAL | 73.074 | 76.9779 | -5.3423926 | *WIN* | | |
| TOTAL | 72.534 | 76.9779 | -6.1266441 | *WIN* | | |
|-----------+--------+---------+-------------+-------+-------------------------------------------------+------------|
#+TBLFM: $4=($2-$3) * 100.0 /$2::$5='(if (not (= $2 0)) (if (>= $3 $2) '*WIN* "") "BAD");N::@>$2=vsum(@2..@-1)::@>$3=vsum(@2..@-1)
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ <h2>Benchmarks</h2>
arrayLabel = ['Chez', 'Loko', 'Gambit', 'Hawk'];
makechart('destruc', [1.2800000000002, 1.1779999732971191, 1.529525, 1.08]);
//makechart('pnpoly', [3.2399999999997817, 3.7260000705718994, 2.29479, 6.8]);
makechart('conform', [1.3599999999996726, 1.2949999570846558, 2.161752, 1.96]);
makechart('conform', [1.3599999999996726, 1.2949999570846558, 2.161752, 1.89]);
//makechart('fibfp', [2.199999999999818, 2.046999931335449, 0.89905, 3.784]);
makechart('puzzle', [1.6299999999996544, 1.5299999713897705, 2.193014, 1.68]);
makechart('puzzle', [1.6299999999996544, 1.5299999713897705, 2.193014, 1.32]);
//makechart('fft', [0.0, 0.9300000071525574, 0.869155, 2.21]);
makechart('dynamic', [1.3899999999998727, 2.3949999809265137, 3.172476, 1.88]);
//makechart('ctak', [0.41000000000030923, 16.945999145507812, 1.854662, 3.29]);
Expand Down Expand Up @@ -208,7 +208,7 @@ <h2>Benchmarks</h2>
makechart('diviter', [0.9800000000000182, 1.1749999523162842, 1.108788, 1.00]);
makechart('equal', [0.3900000000003274, 1.5759999752044678, 0.234992, 0.2]);
makechart('divrec', [1.6200000000, 1.9700000286102295, 1.559836, 1.59]);
makechart('graphs', [1.3099999999999454, 1.7000000476837158, 5.411687, 1.89]);
makechart('graphs', [1.3099999999999454, 1.7000000476837158, 5.411687, 1.75]);
makechart('mperm', [6.8400000000001455, 4.39300012588501, 4.34869, 5.05]);
makechart('mazefun', [1.5799999999999272, 1.6059999465942383, 2.093023, 1.76]);
makechart('array1', [4.5900000000001455, 1.4989999532699585, 2.981551, 2.00]);
Expand Down
1 change: 0 additions & 1 deletion lib/bc.scm
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@
(write-u64 (string-length c) p)
(for-each (lambda (c) (write-u8 (char->integer c) p)) (string->list c)))
((vector? c)
(write-u64 ptr-tag p)
(write-u64 vector-tag p)
(write-u64 (vector-length c) p)
(do ((i 0 (+ i 1)))
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(define (pair? x) ($guard x 3))
(define (procedure? x) ($guard x 5))
(define (symbol? x) ($guard x 6))
(define (vector? x) ($guard x #x11))
(define (vector? x) ($guard x 7))
(define (string? x) ($guard x 9))
(define (port? x) ($guard x #x19))
(define complex? number?)
Expand Down
3 changes: 1 addition & 2 deletions lib/memory_layout.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
(define literal-tag #b100)
(define closure-tag #b101)
(define symbol-tag #b110)
(define forward-tag #b111)
(define vector-tag #b111)
;; ptr-tagged objects
;; Bottom bits must be '001'
;; First 8 bytes are always the tag.
(define string-tag #b001001)
(define vector-tag #b010001)
(define port-tag #b011001)
(define box-tag #b100001)
(define cont-tag #b101001)
Expand Down
20 changes: 14 additions & 6 deletions src/asm_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,13 @@ static void emit_init_funcs() {

void emit_vref(uint8_t reg, uint8_t opcode, trace_s* trace, ir_ins* op, int *slot, uint32_t *next_spill) {
// TODO: fuse.
uint8_t type;
if (ir_is_const(op->op1)) {
type = get_object_ir_type(trace->consts[op->op1 - IR_CONST_BIAS]);
} else {
type = trace->ops[op->op1].type;
}
type &= TAG_MASK;
maybe_assign_register(op->op1, trace, slot, next_spill);
maybe_assign_register(op->op2, trace, slot, next_spill);
assert(reg != REG_NONE);
Expand All @@ -699,14 +706,14 @@ void emit_vref(uint8_t reg, uint8_t opcode, trace_s* trace, ir_ins* op, int *slo

// TODO could be a special reloc type and one mov.
auto c2 = trace->consts[op->op2 - IR_CONST_BIAS];
emit_mem_reg(opcode, 16 - PTR_TAG + c2, R15, reg);
emit_mem_reg(opcode, 16 - type + c2, R15, reg);

auto c1 = trace->consts[op->op1 - IR_CONST_BIAS];
auto re = (reloc){emit_offset(), c1, RELOC_ABS};
arrput(trace->relocs, re);
emit_mov64(R15, c1);
} else {
emit_mem_reg_sib(opcode, 16 - PTR_TAG, 0, trace->ops[op->op2].reg,
emit_mem_reg_sib(opcode, 16 - type, 0, trace->ops[op->op2].reg,
R15, reg);

auto c1 = trace->consts[op->op1 - IR_CONST_BIAS];
Expand All @@ -718,10 +725,10 @@ void emit_vref(uint8_t reg, uint8_t opcode, trace_s* trace, ir_ins* op, int *slo
if (ir_is_const(op->op2)) {
// Must be fixnum
auto c = trace->consts[op->op2 - IR_CONST_BIAS];
emit_mem_reg(opcode, 16 - PTR_TAG + c, trace->ops[op->op1].reg,
emit_mem_reg(opcode, 16 - type + c, trace->ops[op->op1].reg,
reg);
} else {
emit_mem_reg_sib(opcode, 16 - PTR_TAG, 0, trace->ops[op->op2].reg,
emit_mem_reg_sib(opcode, 16 - type, 0, trace->ops[op->op2].reg,
trace->ops[op->op1].reg, reg);
}
}
Expand Down Expand Up @@ -1036,15 +1043,16 @@ void asm_jit(trace_s *trace, snap_s *side_exit, trace_s *parent) {
break;
}
case IR_ABC: {
auto type = op->type & TAG_MASK;
maybe_assign_register(op->op1, trace, slot, &next_spill);
maybe_assign_register(op->op2, trace, slot, &next_spill);
emit_jcc32(JL, snap_labels[cur_snap]);
emit_arith_op(OP_ARITH_CMP, OP_CMP, R15, op->op2, trace, slot);
if (!ir_is_const(op->op1)) {
emit_mem_reg(OP_MOV_MR, 8 - PTR_TAG, trace->ops[op->op1].reg, R15);
emit_mem_reg(OP_MOV_MR, 8 - type, trace->ops[op->op1].reg, R15);
} else {
vector_s *v =
(vector_s *)(trace->consts[op->op1 - IR_CONST_BIAS] - PTR_TAG);
(vector_s *)(trace->consts[op->op1 - IR_CONST_BIAS] - type);
emit_mov64(R15, v->len);
}
break;
Expand Down
3 changes: 3 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static void put_gc_block(gc_block *mem) {
bool is_ptr_type(long obj) {
auto type = obj & TAG_MASK;
if (type == PTR_TAG || type == FLONUM_TAG || type == CONS_TAG ||
type == VECTOR_TAG ||
type == CLOSURE_TAG || type == SYMBOL_TAG) {
return true;
}
Expand Down Expand Up @@ -674,13 +675,15 @@ static void scan_log_buf(void (*add_increment)(long *)) {
auto v = *field;
auto type = v & TAG_MASK;
if (type == PTR_TAG || type == FLONUM_TAG || type == CONS_TAG ||
type == VECTOR_TAG ||
type == CLOSURE_TAG || type == SYMBOL_TAG) {
// printf("Add log increments: %p\n", *field);
add_increment(field);
}
v = cur.addr;
type = v & TAG_MASK;
if (type == PTR_TAG || type == FLONUM_TAG || type == CONS_TAG ||
type == VECTOR_TAG ||
type == CLOSURE_TAG || type == SYMBOL_TAG) {
// printf("Add log decrements: %p\n", v);
arrput(cur_decrements, v);
Expand Down
46 changes: 23 additions & 23 deletions src/readbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,33 @@ long read_const(FILE *fptr) {
}
str->str[len] = '\0';
val = (long)str | PTR_TAG;
} else if (ptrtype == VECTOR_TAG) {
long len;
if (fread(&len, 1, 8, fptr) != 8) {
goto error;
}

long *vals = malloc(sizeof(long) * len);
assert(vals);
for (long i = 0; i < len; i++) {
vals[i] = read_const(fptr);
GC_push_root(&vals[i]);
}

auto v = (vector_s *)GC_malloc(16 + len * sizeof(long));
v->type = ptrtype;
v->len = len << 3;
v->rc = 0;
for (long i = len - 1; i >= 0; i--) {
v->v[i] = vals[i];
GC_pop_root(&vals[i]);
}
free(vals);
val = (long)v | PTR_TAG;
} else {
printf("Unknown boxed type:%lx\\n", ptrtype);
exit(-1);
}
} else if (type == VECTOR_TAG) {
long len;
if (fread(&len, 1, 8, fptr) != 8) {
goto error;
}

long *vals = malloc(sizeof(long) * len);
assert(vals);
for (long i = 0; i < len; i++) {
vals[i] = read_const(fptr);
GC_push_root(&vals[i]);
}

auto v = (vector_s *)GC_malloc(16 + len * sizeof(long));
v->type = VECTOR_TAG;
v->len = len << 3;
v->rc = 0;
for (long i = len - 1; i >= 0; i--) {
v->v[i] = vals[i];
GC_pop_root(&vals[i]);
}
free(vals);
val = (long)v | VECTOR_TAG;
} else if (type == CLOSURE_TAG) {
long bcfunc_num;
if (fread(&bcfunc_num, 1, 8, fptr) != 8) {
Expand Down
32 changes: 19 additions & 13 deletions src/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,8 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto idx = record_stack_load(INS_B(i), frame);
auto obj = record_stack_load(INS_C(i), frame);

push_ir(trace, IR_GCLOG, vec, IR_NONE, VECTOR_TAG);
push_ir(trace, IR_ABC, vec, idx, IR_INS_TYPE_GUARD);
push_ir(trace, IR_GCLOG, vec, IR_NONE, UNDEFINED_TAG);
push_ir(trace, IR_ABC, vec, idx, IR_INS_TYPE_GUARD | VECTOR_TAG);
auto vref = push_ir(trace, IR_VREF, vec, idx, 0);
push_ir(trace, IR_STORE, vref, obj, 0);

Expand All @@ -1347,11 +1347,11 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto vec = record_stack_load(INS_B(i), frame);
auto idx = record_stack_load(INS_C(i), frame);

push_ir(trace, IR_ABC, vec, idx, IR_INS_TYPE_GUARD);
push_ir(trace, IR_ABC, vec, idx, IR_INS_TYPE_GUARD | VECTOR_TAG);
auto vref = push_ir(trace, IR_VREF, vec, idx, 0);

uint64_t pos = frame[INS_C(i)] >> 3;
vector_s *vec_d = (vector_s *)(frame[INS_B(i)] - PTR_TAG);
vector_s *vec_d = (vector_s *)(frame[INS_B(i)] - VECTOR_TAG);
uint8_t type = get_object_ir_type(vec_d->v[pos]);
regs[INS_A(i)] = push_ir(trace, IR_LOAD, vref, 0, IR_INS_TYPE_GUARD | type);
stack_top = INS_A(i) + 1;
Expand All @@ -1362,7 +1362,7 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto str = record_stack_load(INS_B(i), frame);
auto idx = record_stack_load(INS_C(i), frame);

push_ir(trace, IR_ABC, str, idx, IR_INS_TYPE_GUARD);
push_ir(trace, IR_ABC, str, idx, IR_INS_TYPE_GUARD | STRING_TAG);
regs[INS_A(i)] = push_ir(trace, IR_STRLD, str, idx, CHAR_TAG);
stack_top = INS_A(i) + 1;

Expand All @@ -1373,7 +1373,7 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto idx = record_stack_load(INS_B(i), frame);
auto val = record_stack_load(INS_C(i), frame);

push_ir(trace, IR_ABC, str, idx, IR_INS_TYPE_GUARD);
push_ir(trace, IR_ABC, str, idx, IR_INS_TYPE_GUARD | STRING_TAG);
auto ref = push_ir(trace, IR_STRREF, str, idx, 0);
push_ir(trace, IR_STRST, ref, val, 0);
stack_top = INS_A(i) + 1;
Expand Down Expand Up @@ -1507,9 +1507,9 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto alloc_sz_aligned =
push_ir(trace, IR_MUL, alloc_sz, knum | IR_CONST_BIAS, FIXNUM_TAG);
// TODO snaps??
auto cell = push_ir(trace, IR_ALLOC, alloc_sz_aligned, PTR_TAG, VECTOR_TAG);
auto cell = push_ir(trace, IR_ALLOC, alloc_sz_aligned, VECTOR_TAG, VECTOR_TAG);

auto ref = push_ir(trace, IR_REF, cell, 8 - PTR_TAG, UNDEFINED_TAG);
auto ref = push_ir(trace, IR_REF, cell, 8 - VECTOR_TAG, UNDEFINED_TAG);
push_ir(trace, IR_STORE, ref, sz, UNDEFINED_TAG);
regs[INS_A(i)] = cell;

Expand Down Expand Up @@ -1540,14 +1540,14 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
auto knum = arrlen(trace->consts);
arrput(trace->consts, (sizeof(vector_s) + 8 * len) << 3);
auto cell =
push_ir(trace, IR_ALLOC, knum | IR_CONST_BIAS, PTR_TAG, VECTOR_TAG);
push_ir(trace, IR_ALLOC, knum | IR_CONST_BIAS, VECTOR_TAG, VECTOR_TAG);
regs[reg] = cell;
auto ref = push_ir(trace, IR_REF, cell, 8 - PTR_TAG, UNDEFINED_TAG);
auto ref = push_ir(trace, IR_REF, cell, 8 - VECTOR_TAG, UNDEFINED_TAG);
knum = arrlen(trace->consts);
arrput(trace->consts, (long)(len << 3));
push_ir(trace, IR_STORE, ref, knum | IR_CONST_BIAS, UNDEFINED_TAG);
for (uint32_t cnt = 0; cnt < len; cnt++) {
ref = push_ir(trace, IR_REF, cell, 16 + cnt * 8 - PTR_TAG, UNDEFINED_TAG);
ref = push_ir(trace, IR_REF, cell, 16 + cnt * 8 - VECTOR_TAG, UNDEFINED_TAG);
push_ir(trace, IR_STORE, ref, loaded[cnt], UNDEFINED_TAG);
}
stack_top = INS_A(i) + 1;
Expand Down Expand Up @@ -1830,14 +1830,20 @@ int record_instr(unsigned int *pc, long *frame, long argcnt) {
stack_top = INS_A(i) + 1;
break;
}
case STRING_LENGTH:
case VECTOR_LENGTH: {
case STRING_LENGTH: {
auto vec = record_stack_load(INS_B(i), frame);
auto ref = push_ir(trace, IR_REF, vec, 8 - PTR_TAG, UNDEFINED_TAG);
regs[INS_A(i)] = push_ir(trace, IR_LOAD, ref, 0, FIXNUM_TAG);
stack_top = INS_A(i) + 1;
break;
}
case VECTOR_LENGTH: {
auto vec = record_stack_load(INS_B(i), frame);
auto ref = push_ir(trace, IR_REF, vec, 8 - VECTOR_TAG, UNDEFINED_TAG);
regs[INS_A(i)] = push_ir(trace, IR_LOAD, ref, 0, FIXNUM_TAG);
stack_top = INS_A(i) + 1;
break;
}
case CLOSURE_GET: {
auto clo = record_stack_load(INS_B(i), frame);
auto ref = push_ir(trace, IR_REF, clo,
Expand Down
6 changes: 3 additions & 3 deletions src/trace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void print_const_or_val(int i, trace_s *ctrace) {
printf("eof");
} else if ((c & IMMEDIATE_MASK) == NIL_TAG) {
printf("nil");
} else if (type == VECTOR_TAG) {
printf("vector");
} else if (type == SYMBOL_TAG) {
string_s *sym_name =
(string_s *)(((symbol *)(c - SYMBOL_TAG))->name - PTR_TAG);
printf("\e[1;35m%s\e[m", sym_name->str);
} else if (type == PTR_TAG) {
auto type2 = ((long *)(c - PTR_TAG))[0] & 0xff;
if (type2 == VECTOR_TAG) {
printf("vector");
} else if (type2 == STRING_TAG) {
if (type2 == STRING_TAG) {
printf("str");
} else if (type2 == PORT_TAG) {
printf("port");
Expand Down
Loading

0 comments on commit 93f4745

Please sign in to comment.