Skip to content

Commit

Permalink
Performance fixed. Guessing it's within 30% or so of optimal.
Browse files Browse the repository at this point in the history
  • Loading branch information
ExpandingMan committed May 17, 2017
1 parent 85d9404 commit f8f49a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/opcodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export op!, tick!
#===================================================================================================
<opcodes>
===================================================================================================#
# 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
Expand Down
41 changes: 23 additions & 18 deletions test/opcodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit f8f49a5

Please sign in to comment.