gameboy superoptimizer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

52 lines
1.1 KiB

from gbso.program.mutate import create_random_program
from time import time
from gbso.cpu.state import CPUState
from gbso.program.test_case import TestCase
from gbso.cpu.insn import *
from gbso.cpu.regs import R8
from gbso.optimize import OptimizationParameters, cost, optimize
from gbso.program.program import Program
prgm = Program(
insns=[
INC_R(R8.A),
INC_R(R8.A),
INC_R(R8.A),
INC_R(R8.A),
],
)
outputs = [R8.A]
test_cases = [TestCase(), TestCase(state=CPUState(carry=1))]
params = OptimizationParameters(max_size=4)
print("Program to optimize:")
prgm.display()
print(f"Cost: 0.0")
print(f"Cycles: {prgm.perf()}")
start_time = time()
optimized_prgm = optimize(
prgm,
test_cases,
outputs,
params,
)
end_time = time()
print("Optimized result:")
optimized_prgm.display()
optimized_cost = cost(prgm, test_cases, outputs, optimized_prgm)
optimized_cycles = optimized_prgm.perf()
print(f"Cost: {optimized_cost[0]}")
print(f"Cycles: {optimized_cycles}")
print(f"Took {round(end_time - start_time, 3)} seconds")