#!/bin/bash # Phase 75-1: C6 Inline Slots A/B Test # # Goal: Compare baseline (C6 inline OFF) vs treatment (C6 inline ON) # Decision Gate: +1.0% GO, ±1.0% NEUTRAL, -1.0% NO-GO # # Usage: # bash scripts/phase75_c6_inline_test.sh # # Output: # - Baseline: /tmp/c6_inline_baseline.log (10 runs, ENV=0) # - Treatment: /tmp/c6_inline_treatment.log (10 runs, ENV=1) # - Summary: Average throughput delta, decision recommendation set -e # Exit on error echo "=========================================" echo "Phase 75-1: C6 Inline Slots A/B Test" echo "=========================================" echo "" # Verify we're in the hakmem directory if [ ! -f "Makefile" ]; then echo "ERROR: Must run from hakmem root directory" exit 1 fi # Clean any previous builds echo "Cleaning previous builds..." make clean > /dev/null 2>&1 # ============================================================================ # Baseline: C6 Inline OFF (ENV=0, default) # ============================================================================ echo "" echo "=========================================" echo "BASELINE: Building with C6 inline OFF..." echo "=========================================" make -j bench_random_mixed_hakmem > /tmp/c6_inline_build_baseline.log 2>&1 if [ $? -ne 0 ]; then echo "ERROR: Baseline build failed. Check /tmp/c6_inline_build_baseline.log" exit 1 fi echo "Build succeeded (log: /tmp/c6_inline_build_baseline.log)" echo "" echo "Running baseline 10-run (WS=400, ITERS=20000000, HAKMEM_WARM_POOL_SIZE=16)..." echo "" # Run baseline benchmark 10 times for i in {1..10}; do echo "=== Baseline Run $i/10 ===" HAKMEM_WARM_POOL_SIZE=16 HAKMEM_TINY_C6_INLINE_SLOTS=0 \ ./bench_random_mixed_hakmem 20000000 400 1 2>&1 done > /tmp/c6_inline_baseline.log echo "Baseline runs complete (log: /tmp/c6_inline_baseline.log)" # ============================================================================ # Treatment: C6 Inline ON (ENV=1) # ============================================================================ echo "" echo "=========================================" echo "TREATMENT: Building with C6 inline ON..." echo "=========================================" make clean > /dev/null 2>&1 make -j bench_random_mixed_hakmem > /tmp/c6_inline_build_treatment.log 2>&1 if [ $? -ne 0 ]; then echo "ERROR: Treatment build failed. Check /tmp/c6_inline_build_treatment.log" exit 1 fi echo "Build succeeded (log: /tmp/c6_inline_build_treatment.log)" echo "" echo "Running treatment 10-run with perf stat (WS=400, ITERS=20000000, ENV=1)..." echo "" # Run treatment benchmark 10 times with perf stat for i in {1..10}; do echo "=== Treatment Run $i/10 (C6 INLINE=ON) ===" HAKMEM_WARM_POOL_SIZE=16 HAKMEM_TINY_C6_INLINE_SLOTS=1 \ perf stat -e cycles,instructions,branches,branch-misses,cache-misses,dTLB-load-misses \ ./bench_random_mixed_hakmem 20000000 400 1 2>&1 done > /tmp/c6_inline_treatment.log 2>&1 echo "Treatment runs complete (log: /tmp/c6_inline_treatment.log)" # ============================================================================ # Analysis: Extract throughput and calculate delta # ============================================================================ echo "" echo "=========================================" echo "ANALYSIS: Throughput Comparison" echo "=========================================" echo "" # Extract throughput values (look for "ops/s" pattern) baseline_throughput=$(grep -oP '\d+\.\d+M ops/s' /tmp/c6_inline_baseline.log | sed 's/M ops\/s//' | awk '{sum+=$1; count++} END {if (count>0) print sum/count; else print "0"}') treatment_throughput=$(grep -oP '\d+\.\d+M ops/s' /tmp/c6_inline_treatment.log | sed 's/M ops\/s//' | awk '{sum+=$1; count++} END {if (count>0) print sum/count; else print "0"}') # Calculate delta percentage delta=$(echo "scale=2; (($treatment_throughput - $baseline_throughput) / $baseline_throughput) * 100" | bc) echo "Baseline Average: ${baseline_throughput}M ops/s (C6 inline OFF)" echo "Treatment Average: ${treatment_throughput}M ops/s (C6 inline ON)" echo "Delta: ${delta}%" echo "" # Decision gate echo "=========================================" echo "DECISION GATE (+1.0% GO threshold)" echo "=========================================" echo "" # Compare delta against thresholds if (( $(echo "$delta >= 1.0" | bc -l) )); then echo "Result: GO (+${delta}%)" echo "" echo "Recommendation:" echo " - Commit changes: 'Phase 75-1: C6-only Inline Slots (+${delta}%)'" echo " - Update CURRENT_TASK.md: Mark Phase 75-1 DONE" echo " - Proceed to Phase 75-2: Add C5 inline slots (85% coverage target)" elif (( $(echo "$delta <= -1.0" | bc -l) )); then echo "Result: NO-GO (${delta}%)" echo "" echo "Recommendation:" echo " - Revert all changes: 'git checkout -- .'" echo " - Document root cause in docs/analysis/PHASE75_C6_INLINE_SLOTS_FAILURE_ANALYSIS.md" echo " - Plan Phase 76: Alternative optimization axis (not hit-path)" else echo "Result: NEUTRAL (${delta}%)" echo "" echo "Recommendation:" echo " - Keep code (default OFF, no impact)" echo " - Freeze C6 optimization" echo " - Evaluate in Phase 76 or proceed to Phase 75-2 with caution" fi echo "" echo "=========================================" echo "Test complete!" echo "" echo "Logs:" echo " - Baseline: /tmp/c6_inline_baseline.log" echo " - Treatment: /tmp/c6_inline_treatment.log" echo " - Build logs: /tmp/c6_inline_build_*.log" echo "========================================="