code wiki / (root) / nx_codec_grade.nx

nx_codec_grade.nx source

↩ module page · 159 lines · 5502 B

1// nx_codec_grade.nx -- sealed-verdict grader card for the NishiVideo 2// + NishiVoice codec stack. Each axis becomes a row; rows that LOSE 3// must carry a named improvement (cardinal feedback-honest-perf- 4// verdict-no-aspirational-claims). 5// 6// Letter grade follows the substrate's existing rubric (see 7// project-self-evolving-grader-s-class memory entry): 8// F = any axis at INCONCLUSIVE / PROTOCOL_ERROR 9// D = >=2 LOSE rows 10// C = 1 LOSE row with named improvement 11// B = no LOSE; <=1 UNMEASURED 12// A = all measured; >=4 WIN 13// S = all measured; >=6 WIN unanimously across both quantitative 14// and triangulated axes 15// 16// Per-axis verdicts: 17// WIN measurable advantage over incumbents 18// LOSE_BY_X measurable disadvantage; X is the named improvement key 19// TIE parity 20// UNMEASURED apparatus not yet built to compare 21// 22// genealogy_id: project-self-evolving-grader-s-class + 23// feedback-honest-perf-verdict + nx_perf_verdict_q10 24// lineage_id: nishi_codec_grade_q10 25 26// nx_safety_envelope: 27// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 28// sil_target: SIL1 29// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 30// verdict: NOT_YET_EVALUATED 31 32import "nx_syscalls_x86_64.nx" 33 34// Sealed axis identifiers. Add rows; never remove. 35const NX_CG_AXIS_UNKNOWN: i64 = 0 36const NX_CG_AXIS_PATENT_CLEAN: i64 = 1 37const NX_CG_AXIS_DETERMINISM: i64 = 2 38const NX_CG_AXIS_AUDIT_REPLAY: i64 = 3 39const NX_CG_AXIS_FRAME_REFUSAL: i64 = 4 40const NX_CG_AXIS_COMPRESSION_VS_RAW: i64 = 5 41const NX_CG_AXIS_COMPRESSION_VS_RLE: i64 = 6 42const NX_CG_AXIS_MEMORY_BUDGET: i64 = 7 43const NX_CG_AXIS_TIER_PORTABILITY: i64 = 8 44const NX_CG_AXIS_COLOR_FIDELITY: i64 = 9 45const NX_CG_AXIS_MOTION_COMPENSATION: i64 = 10 46const NX_CG_AXIS_PERCEPTUAL_QUANT: i64 = 11 47const NX_CG_AXIS_DEBLOCKING_FILTER: i64 = 12 48const NX_CG_AXIS_N: i64 = 13 49 50const NX_CG_VERDICT_UNKNOWN: i64 = 0 51const NX_CG_VERDICT_WIN: i64 = 1 52const NX_CG_VERDICT_LOSE: i64 = 2 53const NX_CG_VERDICT_TIE: i64 = 3 54const NX_CG_VERDICT_UNMEASURED: i64 = 4 55const NX_CG_VERDICT_N: i64 = 5 56 57const NX_CG_GRADE_F: i64 = 0 58const NX_CG_GRADE_D: i64 = 1 59const NX_CG_GRADE_C: i64 = 2 60const NX_CG_GRADE_B: i64 = 3 61const NX_CG_GRADE_A: i64 = 4 62const NX_CG_GRADE_S: i64 = 5 63 64const NX_CG_MAX_ROWS: i64 = 32 65 66struct CodecGradeRow { 67 axis: i64, 68 verdict: i64, 69 measured_q10: i64, // optional; 0 when not numeric 70 threshold_q10: i64, // for WIN: measured >= threshold; for LOSE: measured < threshold 71 note_off: i64, // offset into caller's note buffer for named improvement 72 note_len: i64 73} 74 75struct CodecGradeCard { 76 rows: *CodecGradeRow, // up to NX_CG_MAX_ROWS 77 row_count: i64, 78 notes: *u8, // append-only note buffer 79 notes_off: i64, 80 notes_cap: i64 81} 82 83func nx_cg_init(c: *CodecGradeCard, rows: *CodecGradeRow, 84 notes: *u8, notes_cap: i64) -> i64 { 85 c.rows = rows 86 c.row_count = 0 87 c.notes = notes 88 c.notes_off = 0 89 c.notes_cap = notes_cap 90 return NX_CG_VERDICT_UNKNOWN 91} 92 93// Append a row. Returns 0 on success, -1 on overflow. 94func nx_cg_row(c: *CodecGradeCard, axis: i64, verdict: i64, 95 measured_q10: i64, threshold_q10: i64, 96 note: *u8, note_len: i64) -> i64 { 97 if c.row_count >= NX_CG_MAX_ROWS { return -1 } 98 let r: *CodecGradeRow = (c.rows as i64 + c.row_count * 48) as *CodecGradeRow 99 r.axis = axis 100 r.verdict = verdict 101 r.measured_q10 = measured_q10 102 r.threshold_q10 = threshold_q10 103 r.note_off = c.notes_off 104 r.note_len = note_len 105 var i: i64 = 0 106 while i < note_len { 107 if c.notes_off >= c.notes_cap { return -1 } 108 c.notes[c.notes_off] = note[i] 109 c.notes_off = c.notes_off + 1 110 i = i + 1 111 } 112 c.row_count = c.row_count + 1 113 return 0 114} 115 116// Compute the letter grade per the rubric. Walks the rows once. 117func nx_cg_letter(c: *CodecGradeCard) -> i64 { 118 var win_count: i64 = 0 119 var lose_count: i64 = 0 120 var tie_count: i64 = 0 121 var unmeasured_count: i64 = 0 122 var has_inconclusive: i64 = 0 123 124 var i: i64 = 0 125 while i < c.row_count { 126 let r: *CodecGradeRow = (c.rows as i64 + i * 48) as *CodecGradeRow 127 if r.verdict == NX_CG_VERDICT_WIN { win_count = win_count + 1 } 128 if r.verdict == NX_CG_VERDICT_LOSE { 129 lose_count = lose_count + 1 130 // LOSE row missing named improvement -> protocol error -> F. 131 if r.note_len == 0 { has_inconclusive = 1 } 132 } 133 if r.verdict == NX_CG_VERDICT_TIE { tie_count = tie_count + 1 } 134 if r.verdict == NX_CG_VERDICT_UNMEASURED { unmeasured_count = unmeasured_count + 1 } 135 if r.verdict == NX_CG_VERDICT_UNKNOWN { has_inconclusive = 1 } 136 i = i + 1 137 } 138 139 if has_inconclusive == 1 { return NX_CG_GRADE_F } 140 if lose_count >= 2 { return NX_CG_GRADE_D } 141 if lose_count == 1 { return NX_CG_GRADE_C } 142 if unmeasured_count > 1 { return NX_CG_GRADE_C } 143 if unmeasured_count == 1 { return NX_CG_GRADE_B } 144 if win_count >= 6 { return NX_CG_GRADE_S } 145 if win_count >= 4 { return NX_CG_GRADE_A } 146 return NX_CG_GRADE_B 147} 148 149// Sealed-enum validity gates. 150func nx_cg_axis_is_valid(a: i64) -> i64 { 151 if a < 0 { return 0 } 152 if a >= NX_CG_AXIS_N { return 0 } 153 return 1 154} 155func nx_cg_verdict_is_valid(v: i64) -> i64 { 156 if v < 0 { return 0 } 157 if v >= NX_CG_VERDICT_N { return 0 } 158 return 1 159}