Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/rung2/gate2.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / rung2 / gate2.sh` 84 lines ยท 7108 bytes Raw Blame History 1 #!/bin/sh 2 # gate2.sh -- rung 2 gates (seed/README.md). Shell only; the Omega encoder/decoder and objdump are 3 # reference checks and never make a byte of seed/. 4 # build: hex1 (rung 1 gate first) turns asm2.hex1 into asm2.bin = committed 5 # self: asm2 assembling table.s2 + asm2.s (asm2 in its own language) gives asm2.bin 6 # audit: every word of asm2 against our decoder and objdump, 0 mismatches 7 # encoder: every form of src/aarch64_encoder.h, 5450 operand sets with numbers in the distance fields 8 # plus the label path (b, b.cond, cbz, cbnz, adr at short and at the largest distances asm2 can 9 # hold): asm2's word = the Omega reference encoder's word, every case; disagreements listed (the manual decides) 10 # refusals: out-of-range operands refused by asm2 (error 8) where the Omega reference encoder refuses them too 11 # controls: each asm2 error code on a broken input, with its line number 12 set -u 13 D=$(cd "$(dirname "$0")/.." && pwd); R=$(cd "$D/.." && pwd); O=$1; mkdir -p "$O" 14 fail=0; ok() { echo "PASS $*"; }; bad() { echo "FAIL $*"; fail=1; } 15 sh "$D/rung1/gate1.sh" "$O/rung1" > "$O/gate1.log" 2>&1 && ok "rung 1 gate (and rung 0 inside it)" || bad "rung 1 gate" 16 H1=$O/rung1/hex1.bin; CHK=$R/build/seed/a64check; A=$O/asm2.bin; T=$D/rung2/table.s2 17 "$H1" < "$D/rung2/asm2.hex1" > "$A"; rc=$?; chmod +x "$A" 18 [ $rc = 0 ] && cmp -s "$A" "$D/rung2/asm2.bin" && ok "build: hex1 makes asm2.bin = committed ($(wc -c < "$A") bytes)" || bad "build rc=$rc" 19 sh "$D/rung2/mks.sh" > "$O/asm2.s"; cmp -s "$O/asm2.s" "$D/rung2/asm2.s" || bad "asm2.s differs from committed" 20 cat "$T" "$O/asm2.s" | "$A" > "$O/asm2.self"; rc=$? 21 [ $rc = 0 ] && cmp -s "$O/asm2.self" "$A" && ok "self: asm2 assembles itself from table.s2 + asm2.s byte for byte" || bad "self rc=$rc" 22 sh "$D/check/audit.sh" "$D/rung2/asm2.hex1" "$A" "$CHK" > "$O/asm2.audit"; rc=$? 23 [ $rc = 0 ] && ok "audit $(tail -1 "$O/asm2.audit")" || bad "audit $(tail -1 "$O/asm2.audit")" 24 # encoder comparison, numbers in the distance fields 25 sh "$D/rung2/enccases.sh" > "$O/cases" 26 cut -d'|' -f1 "$O/cases" | while read -r f args; do "$CHK" encode $f $args 2>&1; done > "$O/c.words" 27 { cat "$T"; cut -d'|' -f2 "$O/cases"; } | "$A" > "$O/a.bin"; rc=$? 28 od -An -v -tx4 -w4 "$O/a.bin" | tr -d ' ' > "$O/a.words" 29 paste -d'|' "$O/cases" "$O/c.words" "$O/a.words" | awk -F'|' 'BEGIN { print "Omega reference encoder call\tasm2 line\treference word\tasm2 word\tverdict" } 30 { v = ($3==$4 && $3 ~ /^[0-9a-f]{8}$/) ? "same" : "DIFFERENT"; print $1 "\t" $2 "\t" $3 "\t" $4 "\t" v }' > "$O/encoder-compare.tsv" 31 nd=$(grep -c 'DIFFERENT$' "$O/encoder-compare.tsv"); nc=$(($(wc -l < "$O/encoder-compare.tsv") - 1)) 32 nf=$(cut -d' ' -f1 "$O/cases" | cut -d'|' -f1 | sort -u | wc -l) 33 [ $rc = 0 ] && [ "$nd" = 0 ] && ok "encoder: $nc cases over $nf forms, asm2 = Omega reference encoder on every one" || bad "encoder: $nd of $nc differ (rc=$rc)" 34 # label path: distance d in words for branches, in bytes for adr 35 fill() { awk -v n="$1" -v s="${2:-0}" 'BEGIN { while (n > 0 && s % 4) { print ".b 0"; n--; s++ } for (i = 0; i < int(n / 4); i++) print ".w 0"; for (i = 0; i < n % 4; i++) print ".b 0" }'; } # n bytes from offset s 36 lcase() { # 37 d=$3; u=$4 38 if [ "$u" = 4 ]; then 39 if [ "$d" -le 0 ]; then { cat "$T"; echo ":T"; fill $((-d * 4)); echo "$2 T"; } > "$O/l.s"; pos=last 40 else { cat "$T"; echo "$2 T"; fill $(((d - 1) * 4)); echo ":T"; } > "$O/l.s"; pos=first; fi 41 else 42 if [ "$d" -le 0 ]; then a=$((-d)); p=$(( (4 - a % 4) % 4 )); { cat "$T"; fill $p; echo ":T"; fill $a $p; echo "$2 T"; } > "$O/l.s"; pos=last 43 else { cat "$T"; echo "$2 T"; fill $((d - 4)); echo ":T"; } > "$O/l.s"; pos=first; fi 44 fi 45 "$A" < "$O/l.s" > "$O/l.bin"; rc=$? 46 if [ $pos = first ]; then got=$(head -c 4 "$O/l.bin" | od -An -tx4 | tr -d ' '); else got=$(tail -c 4 "$O/l.bin" | od -An -tx4 | tr -d ' '); fi 47 want=$("$CHK" encode $1 $d 2>&1) 48 if [ $rc = 0 ] && [ "$got" = "$want" ]; then lab_ok=$((lab_ok + 1)); else lab_bad=$((lab_bad + 1)); echo " label case DIFFERENT: $1 d=$d asm2=$got rc=$rc reference=$want"; fi 49 printf '%s\t%s\t%s\t%s\t%s\n' "$1 $d" "$2