#!/usr/bin/env bash
# PUBPUB hand-SASS backend wrapper — maps the dispatcher's uniform CLI to xcross_host.
#   crosscheck_hsass --xcheck <sources.bin> <a0> <a1> [--hits out.txt]
# hand-tuned RCAsm xcross cubin (sm_89), driver-API launch. ~2.2x the nvcc KGrid; GLV via 3x cuckoo.
# Emits identical "H a i j k glv" lines; the orchestrator re-verifies every hit exactly.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
SRC=""; A0=""; A1=""; HITS=/dev/stdout; PIV=""
while [ $# -gt 0 ]; do case "$1" in
  --xcheck) SRC="$2"; A0="$3"; A1="$4"; shift 4;;
  --hits)   HITS="$2"; shift 2;;
  --pivlo)  PIV="$PIV --pivlo $2"; shift 2;;   # pivot-tile range from the swarm -> xcross_host
  --pivhi)  PIV="$PIV --pivhi $2"; shift 2;;
  *) shift;;
esac; done
: "${SRC:?--xcheck <src> <a0> <a1>}"
# Membership = direct-hash fingerprint table in VRAM (64-bit fp, one bucket read, ZERO FP) so the host
# confirms ONLY genuine relations. FL (bucket count log2) MUST match the cubin's baked Z1_FPT_LOG2.
export XFPT=1 Z1_FPT_LOG2="${Z1_FPT_LOG2:-25}"
exec "$HERE/xcross_host" "$HERE/kernel_xcross_fpt_sm89.cubin" "$A0" "$A1" --src "$SRC" --hits "$HITS" $PIV
