detect more switches as directed simple switches

This commit is contained in:
hneemann 2017-06-23 15:31:24 +02:00
parent 08f92d2e5c
commit 26e3fe89af
6 changed files with 174 additions and 99 deletions

View File

@ -76,8 +76,19 @@ public class Switch implements Element, NodeInterface {
constant = in2.searchConstant();
if (constant != null)
switchModel = new SimpleSwitch(constant, output1);
else
switchModel = new RealSwitch(in1, in2);
else {
// not a constant
boolean def1 = in1.isAlwaysDefined();
boolean def2 = in2.isAlwaysDefined();
if (def1 == def2)
switchModel = new RealSwitch(in1, in2);
else {
if (def1)
switchModel = new SimpleSwitch(input1, output2);
else
switchModel = new SimpleSwitch(input2, output1);
}
}
}
} else {
switchModel = new SimpleSwitch(input1, output2);

View File

@ -63,7 +63,7 @@ public final class CommonBusValue extends ObservableValue implements NodeInterfa
/**
* Returns true if this net is a constant
*
* @return true if this is a constant
* @return the constant if this is a constant, null otherwise
*/
public ObservableValue searchConstant() {
for (ObservableValue i : inputs)
@ -72,6 +72,19 @@ public final class CommonBusValue extends ObservableValue implements NodeInterfa
return null;
}
/**
* Checks if this net is always defined.
* This means it can never be in a high z state.
*
* @return true if this net is always defined
*/
public boolean isAlwaysDefined() {
for (ObservableValue i : inputs)
if (!i.supportsHighZ())
return true;
return false;
}
@Override
public String toString() {
return "CommonBusValue{"

View File

@ -4,7 +4,10 @@
<attributes>
<entry>
<string>Description</string>
<string>10 Transistor Full Adder</string>
<string>10 Transistor Full Adder
The drivers represent p-channel fets. Needed to
avoid the resistance problem
(see https://github.com/hneemann/Digital/issues/30).</string>
</entry>
</attributes>
<visualElements>
@ -51,10 +54,6 @@
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Failing</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
@ -140,16 +139,6 @@
</elementAttributes>
<pos x="780" y="560"/>
</visualElement>
<visualElement>
<elementName>PFET</elementName>
<elementAttributes/>
<pos x="840" y="320"/>
</visualElement>
<visualElement>
<elementName>PFET</elementName>
<elementAttributes/>
<pos x="900" y="320"/>
</visualElement>
<visualElement>
<elementName>NFET</elementName>
<elementAttributes/>
@ -215,6 +204,34 @@
<elementAttributes/>
<pos x="1020" y="360"/>
</visualElement>
<visualElement>
<elementName>DriverInvSel</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="3"/>
</entry>
<entry>
<string>flipSelPos</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="860" y="340"/>
</visualElement>
<visualElement>
<elementName>DriverInvSel</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="3"/>
</entry>
<entry>
<string>flipSelPos</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="920" y="340"/>
</visualElement>
</visualElements>
<wires>
<wire>
@ -229,22 +246,10 @@
<p1 x="1080" y="320"/>
<p2 x="1100" y="320"/>
</wire>
<wire>
<p1 x="880" y="320"/>
<p2 x="900" y="320"/>
</wire>
<wire>
<p1 x="800" y="320"/>
<p2 x="840" y="320"/>
</wire>
<wire>
<p1 x="1100" y="320"/>
<p2 x="1120" y="320"/>
</wire>
<wire>
<p1 x="960" y="240"/>
<p2 x="1160" y="240"/>
</wire>
<wire>
<p1 x="1120" y="480"/>
<p2 x="1140" y="480"/>
@ -257,6 +262,26 @@
<p1 x="1120" y="260"/>
<p2 x="1140" y="260"/>
</wire>
<wire>
<p1 x="1100" y="460"/>
<p2 x="1160" y="460"/>
</wire>
<wire>
<p1 x="780" y="620"/>
<p2 x="1160" y="620"/>
</wire>
<wire>
<p1 x="960" y="240"/>
<p2 x="1160" y="240"/>
</wire>
<wire>
<p1 x="800" y="340"/>
<p2 x="840" y="340"/>
</wire>
<wire>
<p1 x="880" y="340"/>
<p2 x="900" y="340"/>
</wire>
<wire>
<p1 x="780" y="500"/>
<p2 x="860" y="500"/>
@ -271,12 +296,16 @@
</wire>
<wire>
<p1 x="780" y="280"/>
<p2 x="860" y="280"/>
<p2 x="800" y="280"/>
</wire>
<wire>
<p1 x="860" y="280"/>
<p2 x="880" y="280"/>
</wire>
<wire>
<p1 x="800" y="280"/>
<p2 x="860" y="280"/>
</wire>
<wire>
<p1 x="800" y="440"/>
<p2 x="860" y="440"/>
@ -325,29 +354,21 @@
<p1 x="1060" y="540"/>
<p2 x="1120" y="540"/>
</wire>
<wire>
<p1 x="1100" y="460"/>
<p2 x="1160" y="460"/>
</wire>
<wire>
<p1 x="780" y="620"/>
<p2 x="1160" y="620"/>
</wire>
<wire>
<p1 x="800" y="260"/>
<p2 x="800" y="280"/>
</wire>
<wire>
<p1 x="800" y="320"/>
<p2 x="800" y="440"/>
</wire>
<wire>
<p1 x="800" y="280"/>
<p2 x="800" y="320"/>
</wire>
<wire>
<p1 x="800" y="320"/>
<p2 x="800" y="340"/>
</wire>
<wire>
<p1 x="800" y="340"/>
<p2 x="800" y="440"/>
</wire>
<wire>
<p1 x="880" y="280"/>
<p2 x="880" y="320"/>
<p2 x="880" y="340"/>
</wire>
<wire>
<p1 x="880" y="380"/>
@ -474,4 +495,5 @@
<p2 x="1100" y="460"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>

View File

@ -4,7 +4,10 @@
<attributes>
<entry>
<string>Description</string>
<string>Static Energy Recovery Full Adder (SERF)</string>
<string>Static Energy Recovery Full Adder (SERF)
The drivers represent n-channel fets. Needed to
avoid the resistance problem
(see https://github.com/hneemann/Digital/issues/30).</string>
</entry>
</attributes>
<visualElements>
@ -33,21 +36,11 @@
<elementAttributes/>
<pos x="840" y="320"/>
</visualElement>
<visualElement>
<elementName>NFET</elementName>
<elementAttributes/>
<pos x="800" y="400"/>
</visualElement>
<visualElement>
<elementName>PFET</elementName>
<elementAttributes/>
<pos x="840" y="260"/>
</visualElement>
<visualElement>
<elementName>NFET</elementName>
<elementAttributes/>
<pos x="880" y="400"/>
</visualElement>
<visualElement>
<elementName>PFET</elementName>
<elementAttributes/>
@ -63,11 +56,6 @@
<elementAttributes/>
<pos x="1080" y="380"/>
</visualElement>
<visualElement>
<elementName>NFET</elementName>
<elementAttributes/>
<pos x="1120" y="460"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
@ -83,11 +71,6 @@
<elementAttributes/>
<pos x="1120" y="580"/>
</visualElement>
<visualElement>
<elementName>NFET</elementName>
<elementAttributes/>
<pos x="1040" y="460"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
@ -111,10 +94,6 @@
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Failing</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
@ -210,8 +189,60 @@
<elementAttributes/>
<pos x="1100" y="300"/>
</visualElement>
<visualElement>
<elementName>Driver</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
</elementAttributes>
<pos x="900" y="420"/>
</visualElement>
<visualElement>
<elementName>Driver</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
</elementAttributes>
<pos x="1140" y="480"/>
</visualElement>
<visualElement>
<elementName>Driver</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
</elementAttributes>
<pos x="1060" y="480"/>
</visualElement>
<visualElement>
<elementName>Driver</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
</elementAttributes>
<pos x="820" y="420"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="1100" y="480"/>
<p2 x="1120" y="480"/>
</wire>
<wire>
<p1 x="1020" y="480"/>
<p2 x="1040" y="480"/>
</wire>
<wire>
<p1 x="780" y="480"/>
<p2 x="900" y="480"/>
</wire>
<wire>
<p1 x="740" y="320"/>
<p2 x="780" y="320"/>
@ -224,10 +255,6 @@
<p1 x="780" y="320"/>
<p2 x="840" y="320"/>
</wire>
<wire>
<p1 x="780" y="480"/>
<p2 x="900" y="480"/>
</wire>
<wire>
<p1 x="1140" y="640"/>
<p2 x="1180" y="640"/>
@ -236,6 +263,14 @@
<p1 x="1020" y="640"/>
<p2 x="1100" y="640"/>
</wire>
<wire>
<p1 x="860" y="420"/>
<p2 x="880" y="420"/>
</wire>
<wire>
<p1 x="780" y="420"/>
<p2 x="800" y="420"/>
</wire>
<wire>
<p1 x="740" y="260"/>
<p2 x="760" y="260"/>
@ -276,22 +311,6 @@
<p1 x="760" y="720"/>
<p2 x="1140" y="720"/>
</wire>
<wire>
<p1 x="1100" y="500"/>
<p2 x="1120" y="500"/>
</wire>
<wire>
<p1 x="1020" y="500"/>
<p2 x="1040" y="500"/>
</wire>
<wire>
<p1 x="860" y="440"/>
<p2 x="880" y="440"/>
</wire>
<wire>
<p1 x="780" y="440"/>
<p2 x="800" y="440"/>
</wire>
<wire>
<p1 x="1060" y="440"/>
<p2 x="1100" y="440"/>
@ -409,7 +428,7 @@
<p2 x="1100" y="440"/>
</wire>
<wire>
<p1 x="1100" y="500"/>
<p1 x="1100" y="480"/>
<p2 x="1100" y="520"/>
</wire>
<wire>
@ -425,7 +444,7 @@
<p2 x="860" y="260"/>
</wire>
<wire>
<p1 x="860" y="440"/>
<p1 x="860" y="420"/>
<p2 x="860" y="460"/>
</wire>
<wire>
@ -434,22 +453,22 @@
</wire>
<wire>
<p1 x="780" y="320"/>
<p2 x="780" y="440"/>
<p2 x="780" y="420"/>
</wire>
<wire>
<p1 x="780" y="440"/>
<p1 x="780" y="420"/>
<p2 x="780" y="480"/>
</wire>
<wire>
<p1 x="1020" y="380"/>
<p2 x="1020" y="500"/>
<p2 x="1020" y="480"/>
</wire>
<wire>
<p1 x="1020" y="540"/>
<p2 x="1020" y="640"/>
</wire>
<wire>
<p1 x="1020" y="500"/>
<p1 x="1020" y="480"/>
<p2 x="1020" y="540"/>
</wire>
</wires>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>NFET</elementName>
@ -50,6 +51,10 @@
<string>Label</string>
<string>S</string>
</entry>
<entry>
<string>isHighZ</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="500" y="280"/>
</visualElement>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>In</elementName>
@ -45,6 +46,10 @@
<string>Label</string>
<string>D</string>
</entry>
<entry>
<string>isHighZ</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="500" y="280"/>
</visualElement>