code wiki / _hdl_build / nx_superopt_emit.nx

nx_superopt_emit.nx

buildroot/runtime/_hdl_build/nx_superopt_emit.nx

12324 B216 linesdepth 3pulls 3 transitivereach 15 importersview sourcekind librarytopic superopt
docsdependenciesstructsconstsfunctions

about

nx_superopt_emit.nx -- emit COMPETITIVE x86-64 machine code for a superoptimized program (the slot/op/a/b form from nx_superopt_opt). This is the team building UP from machine code: SYNTHESIZE the optimal op sequence, then EMIT it as tight assembly to race gcc -O2. Tightness comes from the same register-allocation insight proved in nx_regalloc_calls: keep the running result in one register (reuse a dead operand's register in place), and use `lea` to fuse a shift/add with its move so each op is ~1 instruction -- exactly how gcc's strength reduction emits. Input x in %rdi, result in %rax. license_tier: ORIGINAL op/a/b: op[t] in {ADD,SUB,MUL,SHL,SAR,XOR,AND,OR}; a[t],b[t] are slot indices (0=x, 1=const0, 2=const1, t+3=result of op t); for shifts b[t] is the shift amount.

dependencies 1 imports · 13 importers

nx_superopt_opt.nx nx_superopt_emit.nx nx_author.nx nx_autoopt_library_test.nx nx_autorace_test.nx nx_builder.nx nx_cost_race_test.nx nx_horizontal_test.nx nx_layer_campaign.nx nx_levels_test.nx nx_mulchain_test.nx nx_overnight.nx

diagram shows first 10 each side; +0 more imports, +3 more importers in the complete lists below.

imports: nx_superopt_opt.nx

imported by: nx_author.nxnx_autoopt_library_test.nxnx_autorace_test.nxnx_builder.nxnx_cost_race_test.nxnx_horizontal_test.nxnx_layer_campaign.nxnx_levels_test.nxnx_mulchain_test.nxnx_overnight.nxnx_selfix.nxnx_superopt_race_test.nxnx_team_tick.nx

structs

none

consts

none

functions

16func se_rn(buf: *u8, oi: i64, id: i64) -> i64
26func se_str(buf: *u8, oi: i64, s: *u8) -> i64 { var j: i64 = 0; while s[j] != (0 as u8) { buf[oi] = s[j]; oi = oi + 1; j = j + 1 } return oi }
27func se_num(buf: *u8, oi: i64, v: i64) -> i64
36func se_opmn(o: i64) -> *u8
called by 1: se_emit_synth
47func se_slot(buf: *u8, oi: i64, slot: i64, sreg: *i64) -> i64
called by 1: se_emit_synth calls 2: se_strse_rn
52func se_slot_isreg(slot: i64) -> i64 { if slot == 1 { return 0 } if slot == 2 { return 0 } return 1 }
called by 1: se_emit_synth
56func se_emit_synth(op: *i64, a: *i64, b: *i64, L: i64, buf: *u8, oi: i64, icnt: *i64) -> i64
188func se_emit_imul_full(c: i64, inputs: *i64, nin: i64, buf: *u8, icnt: *i64) -> i64
called by 1: selfix_emit calls 2: se_strse_num
205func se_emit_full(op: *i64, a: *i64, b: *i64, L: i64, inputs: *i64, nin: i64, buf: *u8, icnt: *i64) -> i64