code wiki / (root) / nx_x86_64.nx

nx_x86_64.nx

buildroot/runtime/nx_x86_64.nx

33418 B1070 linesdepth 3pulls 3 transitivereach 10 importersview sourcekind librarytopic x86
docsdependenciesstructsconstsfunctions

about

nx_x86_64.nx -- x86_64 Linux SysV asm emitter (foundation; session 1). Pure NishiLang port of nxc2/x86_64.c. Lives outside the C side per cardinal feedback-no-nxc2-c-extension-only-nishilang-forward. This file is the FOUNDATION layer; sessions 2-N fill in the per-opcode IR-to-asm dispatch and wire into nx_nxc.nx as --target x86_64. Session 1 scope (this file): * x86_64 register name table (SysV ABI) * function prologue / epilogue (pushq rbp / movq rsp,rbp / subq) * .text / .rodata section directives * label emission * literal constant load (movabsq $imm, %reg) * register-to-register move (movq %src, %dst) * RIP-relative address load (leaq label(%rip), %reg) * add / sub register-to-register (addq / subq) * syscall (the most useful primitive -- emits the 'syscall' insn) * .asciz string literal emission with byte-escape Sessions 2-N (deferred): * IR-instruction dispatch (binop / cmp / branch / call / load / store / GEP / phi / return / tail_call / inline_asm) * stack-machine slot layout per nx_x86_64.c * regalloc integration (linear-scan with SysV-preserved regs) * AVX2 SIMD (vmovdqu / vpaddd / vpsubd / vpmullq for i32x8 etc.) * full nx_nxc.nx wiring as --target x86_64 dispatch Output format: AT&T syntax (movabsq / addq / .quad), Linux SysV ABI, PIC-aware (leaq label(%rip)). Byte-compatible with `gcc` / `as`. genealogy_id: nxc2_x86_64_c_2026 + sysv_x86_64_abi_v0_99_6 lineage_id: nx_x86_64_foundation_v1 nx_safety_envelope: intended_use: "Foundation emit library for x86_64 Linux SysV assembly text. Per-primitive functions that write to a shared OutBuf. Session 1 of N for the full IR-driven backend." sil_target: SIL3 (codegen correctness; silent miscompilation is worse than crash)

dependencies 2 imports · 10 importers

nx_syscalls.nx nx_outbuf.nx nx_x86_64.nx nx_compile_field_candidate_t280.nx nx_compile_x86.nx nx_x86_64_arith_test.nx nx_x86_64_branch_test.nx nx_x86_64_call_test.nx nx_x86_64_ctx.nx nx_x86_64_ctx_test.nx nx_x86_64_loadstore_test.nx nx_x86_64_module_test.nx nx_x86_64_test.nx

imports: nx_syscalls.nxnx_outbuf.nx

imported by: nx_compile_field_candidate_t280.nxnx_compile_x86.nxnx_x86_64_arith_test.nxnx_x86_64_branch_test.nxnx_x86_64_call_test.nxnx_x86_64_ctx.nxnx_x86_64_ctx_test.nxnx_x86_64_loadstore_test.nxnx_x86_64_module_test.nxnx_x86_64_test.nx

structs

none

consts

67const NX_X64_N_ARG_REGS: i64 = 6
352const NX_X64_SYS_READ: i64 = 0
353const NX_X64_SYS_WRITE: i64 = 1
354const NX_X64_SYS_OPEN: i64 = 2
355const NX_X64_SYS_CLOSE: i64 = 3
356const NX_X64_SYS_MMAP: i64 = 9
357const NX_X64_SYS_EXIT: i64 = 60
358const NX_X64_SYS_EXIT_GROUP: i64 = 231 // terminates ALL tasks; _start uses this (threaded runtime, 2026-07-07)
600const NX_X64_CC_EQ: i64 = 0
601const NX_X64_CC_NE: i64 = 1
602const NX_X64_CC_LT_S: i64 = 2
603const NX_X64_CC_LE_S: i64 = 3
604const NX_X64_CC_GT_S: i64 = 4
605const NX_X64_CC_GE_S: i64 = 5
606const NX_X64_CC_LT_U: i64 = 6
607const NX_X64_CC_LE_U: i64 = 7
608const NX_X64_CC_GT_U: i64 = 8
609const NX_X64_CC_GE_U: i64 = 9
611const NX_X64_CC_O: i64 = 10
612const NX_X64_CC_NO: i64 = 11

functions

69func x86_arg_reg_name(idx: i64) -> *u8
82func x86_syscall_arg_reg_name(idx: i64) -> *u8
94func x86_indent(o: *OutBuf) -> i64
102func x86_pct_reg(o: *OutBuf, reg: *u8) -> i64
110func x86_emit_section_text(o: *OutBuf) -> i64
115func x86_emit_section_rodata(o: *OutBuf) -> i64
122func x86_emit_label(o: *OutBuf, name: *u8) -> i64
129func x86_emit_function_start(o: *OutBuf, name: *u8) -> i64
141func x86_emit_function_end(o: *OutBuf, name: *u8) -> i64
156func x86_emit_asciz(o: *OutBuf, s: *u8, n: i64) -> i64
223func x86_round_up_16(n: i64) -> i64
227func x86_emit_prologue(o: *OutBuf, frame_size: i64) -> i64
239func x86_emit_epilogue(o: *OutBuf) -> i64
251func x86_emit_movabsq(o: *OutBuf, reg: *u8, imm: i64) -> i64
262func x86_emit_movq_reg_reg(o: *OutBuf, src: *u8, dst: *u8) -> i64
276func x86_emit_leaq_rip(o: *OutBuf, label: *u8, reg: *u8) -> i64
290func x86_emit_addq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
299func x86_emit_subq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
318func x86_emit_syscall(o: *OutBuf) -> i64
329func x86_emit_syscall_imm(o: *OutBuf, num: i64, n_args: i64,
345func x86_emit_gnu_stack_note(o: *OutBuf) -> i64
370func x86_reg_low32(reg: *u8) -> *u8
390func x86_reg_low16(reg: *u8) -> *u8
410func x86_reg_low8(reg: *u8) -> *u8
434func x86_emit_mem_disp(o: *OutBuf, disp: i64, base: *u8) -> i64
452func x86_emit_load_qword(o: *OutBuf, base: *u8, disp: i64, dst: *u8) -> i64
461func x86_emit_load_dword_signed(o: *OutBuf, base: *u8, disp: i64,
471func x86_emit_load_dword_unsigned(o: *OutBuf, base: *u8, disp: i64,
482func x86_emit_load_word_signed(o: *OutBuf, base: *u8, disp: i64,
492func x86_emit_load_word_unsigned(o: *OutBuf, base: *u8, disp: i64,
502func x86_emit_load_byte_signed(o: *OutBuf, base: *u8, disp: i64,
512func x86_emit_load_byte_unsigned(o: *OutBuf, base: *u8, disp: i64,
527func x86_emit_store_qword(o: *OutBuf, src: *u8, base: *u8, disp: i64) -> i64
536func x86_emit_store_dword(o: *OutBuf, src: *u8, base: *u8, disp: i64) -> i64
546func x86_emit_store_word(o: *OutBuf, src: *u8, base: *u8, disp: i64) -> i64
556func x86_emit_store_byte(o: *OutBuf, src: *u8, base: *u8, disp: i64) -> i64
574func x86_emit_gep_add(o: *OutBuf, base_reg: *u8, off_reg: *u8) -> i64
586func x86_emit_lea_disp(o: *OutBuf, base: *u8, disp: i64, dst: *u8) -> i64
614func x86_cc_suffix(cc: i64) -> *u8
639func x86_emit_cmpq_rr(o: *OutBuf, src1: *u8, src2: *u8) -> i64
648func x86_emit_cmpq_imm(o: *OutBuf, imm: i64, src: *u8) -> i64
657func x86_emit_testq_rr(o: *OutBuf, src1: *u8, src2: *u8) -> i64
671func x86_emit_setcc(o: *OutBuf, cc: i64, dst8: *u8) -> i64
680func x86_emit_movzbq_rr(o: *OutBuf, src8: *u8, dst: *u8) -> i64
691func x86_emit_jmp_label(o: *OutBuf, label: *u8) -> i64
698func x86_emit_jcc_label(o: *OutBuf, cc: i64, label: *u8) -> i64
723func x86_emit_imulq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
735func x86_emit_mulq_r(o: *OutBuf, src: *u8) -> i64
742func x86_emit_cqo(o: *OutBuf) -> i64
750func x86_emit_crc32q_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
763func x86_emit_pdep_rrr(o: *OutBuf, src2: *u8, src1: *u8, dst: *u8) -> i64
777func x86_emit_pext_rrr(o: *OutBuf, src2: *u8, src1: *u8, dst: *u8) -> i64
788func x86_emit_idivq_r(o: *OutBuf, src: *u8) -> i64
795func x86_emit_divq_r(o: *OutBuf, src: *u8) -> i64
802func x86_emit_xorq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
811func x86_emit_andq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
820func x86_emit_orq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
829func x86_emit_negq_r(o: *OutBuf, dst: *u8) -> i64
836func x86_emit_notq_r(o: *OutBuf, dst: *u8) -> i64
846func x86_emit_shlq_cl(o: *OutBuf, dst: *u8) -> i64
853func x86_emit_sarq_cl(o: *OutBuf, dst: *u8) -> i64
860func x86_emit_shrq_cl(o: *OutBuf, dst: *u8) -> i64
870func x86_emit_rolq_cl(o: *OutBuf, dst: *u8) -> i64
877func x86_emit_rorq_cl(o: *OutBuf, dst: *u8) -> i64
886func x86_emit_bswapq_rax(o: *OutBuf) -> i64
892func x86_emit_popcntq_rax(o: *OutBuf) -> i64
900func x86_emit_lzcntl_eax(o: *OutBuf) -> i64
906func x86_emit_tzcntl_eax(o: *OutBuf) -> i64
914func x86_emit_xchgq_rax_mem_r11(o: *OutBuf) -> i64
918func x86_emit_lock_cmpxchgq_rcx_mem_r11(o: *OutBuf) -> i64
922func x86_emit_sete_al(o: *OutBuf) -> i64
926func x86_emit_lock_xaddq_rax_mem_r11(o: *OutBuf) -> i64
930func x86_emit_mfence(o: *OutBuf) -> i64
937func x86_emit_shlq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
946func x86_emit_sarq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
955func x86_emit_shrq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
981func x86_emit_call_label(o: *OutBuf, name: *u8) -> i64
991func x86_emit_call_indirect(o: *OutBuf, reg: *u8) -> i64
1001func x86_emit_tail_call_label(o: *OutBuf, name: *u8) -> i64
1008func x86_emit_tail_call_indirect(o: *OutBuf, reg: *u8) -> i64
1024func x86_emit_push_arg_imm(o: *OutBuf, imm: i64) -> i64
1031func x86_emit_push_arg_reg(o: *OutBuf, reg: *u8) -> i64
1039func x86_emit_pad_for_call(o: *OutBuf, n_stack_args: i64) -> i64
1047func x86_emit_unpad_after_call(o: *OutBuf, n_stack_args: i64,
1064func x86_emit_return_value_to_rax(o: *OutBuf, src: *u8) -> i64