Commit c631cf13
c631cf13a71fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Narrow a poly method-dispatch table double-index to int
optcarrot's CPU memory map is @fetch = [nil]*0x10000, each slot a bound
method (peek_ram, ...) or an int array; fetch(addr) is @fetch[addr][addr].
spinelc compiled the inner [] as a generic poly index returning a boxed
value, so fetch/peek16/store returned poly and the CPU's registers (@_pc,
@addr, @clk, @_a/@_x/@_y, ...) all widened to poly -- the whole interpreter
ran boxed (sp_poly_add/sp_poly_to_i everywhere). Legacy types these int.
Add the legacy poly_index_narrow_int rule: @table[i][j] where @table is a
poly array whose element writes are all int-returning kinds (bound method,
int array, int, or a poly assumed to be a dispatch entry) yields an int.
Emit it via a new sp_poly_index_int runtime helper (calls a bound method on
the int-ABI, gets an int-array element, etc., returning a raw mrb_int).
CPU fetch/peek16/store now return mrb_int and most CPU registers de-poly. optcarrot ~410 -> ~445 fps, checksum 59662. make test 845, make bench 57.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- c631cf13a71f
- Parent
- d1dbf6902bfa
lib/sp_runtime.hmodifiedView file
mrb_int i = (idx.tag == SP_TAG_INT) ? idx.v.i : 0; return sp_poly_arr_get_hash(recv, i);}/* Integer-returning counterpart of sp_poly_index_poly for `poly[int]` where the poly element holds an int-returning callable/container -- a bound method (called with the int arg, int ABI) or an int array. Used when inference proves the double index `@table[i][j]` yields an int (a method dispatch table). Falls back to coercing the generic poly result. */static inline mrb_int sp_poly_index_int(sp_RbVal a, mrb_int i) { if (a.tag == SP_TAG_INT) return (a.v.i >> i) & 1; if (a.tag == SP_TAG_OBJ) { if (a.cls_id == SP_BUILTIN_METHOD) { sp_BoundMethod *m = (sp_BoundMethod *)a.v.p; return ((mrb_int (*)(void *, mrb_int))(uintptr_t)m->fn)((void *)m->self, i); } if (a.cls_id == SP_BUILTIN_INT_ARRAY) return sp_IntArray_get((sp_IntArray *)a.v.p, i); } return sp_poly_to_i(sp_poly_arr_get_hash(a, i));}static sp_RbVal sp_poly_arr_set_hash(sp_RbVal v, mrb_int idx, sp_RbVal val) { if (v.tag != SP_TAG_OBJ) return val; switch (v.cls_id) {src/analyze_infer.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…