interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / lab-page / run.sh

46 lines · 2655 bytes Raw Blame History
1#!/bin/sh
2# The /lab/ kernel on your own machine, from a git clone of the Radicle mirror of aienos.com:
3# git clone --depth 1 https://www.aienos.com/rad/z3iwnx2pktbGhnfBpJSsaFcTmKgHU.git aienos.com && cd aienos.com && sh om/lab-page/run.sh
4# Optional: sh om/lab-page/run.sh A N (1 <= A <= 1000, 1 <= N <= 4194304; defaults 3 1048576)
5# It checks the pinned compiler's sha256, builds axpy.om + harness.om into a Linux program,
6# runs it, checks the checksum against awk, proves the check can fail (add turned into sub),
7# and writes the WebAssembly the browser runs to om/lab-page/out/. Nothing is downloaded.
8set -eu
9cd "$(dirname "$0")"
10a=${1:-3}
11n=${2:-1048576}
12case "$a$n" in *[!0-9]*|'') echo 'A and N must be whole numbers' >&2; exit 2;; esac
13[ "$a" -ge 1 ] && [ "$a" -le 1000 ] && [ "$n" -ge 1 ] && [ "$n" -le 4194304 ] ||
14 { echo 'need 1 <= A <= 1000 and 1 <= N <= 4194304 (keeps the awk reference exact)' >&2; exit 2; }
15if [ "$(uname -s) $(uname -m)" != "Linux aarch64" ]; then
16 echo "NOT_RUN: the pinned omc is a Linux aarch64 program and this is $(uname -s) $(uname -m)."
17 echo 'The same kernel runs in your browser at https://www.aienos.com/lab/'
18 exit 0
19fi
20omc=../hive-page/omc
21irwasm=../hive-page/irwasm
22for f in omc irwasm; do
23 want=$(tr -d ' \n' < "../hive-page/$f.sha256")
24 got=$(sha256sum "../hive-page/$f" | cut -d' ' -f1)
25 [ "$got" = "$want" ] || { echo "$f sha256 $got is not the pin $want" >&2; exit 3; }
26 echo "pin $f sha256 $got"
27done
28mkdir -p out
29cat axpy.om harness.om > out/prog.om
30s=$(date +%s%N); "$omc" < out/prog.om > out/axpy; e=$(date +%s%N)
31chmod +x out/axpy
32echo "build omc: axpy.om + harness.om -> out/axpy in $(( (e - s) / 1000 )) us"
33s=$(date +%s%N); got=$(echo "$a $n" | ./out/axpy); e=$(date +%s%N)
34echo "run out/axpy a=$a n=$n -> $got in $(( (e - s) / 1000 )) us (whole process)"
35ref=$(awk -v a="$a" -v n="$n" 'BEGIN{s=0;for(i=0;i<n;i++)s+=a*i+2*i+1;printf "%.0f\n",s}')
36echo "check awk reference $ref"
37[ "$got" = "$ref" ] || { echo 'FAIL: checksum differs from the reference' >&2; exit 1; }
38sed 's/^ret add mul a x y$/ret sub mul a x y/' out/prog.om > out/mutant.om
39"$omc" < out/mutant.om > out/mutant; chmod +x out/mutant
40bad=$(echo "$a $n" | ./out/mutant || true)
41[ "$bad" != "$ref" ] || { echo 'FAIL: the mutant (add -> sub) also matched, so the check proves nothing' >&2; exit 1; }
42echo "control add -> sub gives $bad: mismatch, so the check can fail"
43{ printf 'ir\n'; cat axpy.om; } | "$omc" > out/axpy.ir
44"$irwasm" < out/axpy.ir > out/axpy.wasm
45echo "wasm out/axpy.wasm $(wc -c < out/axpy.wasm) bytes, sha256 $(sha256sum out/axpy.wasm | cut -d' ' -f1)"
46echo 'PASS'