/* fh1 1001 WA PROBE -- distinct-digit count for ONE byte lane.
Lane is chosen by -DLANE=n (0..3). The probe writes exactly `d` 4-KiB pages,
where d = |{ (a[i] >> 8*LANE) & 255 : i in [0,n) }|, so
mem_kb(probe) - mem_kb(null) = 4 * d.
WA by construction (nothing is sorted). Sent through tools/submit.py. */
#ifndef LANE
#define LANE 0
#endif
void sort(unsigned *a, int n) {
static unsigned char buf[256*4096 + 4096] __attribute__((aligned(4096)));
unsigned char seen[256];
for (int i = 0; i < 256; i++) seen[i] = 0;
int d = 0;
for (int i = 0; i < n; i++) {
unsigned k = (a[i] >> (8*LANE)) & 255u;
if (!seen[k]) { seen[k] = 1; d++; }
}
for (int i = 0; i < d; i++) buf[i*4096] = (unsigned char)i;
if (d < 0) buf[0] = 0; /* never taken; keeps the loop alive */
}