open-standards/wai/wai-quantum/ci/dsp/predicate_branch.c
Transaction Science 05fef6cce9 wai-quantum: the signal processor, and its vector unit as a member
The signal processor (DSP) as a processor: the bit-identity digests (23),
the frame fixtures (2) and the byte-pinning library tests (137) pass for
its Linux target under the user-mode emulator, the standard library built
from source (a tier-3 target).

Emulator releases before 11.0 test a whole predicate register, where the
processor tests its low bit, in a branch on a predicate written in the same
packet. Compiled code relies on the low bit (a predicate from a register's
1, xored with a comparison's 0xff, so 0xfe is "equal"), and one library
test fails under such an emulator though the code is right. The probe
ci/dsp/predicate_branch.c shows it; the workflow builds 11.1.1 from its
release tarball (SHA-256 pinned, signature checked when pinned) and runs
every suite on it.

The member (feature quantum_fabric_dsp, class dsp): the gate's fixed-point
arithmetic in the vector unit's 128-byte vectors, each 64-bit value a pair
of words; the product is the unit's exact 32x32 multiply, and carries and
borrows are bit logic on the words (the standard library's
predicate-producing vector intrinsics do not compile in this release).
Under emulation: 66020 probe pairs agree, 2000 kernel cases match
run_words, all four pinned certificates are reproduced naming the
emulator, circuits up to 20 qubits match native, 3 of 3 mutants are
killed. Elsewhere the member is absent and says why.

Workflow wai-quantum-dsp.yml runs all of it in a pinned container on the
container runner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 10:47:59 -04:00

55 lines
2 KiB
C

/* Does this emulator branch on a predicate's low bit?
*
* The signal processor's conditional instructions test the least significant
* bit of a predicate register. A compiler may build a predicate from a general
* register (`p = r`, so `1` gives 0x01) and combine it with a comparison's
* (0xff) by `xor`, leaving 0xfe for "equal": its low bit is clear, so a branch
* on it is not taken. An emulator that tests the whole register takes it.
*
* Each case branches on the same predicate twice: written in an earlier packet
* (`if (p1) jump`) and in the same packet (`if (p1.new) jump`). Both must test
* the low bit. Exit status 0 when they do, 1 when the emulator differs.
*/
#include <stdio.h>
static int same_packet(int a, int b) {
int r;
__asm__ volatile(
"{ p2 = %1 }\n"
"{ p0 = %2 }\n"
"{ p1 = xor(p2,p0)\n if (p1.new) jump:nt 1f }\n"
"{ %0 = #0 ; jump 2f }\n"
"1: { %0 = #1 }\n"
"2:\n"
: "=&r"(r) : "r"(a), "r"(b) : "p0", "p1", "p2");
return r;
}
static int earlier_packet(int a, int b) {
int r;
__asm__ volatile(
"{ p2 = %1 }\n"
"{ p0 = %2 }\n"
"{ p1 = xor(p2,p0) }\n"
"{ if (p1) jump:nt 1f }\n"
"{ %0 = #0 ; jump 2f }\n"
"1: { %0 = #1 }\n"
"2:\n"
: "=&r"(r) : "r"(a), "r"(b) : "p0", "p1", "p2");
return r;
}
int main(void) {
/* (p2, p0): the predicate is their xor; taken iff its low bit is set. */
static const int cases[][2] = {{1, 0xff}, {0xff, 0xff}, {1, 1}, {0, 0xff}, {0, 1}, {0xfe, 0}, {2, 0}};
int bad = 0;
for (unsigned i = 0; i < sizeof cases / sizeof cases[0]; i++) {
int a = cases[i][0], b = cases[i][1], want = (a ^ b) & 1;
int n = same_packet(a, b), o = earlier_packet(a, b);
printf("predicate %#04x: same packet %s, earlier packet %s, low bit %s\n", (a ^ b) & 0xff, n ? "taken" : "not taken", o ? "taken" : "not taken",
want ? "set" : "clear");
bad += (n != want) + (o != want);
}
printf(bad ? "this emulator does not branch on the low bit\n" : "this emulator branches on the low bit\n");
return bad != 0;
}