From f8f49a5392f9a3c01f8fe7bdae6b5bea671444dd Mon Sep 17 00:00:00 2001 From: ExpandingMan Date: Tue, 16 May 2017 20:04:28 -0400 Subject: [PATCH] Performance fixed. Guessing it's within 30% or so of optimal. --- src/opcodes.jl | 8 ++++++-- test/opcodes.jl | 41 +++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/opcodes.jl b/src/opcodes.jl index a838a56..c3ee2fd 100644 --- a/src/opcodes.jl +++ b/src/opcodes.jl @@ -47,8 +47,12 @@ export op!, tick! #=================================================================================================== ===================================================================================================# -# returns func, nbytes, ncycles -const OPCODES = Dict{UInt8,Tuple{Function,Int,Int}}(); sizehint!(OPCODES, N_OPCODES) +# this is an (efficient) function pointer type for the instructions +# note this works even though ops take AbstractVector +const OpFunc = FunctionWrapper{UInt8,Tuple{Chipset,Vector{UInt8}}} + +# for the time being opcode 0x00 would throw an error +const OPCODES = Vector{Tuple{OpFunc,Int,Int}}(N_OPCODES) # format is # mode, opcode, nbytes, ncycles diff --git a/test/opcodes.jl b/test/opcodes.jl index bccaa03..d7a35fa 100644 --- a/test/opcodes.jl +++ b/test/opcodes.jl @@ -18,34 +18,39 @@ function makechipset() cs.ram[0x00] = 0x01 cs.ram[0x01] = 0x02 - + cs.ram[0xa000] = 0x05 cs.ram[0xa001] = 0x06 # @p Sim6502.op0xa5!(cs, [0x00]) # @p Sim6502.op0xad!(cs, [0x01, 0xa0]) # @p Sim6502.op0xaa!(cs, UInt8[]) - @program [0xa5, 0x00, 0xad, 0x01, 0xa0, 0xaa, 0xaa, 0xaa] + @program [0xaa, 0xa5, 0x00, 0xad, 0x01, 0xa0, 0xaa, 0xaa, 0xaa] cs end -ref = @benchmarkable begin - # cs.cpu.A = 0x00 - # Sim6502.checkNflag!(cs.cpu, cs.cpu.A) - # Sim6502.checkZflag!(cs.cpu, cs.cpu.A) - # cs.cpu.A = cs.ram[0xa001] - cs.cpu.X = cs.cpu.A - Sim6502.checkNflag!(cs.cpu, cs.cpu.X) - Sim6502.checkZflag!(cs.cpu, cs.cpu.X) -end setup=(cs = makechipset()) - -b = @benchmarkable begin - # tick!(cs) - # tick!(cs) - # tick!(cs) - tax!(cs.cpu) -end setup=(cs = makechipset()) +function makebenches() + ref = @benchmarkable begin + # cs.cpu.A = 0x00 + # Sim6502.checkNflag!(cs.cpu, cs.cpu.A) + # Sim6502.checkZflag!(cs.cpu, cs.cpu.A) + # cs.cpu.A = cs.ram[0xa001] + cs.cpu.X = cs.cpu.A + Sim6502.checkNflag!(cs.cpu, cs.cpu.X) + Sim6502.checkZflag!(cs.cpu, cs.cpu.X) + end setup=(cs = makechipset()) + + b = @benchmarkable begin + tick!(cs) + tick!(cs) + tick!(cs) + tick!(cs) + end setup=(cs = makechipset()) + + ref, b +end +ref, b = makebenches()