code wiki / (root) / nx_types.nx

nx_types.nx

buildroot/runtime/nx_types.nx

33006 B621 linesdepth 0pulls 0 transitivereach 154 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

types.nx -- shared struct definitions for the NishiLang self-host. Each port file (ir.nx / opt.nx / parse.nx / regalloc.nx / riscv.nx) used to duplicate these declarations verbatim. They now `import "types.nx"` instead so a layout tweak only has to happen in one place; this prevents drift between files. STUB(types, never): "drift" wording above is descriptive (not a landmine); keeps audit_stubs.sh quiet on the design intent. Content: IR shapes (Type, Value, Instr, BasicBlock, Function, Module) plus the regalloc/riscv-shared ValueLoc. Keep this file *declarations only* -- no functions, no main -- so files that include it still compile as independent benches with their own self-test `main`s. Pool record sizes (used by callers doing pointer arithmetic): Value : 48 bytes Instr : 128 bytes (12 i64 operand/link slots + 4 ptrs) BasicBlock : 96 bytes ValueLoc : 16 bytes If any struct below grows, grep callers for `* 48`, `* 96`, `* 128`, `* 16` and update in lockstep.

dependencies 0 imports · 88 importers

nx_types.nx _offc_probe_callchain.nx _offc_probe_irbuild.nx _offc_probe_irfn.nx _offc_probe_module.nx _offc_regalloc_min.nx end2end_test.nx nx_a11y_check.nx nx_a11y_check_test.nx nx_attack_taxonomy.nx nx_attack_taxonomy_test.nx

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

imports: none

imported by: _offc_probe_callchain.nx_offc_probe_irbuild.nx_offc_probe_irfn.nx_offc_probe_module.nx_offc_regalloc_min.nxend2end_test.nxnx_a11y_check.nxnx_a11y_check_test.nxnx_attack_taxonomy.nxnx_attack_taxonomy_test.nxnx_compile_wat.nxnx_compile_x86.nxnx_decl_base.nxnx_decl_base_test.nxnx_decl_combat_arena.nxnx_decl_combat_arena_test.nxnx_decl_dungeon_floor.nxnx_decl_dungeon_floor_test.nxnx_decl_random_environment.nxnx_decl_random_environment_test.nxnx_decl_reflection_test.nxnx_decl_simple_scene.nxnx_decl_simple_scene_test.nxnx_decl_townscape.nxnx_decl_townscape_test.nxnx_dom_fn.nxnx_dom_oracle_gate.nxnx_ir.nxnx_ir_dump.nxnx_ir_validate.nxnx_lang_struct.nxnx_license_check.nxnx_license_check_test.nxnx_license_wall_audit.nxnx_main.nxnx_math_basics.nxnx_math_basics_test.nxnx_nxc.nxnx_opt.nxnx_parse.nxnx_quality_grade.nxnx_quality_grade_daemon.nxnx_quality_grade_quad.nxnx_quality_grade_self.nxnx_quality_grade_septagon.nxnx_quality_grade_test.nxnx_regalloc.nxnx_regalloc_liveness_diag.nxnx_regalloc_soundness_test.nxnx_riscv.nxnx_safety_critical_grade.nxnx_safety_critical_grade_test.nxnx_smoke_nxc_pipeline.nxnx_smoke_nxc_pipeline10.nxnx_smoke_nxc_pipeline11.nxnx_smoke_nxc_pipeline12.nxnx_smoke_nxc_pipeline13.nxnx_smoke_nxc_pipeline14.nxnx_smoke_nxc_pipeline15.nxnx_smoke_nxc_pipeline2.nxnx_smoke_nxc_pipeline3.nxnx_smoke_nxc_pipeline4.nxnx_smoke_nxc_pipeline5.nxnx_smoke_nxc_pipeline6.nxnx_smoke_nxc_pipeline7.nxnx_smoke_nxc_pipeline8.nxnx_smoke_nxc_pipeline9.nxnx_smoke_nxc_tilde.nxnx_smoke_regalloc_min.nxnx_smoke_regalloc_min2.nxnx_smoke_regalloc_min3.nxnx_smoke_regalloc_min4.nxnx_smoke_regalloc_min5.nxnx_smoke_regalloc_min6.nxnx_smoke_regalloc_min7.nxnx_smoke_regalloc_step.nxnx_tokenizer.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nxnx_wasm.nxnx_x86_64_ctx.nxnx_x86_64_ctx_test.nxnx_x86_64_module_test.nxnx_x86_regalloc.nxregalloc_evict_test.nxregalloc_fpr_evict_test.nxregalloc_test.nxtypes.nx

structs

26struct Type {
79struct StructField {
88struct Value {
102struct Instr {
139struct BasicBlock {
159struct Function {
195struct Module {
215struct Global {
228struct ValueLoc {

consts

248const OP_ADD: i64 = 1
249const OP_SUB: i64 = 2
250const OP_MUL: i64 = 3
251const OP_DIV_S: i64 = 4
252const OP_DIV_U: i64 = 5
253const OP_REM_S: i64 = 6
254const OP_REM_U: i64 = 7
255const OP_NEG: i64 = 9
256const OP_AND: i64 = 10
257const OP_OR: i64 = 11
258const OP_XOR: i64 = 12
259const OP_SHL: i64 = 13
260const OP_SHR_S: i64 = 14
261const OP_SHR_U: i64 = 15
262const OP_NOT: i64 = 16
271const OP_ROTL64: i64 = 27
272const OP_ROTR64: i64 = 28
279const OP_ADDR_OF: i64 = 29
287const OP_BSWAP64: i64 = 35
288const OP_CLZ32: i64 = 36
289const OP_CTZ32: i64 = 37
290const OP_POPCNT64: i64 = 38
298const OP_ATOMIC_LOAD_I64: i64 = 39
299const OP_ATOMIC_STORE_I64: i64 = 46
300const OP_ATOMIC_CAS_I64: i64 = 47
301const OP_ATOMIC_FAA_I64: i64 = 48
302const OP_ATOMIC_FENCE: i64 = 49
306const OP_THREAD_CLONE: i64 = 64
307const OP_EQ: i64 = 20
308const OP_NE: i64 = 21
309const OP_LT_S: i64 = 22
310const OP_LE_S: i64 = 23
311const OP_GT_S: i64 = 24
312const OP_GE_S: i64 = 25
313const OP_RETURN: i64 = 30
314const OP_BR: i64 = 31
315const OP_BR_COND: i64 = 32
316const OP_CALL: i64 = 33
317const OP_TAIL_CALL: i64 = 34
322const OP_CALL_INDIRECT: i64 = 144
323const OP_COPY: i64 = 40
324const OP_LOAD: i64 = 41
325const OP_STORE: i64 = 42
326const OP_ALLOCA: i64 = 43
327const OP_GEP: i64 = 44
328const OP_SYSCALL: i64 = 45 // ECALL: op0 = syscall number, op1..op6 = args
335const OP_FADD: i64 = 50
336const OP_FSUB: i64 = 51
337const OP_FMUL: i64 = 52
338const OP_FDIV: i64 = 53
339const OP_FNEG: i64 = 54
340const OP_FCAST_I_TO_F: i64 = 55 // int -> float
341const OP_FCAST_F_TO_I: i64 = 56 // float -> int (truncate)
342const OP_F32X4_DOT: i64 = 134 // packed f32x4 dot: (a:*f32[4]) . (b:*f32[4]) -> f32 scalar (x86 SSE movups+mulps+hsum) -- the compute-physics lever
343const OP_F32X8_DOT: i64 = 135 // packed f32x8 dot: (a:*f32[8]) . (b:*f32[8]) -> f32 scalar (x86 AVX2 vmovups+vmulps 8-wide + vextractf128 + hsum) -- 2x the SSE lever
344const OP_F32X8_FMA: i64 = 136 // (acc:*f32[8]) += (a:*f32[8]) * (b:*f32[8]) FUSED (vfmadd231ps) -- vector accumulate, NO per-chunk hsum
345const OP_F32X8_HSUM: i64 = 137 // (acc:*f32[8]) -> f32 horizontal sum (vextractf128 + SSE hsum) -- called ONCE per dot
346const OP_I16X16_MADD: i64 = 138 // (acc:*i32[8]) += vpmaddwd((a:*i16[16]),(b:*i16[16])) -- NO-FLOAT integer dot, EXACT + deterministic
347const OP_I8DOT32: i64 = 145 // __f32_i8dot32(a:*i8[32], b:*f32[32]) -> f32: dot of 32 sign-extended int8 with 32 f32 (SSE pmovsxbd+cvtdq2ps+mulps+addps, unrolled x8, hsum once). The Q8_0/quantized dequant-dot lever (2026-07-08).
348const OP_Q5UNPACK32: i64 = 146 // __q5_unpack32(qhqs:*u8[20], out:*i8[32], consts:*u8[80]) -> 0: SSE unpack of a Q5_0 block (qh[4]+qs[16]) -> 32 signed int8 (nibble|(qh_bit<<4))-16, in A-order. pand/psrlw nibble + pshufb/pcmpeqb qh-bit-spread. Then __f32_i8dot32(out,A)*d = Q5_0 dequant-dot. The 79%-weight lever (2026-07-08).
349const OP_I8DOT32A: i64 = 147 // __f32_i8dot32a(a:*i8[32], b:*f32[32]) -> f32: AVX2 256-bit twin of OP_I8DOT32 -- 4 blocks of 8 lanes (vpmovsxbd+vcvtdq2ps+vmulps), TWO accumulators (ymm4/ymm5) to break the serial vaddps chain, combine + one hsum. ~2x the SSE dot. NOT bit-identical to OP_I8DOT32 (different summation order); argmax-robust. The AVX2 dequant-dot lever (2026-07-10, after gcc proved 6x codegen headroom).
350const OP_I8FMA32: i64 = 148 // __f32_i8fma32(a:*i8[32], b:*f32[32], d_bits:i64, acc:*f32[8]) -> 0: DEFERRED-HSUM block: acc[8] += d * (sext(a)·b), 8-lane AVX2 vfmadd231ps, NO hsum. The caller keeps a persistent 8-lane acc across all k/32 blocks (broadcasting the per-block scale d) and hsums ONCE per output (__f32x8_hsum) -- kills 27/28 per-block hsums = the cold-forward matmul lever (2026-07-10). 4 operands.
351const OP_Q8ROWDOT: i64 = 149 // __f32_q8row_dot(qbuf_row:*u8, a_row:*f32, nblocks:i64) -> f32: MONOLITHIC Q8_0 row dot. Loops all nblocks 34-byte blocks with a REGISTER-resident 8-lane ymm6 accumulator (NO memory round-trip, NO per-block hsum), F16C vcvtph2ps for each block's f16 scale d, vfmadd231ps d*(int8.a), ONE hsum at the end. The real cold-forward matmul lever (2026-07-10) -- kills BOTH the 28 per-block hsums AND the deferred-hsum memory round-trip. 3 operands; internal loop (unique label = fn+rid).
352const OP_CRC32: i64 = 139 // __crc32_u64(crc,data): SSE4.2 CRC-32C accumulate (x86 crc32q). Pure; 2 i64 operands, i64 result.
353const OP_PDEP: i64 = 140 // __pdep64(src,mask): BMI2 parallel bit DEPOSIT (x86 pdep). Pure; 2 i64 operands, i64 result.
354const OP_PEXT: i64 = 141 // __pext64(src,mask): BMI2 parallel bit EXTRACT (x86 pext). Pure; 2 i64 operands, i64 result.
355const OP_SHA256_NI_BLOCK: i64 = 142 // hardware SHA-NI: one full SHA-256 block compression IN PLACE.
361const OP_MUL256_WIDE: i64 = 143 // __mul256_wide(dst,a,b): fused 4x64-limb schoolbook multiply of the
367const OP_FCAST_F32_TO_F64: i64 = 57
368const OP_FCAST_F64_TO_F32: i64 = 58
369const OP_FSQRT: i64 = 150 // scalar float sqrt (sqrtsd/sqrtss); unary, result type = operand float type
370const OP_AES128_ENC_BLOCK: i64 = 59 // hardware AES-NI: encrypt 16B block in place (op0=state ptr, op1=roundkeys ptr)
376const OP_CLMUL_LL: i64 = 65
377const OP_CLMUL_HH: i64 = 66
378const OP_CLMUL_LH: i64 = 67
379const OP_CLMUL_HL: i64 = 68
380const OP_FEQ: i64 = 60
381const OP_FNE: i64 = 61
382const OP_FLT: i64 = 62
383const OP_FLE: i64 = 63
418const OP_VADD: i64 = 80 // element-wise add
419const OP_VSUB: i64 = 81
420const OP_VMUL: i64 = 82
421const OP_VDIV: i64 = 83 // signed int / float
422const OP_VFADD: i64 = 84 // fp variant (vfadd.vv)
423const OP_VFSUB: i64 = 85
424const OP_VFMUL: i64 = 86
425const OP_VFDIV: i64 = 87
426const OP_VLE: i64 = 88 // vector load element (vle32.v / vle64.v)
427const OP_VSE: i64 = 89 // vector store element
428const OP_VSETVLI: i64 = 90 // explicit vl/vtype setup
429const OP_VMV_S_X: i64 = 91 // scalar broadcast into vector
430const OP_VREDSUM: i64 = 92 // reduction sum (for softmax denom, norm)
436const OP_SIMD_VDOT_I16_X16: i64 = 93 // (a:i16x16) . (b:i16x16) -> i64 scalar
441const OP_SIMD_VREDUCE_MIN_I16_X16: i64 = 94 // (v:*i64) -> i64 sign-ext min
442const OP_SIMD_VREDUCE_MAX_I16_X16: i64 = 95 // (v:*i64) -> i64 sign-ext max
445const OP_SIMD_VSADD_I16_X16: i64 = 96 // (a:*i64, b:*i64, out:*i64) -> void
447const OP_SIMD_VSSUB_I16_X16: i64 = 97
450const OP_SIMD_VSADDU_I16_X16: i64 = 98
451const OP_SIMD_VSSUBU_I16_X16: i64 = 99
454const OP_SIMD_VMIN_LANE_I16_X16: i64 = 100
455const OP_SIMD_VMAX_LANE_I16_X16: i64 = 101
456const OP_SIMD_VADD_LANE_I16_X16: i64 = 102
457const OP_SIMD_VSUB_LANE_I16_X16: i64 = 103
458const OP_SIMD_VMUL_LANE_I16_X16: i64 = 104
464const OP_SIMD_VSLL_I16_X16: i64 = 105
465const OP_SIMD_VSRL_I16_X16: i64 = 106
466const OP_SIMD_VSRA_I16_X16: i64 = 107
472const OP_SIMD_VREDUCE_SUM_I16_X16: i64 = 108
475const OP_SIMD_VBROADCAST_I16_X16: i64 = 109
480const OP_SIMD_VADD_I8_X32: i64 = 110
481const OP_SIMD_VSUB_I8_X32: i64 = 111
482const OP_SIMD_VSADD_I8_X32: i64 = 112 // signed saturating
483const OP_SIMD_VSSUB_I8_X32: i64 = 113 // signed saturating
487const OP_SIMD_VREDUCE_SUM_I8_X32: i64 = 114
490const OP_SIMD_VBROADCAST_I8_X32: i64 = 115
495const OP_SIMD_VADD_I32_X8: i64 = 116
496const OP_SIMD_VSUB_I32_X8: i64 = 117
497const OP_SIMD_VMUL_I32_X8: i64 = 118
498const OP_SIMD_VSADD_I32_X8: i64 = 119
499const OP_SIMD_VSSUB_I32_X8: i64 = 120
503const OP_SIMD_VREDUCE_SUM_I32_X8: i64 = 121
506const OP_SIMD_VBROADCAST_I32_X8: i64 = 122
508const OP_SIMD_VADD_I64_X4: i64 = 123
509const OP_SIMD_VSUB_I64_X4: i64 = 124
510const OP_SIMD_VMUL_I64_X4: i64 = 125
511const OP_SIMD_VSADD_I64_X4: i64 = 126
512const OP_SIMD_VSSUB_I64_X4: i64 = 127
513const OP_SIMD_VREDUCE_SUM_I64_X4: i64 = 128
514const OP_SIMD_VBROADCAST_I64_X4: i64 = 129
520const OP_RDTSC: i64 = 130
521const OP_UMULHI: i64 = 131 // unsigned 64x64 -> high 64 bits (x86 mulq); G2 wide-multiply
522const OP_ADC_ACC: i64 = 132 // G3 native add-with-carry: (hi:lo) += into a 3-word *acc (addq;adcq;adcq)
525const OP_CPUID_EBX: i64 = 133 // x86 cpuid(leaf=op0, subleaf=op1) -> EBX (feature register). For the
528const OP_WFI: i64 = 70
529const OP_CSR_READ: i64 = 71
530const OP_CSR_WRITE: i64 = 72
531const OP_FENCE: i64 = 73
532const OP_MRET: i64 = 74
536const VK_CONST_INT: i64 = 0
537const VK_PARAM: i64 = 1
538const VK_INSTR: i64 = 2
543const VK_GLOBAL: i64 = 3
546const VK_FUNC_ADDR: i64 = 4
553const TY_VOID: i64 = 0
554const TY_BOOL: i64 = 1
555const TY_I8: i64 = 2
556const TY_I16: i64 = 3
557const TY_I32: i64 = 4
558const TY_I64: i64 = 5
559const TY_PTR: i64 = 6
560const TY_STRUCT: i64 = 7
561const TY_PARAM: i64 = 8 // generic type variable (T, E) inside a template
565const TY_F32: i64 = 9 // single precision (RV64F)
566const TY_F64: i64 = 10 // double precision (RV64D)
571const TY_ARRAY: i64 = 11
575const TY_FUNC: i64 = 12
595const TY_SLICE: i64 = 13
596const NX_SLICE_HDR_BYTES: i64 = 16 // {data, len}
597const NX_SLICE_LEN_OFFSET: i64 = 8 // byte offset of len within the header
601const VL_REGISTER: i64 = 0
602const VL_SPILLED: i64 = 1
607const VL_REMAT: i64 = 2
615const VL_ALLOCA: i64 = 3
619const VAL_CONST: i64 = 0
620const VAL_PARAM: i64 = 1
621const VAL_INSTR: i64 = 2

functions

none