1
0
mirror of https://github.com/mist64/perfect6502.git synced 2024-06-02 17:41:32 +00:00

added concept of dependants - same speed, but might

lead to more optimization opportunities
This commit is contained in:
Michael Steil 2010-10-07 04:39:40 +00:00
parent 6e8fd7f401
commit c0d191a03f

View File

@ -125,6 +125,8 @@ nodenum_t nodes_gates[NODES][NODES];
nodenum_t nodes_c1c2s[NODES][2*NODES]; nodenum_t nodes_c1c2s[NODES][2*NODES];
count_t nodes_gatecount[NODES]; count_t nodes_gatecount[NODES];
count_t nodes_c1c2count[NODES]; count_t nodes_c1c2count[NODES];
nodenum_t nodes_dependants[NODES];
nodenum_t nodes_dependant[NODES][NODES];
/* /*
* The "value" propertiy of VCC and GND is never evaluated in the code, * The "value" propertiy of VCC and GND is never evaluated in the code,
@ -182,6 +184,10 @@ DECLARE_BITMAP(transistors_on, TRANSISTORS);
static inline void static inline void
set_transistors_on(transnum_t t, BOOL state) set_transistors_on(transnum_t t, BOOL state)
{ {
#ifdef BROKEN_TRANSISTORS
if (t == broken_transistor)
return;
#endif
set_bitmap(transistors_on, t, state); set_bitmap(transistors_on, t, state);
} }
@ -431,25 +437,6 @@ getGroupValue()
unsigned int broken_transistor = (unsigned int)-1; unsigned int broken_transistor = (unsigned int)-1;
#endif #endif
void
toggleTransistor(transnum_t tn)
{
#ifdef DEBUG
printf(" %s tn %d => %d--%d\n", __func__, tn, transistors_c1[tn], transistors_c2[tn]);
#endif
#ifdef BROKEN_TRANSISTORS
if (tn == broken_transistor) {
if (!get_transistors_on(tn))
return;
}
#endif
set_transistors_on(tn, !get_transistors_on(tn));
/* next time, we'll have to look at both nodes behind the transistor */
listout_add(transistors_c1[tn]);
listout_add(transistors_c2[tn]);
}
void void
recalcNode(nodenum_t node) recalcNode(nodenum_t node)
{ {
@ -479,8 +466,12 @@ printf(" %s node %d -> ", __func__, node);
nodenum_t nn = group_get(i); nodenum_t nn = group_get(i);
if (get_nodes_value(nn) != newv) { if (get_nodes_value(nn) != newv) {
set_nodes_value(nn, newv); set_nodes_value(nn, newv);
for (count_t t = 0; t < nodes_gatecount[nn]; t++) for (count_t t = 0; t < nodes_gatecount[nn]; t++) {
toggleTransistor(nodes_gates[nn][t]); transnum_t tn = nodes_gates[nn][t];
set_transistors_on(tn, !get_transistors_on(tn));
}
for (count_t g = 0; g < nodes_dependants[nn]; g++)
listout_add(nodes_dependant[nn][g]);
} }
} }
} }
@ -726,6 +717,16 @@ step()
unsigned int transistors; unsigned int transistors;
static inline void
add_nodes_dependant(nodenum_t a, nodenum_t b)
{
for (count_t g = 0; g < nodes_dependants[a]; g++)
if (nodes_dependant[a][g] == b)
return;
nodes_dependant[a][nodes_dependants[a]++] = b;
}
void void
setupNodesAndTransistors() setupNodesAndTransistors()
{ {
@ -778,17 +779,22 @@ setupNodesAndTransistors()
nodes_c1c2s[c2][nodes_c1c2count[c2]++] = i; nodes_c1c2s[c2][nodes_c1c2count[c2]++] = i;
} }
for (i = 0; i < NODES; i++) {
nodes_dependants[i] = 0;
for (count_t g = 0; g < nodes_gatecount[i]; g++) {
transnum_t t = nodes_gates[i][g];
add_nodes_dependant(i, transistors_c1[t]);
add_nodes_dependant(i, transistors_c2[t]);
}
}
#ifdef DEBUG #ifdef DEBUG
for (i = 0; i < NODES; i++) { for (i = 0; i < NODES; i++) {
printf("%d: ", i); printf("%d: ", i);
int count = 0; for (count_t g = 0; g < nodes_dependants[i]; g++) {
for (count_t g = 0; g < nodes_gatecount[i]; g++) { printf("%d ", nodes_dependant[i][g]);
transnum_t t = nodes_gates[i][g];
printf("%d/%d ", transistors_c1[t], transistors_c2[t]);
count += 2;
} }
printf("(%d)\n", count); printf("(%d)\n", nodes_dependants[i]);
} }
#endif #endif
} }