omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / sm80 / gate80.sh
| 1 | #!/bin/sh |
| 2 | # gate80.sh -- the checks of seed/sm80 (Ampere sm_80/86/87, Ada sm_89): asm2 (rung 2, unchanged) with |
| 3 | # sm80.tbl must write the exact words Mesa NAK's encoder writes. Run from the repo root: |
| 4 | # sh seed/sm80/gate80.sh |
| 5 | # 1. the vectors (vectors/: listings and NAK's bytes, made by the nakref oracle, seed/sm80/README.md) are the |
| 6 | # ones recorded in vectors/SHA256SUMS; |
| 7 | # 2. asm2 + sm80.tbl assembles the edge listing (every form, every guard predicate, each field at its edges, |
| 8 | # each control field at its edges, branch distances, 64 random valid combinations per form); the words |
| 9 | # must equal NAK's, bit for bit; |
| 10 | # 3. the hand-written vector add (vecadd.s2) assembles twice to the same bytes, and to NAK's bytes for the |
| 11 | # same instructions (vectors/vecadd.nak.bin); |
| 12 | # 4. controls: a wrong register, a wrong offset, an out-of-range register, a wrong table bit and a field in |
| 13 | # the wrong place must each change the vector add; a moved field in a form only the edge listing uses must |
| 14 | # be caught by the edge check. |
| 15 | # Host only: no NVIDIA tool and no GPU is run; a pass is not hardware qualification. Results: evidence/SEED-0/sm80/. |
| 16 | set -eu |
| 17 | R=seed/sm80; V=$R/vectors; B=build/seed/sm80; E=evidence/SEED-0/sm80 |
| 18 | ASM=seed/rung2/asm2.bin; TAB=$R/sm80.tbl |
| 19 | mkdir -p "$E" "$B" |
| 20 | fail=0 |
| 21 | : > "$E/gate80.log" |
| 22 | say() { printf '%s\n' "$*" | tee -a "$E/gate80.log"; } |
| 23 | bad() { say "FAIL: $*"; fail=1; } |
| 24 | say "gate80 $(date -u +%FT%TZ) at $(git rev-parse HEAD)" |
| 25 | say "asm2 $(sha256sum $ASM | cut -d' ' -f1) table $(sha256sum $TAB | cut -d' ' -f1) ($(grep -c '^=' $TAB) lines)" |
| 26 | |
| 27 | # 1. vectors |
| 28 | gzip -dc $V/edges.s2.gz > $B/edges.s2 |
| 29 | gzip -dc $V/edges.nak.bin.gz > $B/edges.nak.bin |
| 30 | gzip -dc $V/cases.tsv.gz > $B/cases.tsv |
| 31 | cp $V/vecadd.nak.bin $B/vecadd.nak.bin |
| 32 | if (cd $B && sha256sum -c --quiet ../../../$V/SHA256SUMS); then say "PASS vectors match vectors/SHA256SUMS" |
| 33 | else bad "vectors differ from vectors/SHA256SUMS"; fi |
| 34 | |
| 35 | # 2. edge cases |
| 36 | cat $TAB $B/edges.s2 | $ASM > $B/edges.a.bin 2> $B/edges.err || true |
| 37 | if cmp -s $B/edges.a.bin $B/edges.nak.bin; then |
| 38 | say "PASS edges: $(( $(wc -c < $B/edges.nak.bin) / 16 )) instructions in $(wc -l < $B/cases.tsv) cases bit-identical to NAK" |
| 39 | else |
| 40 | bad "edges differ: $(head -1 $B/edges.err) $(cmp $B/edges.a.bin $B/edges.nak.bin 2>&1 | head -1)" |
| 41 | fi |
| 42 | |
| 43 | # 3. the hand-written vector add |
| 44 | cat $TAB $R/vecadd.s2 | $ASM > $R/vecadd.bin |
| 45 | cat $TAB $R/vecadd.s2 | $ASM > $B/vecadd.again |
| 46 | cmp -s $R/vecadd.bin $B/vecadd.again && say "PASS vecadd built by asm2 twice, same bytes" || bad "vecadd two builds differ" |
| 47 | cmp -s $R/vecadd.bin $B/vecadd.nak.bin && say "PASS vecadd.bin = NAK's words ($(stat -c %s $R/vecadd.bin) bytes)" \ |
| 48 | || bad "vecadd differs from NAK's words" |
| 49 | sha256sum $R/vecadd.bin | sed 's| .*| seed/sm80/vecadd.bin|' > "$E/vecadd.sha256" |
| 50 | |
| 51 | # 4. controls |
| 52 | ctrl() { # description, sed edit, file (listing or table), listing to assemble, reference bytes |
| 53 | sed "$2" "$3" > $B/ctrl.in |
| 54 | if cmp -s $B/ctrl.in "$3"; then bad "control edit did nothing: $1"; return; fi |
| 55 | if [ "$3" = $TAB ]; then cat $B/ctrl.in "$4"; else cat $TAB $B/ctrl.in; fi | $ASM > $B/ctrl.bin 2> $B/ctrl.err || true |
| 56 | if cmp -s $B/ctrl.bin "$5"; then bad "control not caught: $1"; else say "PASS control caught: $1 ($(head -c 60 $B/ctrl.err))"; fi |
| 57 | } |
| 58 | VA=$R/vecadd.s2; VN=$B/vecadd.nak.bin |
| 59 | ctrl "wrong register (IADD3 R9 -> R8)" 's/^iadd3.0 7 9 2 /iadd3.0 7 8 2 /' $VA $VA $VN |
| 60 | ctrl "wrong offset (LDC.64 b 0x388 -> 0x38c)" 's/^cb.1 0x388 0$/cb.1 0x38c 0/' $VA $VA $VN |
| 61 | ctrl "register out of range (256)" 's/^ldc.0 7 1 255 /ldc.0 7 256 255 /' $VA $VA $VN |
| 62 | ctrl "wrong table bit (LDG word 2)" 's/^= ldg.2 0x080e0000/= ldg.2 0x080e0080/' $TAB $VA $VN |
| 63 | ctrl "wrong field position (S2R register at bit 9)" 's/^= s2r.2 0x00000000 i8.8 /= s2r.2 0x00000000 i9.7 /' $TAB $VA $VN |
| 64 | ctrl "edge-only form (SHFL clamp number at bit 41)" 's/^\(= shfl.ii.1 *0x00000000\) i8.13 /\1 i9.13 /' $TAB $B/edges.s2 $B/edges.nak.bin |
| 65 | |
| 66 | if [ $fail = 0 ]; then say "GATE80 PASS"; else say "GATE80 FAIL"; fi |
| 67 | exit $fail |