#!/bin/perl -w if( @ARGV != 2 ) { printf "Usage: brcompare training_data_file reference_data_file2\n"; exit 1; } $file = $ARGV[0]; shift( @ARGV ); if( !open( FILE, "<$file" )){ print "$0: Can't open input file $file\n"; exit 1; } # Process input file while () { if ( (/\s*([\dabcdef]+).*\%.*\%\s+(\S)\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)\@/ ) ) { $ip=hex($1); $IP_trip_cnt_train{$ip} = $3; $IP_taken_train{$ip} = $4; } } close(FILE); $file = $ARGV[0]; shift( @ARGV ); if( !open( FILE, "<$file" )){ print "$0: Can't open input file $file\n"; exit 1; } # Process input file $maxexec=0; while () { # Parse input item in accordance with file style if ( (/\s*([\dabcdef]+).*\%.*\%\s+(\S)\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)\@/ ) ) { $ip = hex($1); $cnt = $3; $taken = $4; if ($cnt==0) { next; } if ($IP_trip_cnt_train{$ip}==0) { $Pt1=0.5; } else { $Pt1 = $IP_taken_train{$ip} / $IP_trip_cnt_train{$ip}; } my $Pt2 = $taken / $cnt; if( ($Pt1 >= 0.5 && $Pt2 >= 0.5) || ($Pt1 < 0.5 && $Pt2 < 0.5) ) { $Npredexec += $cnt; } else { $Nmispexec += $cnt; } if ($cnt > $maxexec) { $maxexec = $cnt; } # Process gnuplot info $x{$cnt.".".$ip} = $Pt1; $y{$cnt.".".$ip} = $Pt2; $weight{$cnt.".".$ip} = $cnt; } } close(FILE); my $Nexec = $Nmispexec + $Npredexec; # Dump gnuplot graph data files use POSIX; $outputfile = POSIX::tmpnam(); $outputscript = POSIX::tmpnam(); open OUTFILE,">$outputfile"; open OUTSCRIPT,">$outputscript"; print OUTSCRIPT "set output './graph.ps'\n"; print OUTSCRIPT "set terminal postscript color\n"; print OUTSCRIPT "set xlabel 'Probability taken (train)'\n"; print OUTSCRIPT "set ylabel 'Probability taken (ref)'\n"; print OUTSCRIPT "set title '3d plot of all branch instructions'\n"; print OUTSCRIPT "set time\n"; print OUTSCRIPT "set parametric\n"; print OUTSCRIPT "set ticslevel 0\n"; print OUTSCRIPT "plot \"$outputfile\" using 1:2:3:4 t 'times ref branch taken' with boxxyerrorbars\n"; sub numerically {$a <=> $b;} for my $i (sort numerically keys( %x)) { $total_weight += $weight{$i}; my $wt = $total_weight/$Nexec; my $rwt = $weight{$i}/$maxexec; $rwt = $rwt/4; if ($rwt <0.001) {$rwt=0.001}; print OUTFILE "$x{$i}\t$y{$i}\t$rwt\t$rwt\n"; } close OUTFILE; close OUTSCRIPT; `gnuplot $outputscript`; printf " Correspondence value: %6.2f%%\n", $Npredexec / $Nexec * 100.0;