more optimizations: move port states into gates, inline net queue checks
This commit is contained in:
31
sim/gate.lua
31
sim/gate.lua
@@ -5,13 +5,11 @@ Gate = {}
|
||||
|
||||
function Gate.new(objref, definition)
|
||||
local o = {
|
||||
--in_queue = ffi.new("bool", false),
|
||||
--in_queue = false,
|
||||
--in_queue = ffi.new("long long", 0),
|
||||
in_queue = 0,
|
||||
port_nets = {},
|
||||
logic = definition.logic,
|
||||
ports = {},
|
||||
port_nets = {},
|
||||
port_states = {},
|
||||
|
||||
objref = objref,
|
||||
definition = definition,
|
||||
@@ -19,30 +17,33 @@ function Gate.new(objref, definition)
|
||||
return o
|
||||
end
|
||||
|
||||
function Gate.addport(gate, port)
|
||||
gate.ports[#gate.ports+1] = port
|
||||
Port.setgate(port, gate)
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Gate.getportstate(gate, index)
|
||||
--return gate[index*2].state
|
||||
return gate.port_nets[index].state
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Gate.setportstate(gate, index, state)
|
||||
local port = gate.ports[index]
|
||||
if state ~= port.state then
|
||||
local group = port.group
|
||||
group.state_num = group.state_num - port.state + state
|
||||
port.state = state
|
||||
--if state ~= gate[index*2+1] then
|
||||
if state ~= gate.port_states[index] then
|
||||
--local group = gate[index*2]
|
||||
local group = gate.port_nets[index]
|
||||
--group.state_num = group.state_num - gate[index*2+1] + state
|
||||
group.state_num = group.state_num - gate.port_states[index] + state
|
||||
--gate[index*2+1] = state
|
||||
gate.port_states[index] = state
|
||||
|
||||
if (group.state_num>0) ~= (group.state==1) then
|
||||
if (group.state_num>0) ~= (group.state==1) and (group.in_queue==0) then
|
||||
Simulation.queuegroup(GSim, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Gate.preinit(gate)
|
||||
|
||||
end
|
||||
|
||||
function Gate.initdata(gate)
|
||||
gate.data = {}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user