Skip to content

Commit

Permalink
faster dyn
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawSumma committed May 15, 2024
1 parent 4ff9c36 commit 3ba5693
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 108 deletions.
2 changes: 1 addition & 1 deletion vendor/cuik
Submodule cuik updated 1 files
+35 −34 tb/src/opt/print_c.h
149 changes: 45 additions & 104 deletions vm/backend/tb_dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct vm_tb_dyn_state_t {

size_t nlocals;
TB_Node *locals;
TB_Node **regs;
vm_tb_dyn_pair_t *regs;
};

TB_Node *vm_tb_dyn_ptr(vm_tb_dyn_state_t *state, const void *ptr) {
Expand Down Expand Up @@ -143,41 +143,9 @@ vm_tb_dyn_pair_t vm_tb_dyn_arg(vm_tb_dyn_state_t *state, vm_arg_t arg) {
);
}
case VM_ARG_REG: {
return (vm_tb_dyn_pair_t){
.val = tb_inst_load(
state->func,
VM_TB_TYPE_VALUE,
tb_inst_member_access(
state->func,
tb_inst_load(
state->func,
TB_TYPE_PTR,
state->regs[arg.reg],
4,
false
),
offsetof(vm_std_value_t, value)
),
4,
false
),
.tag = tb_inst_load(
state->func,
VM_TB_TYPE_TAG,
tb_inst_member_access(
state->func,
tb_inst_load(
state->func,
TB_TYPE_PTR,
state->regs[arg.reg],
4,
false
),
offsetof(vm_std_value_t, tag)
),
4,
false
),
return (vm_tb_dyn_pair_t) {
.tag = tb_inst_load(state->func, VM_TB_TYPE_TAG, state->regs[arg.reg].tag, 1, false),
.val = tb_inst_load(state->func, VM_TB_TYPE_VALUE, state->regs[arg.reg].val, 4, false),
};
}
case VM_ARG_FUN: {
Expand All @@ -199,64 +167,38 @@ TB_Node *vm_tb_dyn_tag_eq(vm_tb_dyn_state_t *state, TB_Node *lhs, TB_Node *rhs)
state->func,
lhs,
rhs
// tb_inst_load(
// state->func,
// TB_TYPE_I32,
// lhs,
// offsetof(vm_type_value_t, tag),
// false
// ),
// tb_inst_load(
// state->func,
// TB_TYPE_I32,
// rhs,
// offsetof(vm_type_value_t, tag),
// false
// )
);
}

void vm_tb_dyn_set(vm_tb_dyn_state_t *state, vm_arg_t out, vm_tb_dyn_pair_t pair) {
tb_inst_store(
state->func,
VM_TB_TYPE_VALUE,
tb_inst_member_access(
if (pair.tag) {
tb_inst_store(
state->func,
tb_inst_load(
VM_TB_TYPE_TAG,
state->regs[out.reg].tag,
pair.tag,
1,
false
);
}
if (pair.val) {
TB_Node *val = pair.val;;
if (val->dt.raw != VM_TB_TYPE_VALUE.raw) {
val = tb_inst_bitcast(
state->func,
TB_TYPE_PTR,
state->regs[out.reg],
4,
false
),
offsetof(vm_std_value_t, value)
),
tb_inst_bitcast(
state->func,
pair.val,
VM_TB_TYPE_VALUE
),
4,
false
);
tb_inst_store(
state->func,
VM_TB_TYPE_TAG,
tb_inst_member_access(
val,
VM_TB_TYPE_VALUE
);
}
tb_inst_store(
state->func,
tb_inst_load(
state->func,
TB_TYPE_PTR,
state->regs[out.reg],
4,
false
),
offsetof(vm_std_value_t, tag)
),
pair.tag,
4,
false
);
VM_TB_TYPE_VALUE,
state->regs[out.reg].val,
val,
4,
false
);
}
}

TB_Node *vm_tb_dyn_lt(TB_Function *f, TB_Node *a, TB_Node *b) {
Expand Down Expand Up @@ -1078,24 +1020,23 @@ void vm_tb_dyn_func(vm_tb_dyn_state_t *state, TB_Function *xfunc, vm_block_t *en

TB_Node *compiled_start = tb_inst_region(state->func);

state->regs = vm_malloc(sizeof(TB_Node *) * entry->nregs);

TB_Node *locals = tb_inst_local(state->func, sizeof(vm_std_value_t) * entry->nregs, 4);
state->nlocals = entry->nregs;
state->locals = locals;
state->regs = vm_malloc(sizeof(vm_tb_dyn_pair_t) * entry->nregs);

for (size_t i = 0; i < entry->nregs; i++) {
TB_Node *ptr = tb_inst_local(state->func, sizeof(vm_std_value_t *), 4);
TB_Node *local = tb_inst_member_access(state->func, locals, sizeof(vm_std_value_t) * i);
tb_inst_store(
state->func,
TB_TYPE_PTR,
ptr,
local,
4,
false
);
state->regs[i] = ptr;
// TB_Node *ptr = tb_inst_local(state->func, sizeof(vm_std_value_t *), 4);
// TB_Node *local = tb_inst_member_access(state->func, locals, sizeof(vm_std_value_t) * i);
// tb_inst_store(
// state->func,
// TB_TYPE_PTR,
// ptr,
// local,
// 4,
// false
// );
state->regs[i] = (vm_tb_dyn_pair_t) {
.tag = tb_inst_local(state->func, sizeof(vm_tag_t), 1),
.val = tb_inst_local(state->func, sizeof(vm_value_t), 4),
};
}

TB_Node *head = tb_inst_param(state->func, 0);
Expand Down Expand Up @@ -1125,7 +1066,7 @@ void vm_tb_dyn_func(vm_tb_dyn_state_t *state, TB_Function *xfunc, vm_block_t *en
state,
arg,
(vm_tb_dyn_pair_t){
.val = tb_inst_uint(state->func, VM_TB_TYPE_VALUE, 0),
.val = NULL,
.tag = nil_tag,
}
);
Expand Down
3 changes: 0 additions & 3 deletions vm/backend/tb_ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ static void vm_tb_ver_func_branch(vm_tb_ver_state_t *state, vm_block_t *target,
}

static void vm_tb_ver_func_branch_on_ptr(vm_tb_ver_state_t *state, vm_arg_t out, vm_block_t *target, vm_rblock_t **rtargets, TB_Node *value, TB_Node *tag, void **mem) {

// tb_inst_debugbreak(state->fun);

size_t next_nargs = target->nargs;

while (out.type == VM_ARG_REG) {
Expand Down

0 comments on commit 3ba5693

Please sign in to comment.