aboutsummaryrefslogtreecommitdiff
path: root/tests/bench
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
commit7451eb090d890fb5ea5e4d40627a1b4df15a49de (patch)
tree357bdf4b528e860bffa688865306f656b788d2c2 /tests/bench
parentanalyzer: close the ownership gaps that stopped the compiler compiling itself (diff)
build: embed images with #embed, keep everything generated in build/
the cores take their genome in with c23 #embed through src/core/genome.h, so images are plain little-endian word files (genome.bin) instead of generated c headers. zc0 writes that format, mkgenome checks an image against its map and shows a compiler's diagnostics when it gets them, and the javascript vm and the editor's vm host read the same files. src/tools/findcc.sh picks a compiler with #embed (clang 19 or gcc 15). zc gets an embed declaration, embed "file" as [type] name, for globals and locals: a byte string by default, char*, numbers read little-endian, and arrays of numbers. the compiler and language server carry their library and source texts through it, so embed.sh and the text it spliced into compiler.zc are gone. make writes executables to build/bin, the default map to build/core/map, the web page to build/web and the extension staging to build/vsix, and the genome now rebuilds when its sources change. the test suite lays out its own map and bootstrap and reads nothing from build/. also: rt.put_s of a byte string in zc0 images, retained function sources no longer count as live objects, a missing include no longer cascades into undefined-name errors, consecutive comment lines join into one hover paragraph, and stale test fixtures follow the include format.
Diffstat (limited to 'tests/bench')
-rw-r--r--tests/bench/bench.sh8
-rw-r--r--tests/bench/bench_bytes.sh12
-rw-r--r--tests/bench/bench_float.sh10
-rw-r--r--tests/bench/bench_share.sh15
-rw-r--r--tests/bench/bench_strings.sh15
-rwxr-xr-xtests/bench/run.py9
6 files changed, 40 insertions, 29 deletions
diff --git a/tests/bench/bench.sh b/tests/bench/bench.sh
index ab6b07d..65f455e 100644
--- a/tests/bench/bench.sh
+++ b/tests/bench/bench.sh
@@ -2,13 +2,15 @@
# o3 against plain code: each kernel in tests/programs/bench.zc on each backend, with
# the time to start up and compile (the 'z' run) taken off. needs bc.
cd "$(dirname "$0")/../.."; T=$(mktemp -d); trap 'rm -rf $T' EXIT
-gcc -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -o $T/zy
+CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
+make -s build/core/genome.bin || exit 1
+$CC -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o $T/zy
vms=("$T/zy"); names=("interp")
if command -v llvm-config >/dev/null; then
- gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -o $T/zyl $(llvm-config --ldflags --libs) && { vms+=("$T/zyl"); names+=("llvm"); }
+ $CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o $T/zyl $(llvm-config --ldflags --libs) && { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
- aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static src/core/core.c src/core/io_linux.c -Isrc/core -o $T/zyj && { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64 (qemu)"); }
+ aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o $T/zyj && { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64 (qemu)"); }
fi
# seconds per run of kernel $2 on vm $1: the slope between $3 runs and 1 run,
# best of three each, so starting up and compiling cancel out
diff --git a/tests/bench/bench_bytes.sh b/tests/bench/bench_bytes.sh
index acff074..775b71d 100644
--- a/tests/bench/bench_bytes.sh
+++ b/tests/bench/bench_bytes.sh
@@ -4,16 +4,18 @@ set -e
# in the process. the slope between 1 repetition and N drops startup.
# prints: backend ms/rep checksum
cd "$(dirname "$0")/../.."
+CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
+make -s build/core/genome.bin || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
-gcc -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
+$CC -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
GENMAP="$T/genmap" bash src/tools/automap.sh run "$T/run" src/runtime/run.zc tests/programs/bench_bytes.zc >/dev/null || exit 1
-cp src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h "$T/run/"
-gcc -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
-gcc -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
+cp src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h src/core/genome.h "$T/run/"
+$CC -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
+$CC -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
vms=("$T/zy" "$T/zym"); names=("interp" "micro")
if command -v llvm-config >/dev/null; then
- gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
+ $CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
diff --git a/tests/bench/bench_float.sh b/tests/bench/bench_float.sh
index 794e976..4ebfbe4 100644
--- a/tests/bench/bench_float.sh
+++ b/tests/bench/bench_float.sh
@@ -5,17 +5,19 @@
# this does not bootstrap the compiler. each kernel is poly() of 20000,
# and (int) of one call is 59997.
cd "$(dirname "$0")/../.."
+CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
+make -s build/core/genome.bin || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
-gcc -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -o "$T/zy" || exit 1
+$CC -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zy" || exit 1
vms=("$T/zy"); names=("interp")
-gcc -O2 -w src/micro/micro.c src/micro/port_linux.c -Isrc/core -Isrc/micro -o "$T/zym" && { vms+=("$T/zym"); names+=("micro"); }
+$CC -O2 -w src/micro/micro.c src/micro/port_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -Isrc/micro -o "$T/zym" && { vms+=("$T/zym"); names+=("micro"); }
if command -v llvm-config >/dev/null; then
- gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -o "$T/zyl" $(llvm-config --ldflags --libs) \
+ $CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
- aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static src/core/core.c src/core/io_linux.c -Isrc/core -o "$T/zyj" \
+ aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zyj" \
&& { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
fi
src=$(cat tests/programs/fbench.zc)
diff --git a/tests/bench/bench_share.sh b/tests/bench/bench_share.sh
index b449e09..5cb1bfd 100644
--- a/tests/bench/bench_share.sh
+++ b/tests/bench/bench_share.sh
@@ -3,18 +3,19 @@
# resident compiler is not in the process. the slope between 1 repetition
# and N drops startup. prints: backend ms/rep checksum
cd "$(dirname "$0")/../.."
+CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
-gcc -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
+$CC -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
"$T/genmap" --preset run -o "$T/run" >/dev/null || exit 1
-cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h "$T/run/"
-gcc -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
-cat "$T/run/rt.zc" src/runtime/run.zc tests/programs/bench_share.zc | "$T/zc0" > "$T/run/genome.h" || exit 1
-gcc -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
-gcc -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
+cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h src/core/genome.h "$T/run/"
+$CC -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
+cat "$T/run/rt.zc" src/core/core.zc src/runtime/run.zc tests/programs/bench_share.zc | "$T/zc0" > "$T/run/genome.bin" || exit 1
+$CC -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
+$CC -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
vms=("$T/zy" "$T/zym"); names=("interp" "micro")
if command -v llvm-config >/dev/null; then
- gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
+ $CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
diff --git a/tests/bench/bench_strings.sh b/tests/bench/bench_strings.sh
index c353342..b14bf57 100644
--- a/tests/bench/bench_strings.sh
+++ b/tests/bench/bench_strings.sh
@@ -3,18 +3,19 @@
# resident compiler is not in the process. the slope between 1 repetition
# and N drops startup. prints: backend ms/rep checksum
cd "$(dirname "$0")/../.."
+CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
-gcc -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
+$CC -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
"$T/genmap" --preset run -o "$T/run" >/dev/null || exit 1
-cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h "$T/run/"
-gcc -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
-cat "$T/run/rt.zc" src/runtime/run.zc tests/programs/bench_strings.zc | "$T/zc0" > "$T/run/genome.h" || exit 1
-gcc -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
-gcc -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
+cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h src/core/genome.h "$T/run/"
+$CC -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
+cat "$T/run/rt.zc" src/core/core.zc src/runtime/run.zc tests/programs/bench_strings.zc | "$T/zc0" > "$T/run/genome.bin" || exit 1
+$CC -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
+$CC -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
vms=("$T/zy" "$T/zym"); names=("interp" "micro")
if command -v llvm-config >/dev/null; then
- gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
+ $CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
diff --git a/tests/bench/run.py b/tests/bench/run.py
index cb28b92..7f7ea6f 100755
--- a/tests/bench/run.py
+++ b/tests/bench/run.py
@@ -79,18 +79,21 @@ def machine_lines():
def build(td):
td = Path(td)
log("building vms")
+ need(["make", "-s", "build/core/genome.bin"], cwd=ROOT)
+ cc = os.environ.get("CC") or subprocess.check_output(["sh", "src/tools/findcc.sh"], cwd=ROOT, text=True).strip()
+ core = ["-Isrc/core", "-Ibuild/core/map", "--embed-dir=build/core"]
zy = td / "zy"
- need(["gcc", "-O3", "-w", "-DJTYPE=int", "src/core/core.c", "src/core/io_linux.c", "-Isrc/core", "-o", str(zy)], cwd=ROOT)
+ need([cc, "-O3", "-w", "-DJTYPE=int", "src/core/core.c", "src/core/io_linux.c", *core, "-o", str(zy)], cwd=ROOT)
vms = {"interp": [str(zy)]}
if shutil.which("llvm-config"):
cflags = subprocess.check_output(["llvm-config", "--cflags"], text=True).split()
ld = subprocess.check_output(["llvm-config", "--ldflags", "--libs"], text=True).split()
zyl = td / "zyl"
- need(["gcc", "-O3", "-w", "-DJTYPE=int", "-DZYLLVM", *cflags, "src/core/core.c", "src/core/io_linux.c", "-Isrc/core", "-o", str(zyl), *ld], cwd=ROOT)
+ need([cc, "-O3", "-w", "-DJTYPE=int", "-DZYLLVM", *cflags, "src/core/core.c", "src/core/io_linux.c", *core, "-o", str(zyl), *ld], cwd=ROOT)
vms["llvm"] = [str(zyl)]
if shutil.which("aarch64-linux-gnu-gcc") and shutil.which("qemu-aarch64"):
zyj = td / "zyj"
- need(["aarch64-linux-gnu-gcc", "-O3", "-w", "-DJTYPE=int", "-static", "src/core/core.c", "src/core/io_linux.c", "-Isrc/core", "-o", str(zyj)], cwd=ROOT)
+ need(["aarch64-linux-gnu-gcc", "-O3", "-w", "-DJTYPE=int", "-static", "src/core/core.c", "src/core/io_linux.c", *core, "-o", str(zyj)], cwd=ROOT)
vms["arm64"] = ["qemu-aarch64", str(zyj)]
log("building C")
bins = {}