diff --git a/distribution/ReleaseNotes.txt b/distribution/ReleaseNotes.txt index 8a4ec69b7..beaf438fd 100644 --- a/distribution/ReleaseNotes.txt +++ b/distribution/ReleaseNotes.txt @@ -11,7 +11,7 @@ planned as v0.13 - added an enable input to the T flip-flop CAUTION: By default this input is activated now. In circuits which used the T flip-flop in the past, the new input needs to be disabled. -- A warning message shows up if a circuit with unnamed inputs/outputs is analysed. +- A warning message shows up if a circuit with unnamed inputs is analysed. - A warning message shows up if a circuit with missing pin numbers is exported to a hardware-related file. - Unidirectional FETs are added to overcome certain CMOS issues. diff --git a/src/main/java/de/neemann/digital/core/arithmetic/BarrelShifter.java b/src/main/java/de/neemann/digital/core/arithmetic/BarrelShifter.java index 865c67a85..2a2790c23 100644 --- a/src/main/java/de/neemann/digital/core/arithmetic/BarrelShifter.java +++ b/src/main/java/de/neemann/digital/core/arithmetic/BarrelShifter.java @@ -52,7 +52,7 @@ public class BarrelShifter extends Node implements Element { signed = attributes.get(Keys.BARREL_SIGNED); int sBits = 1; - while ((1 << sBits) < bits) + while ((1 << sBits) <= bits) sBits++; if (signed) diff --git a/src/test/java/de/neemann/digital/core/arithmetic/BarrelShifterTest.java b/src/test/java/de/neemann/digital/core/arithmetic/BarrelShifterTest.java index f80c47736..05e835715 100644 --- a/src/test/java/de/neemann/digital/core/arithmetic/BarrelShifterTest.java +++ b/src/test/java/de/neemann/digital/core/arithmetic/BarrelShifterTest.java @@ -26,6 +26,9 @@ public class BarrelShifterTest extends TestCase { bsTest.check(0b001100, -1, 0b000000); bsTest.check(0b001100, -4, 0b000000); bsTest.check(0b001100, -5, 0b100000); + + for (int s = 0; s < 7; s++) + bsTest.check(1, s, (1 << s) & 0b111111); } public void testRotateUnsignedLeft() throws Exception { @@ -39,6 +42,9 @@ public class BarrelShifterTest extends TestCase { bsTest.check(0b001100, -1, 0b011000); bsTest.check(0b001100, -4, 0b000011); bsTest.check(0b001100, -5, 0b100001); + + for (int s = 0; s < 7; s++) + bsTest.check(0b10101010, s, (s & 1) == 0 ? 0b10101010 : 0b01010101); } public void testNormalSignedLeft() throws Exception { @@ -115,20 +121,27 @@ public class BarrelShifterTest extends TestCase { } public void testShiftSizeCalculationTest() throws Exception { + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 1, 1); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 2, 2); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 3, 2); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 4, 3); getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 7, 3); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 8, 4); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 15, 4); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 16, 5); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 31, 5); + getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 32, 6); + + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 1, 2); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 2, 3); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 3, 3); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 4, 4); getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 7, 4); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.right, 7, 4); - getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 8, 3); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 8, 4); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.right, 8, 4); - getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 9, 4); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 9, 5); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.right, 9, 5); - getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 16, 4); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 16, 5); - getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 17, 5); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 17, 6); - getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.right, 17, 6); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 8, 5); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 15, 5); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 16, 6); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 31, 6); + getTestExecuter(BarrelShifterMode.rotate, true, LeftRightFormat.left, 32, 7); } private TestExecuter getTestExecuter(BarrelShifterMode mode, boolean signed, LeftRightFormat direction, int valueWidth, int shiftWidth) throws Exception {