use of de.neemann.digital.TestExecuter in project Digital by hneemann.
the class AddTest method testAdd.
public void testAdd() throws Exception {
ObservableValue a = new ObservableValue("a", 4);
ObservableValue b = new ObservableValue("b", 4);
ObservableValue c = new ObservableValue("c", 1);
Model model = new Model();
Add node = new Add(new ElementAttributes().setBits(4));
node.setInputs(ovs(a, b, c));
model.add(node);
TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
sc.check(0, 0, 0, 0, 0);
sc.check(0, 0, 1, 1, 0);
sc.check(2, 3, 0, 5, 0);
sc.check(2, 3, 1, 6, 0);
sc.check(7, 7, 0, 14, 0);
sc.check(8, 8, 0, 0, 1);
sc.check(8, 8, 1, 1, 1);
}
use of de.neemann.digital.TestExecuter in project Digital by hneemann.
the class BarrelShifterTest method getTestExecuter.
private TestExecuter getTestExecuter(BarrelShifterMode mode, boolean signed, LeftRightFormat direction, int valueWidth, int shiftWidth) throws Exception {
ObservableValue value = new ObservableValue("value", valueWidth);
ObservableValue shift = new ObservableValue("shift", shiftWidth);
ElementAttributes attributes = new ElementAttributes().set(Keys.BARREL_SHIFTER_MODE, mode).set(Keys.BARREL_SIGNED, signed).set(Keys.DIRECTION, direction).set(Keys.BITS, valueWidth);
Model model = new Model();
BarrelShifter bs = new BarrelShifter(attributes);
bs.setInputs(ovs(value, shift));
model.add(bs);
ObservableValues outputs = bs.getOutputs();
assertEquals(1, outputs.size());
assertEquals(value.getBits(), outputs.get(0).getBits());
return new TestExecuter(model).setInputs(value, shift).setOutputs(outputs);
}
use of de.neemann.digital.TestExecuter in project Digital by hneemann.
the class BarrelShifterTest method test64Bit.
public void test64Bit() throws Exception {
TestExecuter bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 64, 7);
bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
bsTest.check(0xC000000000000000L, 1, 0x8000000000000001L);
bsTest.check(0x8000000000000001L, 1, 0x0000000000000003L);
bsTest.check(0x4000000000000001L, 1, 0x8000000000000002L);
bsTest = getTestExecuter(BarrelShifterMode.arithmetic, false, LeftRightFormat.left, 64, 7);
bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
bsTest.check(0x4000000000000000L, 1, 0x8000000000000000L);
bsTest.check(0x2000000000000000L, 1, 0x4000000000000000L);
bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.left, 64, 7);
bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
bsTest.check(0x4000000000000000L, 1, 0x8000000000000000L);
bsTest.check(0x2000000000000000L, 1, 0x4000000000000000L);
bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.right, 64, 7);
bsTest.check(0xC000000000000001L, 0, 0xC000000000000001L);
bsTest.check(0x8000000000000001L, 1, 0xC000000000000000L);
bsTest.check(0x4000000000000001L, 1, 0xA000000000000000L);
bsTest = getTestExecuter(BarrelShifterMode.arithmetic, false, LeftRightFormat.right, 64, 7);
bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
bsTest.check(0x8000000000000000L, 1, 0xC000000000000000L);
bsTest.check(0x4000000000000000L, 1, 0x2000000000000000L);
bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.right, 64, 7);
bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
bsTest.check(0x8000000000000000L, 1, 0x4000000000000000L);
bsTest.check(0x4000000000000000L, 1, 0x2000000000000000L);
}
use of de.neemann.digital.TestExecuter in project Digital by hneemann.
the class BarrelShifterTest method testRotateUnsignedLeft.
public void testRotateUnsignedLeft() throws Exception {
TestExecuter bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 6, 3);
bsTest.check(0b001100, 0, 0b001100);
bsTest.check(0b001100, 1, 0b011000);
bsTest.check(0b001100, 2, 0b110000);
bsTest.check(0b010001, 2, 0b000101);
bsTest.check(0b001100, 3, 0b100001);
bsTest.check(0b001100, 5, 0b000110);
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);
}
use of de.neemann.digital.TestExecuter in project Digital by hneemann.
the class BarrelShifterTest method testNormalUnsignedRight.
public void testNormalUnsignedRight() throws Exception {
TestExecuter bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.right, 6, 3);
bsTest.check(0b001100, 0, 0b001100);
bsTest.check(0b001100, 1, 0b000110);
bsTest.check(0b001100, 2, 0b000011);
bsTest.check(0b010001, 2, 0b000100);
bsTest.check(0b001100, 3, 0b000001);
bsTest.check(0b001100, 5, 0b000000);
bsTest.check(0b001100, -1, 0b000000);
bsTest.check(0b001100, -4, 0b000000);
bsTest.check(0b001100, -5, 0b000001);
}
Aggregations