more optimizations: move port states into gates, inline net queue checks

This commit is contained in:
Redo0
2021-06-05 18:41:50 -05:00
parent 14c61e35d1
commit 19d2e36fd6
6 changed files with 38 additions and 44 deletions

View File

@@ -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