#!/usr/bin/env python3 from pathlib import Path import subprocess,re,json,hashlib R=Path(__file__).resolve().parent.parent;rows=[] for precision in['f32','f64']: binary=R/f'local-sources/bench-reuse-{precision}';text=subprocess.check_output(['objdump','-Cd','--no-show-raw-insn',str(binary)],text=True);blocks=re.split(r'\n(?=[0-9a-f]+ <)',text);body=next(b for b in blocks if re.match(r'[0-9a-f]+ < as bench_reuse::Processor>::process_samples>:',b));instructions=[] for line in body.splitlines()[1:]: m=re.match(r'\s*([0-9a-f]+):\s+(\w+)\s*(.*)',line) if m:instructions.append((int(m[1],16),m[2],m[3],line)) back=[(a,int(re.match(r'([0-9a-f]+)',operand)[1],16))for a,m,operand,_ in instructions if m=='jne'and re.match(r'[0-9a-f]+',operand)and int(re.match(r'([0-9a-f]+)',operand)[1],16)::process_samples',loop_start=hex(start),loop_end=hex(end),loop_static_instructions=len(loop),loop_stack_memory_operands=sum('%rsp'in i[2]for i in loop),loop_shuffle_instructions=sum(i[1].startswith(('shuf','pshuf','punpck','unpck'))or i[1]in['movlhps','movhlps']for i in loop),loop_scalar_float_arithmetic=sum(i[1]in['mulss','addss','subss','divss','mulsd','addsd','subsd','divsd']for i in loop));rows.append(row) (R/'data/eq-svf-assembly-summary.json').write_text(json.dumps(rows,indent=2)+'\n');print(json.dumps(rows,indent=2))