tensor_lower.nx
buildroot/runtime/tensor_lower.nx
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
imports: syscalls.nxoutbuf.nxtensor_ir.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 50 | func tir_lower_unary_ew(g: *TirGraph, n: *TirNode, |
| 98 | func tir_lower_binary_ew(g: *TirGraph, n: *TirNode, |
| 169 | func tir_lower_matmul(g: *TirGraph, n: *TirNode, |
| 293 | func tir_lower_node(g: *TirGraph, node_id: i64, |
| 319 | func ew_substr(buf: *u8, len: i64, needle: *u8, nlen: i64) -> i64 {
called by 1: main |
| 334 | func main() -> i64 { |