code wiki / (root) / nx_x86_64.nx

nx_x86_64.nx

buildroot/runtime/nx_x86_64.nx

33162 B1065 linesdepth 3pulls 3 transitivereach 9 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 · 9 importers

nx_syscalls.nx nx_outbuf.nx nx_x86_64.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_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

functions

69func x86_arg_reg_name(idx: i64) -> *u8
82func x86_syscall_arg_reg_name(idx: i64) -> *u8
94func x86_indent(o: *OutBuf) -> i64
calls 1: out_char
102func x86_pct_reg(o: *OutBuf, reg: *u8) -> i64
calls 2: out_charout_str
110func x86_emit_section_text(o: *OutBuf) -> i64
called by 1: x86_emit_function_start calls 1: out_str
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
called by 2: mainmain calls 2: out_strout_char
223func x86_round_up_16(n: i64) -> i64
called by 1: x86_emit_prologue
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
called by 2: mainmain calls 2: out_strout_char
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
called by 1: x86_emit_store_word
410func x86_reg_low8(reg: *u8) -> *u8
called by 1: x86_emit_store_byte
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
called by 2: x86ctx_emit_gepmain calls 2: out_strout_char
586func x86_emit_lea_disp(o: *OutBuf, base: *u8, disp: i64, dst: *u8) -> i64
611func x86_cc_suffix(cc: i64) -> *u8
634func x86_emit_cmpq_rr(o: *OutBuf, src1: *u8, src2: *u8) -> i64
called by 2: mainx86ctx_emit_cmp calls 2: out_strout_char
643func x86_emit_cmpq_imm(o: *OutBuf, imm: i64, src: *u8) -> i64
652func x86_emit_testq_rr(o: *OutBuf, src1: *u8, src2: *u8) -> i64
666func x86_emit_setcc(o: *OutBuf, cc: i64, dst8: *u8) -> i64
675func x86_emit_movzbq_rr(o: *OutBuf, src8: *u8, dst: *u8) -> i64
686func x86_emit_jmp_label(o: *OutBuf, label: *u8) -> i64
called by 1: main calls 2: out_strout_char
693func x86_emit_jcc_label(o: *OutBuf, cc: i64, label: *u8) -> i64
called by 1: main calls 3: out_strx86_cc_suffixout_char
718func x86_emit_imulq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
730func x86_emit_mulq_r(o: *OutBuf, src: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
737func x86_emit_cqo(o: *OutBuf) -> i64
called by 2: mainx86ctx_emit_binop calls 1: out_str
745func x86_emit_crc32q_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
758func x86_emit_pdep_rrr(o: *OutBuf, src2: *u8, src1: *u8, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
772func x86_emit_pext_rrr(o: *OutBuf, src2: *u8, src1: *u8, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
783func x86_emit_idivq_r(o: *OutBuf, src: *u8) -> i64
790func x86_emit_divq_r(o: *OutBuf, src: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
797func x86_emit_xorq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
806func x86_emit_andq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
815func x86_emit_orq_rr(o: *OutBuf, src: *u8, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
824func x86_emit_negq_r(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_unop calls 2: out_strout_char
831func x86_emit_notq_r(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_unop calls 2: out_strout_char
841func x86_emit_shlq_cl(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
848func x86_emit_sarq_cl(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
855func x86_emit_shrq_cl(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
865func x86_emit_rolq_cl(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
872func x86_emit_rorq_cl(o: *OutBuf, dst: *u8) -> i64
called by 1: x86ctx_emit_binop calls 2: out_strout_char
881func x86_emit_bswapq_rax(o: *OutBuf) -> i64
called by 1: x86ctx_emit_unop calls 1: out_str
887func x86_emit_popcntq_rax(o: *OutBuf) -> i64
called by 1: x86ctx_emit_unop calls 1: out_str
895func x86_emit_lzcntl_eax(o: *OutBuf) -> i64
called by 1: x86ctx_emit_unop calls 1: out_str
901func x86_emit_tzcntl_eax(o: *OutBuf) -> i64
called by 1: x86ctx_emit_unop calls 1: out_str
909func x86_emit_xchgq_rax_mem_r11(o: *OutBuf) -> i64
called by 1: x86ctx_emit_atomic calls 1: out_str
913func x86_emit_lock_cmpxchgq_rcx_mem_r11(o: *OutBuf) -> i64
called by 1: x86ctx_emit_atomic calls 1: out_str
917func x86_emit_sete_al(o: *OutBuf) -> i64
called by 1: x86ctx_emit_atomic calls 1: out_str
921func x86_emit_lock_xaddq_rax_mem_r11(o: *OutBuf) -> i64
called by 1: x86ctx_emit_atomic calls 1: out_str
925func x86_emit_mfence(o: *OutBuf) -> i64
called by 1: x86ctx_emit_atomic calls 1: out_str
932func x86_emit_shlq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
941func x86_emit_sarq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
950func x86_emit_shrq_imm(o: *OutBuf, n: i64, dst: *u8) -> i64
976func x86_emit_call_label(o: *OutBuf, name: *u8) -> i64
986func x86_emit_call_indirect(o: *OutBuf, reg: *u8) -> i64
996func x86_emit_tail_call_label(o: *OutBuf, name: *u8) -> i64
1003func x86_emit_tail_call_indirect(o: *OutBuf, reg: *u8) -> i64
calls 2: out_strout_char
1019func x86_emit_push_arg_imm(o: *OutBuf, imm: i64) -> i64
1026func x86_emit_push_arg_reg(o: *OutBuf, reg: *u8) -> i64
calls 2: out_strout_char
1034func x86_emit_pad_for_call(o: *OutBuf, n_stack_args: i64) -> i64
calls 1: out_str
1042func x86_emit_unpad_after_call(o: *OutBuf, n_stack_args: i64,
calls 2: out_strout_i64
1059func x86_emit_return_value_to_rax(o: *OutBuf, src: *u8) -> i64