interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / codegen_moe_ragged_test.c

285 lines · 20534 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/*
3 * Ragged-K FP8 GEMV (omega_blackwell_codegen_fp8_gemv_ragged_prog): k a multiple of 128 but not of 32 * lane_bytes, for example Qwen3.8-Flash-Next's
4 * expert down_proj, k = 640 (n = 2560). The K loop runs floor(k / (32 * lane_bytes)) + 1 steps; in the last one a BSSY region is
5 * entered only by the first (k mod 32 * lane_bytes) / lane_bytes lanes, which alone load, decode and accumulate.
6 *
7 * This test runs the generated program on the host warp simulator (functional, NOT scoreboard timing, NOT the chip) and
8 * compares y with omega_fp8_gemv_oracle (double precision, independent of the kernel arithmetic). Host only.
9 *
10 * Every refusal row has a passing twin built in the same run. Every mutant must be caught by the oracle comparison.
11 */
12#include <inttypes.h>
13#include <math.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include "bw_warp_sim.h"
18#include "omega_blackwell_codegen_moe.h"
19#include "omega_blackwell_codegen_moe2.h"
20#include "omega_gpu_fp8_api.h"
21#include "omega_sm121_disasm.h"
22
23static int g_checks, g_failed;
24#define CHECK(cond, ...) do { g_checks++; if (!(cond)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0)
25
26#include "fp8_sim_gemv.h"
27
28/* one parity point: 0 = parity holds, 1 = rejected or wrong (caught) */
29static int point(const OmegaFp8GemvSpec *sp, uint32_t experts, uint32_t n, uint32_t groups, uint32_t x_rows, uint32_t seed, int slack, double *worst_out, size_t *bad_out, char *msg, size_t ml) {
30 Weights W; weights_make(&W, experts, n, sp->k, seed);
31 uint32_t ids[4], st = seed ^ 0x5bd1e995u;
32 for (uint32_t g = 0; g < groups; g++) ids[g] = lcg(&st) % experts;
33 float *x = malloc((size_t)x_rows * sp->k * 4), *y = malloc((size_t)groups * n * 4);
34 for (size_t j = 0; j < (size_t)x_rows * sp->k; j++) x[j] = frand(&st, -1.0f, 1.0f);
35 msg[0] = 0;
36 const int rc = sim_gemv(sp, &W, groups, ids, x, x_rows, y, 3, slack, msg, ml);
37 size_t bad = 0; const double worst = rc == 0 ? parity(&W, groups, ids, x, x_rows, y, &bad) : 1.0;
38 if (worst_out) *worst_out = worst;
39 if (bad_out) *bad_out = bad;
40 free(x); free(y); weights_free(&W);
41 return rc != 0 || bad != 0;
42}
43
44static int same_program(const BlackwellIRProgram *a, const BlackwellIRProgram *b) {
45 return a->count == b->count && !memcmp(a->insns, b->insns, a->count * sizeof a->insns[0]) && !memcmp(&a->regalloc, &b->regalloc, sizeof a->regalloc);
46}
47
48/* Independent stall-distance walk (the same rule as tests/gpu_fp8_api_test.c fp8_stall_violations, restated here): every fixed-latency write must be
49 * OMEGA_FP8_FIXED_LAT cycles behind each user and each control instruction or branch target. Not scoreboard timing, but the rule the repo keeps. */
50static int chk_fixed(BlackwellIROpcode op) {
51 return op == BW_IR_IMAD || op == BW_IR_IMAD_WIDE || op == BW_IR_SHF_R || op == BW_IR_LOP3_AND || op == BW_IR_LOP3_XOR ||
52 op == BW_IR_MOV_IMM || op == BW_IR_MOV_RZ || op == BW_IR_FFMA || op == BW_IR_FADD;
53}
54static int chk_overlap(const BlackwellIRProgram *p, int a, int b) {
55 if (a < 0 || b < 0) return 0;
56 const int pa = p->regalloc.vreg_to_phys[a], pb = p->regalloc.vreg_to_phys[b];
57 if (pa < 0 || pb < 0) return 0;
58 const int na = (int)(p->regalloc.intervals[a].bundle_size ? p->regalloc.intervals[a].bundle_size : 1u);
59 const int nb = (int)(p->regalloc.intervals[b].bundle_size ? p->regalloc.intervals[b].bundle_size : 1u);
60 return pa < pb + nb && pb < pa + na;
61}
62static long stall_violations(const BlackwellIRProgram *p) {
63 static uint8_t tgt[BW_MAX_IR_INSNS + 1];
64 memset(tgt, 0, sizeof tgt);
65 long bad = 0;
66 for (size_t i = 0; i < p->count; i++) {
67 const BlackwellIRInsn *in = &p->insns[i];
68 if (in->op == BW_IR_BRA || in->op == BW_IR_BSSY) { long t = (long)i + (long)(int32_t)in->imm; if (t >= 0 && t <= (long)p->count) tgt[t] = 1; }
69 }
70 for (size_t i = 0; i < p->count; i++) {
71 const BlackwellIRInsn *in = &p->insns[i];
72 if (!chk_fixed(in->op) || in->dst_vreg < 0) continue;
73 uint32_t dist = 0;
74 for (size_t j = i + 1; j < p->count; j++) {
75 dist += (p->insns[j - 1].control >> 9) & 0xfu;
76 if (dist >= OMEGA_FP8_FIXED_LAT) break;
77 const BlackwellIRInsn *u = &p->insns[j];
78 const BlackwellIROpcode o = u->op;
79 if (o == BW_IR_BRA || o == BW_IR_EXIT || o == BW_IR_BSSY || o == BW_IR_BSYNC || o == BW_IR_BAR_SYNC || tgt[j]) { bad++; break; }
80 if (chk_overlap(p, in->dst_vreg, u->dst_vreg) || chk_overlap(p, in->dst_vreg, u->src1_vreg) ||
81 chk_overlap(p, in->dst_vreg, u->src2_vreg) || chk_overlap(p, in->dst_vreg, u->src3_vreg)) { bad++; break; }
82 }
83 }
84 return bad;
85}
86/* Encode the ragged program and list it with the repository's own sm121 disassembler (an independent decoder of the encoder's words):
87 * every line must decode, and the BSSY / BSYNC / BRA counts must match the structure the builder claims. Returns -1 on a failure. */
88static int listing_counts(const OmegaFp8GemvSpec *spec, unsigned *lines, unsigned *undecodable, unsigned *bssy, unsigned *bsync) {
89 static BlackwellIRProgram prog;
90 if (omega_blackwell_codegen_fp8_gemv_ragged_prog(spec, &prog) != 0) return -1;
91 const size_t need = omega_bw_program_code_bytes(&prog);
92 uint8_t *buf = malloc(need);
93 OmegaBlackwellKernel k; memset(&k, 0, sizeof k);
94 if (!buf || omega_blackwell_kernel_encode_into(&prog, buf, need, &k) != 0) { free(buf); return -1; }
95 FILE *f = tmpfile();
96 if (!f || omega_sm121_listing(k.code, k.code_size, f) != 0) { if (f) fclose(f); free(buf); return -1; }
97 fflush(f); fseek(f, 0, SEEK_SET);
98 char line[512]; *lines = *undecodable = *bssy = *bsync = 0;
99 while (fgets(line, sizeof line, f)) {
100 if (!strstr(line, "/*") || !strstr(line, "*/")) continue;
101 (*lines)++;
102 if (strstr(line, "?") || strstr(line, "error")) (*undecodable)++;
103 if (strstr(line, "BSSY")) (*bssy)++;
104 if (strstr(line, "BSYNC")) (*bsync)++;
105 }
106 fclose(f); free(buf);
107 return 0;
108}
109
110int main(void) {
111 char msg[240];
112 /* 1. parity on the simulator: every ragged shape, row count, warp count, group layout and kernel option */
113 static const struct { uint32_t k, lb; } shapes[] = {
114 { 128, 8 }, { 128, 16 }, { 384, 8 }, { 384, 16 }, { 640, 8 }, { 640, 16 }, { 896, 8 }, { 1152, 16 }, { 2688, 16 }, { 1664, 8 },
115 };
116 unsigned points = 0; double worst_all = 0.0;
117 for (size_t a = 0; a < sizeof shapes / sizeof shapes[0]; a++)
118 for (uint32_t rows = 1; rows <= 8; rows *= 2)
119 for (uint32_t warps = 1; warps <= 8; warps += (warps == 1 ? 2 : 5))
120 for (unsigned opt = 0; opt < 8; opt++) {
121 OmegaFp8GemvSpec sp = { .k = shapes[a].k, .lane_bytes = shapes[a].lb, .rows = rows, .warps = warps,
122 .sched = opt & 1, .coal = (opt >> 1) & 1, .wfirst = (opt >> 2) & 1 };
123 if (sp.coal && warps * rows > 32) continue;
124 /* thin the grid: the full product is run for k = 640 lb 8, every other shape runs rows 1 and 8 */
125 if (!(shapes[a].k == 640 && shapes[a].lb == 8) && rows != 1 && rows != 8) continue;
126 double w = 0; size_t bad = 0;
127 const int groups = (opt & 2) ? 3 : 1, x_rows = (opt & 4) ? groups : 1;
128 const int caught = point(&sp, 4, 256, (uint32_t)groups, (uint32_t)x_rows, 100u + (uint32_t)points, points & 1, &w, &bad, msg, sizeof msg);
129 CHECK(!caught, "ragged k=%u lb=%u rows=%u warps=%u sched=%u coal=%u wfirst=%u groups=%d: bad=%zu worst_rel=%.3e %s",
130 sp.k, sp.lane_bytes, rows, warps, sp.sched, sp.coal, sp.wfirst, groups, bad, w, msg);
131 if (w > worst_all) worst_all = w;
132 points++;
133 }
134 printf("ragged parity: %u simulator points, worst relative error %.3e\n", points, worst_all);
135
136 /* 2. negative controls: each mutant must fail for its own reason on the point where the passing twin (mutant 0) passes.
137 * 1, 2, 3 and 7 give wrong values (scale dropped, scale pointer stuck, group table swapped, tail step never run);
138 * 6 = tail not masked: lanes past the tail columns also load. With the buffers ending at the tensor it faults (MEM),
139 * with junk declared behind the tensor (slack) it computes wrong values. The correct kernel passes both ways, so it
140 * reads nothing past its row, its scale blocks or x'. */
141 {
142 OmegaFp8GemvSpec twin = { .k = 640, .lane_bytes = 8, .rows = 1, .warps = 3 };
143 double w = 0; size_t bad = 0;
144 CHECK(!point(&twin, 4, 256, 2, 2, 777, 0, &w, &bad, msg, sizeof msg), "mutant twin (mutant 0, strict buffers) passes: bad=%zu worst=%.3e %s", bad, w, msg);
145 CHECK(!point(&twin, 4, 256, 2, 2, 777, 1, &w, &bad, msg, sizeof msg), "mutant twin (mutant 0, junk behind the tensor) passes: bad=%zu worst=%.3e %s", bad, w, msg);
146 static const int wrong[] = { 1, 2, 3, 7 };
147 for (size_t m = 0; m < sizeof wrong / sizeof wrong[0]; m++) {
148 OmegaFp8GemvSpec ms = twin; ms.mutant = wrong[m];
149 const int caught = point(&ms, 4, 256, 2, 2, 777, 0, &w, &bad, msg, sizeof msg);
150 CHECK(caught && bad > 0 && msg[0] == 0, "ragged mutant %d must give wrong values (caught %d, bad=%zu, sim: '%s')", wrong[m], caught, bad, msg);
151 printf("ragged mutant %d: wrong values (bad=%zu worst_rel=%.3e)\n", wrong[m], bad, w);
152 }
153 OmegaFp8GemvSpec m6 = twin; m6.mutant = 6;
154 int c6 = point(&m6, 4, 256, 2, 2, 777, 0, &w, &bad, msg, sizeof msg);
155 CHECK(c6 && strstr(msg, "MEM"), "ragged mutant 6 (strict buffers) must fault outside the declared buffers (caught %d, sim: '%s')", c6, msg);
156 printf("ragged mutant 6 strict: %s\n", msg);
157 c6 = point(&m6, 4, 256, 2, 2, 777, 1, &w, &bad, msg, sizeof msg);
158 CHECK(c6 && bad > 0 && msg[0] == 0, "ragged mutant 6 (junk behind the tensor) must give wrong values (caught %d, bad=%zu, sim: '%s')", c6, bad, msg);
159 printf("ragged mutant 6 slack: wrong values (bad=%zu worst_rel=%.3e)\n", bad, w);
160 /* the same on a lb 16 shape (a different tail width: 8 lanes) */
161 OmegaFp8GemvSpec t16 = { .k = 640, .lane_bytes = 16, .rows = 2, .warps = 2 };
162 CHECK(!point(&t16, 4, 256, 2, 1, 778, 0, &w, &bad, msg, sizeof msg) && !point(&t16, 4, 256, 2, 1, 778, 1, &w, &bad, msg, sizeof msg), "lb16 twin passes strict and with junk");
163 static const int all[] = { 1, 2, 3, 6, 7 };
164 for (size_t m = 0; m < sizeof all / sizeof all[0]; m++) {
165 OmegaFp8GemvSpec ms = t16; ms.mutant = all[m];
166 CHECK(point(&ms, 4, 256, 2, 1, 778, all[m] == 6, &w, &bad, msg, sizeof msg), "lb16 ragged mutant %d NOT caught", all[m]);
167 }
168 }
169
170 /* 3. the tail contributes exactly: weights non-zero only in the tail columns (512..639), x = 1, all scales 1 */
171 {
172 const uint32_t n = 128, k = 640;
173 Weights W; W.experts = 1; W.n = n; W.k = k;
174 W.w = aligned_alloc(64, n * k); memset(W.w, 0, (size_t)n * k); W.s = malloc((n / 128) * (k / 128) * 2);
175 for (uint32_t b = 0; b < (n / 128) * (k / 128); b++) W.s[b] = bf16_of(1.0f);
176 for (uint32_t r = 0; r < n; r++) for (uint32_t c = 512; c < 640; c++) W.w[(size_t)r * k + c] = 0x38; /* e4m3 1.0 */
177 float x[640]; for (int i = 0; i < 640; i++) x[i] = 1.0f;
178 uint32_t id = 0; float y[128];
179 OmegaFp8GemvSpec sp = { .k = k, .lane_bytes = 8, .rows = 1, .warps = 2 };
180 const int rc = sim_gemv(&sp, &W, 1, &id, x, 1, y, 3, 0, msg, sizeof msg);
181 unsigned exact = 0; if (rc == 0) for (uint32_t r = 0; r < n; r++) exact += y[r] == 128.0f;
182 CHECK(rc == 0 && exact == n, "tail-only weights: %u/%u rows equal 128 (%s)", exact, n, msg);
183 /* weights non-zero only in the full steps: the tail must add nothing (a stale or unmasked tail would) */
184 for (uint32_t r = 0; r < n; r++) for (uint32_t c = 0; c < 640; c++) W.w[(size_t)r * k + c] = c < 512 ? 0x38 : 0;
185 const int rc2 = sim_gemv(&sp, &W, 1, &id, x, 1, y, 3, 0, msg, sizeof msg);
186 exact = 0; if (rc2 == 0) for (uint32_t r = 0; r < n; r++) exact += y[r] == 512.0f;
187 CHECK(rc2 == 0 && exact == n, "full-step-only weights: %u/%u rows equal 512 (%s)", exact, n, msg);
188 free(W.w); free(W.s);
189 }
190
191 /* 4. refusals, each beside a passing twin built in this run; the plain entry points keep refusing a ragged k; a ragged-capable
192 * call on an exact multiple builds the same program as the plain one */
193 {
194 static BlackwellIRProgram p, q;
195 const OmegaFp8GemvSpec ok = { .k = 640, .lane_bytes = 8, .rows = 1, .warps = 8 };
196#define RAGGED_REFUSED(spec_, why_) CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&(spec_), &q) != 0, why_)
197 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&ok, &p) == 0, "twin: ragged k=640 lb8 builds");
198 CHECK(omega_blackwell_codegen_fp8_gemv_prog(&ok, &q) != 0, "the plain entry point still refuses k=640 lb8 (the existing contract)");
199 CHECK(omega_fp8_gemv_steps(&ok) == 0 && omega_fp8_gemv_shared_bytes(&ok) == 0 && omega_fp8_gemv_prog_stats(&ok, NULL, NULL) != 0, "plain steps, shared bytes and stats refuse k=640 lb8");
200 OmegaFp8GemvSpec b = ok; b.depth = 2;
201 RAGGED_REFUSED(b, "ragged with a deep kernel is refused");
202 b = ok; b.k = 640 + 64;
203 RAGGED_REFUSED(b, "ragged k not a multiple of 128 is refused");
204 b = ok; b.k = 128;
205 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&b, &q) == 0 && omega_fp8_gemv_ragged_steps(&b) == 1, "ragged k = 128 lb8 (no full step, one masked step) builds");
206 b.lane_bytes = 16; b.k = 384;
207 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&b, &q) == 0 && omega_fp8_gemv_ragged_steps(&b) == 1, "ragged k = 384 lb16 (one masked step of 24 lanes) builds");
208 b = ok; b.lane_bytes = 4;
209 RAGGED_REFUSED(b, "ragged lane_bytes 4 is refused");
210 b = ok; b.mutant = 8;
211 RAGGED_REFUSED(b, "mutant 8 is refused on a ragged k");
212 b = ok; b.mutant = 6;
213 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&b, &q) == 0, "twin: mutant 6 builds on a ragged k");
214 b = (OmegaFp8GemvSpec){ .k = 2048, .lane_bytes = 16, .rows = 1, .warps = 8, .mutant = 6 };
215 RAGGED_REFUSED(b, "mutant 6 on an exact multiple is refused (the existing selector range 0..5)");
216 b.mutant = 5;
217 RAGGED_REFUSED(b, "mutant 5 without coal is refused on an exact multiple (the existing rule)");
218 b = (OmegaFp8GemvSpec){ .k = 2048, .lane_bytes = 16, .rows = 1, .warps = 8 };
219 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&b, &q) == 0, "twin: the exact multiple builds");
220 CHECK(omega_blackwell_codegen_fp8_gemv2_prog(&ok, &q) != 0, "variant 2 refuses a ragged k");
221 OmegaFp8GemvSpec v2 = { .k = 512, .lane_bytes = 8, .rows = 1, .warps = 3, .depth = 2 };
222 CHECK(omega_blackwell_codegen_fp8_gemv2_prog(&v2, &q) == 0, "twin: variant 2 builds a normal spec");
223 /* steps and shared bytes of a ragged spec */
224 CHECK(omega_fp8_gemv_ragged_steps(&ok) == 3, "k=640 lb8 runs 3 steps (2 full + tail), got %u", omega_fp8_gemv_ragged_steps(&ok));
225 OmegaFp8GemvSpec l16 = ok; l16.lane_bytes = 16;
226 CHECK(omega_fp8_gemv_ragged_steps(&l16) == 2, "k=640 lb16 runs 2 steps (1 full + tail), got %u", omega_fp8_gemv_ragged_steps(&l16));
227 CHECK(omega_fp8_gemv_ragged_shared_bytes(&ok) == 0, "ragged step kernel declares no shared memory");
228 OmegaFp8GemvSpec cl = ok; cl.coal = 1; cl.warps = 4;
229 CHECK(omega_fp8_gemv_ragged_shared_bytes(&cl) == 2u * 4u * 1u * 4u, "ragged coal kernel declares its two slot sets, got %u", omega_fp8_gemv_ragged_shared_bytes(&cl));
230 /* the ragged-capable entry points and the plain ones agree on every exact multiple (same program, steps, shared bytes) */
231 unsigned agree = 0;
232 for (unsigned lb = 8; lb <= 16; lb *= 2)
233 for (unsigned sched = 0; sched < 2; sched++)
234 for (unsigned coal = 0; coal < 2; coal++)
235 for (unsigned k = 256; k <= 2048; k += 256) {
236 if (k % (32 * lb)) continue;
237 OmegaFp8GemvSpec e = { .k = k, .lane_bytes = lb, .rows = 1, .warps = 4, .sched = sched, .coal = coal };
238 static BlackwellIRProgram pa, pb;
239 const int ra = omega_blackwell_codegen_fp8_gemv_prog(&e, &pa), rb = omega_blackwell_codegen_fp8_gemv_ragged_prog(&e, &pb);
240 CHECK(ra == 0 && rb == 0 && same_program(&pa, &pb) && omega_fp8_gemv_steps(&e) == omega_fp8_gemv_ragged_steps(&e) &&
241 omega_fp8_gemv_shared_bytes(&e) == omega_fp8_gemv_ragged_shared_bytes(&e),
242 "k=%u lb%u sched%u coal%u: ragged-capable entry equals the plain entry on an exact multiple", k, lb, sched, coal);
243 agree++;
244 }
245 printf("ragged-capable entry equals the plain entry on %u exact-multiple specs\n", agree);
246 }
247
248 /* 5. Stall distances and the independent decoder, on the ragged kernels the Flash-Next shapes use and the shapes around them */
249 {
250 long viol = 0; unsigned built = 0;
251 for (unsigned lb = 8; lb <= 16; lb *= 2)
252 for (unsigned rows = 1; rows <= 8; rows *= 2)
253 for (unsigned sched = 0; sched < 2; sched++)
254 for (unsigned coal = 0; coal < 2; coal++)
255 for (unsigned k = 128; k <= 2688; k += 128) {
256 if (k % (32 * lb) == 0 || (coal && rows * 4 > 32)) continue;
257 OmegaFp8GemvSpec e = { .k = k, .lane_bytes = lb, .rows = rows, .warps = 4, .sched = sched, .coal = coal };
258 static BlackwellIRProgram pr;
259 const int rc = omega_blackwell_codegen_fp8_gemv_ragged_prog(&e, &pr);
260 CHECK(rc == 0 && pr.count <= BW_MAX_IR_INSNS, "k=%u lb%u rows%u sched%u coal%u builds", k, lb, rows, sched, coal);
261 if (rc != 0) continue;
262 const long v = stall_violations(&pr);
263 viol += v; built++;
264 CHECK(v == 0, "ragged k=%u lb%u rows%u sched%u coal%u: %ld stall-distance violations", k, lb, rows, sched, coal, v);
265 }
266 printf("ragged stall distances: %u kernels, %ld violations\n", built, viol);
267 /* the checker says no on a shortened stall (a control: the walk is not vacuous) */
268 static BlackwellIRProgram pc;
269 OmegaFp8GemvSpec cs = { .k = 640, .lane_bytes = 8, .rows = 1, .warps = 8, .sched = 1 };
270 CHECK(omega_blackwell_codegen_fp8_gemv_ragged_prog(&cs, &pc) == 0 && stall_violations(&pc) == 0, "twin: sched 1 ragged k=640 has no violation");
271 size_t at = pc.count;
272 for (size_t i = 0; i < pc.count; i++) if (chk_fixed(pc.insns[i].op) && ((pc.insns[i].control >> 9) & 0xfu) > 1u) { at = i; break; }
273 if (at < pc.count) pc.insns[at].control = (pc.insns[at].control & ~(0xfu << 9)) | (1u << 9);
274 CHECK(at < pc.count && stall_violations(&pc) > 0, "the stall walk catches one shortened stall");
275 /* decoder: the ragged kernel has the tail region (one BSSY / BSYNC pair) besides the lane-0 store region; an exact multiple has one pair */
276 unsigned lines, bad, bssy, bsync;
277 OmegaFp8GemvSpec r1 = { .k = 640, .lane_bytes = 8, .rows = 1, .warps = 8 }, r0 = { .k = 512, .lane_bytes = 8, .rows = 1, .warps = 8 };
278 CHECK(listing_counts(&r1, &lines, &bad, &bssy, &bsync) == 0 && bad == 0 && bssy == 2 && bsync == 2, "ragged k=640 listing: %u lines, %u undecodable, BSSY %u BSYNC %u (want 2 / 2)", lines, bad, bssy, bsync);
279 printf("ragged k=640 decoded by the sm121 disassembler: %u lines, %u undecodable, BSSY %u, BSYNC %u\n", lines, bad, bssy, bsync);
280 CHECK(listing_counts(&r0, &lines, &bad, &bssy, &bsync) == 0 && bad == 0 && bssy == 1 && bsync == 1, "exact-multiple k=512 listing: %u lines, %u undecodable, BSSY %u BSYNC %u (want 1 / 1)", lines, bad, bssy, bsync);
281 }
282
283 printf("%s: %d checks, %d failed\n", g_failed ? "CODEGEN MOE RAGGED FAIL" : "CODEGEN MOE RAGGED PASS", g_checks, g_failed);
284 return g_failed ? 1 : 0;
285}