From 9c98bb5456a7ead6d92fcc6acd9d1497688b244d Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Sun, 15 Sep 2019 18:15:06 +0200 Subject: [PATCH] Removed old and incorrect CoreWire#get(Un)SignedValue --- .../logic/core/components/CoreDemux.java | 2 +- .../logic/core/components/CoreMux.java | 2 +- .../mograsim/logic/core/types/BitVector.java | 25 +++++ .../mograsim/logic/core/wires/CoreWire.java | 98 ------------------- .../logic/core/tests/CoreComponentTest.java | 10 +- .../CoreMicroInstructionMemory.java | 4 +- .../memory/CoreWordAddressableMemory.java | 4 +- .../memory/WordAddressableMemoryTest.java | 1 - 8 files changed, 36 insertions(+), 110 deletions(-) diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreDemux.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreDemux.java index 76982e00..8f4fe428 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreDemux.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreDemux.java @@ -57,7 +57,7 @@ public class CoreDemux extends BasicCoreComponent @Override public TimelineEventHandler compute() { - int selectValue = select.hasNumericValue() ? (int) select.getUnsignedValue() : -1; + int selectValue = select.getValues().isBinary() ? (int) select.getValues().getUnsignedValueLong() : -1; if (selectValue >= outputs.length) selectValue = -1; diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreMux.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreMux.java index a47ad6b5..5b4220a5 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreMux.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreMux.java @@ -71,7 +71,7 @@ public class CoreMux extends BasicCoreComponent public TimelineEventHandler compute() { int selectValue; - if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) + if (!select.getValues().isBinary() || (selectValue = (int) select.getValues().getUnsignedValueLong()) >= inputs.length) { return e -> out.clearSignals(); } diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java index ee957566..13466949 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java @@ -437,6 +437,31 @@ public final class BitVector implements StrictLogicType, Iterabletrue if all bits are either Bit.ONE or Bit.ZERO (they do not all have to have the same - * value), not Bit.U, Bit.X or Bit.Z. false is returned otherwise. - * - * @author Fabian Stemmler - */ - public boolean hasNumericValue() - { - return getValues().isBinary(); - } - - /** - * The {@link CoreWire} is interpreted as an unsigned integer with n bits. - * - * @return The unsigned value of the {@link CoreWire}'s bits, where value 0 corresponds with 2^0, value 1 is 2^1 and so on. - * - * @author Fabian Stemmler - */ - public long getUnsignedValue() - { - long val = 0; - long mask = 1; - for (Bit bit : getValues()) - { - switch (bit) - { - default: - case Z: - case X: - return 0; // TODO: Proper handling for getUnsignedValue(), if not all bits are 1 or 0; - case ONE: - val |= mask; - break; - case ZERO: - } - mask = mask << 1; - } - return val; - } - - /** - * The {@link CoreWire} is interpreted as a signed integer with n bits. - * - * @return The signed value of the {@link CoreWire}'s bits, where value 0 corresponds with 2^0, value 1 is 2^1 and so on. - * - * @author Fabian Stemmler - */ - public long getSignedValue() - { - long val = getUnsignedValue(); - long mask = 1 << (width - 1); - if ((mask & val) != 0) - { - int shifts = 64 - width; - return (val << shifts) >> shifts; - } - return val; - } - /** * Returns the least significant bit (LSB) */ @@ -326,43 +265,6 @@ public class CoreWire return CoreWire.this.getValues(start, end); } - /** - * The {@link CoreWire} is interpreted as an unsigned integer with n bits. - * - * @return true if all bits are either Bit.ONE or Bit.ZERO (they do not all have to have the - * same value), not Bit.X or Bit.Z. false is returned otherwise. - * - * @author Fabian Stemmler - */ - public boolean hasNumericValue() - { - return CoreWire.this.hasNumericValue(); - } - - /** - * The {@link CoreWire} is interpreted as an unsigned integer with n bits. - * - * @return The unsigned value of the {@link CoreWire}'s bits, where value 0 corresponds with 2^0, value 1 is 2^1 and so on. - * - * @author Fabian Stemmler - */ - public long getUnsignedValue() - { - return CoreWire.this.getUnsignedValue(); - } - - /** - * The {@link CoreWire} is interpreted as a signed integer with n bits. - * - * @return The signed value of the {@link CoreWire}'s bits, where value 0 corresponds with 2^0, value 1 is 2^1 and so on. - * - * @author Fabian Stemmler - */ - public long getSignedValue() - { - return CoreWire.this.getSignedValue(); - } - @Override public String toString() { diff --git a/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/CoreComponentTest.java b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/CoreComponentTest.java index ebebd6bf..12df5844 100644 --- a/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/CoreComponentTest.java +++ b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/CoreComponentTest.java @@ -218,7 +218,7 @@ class CoreComponentTest t.executeAll(); assertBitArrayEquals(out.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO); - selectIn.feedSignals(Bit.ZERO, Bit.ONE); + selectIn.feedSignals(Bit.ONE, Bit.ZERO); t.executeAll(); assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE); @@ -247,7 +247,7 @@ class CoreComponentTest assertBitArrayEquals(a.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO); assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U); assertBitArrayEquals(c.getValues(), Bit.U, Bit.U, Bit.U, Bit.U); - selectIn.feedSignals(Bit.ZERO, Bit.ONE); + selectIn.feedSignals(Bit.ONE, Bit.ZERO); t.executeAll(); assertBitArrayEquals(a.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z); @@ -382,12 +382,12 @@ class CoreComponentTest void numericValueTest() { CoreWire a = new CoreWire(t, 4, 1); - a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ONE, Bit.ONE); + a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ONE); t.executeAll(); - assertEquals(15, a.getUnsignedValue()); - assertEquals(-1, a.getSignedValue()); + assertEquals(11, a.getValues().getUnsignedValueLong()); + assertEquals(-5, a.getValues().getSignedValueLong()); } boolean flag = false; diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java b/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java index 12b44ddd..73940280 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java +++ b/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java @@ -47,11 +47,11 @@ public class CoreMicroInstructionMemory extends BasicCoreComponent @Override protected TimelineEventHandler compute() { - if (!address.hasNumericValue()) + if (!address.getValues().isBinary()) { return e -> data.feedSignals(Bit.U.toVector(data.width()));// TODO don't always feed U, but decide to feed X or U. } - long addressed = address.getUnsignedValue(); + long addressed = address.getValues().getUnsignedValueLong(); BitVector storedData = memory.getCell(addressed).toBitVector(); return e -> data.feedSignals(storedData); } diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java index dcbd25ef..ca557a6b 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java @@ -58,13 +58,13 @@ public class CoreWordAddressableMemory extends BasicCoreComponent @Override protected TimelineEventHandler compute() { - if (!address.hasNumericValue()) + if (!address.getValues().isBinary()) { if (read.equals(rWBit.getValue())) return e -> data.feedSignals(Bit.U.toVector(data.width()));// TODO don't always feed U, but decide to feed X or U. return e -> data.clearSignals(); } - long addressed = address.getUnsignedValue(); + long addressed = address.getValues().getUnsignedValueLong(); if (read.equals(rWBit.getValue())) { BitVector storedData = memory.getCell(addressed); diff --git a/net.mograsim.machine/test/net/mograsim/machine/standard/memory/WordAddressableMemoryTest.java b/net.mograsim.machine/test/net/mograsim/machine/standard/memory/WordAddressableMemoryTest.java index 5adfc253..9d38b894 100644 --- a/net.mograsim.machine/test/net/mograsim/machine/standard/memory/WordAddressableMemoryTest.java +++ b/net.mograsim.machine/test/net/mograsim/machine/standard/memory/WordAddressableMemoryTest.java @@ -40,7 +40,6 @@ class WordAddressableMemoryTest for (int i = 0; i < 50; i++) { String sAddress = String.format("%64s", BigInteger.valueOf(4096 + i + j).toString(2)).replace(' ', '0'); - sAddress = new StringBuilder(sAddress).reverse().toString(); BitVector bAddress = BitVector.parse(sAddress); addressI.feedSignals(bAddress); t.executeAll(); -- 2.17.1