code wiki / (root) / tensor_lower.nx

tensor_lower.nx

buildroot/runtime/tensor_lower.nx

12049 B373 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind orphan librarytopic tensor
docsdependenciesstructsconstsfunctions

about

tensor_lower.nx -- TirGraph -> RV64 asm lowering pass. Bridges the fusion pass (tensor_ir.nx) to actual machine code. Walks the TirGraph in topological order, emitting asm into an OutBuf for each non-fused node. Fused producers are inlined into their consumer's kernel emit -- the headline "comptime fusion" win. v0.0.1 covers: - Element-wise unary/binary ops on i32/i64 tensors (loops) - LOAD: data pointer comes from caller (we just expose it) - PARAM: tensor is a function parameter, address in a-register Out of scope for v0.0.1 (subsequent commits): - MATMUL (triple-nested loop with tile blocking) - ATTENTION (fused softmax+matmul) - fp16/fp32 (waiting on F-extension codegen) - SIMD intrinsics (waiting on RVV codegen) - GPU backends (CUDA / SPIR-V) Each emit follows the standard nxc2 codegen ABI: a0..a7 hold input tensor data pointers the function emits a loop that computes element-by-element

dependencies 3 imports · 0 importers

syscalls.nx outbuf.nx tensor_ir.nx tensor_lower.nx

imports: syscalls.nxoutbuf.nxtensor_ir.nx

imported by: nobody (leaf or entry point)

structs

none

consts

none

functions

50func tir_lower_unary_ew(g: *TirGraph, n: *TirNode,
98func tir_lower_binary_ew(g: *TirGraph, n: *TirNode,
169func tir_lower_matmul(g: *TirGraph, n: *TirNode,
293func tir_lower_node(g: *TirGraph, node_id: i64,
319func ew_substr(buf: *u8, len: i64, needle: *u8, nlen: i64) -> i64 {
334func main() -> i64 {