code wiki / _hdl_build / nx_intfp_rope_gate.nx

nx_intfp_rope_gate.nx

buildroot/runtime/_hdl_build/nx_intfp_rope_gate.nx

5184 B83 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic intfp
docsdependenciesstructsconstsfunctions

about

nx_intfp_rope_gate.nx -- RoPE (Rotary Position Embedding, universal in 2026) in Q20 INTEGER, no float. Adds integer sin/cos (range-reduced Taylor) to the transcendental set. RoPE rotates each (2i,2i+1) dim-pair of Q,K by angle pos*freq_i. Verifies the DEFINING property: <RoPE(q,m),RoPE(k,n)> depends ONLY on (m-n) (relative pos), and norm preservation, and gradchecks the rotation. Closes the "RoPE integer-native pending" note. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_intfp_rope_gate.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main w sys_write wsi sys_write ↻ sys_mmap fp_sin fp_cos fp_sin ↻ sys_mmap ↻ rope fp_cos ↻ fp_sin ↻ dot iabs

structs

none

consts

11const S: i64 = 1048576
12const PI: i64 = 3294199 // pi in Q20
13const PI2: i64 = 1647099 // pi/2
14const TAU: i64 = 6588397 // 2pi
15const DM: i64 = 4 // head dim (even)

functions

7func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
8func wsi(v: i64) -> i64 { if v<0 { sys_write(1,"-" as *u8,1); v=0-v } var m: i64=v; if m==0 { sys_write(1,"0" as *u8,1); return 0 } let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var q: i64=k-1; var i: i64=0; while q>=0{o[i]=t[q];i=i+1;q=q-1} sys_write(1,o,i); return 0 }
called by 1: main calls 2: sys_writesys_mmap
9func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v }
called by 1: main
18func fp_sin(xin: i64) -> i64
called by 3: fp_cosropemain
29func fp_cos(x: i64) -> i64 { return fp_sin(PI2-x) }
called by 2: ropemain calls 1: fp_sin
32func rope(q: *i64, pos: i64, freq: *i64, out: *i64) -> i64
called by 1: main calls 2: fp_cosfp_sin
44func dot(a: *i64, b: *i64) -> i64 { var d: i64=0; var i: i64=0; while i<DM { d=d+(a[i]*b[i])/S; i=i+1 } return d }
called by 1: main
46func main() -> i64