code wiki / _hdl_build / nx_intfp_rope_gate.nx
nx_intfp_rope_gate.nx
buildroot/runtime/_hdl_build/nx_intfp_rope_gate.nx
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
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
structs
| none |
consts
| 11 | const S: i64 = 1048576 |
| 12 | const PI: i64 = 3294199 // pi in Q20 |
| 13 | const PI2: i64 = 1647099 // pi/2 |
| 14 | const TAU: i64 = 6588397 // 2pi |
| 15 | const DM: i64 = 4 // head dim (even) |
functions
| 7 | func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 8 | func 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 } |
| 9 | func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v } called by 1: main |
| 18 | func fp_sin(xin: i64) -> i64 |
| 29 | func fp_cos(x: i64) -> i64 { return fp_sin(PI2-x) } |
| 32 | func rope(q: *i64, pos: i64, freq: *i64, out: *i64) -> i64 |
| 44 | func 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 |
| 46 | func main() -> i64 |