#!/usr/bin/env bash # benchCyclesCalypsi.sh — measure per-call cycles for each benchmark in # benchmarks/ compiled with Calypsi cc65816 5.16 (--speed -O 2). # Mirrors benchCyclesPrecise.sh but for Calypsi. Output: markdown # table; per-call cycles via MAME emu.time(). set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" BENCH_DIR="$PROJECT_ROOT/benchmarks" CC="$PROJECT_ROOT/tools/calypsi/usr/local/lib/calypsi-65816-5.16/bin/cc65816" LN="$PROJECT_ROOT/tools/calypsi/usr/local/lib/calypsi-65816-5.16/bin/ln65816" RUNNER="$PROJECT_ROOT/scripts/runInMameCyclesCalypsi.sh" LINKER_SCM=$(mktemp --suffix=.scm) trap 'rm -f "$LINKER_SCM"' EXIT cat > "$LINKER_SCM" < "$cwrap" </dev/null \ || { echo "compile-fail-wrap"; return; } "$CC" -O 2 --speed --code-model=small -c "$BENCH_DIR/$name.c" -o "$obench" 2>/dev/null \ || { echo "compile-fail-bench"; return; } # ln65816 emits the raw alongside the bin; one per memory "$LN" "$LINKER_SCM" "$owrap" "$obench" -o "$bin" \ --output-format raw --raw-multiple-memories --rtattr exit=simplified \ --list-file "$lst" clib-sc-sd.a 2>/dev/null \ || { echo "link-fail"; return; } local entry entry=$(grep "__program_start =" "$lst" | head -1 | awk '{print substr($NF,3)}') [ -z "$entry" ] && { echo "no-entry"; return; } local val val=$(bash "$RUNNER" "$bin_raw" "$entry" "$iters" 2>&1 | grep -oE 'cyc_per_call=[0-9.]+' | head -1 | sed 's/cyc_per_call=//') if [ -z "$val" ]; then echo "(no read)" else printf '%.0f cyc/call' "$val" fi } printf '| Benchmark | Calypsi (cyc) |\n' printf '|-----------|--------------:|\n' for src in "$BENCH_DIR"/*.c; do name=$(basename "$src" .c) extern_decl=$(benchExtern "$name") [ -z "$extern_decl" ] && continue result=$(runOneCalypsiBench "$name") printf '| %s | %s |\n' "$name" "$result" done