Support 32 bit and 64 bit decoding with one binary
It is possible to configure the build process such that decoding of 32 bit and 64 bit instructions can be chosen at runtime using an additional parameter of the decode function. The header file is now entirely architecture-independent and no longer required any previous defines. Decoding x86-64 still requires a 64-bit pointer size.
This commit is contained in:
@@ -5,12 +5,12 @@ import statistics
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run(args, code, expected):
|
||||
def run(args, mode, code, expected):
|
||||
inner_reps = 10000000 if args.benchmark else 1
|
||||
outer_reps = 3 if args.benchmark else 1
|
||||
times = []
|
||||
for _ in range(outer_reps):
|
||||
output = subprocess.check_output([args.driver, code, str(inner_reps)],
|
||||
output = subprocess.check_output([args.driver, str(mode), code, str(inner_reps)],
|
||||
universal_newlines=True)
|
||||
instr, time = tuple(output.split("\n", 1))
|
||||
if instr != expected:
|
||||
@@ -22,26 +22,29 @@ def run(args, code, expected):
|
||||
if args.benchmark:
|
||||
mean = statistics.mean(times)
|
||||
stdev = statistics.stdev(times)
|
||||
print("{:53} {:6.3f} ns (std: {:6.3f} ns)".format(expected, mean, stdev))
|
||||
print("{:2} {:50} {:6.3f} ns (std: {:6.3f} ns)".format(mode, expected, mean, stdev))
|
||||
|
||||
return times
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--benchmark", action="store_true")
|
||||
parser.add_argument("--32", dest="test_modes", action="append_const", const=32)
|
||||
parser.add_argument("--64", dest="test_modes", action="append_const", const=64)
|
||||
parser.add_argument("driver")
|
||||
parser.add_argument("archmode", choices=[32, 64], type=int)
|
||||
parser.add_argument("cases", nargs="+", type=argparse.FileType('r'))
|
||||
args = parser.parse_args()
|
||||
|
||||
failed, total = 0, 0
|
||||
total_times = []
|
||||
|
||||
test_modes = frozenset(args.test_modes if args.test_modes else [32, 64])
|
||||
|
||||
for file in args.cases:
|
||||
cases = [tuple(ln.strip().split(maxsplit=2)) for ln in file.readlines()]
|
||||
for op, code, expected in cases:
|
||||
if op == "decode32" and args.archmode != 32: continue
|
||||
if op == "decode64" and args.archmode != 64: continue
|
||||
case_modes = {"decode":{32,64},"decode32":{32},"decode64":{64}}[op]
|
||||
if not case_modes & test_modes: continue
|
||||
|
||||
# Compatibility with old test system
|
||||
if expected[0] == '"' and expected[-1] == '"':
|
||||
@@ -49,7 +52,8 @@ if __name__ == "__main__":
|
||||
|
||||
try:
|
||||
total += 1
|
||||
total_times += run(args, code, expected)
|
||||
for mode in case_modes & test_modes:
|
||||
total_times += run(args, mode, code, expected)
|
||||
except Exception as e:
|
||||
failed += 1
|
||||
print("FAILED: %s" % e)
|
||||
|
||||
Reference in New Issue
Block a user