code wiki / _hdl_build / nx_bd_calc.nx
nx_bd_calc.nx
buildroot/runtime/_hdl_build/nx_bd_calc.nx
about
nx_bd_calc.nx -- SOVEREIGN Bjontegaard BD-rate (2026-07-29; retires the bd_*.py lane instruments
per the sovereign-no-python law -- python remains ONLY as the cubic ORACLE inside this organ's gate).
ESTIMATOR (declared): BD-PWL -- piecewise-LINEAR interpolation of log10(rate) over the overlapping
PSNR span, trapezoid-integrated. The classic estimator fits a cubic; on the 4-5 point curves this
lane sweeps, PWL is monotone, has no ill-conditioned Vandermonde solve, and its delta vs the cubic
oracle is MEASURED and bounded in nx_bd_calc_gate (tolerance derived from measurement, never taste).
All math is bits-up sovereign binary64 (nx_f64 add/sub/mul/div/log2/exp/cvt).
usage: nx_bd_calc <anchor.pts> <test.pts>
each line: "<kbps_milli> <psnr_milli>" (integers; kbps_milli = bytes*5 for 48f@30fps CIF sweeps;
the milli scaling cancels: log10(1000x)=log10(x)+3 shifts BOTH curves equally, psnr-milli scales
numerator and denominator of the average equally)
output: "BD_PWL_PERMILLE=<n>" (test-vs-anchor bits at equal quality; negative = test wins)
license: ORIGINAL
dependencies 7 imports · 0 importers
imports: nx_syscalls.nxnx_tier.nxnx_f64.nxnx_f64_div.nxnx_f64_cvt.nxnx_f64_exp.nxnx_f64_log2.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
| 22 | const BD_MAXPTS: i64 = 64 |
| 23 | const BD_LOG10_2: i64 = 0x3FD34413509F79FF // log10(2) in binary64 |
| 24 | const BD_LN10: i64 = 0x40026BB1BBB55516 // ln(10) in binary64 |
| 25 | const BD_ONE: i64 = 0x3FF0000000000000 |
| 26 | const BD_HALF: i64 = 0x3FE0000000000000 |
| 27 | const BD_KILO: i64 = 0x408F400000000000 // 1000.0 |
functions
| 29 | func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 30 | func gn(v: i64) -> i64 |
| 36 | func bd_parse(path: *u8, km: *i64, pm: *i64) -> i64 |
| 63 | func bd_sort(km: *i64, pm: *i64, n: i64) -> i64 called by 1: main |
| 74 | func bd_logs(km: *i64, v: *i64, n: i64) -> i64 |
| 81 | func bd_integ(pm: *i64, v: *i64, n: i64, lo: i64, hi: i64) -> i64 |
| 100 | func main(argc: i64, argv: *i64) -> i64 |