Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
djwatson committed Oct 20, 2023
1 parent 65caf45 commit 2f2ee49
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
22 changes: 10 additions & 12 deletions src/asm_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,22 +1080,20 @@ void asm_jit(trace_s *trace, snap_s *side_exit, trace_s *parent) {
maybe_assign_register(op->op2, trace, slot, &next_spill);
uint8_t op1_reg;
if (ir_is_const(op->op1)) {
op1_reg = get_free_reg(trace, &next_spill, slot, false);
op1_reg = get_free_reg(trace, &next_spill, slot, false);
} else {
op1_reg = trace->ops[op->op1].reg;
op1_reg = trace->ops[op->op1].reg;
}
if (ir_is_const(op->op2)) {
// must be fixnum
auto c = to_fixnum(trace->consts[op->op2 - IR_CONST_BIAS]);
assert(((int64_t)((int32_t)c)) == c);
emit_mem_reg(OP_LEA, (int32_t)(16 - PTR_TAG + c),
op1_reg, op->reg);
// must be fixnum
auto c = to_fixnum(trace->consts[op->op2 - IR_CONST_BIAS]);
assert(((int64_t)((int32_t)c)) == c);
emit_mem_reg(OP_LEA, (int32_t)(16 - PTR_TAG + c), op1_reg, op->reg);
} else {
emit_mem_reg_sib(OP_LEA, 16 - PTR_TAG, 0, R15, op1_reg,
op->reg);
emit_imm8(3);
emit_reg_reg(OP_SAR_CONST, 7, R15);
emit_reg_reg(OP_MOV_MR, R15, trace->ops[op->op2].reg);
emit_mem_reg_sib(OP_LEA, 16 - PTR_TAG, 0, R15, op1_reg, op->reg);
emit_imm8(3);
emit_reg_reg(OP_SAR_CONST, 7, R15);
emit_reg_reg(OP_MOV_MR, R15, trace->ops[op->op2].reg);
}
if (ir_is_const(op->op1)) {
auto c = trace->consts[op->op1 - IR_CONST_BIAS];
Expand Down
6 changes: 3 additions & 3 deletions src/hawk.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static void init() {
#endif
// TODO(djwatson) this should work without joff?
auto old_joff = joff;
//joff = 1;
// joff = 1;
load_bootstrap();
joff = old_joff;
#ifdef AFL
Expand Down Expand Up @@ -220,7 +220,7 @@ static void parse_args(int argc, char *argv[]) {
case 's':
printf("Random: %s\n", optarg);
srandom(atoi(optarg));
break;
break;
default:
print_help();
exit(-1);
Expand All @@ -243,7 +243,7 @@ int main(int argc, char *argv[]) {
printf("Compiling script %s\n", argv[i]);
{
auto old_joff = joff;
//joff = 1;
// joff = 1;
compile_file(argv[i]);
joff = old_joff;
}
Expand Down
16 changes: 8 additions & 8 deletions src/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,14 @@ bool record_instr(uint32_t *pc, gc_obj *frame, int64_t argcnt) {
}
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 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);
Expand Down
3 changes: 2 additions & 1 deletion src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ INLINE inline size_t heap_object_size(void *obj) {
}
}

INLINE inline void trace_heap_object(void *obj, trace_callback visit, void *ctx) {
INLINE inline void trace_heap_object(void *obj, trace_callback visit,
void *ctx) {
// printf("Trace heap obj %p\n", obj);
auto type = *(uint32_t *)obj;
switch (type) {
Expand Down
36 changes: 17 additions & 19 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ uint8_t hotmap[hotmap_sz];
static bool should_jit() {
static uint8_t next = 0;
if (next-- == 0) {
next = random()%256;
next = random() % 256;
return true;
}
return false;
Expand All @@ -87,9 +87,6 @@ static void vm_init() {

EXPORT void free_vm() { free(stack); }




/*
This is a tail-calling interpreter that requires 'musttail' attribute, so
currently limited to only clang.
Expand Down Expand Up @@ -168,23 +165,23 @@ void RECORD_START(PARAMS) {
hotmap[hotmap_hash(pc)] = hotmap_cnt;
// Extra check: we may have attempted to start recording *during*
// a recording.

// Reload values. We may be trying to record a non-match.
auto op = INS_OP(*pc);
{
if (op == JFUNC || op == JLOOP) {
instr = trace_cache_get(INS_D(*pc))->startpc;
op = INS_OP(instr);
ra = (instr >> 8) & 0xff;
instr >>= 16;
instr >>= 16;
}
}
if (joff || (op_table_arg == l_op_table_record)) {
// Tail call with original op table.
MUSTTAIL return l_op_table[op](ARGS);
}
MUSTTAIL return l_op_table_record[op](ra, instr, pc, frame,
l_op_table_record, argcnt);
MUSTTAIL return l_op_table_record[op](ra, instr, pc, frame, l_op_table_record,
argcnt);
}

void NO_LINT RECORD(PARAMS) {
Expand Down Expand Up @@ -332,7 +329,7 @@ LIBRARY_FUNC(LOOP) {
if (CHECK_RECORD_START(hotmap_loop)) {
MUSTTAIL return RECORD_START(ARGS);
}
hotmap[hotmap_hash(pc)]-= (hotmap_loop - 1);
hotmap[hotmap_hash(pc)] -= (hotmap_loop - 1);
}
END_LIBRARY_FUNC

Expand Down Expand Up @@ -745,7 +742,7 @@ LIBRARY_FUNC_D(GSET) {
if (gp->opt != 0 && gp->opt != -1) {
if (!is_undefined(gp->val)) {
// printf("Gupgrade %s\n", ((string_s*)(gp->name-PTR_TAG))->str);
while(hmlen(gp->lst)) {
while (hmlen(gp->lst)) {
// printf("Get trace %i\n", gp->lst[i].key);
trace_flush(trace_cache_get(gp->lst[0].key), true);
}
Expand Down Expand Up @@ -844,7 +841,7 @@ LIBRARY_FUNC_B(CLOSURE) {
auto fun = to_func(frame[ra]);
if (fun->poly_cnt < 50) {
if (fun->poly_cnt == 1) {
while(hmlen(fun->lst)) {
while (hmlen(fun->lst)) {
trace_flush(trace_cache_get(fun->lst[0].key), true);
}
hmfree(fun->lst);
Expand Down Expand Up @@ -1254,30 +1251,31 @@ 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) {
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);
&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);
auto tostart = frame[ra+1];
auto tostart = frame[ra + 1];
TYPECHECK_FIXNUM(tostart);
LOAD_TYPE_WITH_CHECK(fromstr, string_s, frame[ra+2], STRING_TAG);
auto fromstart = frame[ra+3];
LOAD_TYPE_WITH_CHECK(fromstr, string_s, frame[ra + 2], STRING_TAG);
auto fromstart = frame[ra + 3];
TYPECHECK_FIXNUM(fromstart);
auto fromend = frame[ra+4];
auto fromend = frame[ra + 4];
TYPECHECK_FIXNUM(fromend);
// TODO(djwatson) more checking: len is positive, bounds check
// tostr, endstr, check tostr != fromstr??
auto len = to_fixnum(fromend) - to_fixnum(fromstart);

memcpy(&tostr->str[to_fixnum(tostart)], &fromstr->str[to_fixnum(fromstart)], len);
memcpy(&tostr->str[to_fixnum(tostart)], &fromstr->str[to_fixnum(fromstart)],
len);
}
END_LIBRARY_FUNC


#define LIBRARY_FUNC_CONS_SET_OP(str, name, field) \
LIBRARY_FUNC_B_LOAD_NAME(str, name) \
Expand Down
3 changes: 2 additions & 1 deletion src/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ 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);
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 2f2ee49

Please sign in to comment.