CoreComponents now have a transport delay
authorFabian Stemmler <stemmler@in.tum.de>
Sun, 8 Sep 2019 14:21:39 +0000 (16:21 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Sun, 8 Sep 2019 14:21:39 +0000 (16:21 +0200)
There is now an issue with simultaneous signal changes, because the
generated events might not be executed in the order in which they are
created.

net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreBitDisplay.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreDemux.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreMux.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreTriStateBuffer.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/CoreNotGate.java
net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/MultiInputCoreGate.java
net.mograsim.logic.core/test/net/mograsim/logic/core/tests/TestCoreBitDisplay.java
net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryComponent.java

index 9f3da4a..369a05f 100644 (file)
@@ -3,6 +3,7 @@ package net.mograsim.logic.core.components;
 import net.mograsim.logic.core.LogicObservable;
 import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 
 /**
  * A basic component that recomputes all outputs (with a delay), when it is updated.
@@ -26,10 +27,12 @@ public abstract class BasicCoreComponent extends CoreComponent implements LogicO
        }
 
        @Override
-       public void update(LogicObservable initiator)
+       public final void update(LogicObservable initiator)
        {
-               timeline.addEvent(e -> compute(), processTime);
+               TimelineEventHandler delayedUpdates = compute();
+               if (delayedUpdates != null)
+                       timeline.addEvent(delayedUpdates, processTime);
        }
 
-       protected abstract void compute();
+       protected abstract TimelineEventHandler compute();
 }
index 8cd509c..345bc0a 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 import net.mograsim.logic.core.LogicObservable;
 import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
@@ -28,10 +29,14 @@ public class CoreBitDisplay extends BasicCoreComponent implements LogicObservabl
        }
 
        @Override
-       protected void compute()
+       protected TimelineEventHandler compute()
        {
-               displayedValue = in.getValues();
-               notifyObservers();
+               BitVector newValues = in.getValues();
+               return e ->
+               {
+                       displayedValue = newValues;
+                       notifyObservers();
+               };
        }
 
        public BitVector getDisplayedValue()
index a5bb0fc..76982e0 100644 (file)
@@ -3,6 +3,8 @@ package net.mograsim.logic.core.components;
 import java.util.List;
 
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
@@ -53,19 +55,27 @@ public class CoreDemux extends BasicCoreComponent
        }
 
        @Override
-       public void compute()
+       public TimelineEventHandler compute()
        {
                int selectValue = select.hasNumericValue() ? (int) select.getUnsignedValue() : -1;
                if (selectValue >= outputs.length)
                        selectValue = -1;
 
-               if (selected != selectValue && selected != -1)
-                       outputs[selected].clearSignals();
+               boolean hasOldSelection = selected != selectValue && selected != -1;
+               int oldSelection = selected;
+               boolean hasNewSelection = selectValue != -1;
+               int newSelection = selectValue;
+               BitVector inputValues = in.getValues();
 
                selected = selectValue;
 
-               if (selectValue != -1)
-                       outputs[selectValue].feedSignals(in.getValues());
+               return e ->
+               {
+                       if (hasOldSelection)
+                               outputs[oldSelection].clearSignals();
+                       if (hasNewSelection)
+                               outputs[newSelection].feedSignals(inputValues);
+               };
        }
 
        @Override
index b85168d..a47ad6b 100644 (file)
@@ -6,6 +6,8 @@ import java.util.Collections;
 import java.util.List;
 
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
@@ -66,17 +68,16 @@ public class CoreMux extends BasicCoreComponent
        }
 
        @Override
-       public void compute()
+       public TimelineEventHandler compute()
        {
                int selectValue;
                if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length)
                {
-                       out.clearSignals();
-                       return;
+                       return e -> out.clearSignals();
                }
 
-               ReadEnd active = inputs[selectValue];
-               out.feedSignals(active.getValues());
+               BitVector activeValues = inputs[selectValue].getValues();
+               return e -> out.feedSignals(activeValues);
        }
 
        @Override
index 6568d1b..4b7a339 100644 (file)
@@ -3,7 +3,9 @@ package net.mograsim.logic.core.components;
 import java.util.List;
 
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
 
@@ -28,12 +30,14 @@ public class CoreTriStateBuffer extends BasicCoreComponent
        }
 
        @Override
-       protected void compute()
+       protected TimelineEventHandler compute()
        {
                if (enable.getValue() == Bit.ONE)
-                       out.feedSignals(in.getValues());
-               else
-                       out.clearSignals();
+               {
+                       BitVector inValues = in.getValues();
+                       return e -> out.feedSignals(inValues);
+               }
+               return e -> out.clearSignals();
        }
 
        @Override
index 57f3a18..b7808be 100644 (file)
@@ -4,6 +4,8 @@ import java.util.List;
 
 import net.mograsim.logic.core.components.BasicCoreComponent;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
 
@@ -21,9 +23,10 @@ public class CoreNotGate extends BasicCoreComponent
        }
 
        @Override
-       protected void compute()
+       protected TimelineEventHandler compute()
        {
-               out.feedSignals(in.getValues().not());
+               BitVector values = in.getValues().not();
+               return e -> out.feedSignals(values);
        }
 
        public ReadEnd getIn()
index 59fc3cd..010ae74 100644 (file)
@@ -4,6 +4,7 @@ import java.util.List;
 
 import net.mograsim.logic.core.components.BasicCoreComponent;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
 import net.mograsim.logic.core.types.MutationOperation;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
@@ -53,11 +54,11 @@ public abstract class MultiInputCoreGate extends BasicCoreComponent
        }
 
        @Override
-       protected void compute()
+       public TimelineEventHandler compute()
        {
                BitVectorMutator mutator = BitVectorMutator.empty();
                for (ReadEnd w : in)
                        op.apply(mutator, w.getValues());
-               out.feedSignals(invert ? mutator.toBitVector().not() : mutator.toBitVector());
+               return e -> out.feedSignals(invert ? mutator.toBitVector().not() : mutator.toBitVector());
        }
 }
index 2e5e5fd..5056345 100644 (file)
@@ -6,6 +6,7 @@ import java.util.function.LongConsumer;
 
 import net.mograsim.logic.core.components.CoreBitDisplay;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 
@@ -39,9 +40,13 @@ public final class TestCoreBitDisplay extends CoreBitDisplay
        }
 
        @Override
-       protected void compute()
+       protected TimelineEventHandler compute()
        {
-               super.compute();
-               System.out.println("update: value is " + getDisplayedValue());
+               TimelineEventHandler handler = super.compute();
+               return e ->
+               {
+                       handler.handle(e);
+                       System.out.println("update: value is " + getDisplayedValue());
+               };
        }
 }
index 3c135ec..b965dba 100644 (file)
@@ -4,7 +4,9 @@ import java.util.List;
 
 import net.mograsim.logic.core.components.BasicCoreComponent;
 import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
 import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
 import net.mograsim.machine.MainMemoryDefinition;
@@ -47,23 +49,28 @@ public class WordAddressableMemoryComponent extends BasicCoreComponent
        }
 
        @Override
-       protected void compute()
+       protected TimelineEventHandler compute()
        {
                if (!address.hasNumericValue())
                {
                        if (read.equals(rWBit.getValue()))
-                               data.feedSignals(Bit.U.toVector(data.width()));
-                       else
-                               data.clearSignals();
-                       return;
+                               return e -> data.feedSignals(Bit.U.toVector(data.width()));
+                       return e -> data.clearSignals();
                }
                long addressed = address.getUnsignedValue();
                if (read.equals(rWBit.getValue()))
-                       data.feedSignals(memory.getCell(addressed));
+               {
+                       BitVector storedData = memory.getCell(addressed);
+                       return e -> data.feedSignals(storedData);
+               }
                else
                {
-                       data.clearSignals();
-                       memory.setCell(addressed, data.getValues());
+                       BitVector transData = data.getValues();
+                       return e ->
+                       {
+                               data.clearSignals();
+                               memory.setCell(addressed, transData);
+                       };
                }
        }