Skip to content

Commit

Permalink
record: Record string_copy calls
Browse files Browse the repository at this point in the history
  • Loading branch information
djwatson committed Oct 18, 2023
1 parent a4c3734 commit 0b36174
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/asm_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ static const uint8_t call_regs[] = {RDI, RSI, RDX, RCX, R8, R9};

static void assign_call_registers(uint16_t op, trace_s *trace, int *slot,
uint32_t *next_spill, int arg) {
assert(arg < 6); // all in reg
if (!ir_is_const(op)) {
auto cop = &trace->ops[op];
if (cop->op == IR_CARG) {
Expand Down
17 changes: 17 additions & 0 deletions src/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,23 @@ bool record_instr(uint32_t *pc, gc_obj *frame, int64_t argcnt) {
// No stack top tracking
break;
}
case STRING_COPY: {
auto slot = INS_A(i);
auto arg4 = push_ir(trace, IR_CARG, record_stack_load(slot+3, frame),
record_stack_load(slot+4, frame), UNDEFINED_TAG);
auto arg3 = push_ir(trace, IR_CARG,
record_stack_load(slot+2, frame), arg4, UNDEFINED_TAG);
auto arg2 = push_ir(trace, IR_CARG,
record_stack_load(slot+1, frame), arg3, UNDEFINED_TAG);
auto arg1 = push_ir(trace, IR_CARG,
record_stack_load(slot, frame), arg2, UNDEFINED_TAG);
auto knum = arrlen(trace->consts);
arrput(trace->consts, tag_ptr(vm_string_copy));
push_ir(trace, IR_CALLXS, arg1, knum | IR_CONST_BIAS, UNDEFINED_TAG);
stack_top = INS_A(i);
add_snap(regs_list, regs - regs_list - 1, trace, pc + 1, depth, stack_top);
break;
}
case READ: {
port_s *port = to_port(frame[INS_B(i)]);
uint8_t type = CHAR_TAG;
Expand Down
9 changes: 7 additions & 2 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,8 @@ LIBRARY_FUNC_B(CLOSURE) {
auto fun = to_func(frame[ra]);
if (fun->poly_cnt < 50) {
if (fun->poly_cnt == 1) {
printf("Make polymorphic %s\n", fun->name);
for (uint32_t i = 0; i < hmlen(fun->lst); i++) {
printf("POLYMORPHIC %s flush of trace %i\n", fun->name, fun->lst[i].key);
//printf("POLYMORPHIC %s flush of trace %i\n", fun->name, fun->lst[i].key);
trace_flush(trace_cache_get(fun->lst[i].key), true);
}
hmfree(fun->lst);
Expand Down Expand Up @@ -1222,6 +1221,12 @@ LIBRARY_FUNC_BC_LOAD_NAME("STRING-SET!", STRING_SET) {
}
END_LIBRARY_FUNC

void vm_string_copy(gc_obj tostr, gc_obj tostart, gc_obj fromstr, gc_obj fromstart, gc_obj fromend) {
auto len = to_fixnum(fromend) - to_fixnum(fromstart);
memcpy(&to_string(tostr)->str[to_fixnum(tostart)],
&to_string(fromstr)->str[to_fixnum(fromstart)], len);
}

LIBRARY_FUNC_NAME("STRING-COPY", STRING_COPY) {
// TODO(djwatson) Some of this is already checked in bootstrap?
LOAD_TYPE_WITH_CHECK(tostr, string_s, frame[ra], STRING_TAG);
Expand Down
1 change: 1 addition & 0 deletions src/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ gc_obj vm_length(gc_obj fb);
gc_obj vm_memq(gc_obj fb, gc_obj fc);
gc_obj vm_assq(gc_obj fb, gc_obj fc);
gc_obj vm_assv(gc_obj fb, gc_obj fc);
void vm_string_copy(gc_obj tostr, gc_obj tostart, gc_obj fromstr, gc_obj fromstart, gc_obj fromend);

static inline uint32_t hotmap_hash(const uint32_t *pc) {
return (((uint64_t)pc) >> 2) & hotmap_mask;
Expand Down

0 comments on commit 0b36174

Please sign in to comment.