diff --git a/src/main/java/de/neemann/digital/core/switching/Switch.java b/src/main/java/de/neemann/digital/core/switching/Switch.java index 89a1a27a4..8fe81a74d 100644 --- a/src/main/java/de/neemann/digital/core/switching/Switch.java +++ b/src/main/java/de/neemann/digital/core/switching/Switch.java @@ -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); diff --git a/src/main/java/de/neemann/digital/core/wiring/bus/CommonBusValue.java b/src/main/java/de/neemann/digital/core/wiring/bus/CommonBusValue.java index f4dea1338..470700d9e 100644 --- a/src/main/java/de/neemann/digital/core/wiring/bus/CommonBusValue.java +++ b/src/main/java/de/neemann/digital/core/wiring/bus/CommonBusValue.java @@ -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{" diff --git a/src/test/resources/dig/test/fet/cmos10TFullAdder.dig b/src/test/resources/dig/test/fet/cmos10TFullAdder.dig index 226b60599..0c63bfaef 100644 --- a/src/test/resources/dig/test/fet/cmos10TFullAdder.dig +++ b/src/test/resources/dig/test/fet/cmos10TFullAdder.dig @@ -4,7 +4,10 @@ Description - 10 Transistor Full Adder + 10 Transistor Full Adder +The drivers represent p-channel fets. Needed to +avoid the resistance problem +(see https://github.com/hneemann/Digital/issues/30). @@ -51,10 +54,6 @@ Testcase - - Label - Failing - Testdata @@ -140,16 +139,6 @@ - - PFET - - - - - PFET - - - NFET @@ -215,6 +204,34 @@ + + DriverInvSel + + + rotation + + + + flipSelPos + true + + + + + + DriverInvSel + + + rotation + + + + flipSelPos + true + + + + @@ -229,22 +246,10 @@ - - - - - - - - - - - - @@ -257,6 +262,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -271,12 +296,16 @@ - + + + + + @@ -325,29 +354,21 @@ - - - - - - - - - - - - - - - - + + + + + + + + - + @@ -474,4 +495,5 @@ + \ No newline at end of file diff --git a/src/test/resources/dig/test/fet/cmosSERFFullAdder.dig b/src/test/resources/dig/test/fet/cmosSERFFullAdder.dig index 31f1e88e3..84e6d5485 100644 --- a/src/test/resources/dig/test/fet/cmosSERFFullAdder.dig +++ b/src/test/resources/dig/test/fet/cmosSERFFullAdder.dig @@ -4,7 +4,10 @@ Description - Static Energy Recovery Full Adder (SERF) + 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). @@ -33,21 +36,11 @@ - - NFET - - - PFET - - NFET - - - PFET @@ -63,11 +56,6 @@ - - NFET - - - In @@ -83,11 +71,6 @@ - - NFET - - - Out @@ -111,10 +94,6 @@ Testcase - - Label - Failing - Testdata @@ -210,8 +189,60 @@ + + Driver + + + rotation + + + + + + + Driver + + + rotation + + + + + + + Driver + + + rotation + + + + + + + Driver + + + rotation + + + + + + + + + + + + + + + + + @@ -224,10 +255,6 @@ - - - - @@ -236,6 +263,14 @@ + + + + + + + + @@ -276,22 +311,6 @@ - - - - - - - - - - - - - - - - @@ -409,7 +428,7 @@ - + @@ -425,7 +444,7 @@ - + @@ -434,22 +453,22 @@ - + - + - + - + diff --git a/src/test/resources/dig/test/fet/nchan.dig b/src/test/resources/dig/test/fet/nchan.dig index 30a02d52f..d0370b3f1 100644 --- a/src/test/resources/dig/test/fet/nchan.dig +++ b/src/test/resources/dig/test/fet/nchan.dig @@ -1,6 +1,7 @@ 1 + NFET @@ -50,6 +51,10 @@ Label S + + isHighZ + true + diff --git a/src/test/resources/dig/test/fet/pchan.dig b/src/test/resources/dig/test/fet/pchan.dig index cdcca4c48..d329c99fa 100644 --- a/src/test/resources/dig/test/fet/pchan.dig +++ b/src/test/resources/dig/test/fet/pchan.dig @@ -1,6 +1,7 @@ 1 + In @@ -45,6 +46,10 @@ Label D + + isHighZ + true +