Chipsim change of states to booleans, and performance

This commit is contained in:
Barry Silverman 2010-10-13 17:53:40 -04:00
parent 3258a24c91
commit 282c815791
3 changed files with 34 additions and 24 deletions

View File

@ -54,14 +54,20 @@ function recalcNode(node, recalclist){
if(node==npwr) return; if(node==npwr) return;
var group = getNodeGroup(node); var group = getNodeGroup(node);
var newv = getNodeValue(group); var newv = getNodeValue(group);
var newState = (newv[0]=='h');
var newFloat = (newv[1]=='f');
if(ctrace && (traceTheseNodes.indexOf(node)!=-1)) if(ctrace && (traceTheseNodes.indexOf(node)!=-1))
console.log('recalc', node, group); console.log('recalc', node, group);
for(var i in group){ for(var i in group){
var n = nodes[group[i]]; var n = nodes[group[i]];
if(n.state==newv)continue; /******Performance********/ var oldState = n.state;
if(n.state!=newv && ctrace && (traceTheseNodes.indexOf(n)!=-1)) if(n.state==newState && n.float==newFloat)continue; /******Performance********/
if(n.state!=newState && ctrace && (traceTheseNodes.indexOf(n)!=-1))
console.log(group[i], n.state, newv); console.log(group[i], n.state, newv);
n.state = newv; n.state = newState;
n.float = newFloat;
if(n.state==oldState)
continue;
for(var t in n.gates) recalcTransistor(n.gates[t], recalclist); for(var t in n.gates) recalcTransistor(n.gates[t], recalclist);
} }
} }
@ -96,12 +102,9 @@ function floatnode(nn){
if(nn==ngnd) return; if(nn==ngnd) return;
if(nn==npwr) return; if(nn==npwr) return;
var n = nodes[nn]; var n = nodes[nn];
if(n.state=='gnd') n.state = 'fl'; n.float = true;
if(n.state=='pd') n.state = 'fl';
if(n.state=='vcc') n.state = 'fh';
if(n.state=='pu') n.state = 'fh';
if(ctrace && (traceTheseNodes.indexOf(nn)!=-1)) if(ctrace && (traceTheseNodes.indexOf(nn)!=-1))
console.log('floating', nn, 'to', n.state); console.log('floating', nn, 'at', n.state);
} }
function addRecalcNode(nn, recalclist){ function addRecalcNode(nn, recalclist){
@ -137,16 +140,16 @@ function addNodeTransistor(node, t, group){
function getNodeValue(group){ function getNodeValue(group){
if(arrayContains(group, ngnd)) return 'gnd'; if(arrayContains(group, ngnd)) return 'l ';
if(arrayContains(group, npwr)) return 'vcc'; if(arrayContains(group, npwr)) return 'h ';
var flstate; var flstate;
for(var i in group){ for(var i in group){
var nn = group[i]; var nn = group[i];
var n = nodes[nn]; var n = nodes[nn];
if(n.pullup) return 'pu'; if(n.pullup) return 'h ';
if(n.pulldown) return 'pd'; if(n.pulldown) return 'l ';
if((n.state=='fl')&&(flstate==undefined)) flstate = 'fl'; if((!n.state && n.float)&&(flstate==undefined)) flstate = 'lf';
if(n.state=='fh') flstate = 'fh'; if(n.state && n.float) flstate = 'hf';
} }
if(flstate==undefined && ctrace) console.log(group); if(flstate==undefined && ctrace) console.log(group);
return flstate; return flstate;
@ -154,7 +157,7 @@ function getNodeValue(group){
function isNodeHigh(nn){ function isNodeHigh(nn){
return arrayContains(['vcc','pu','fh'], nodes[nn].state); return(nodes[nn].state);
} }
function saveString(name, str){ function saveString(name, str){
@ -172,23 +175,24 @@ function allNodes(){
} }
function stateString(){ function stateString(){
var codes = {gnd: 'g', vcc: 'v', pu: 'p', pd: 'd', fh: 'f', fl: 'l'}; var codes = ['g','l','h','f' ];
var res = ''; var res = '';
for(var i=0;i<1725;i++){ for(var i=0;i<1725;i++){
var n = nodes[i]; var n = nodes[i];
if(n==undefined) res+='x'; if(n==undefined) res+='x';
else if(i==ngnd) res+='g'; else if(i==ngnd) res+='g';
else if(i==npwr) res+='v'; else if(i==npwr) res+='h';
else res+= codes[n.state]; else res+= codes[n.state*2 + n.float];
} }
return res; return res;
} }
function showState(str){ function showState(str){
var codes = {g: 'gnd', v: 'vcc', p: 'pu', d: 'pd', f: 'fh', l: 'fl'}; var codes = {g: 'l ', h: 'h ', f: 'hf', l: 'lf'};
for(var i=0;i<str.length;i++){ for(var i=0;i<str.length;i++){
if(str[i]=='x') continue; if(str[i]=='x') continue;
nodes[i].state = codes[str[i]]; nodes[i].state = ((codes[str[i]])[0]=='h');
nodes[i].float = ((codes[str[i]])[1]=='f');
var gates = nodes[i].gates; var gates = nodes[i].gates;
for(var t in gates) transistors[gates[t]].on = isNodeHigh(i); for(var t in gates) transistors[gates[t]].on = isNodeHigh(i);
} }

View File

@ -121,9 +121,15 @@ function testNMI(n){
function initChip(){ function initChip(){
var start = now(); var start = now();
for(var nn in nodes) nodes[nn].state = 'fl'; for(var nn in nodes) {
nodes[ngnd].state = 'gnd'; nodes[nn].state = false;
nodes[npwr].state = 'vcc'; nodes[nn].float = true;
}
nodes[ngnd].state = false;
nodes[ngnd].float = false;
nodes[npwr].state = true;
nodes[npwr].float = false;
for(var tn in transistors) transistors[tn].on = false; for(var tn in transistors) transistors[tn].on = false;
setLow('res'); setLow('res');
setLow('clk0'); setLow('clk0');

View File

@ -36,7 +36,7 @@ function setupNodes(){
var w = seg[0]; var w = seg[0];
if(nodes[w]==undefined) if(nodes[w]==undefined)
nodes[w] = {segs: new Array(), num: w, pullup: seg[1]=='+', nodes[w] = {segs: new Array(), num: w, pullup: seg[1]=='+',
state: 'fl', gates: new Array(), c1c2s: new Array()}; state: false, float: true, gates: new Array(), c1c2s: new Array()};
if(w==ngnd) continue; if(w==ngnd) continue;
if(w==npwr) continue; if(w==npwr) continue;
nodes[w].segs.push(seg.slice(3)); nodes[w].segs.push(seg.slice(3));