fixed 64 bit bugs in basic gates, closes #234

This commit is contained in:
hneemann 2019-01-21 14:17:50 +01:00
parent a03781c606
commit 0cea738d74
14 changed files with 101 additions and 12 deletions

View File

@ -33,8 +33,8 @@ public class And extends Function {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
int f = -1;
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
long f = -1;
for (ObservableValue i : inputs) {
f &= i.getValue();
}

View File

@ -30,6 +30,6 @@ abstract class Function extends FanIn {
getOutput().setValue(value);
}
protected abstract int calculate(ArrayList<ObservableValue> inputs) throws NodeException;
protected abstract long calculate(ArrayList<ObservableValue> inputs) throws NodeException;
}

View File

@ -33,7 +33,7 @@ public class NAnd extends And {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
return ~super.calculate(inputs);
}
}

View File

@ -33,7 +33,7 @@ public class NOr extends Or {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
return ~super.calculate(inputs);
}
}

View File

@ -33,8 +33,8 @@ public class Or extends Function {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
int f = 0;
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
long f = 0;
for (ObservableValue i : inputs) {
f |= i.getValue();
}

View File

@ -33,7 +33,7 @@ public class XNOr extends XOr {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
return ~super.calculate(inputs);
}
}

View File

@ -33,8 +33,8 @@ public class XOr extends Function {
}
@Override
protected int calculate(ArrayList<ObservableValue> inputs) throws NodeException {
int f = 0;
protected long calculate(ArrayList<ObservableValue> inputs) throws NodeException {
long f = 0;
for (ObservableValue i : inputs) {
f ^= i.getValue();
}

View File

@ -33,4 +33,16 @@ public class AndTest extends TestCase {
sc.check(1, 0, 0);
sc.check(0, 1, 0);
}
public void testAnd64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
FanIn out = model.add(new And(new ElementAttributes().setBits(64)));
out.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
sc.check(0xff00000000000000L, 0x2200000000000000L, 0x2200000000000000L);
}
}

View File

@ -17,7 +17,7 @@ import static de.neemann.digital.core.ObservableValues.ovs;
*/
public class NAndTest extends TestCase {
public void testAnd() throws Exception {
public void testNAnd() throws Exception {
ObservableValue a = new ObservableValue("a", 1);
ObservableValue b = new ObservableValue("b", 1);
@ -34,4 +34,17 @@ public class NAndTest extends TestCase {
sc.check(1, 0, 1);
sc.check(0, 1, 1);
}
public void testNAnd64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
FanIn out = model.add(new NAnd(new ElementAttributes().setBits(64)));
out.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
sc.check(0xff00000000000000L, 0x2200000000000000L, 0xddffffffffffffffL);
}
}

View File

@ -34,4 +34,17 @@ public class NOrTest extends TestCase {
sc.check(0, 1, 0);
sc.check(0, 0, 1);
}
public void testNOr64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
FanIn and = model.add(new NOr(new ElementAttributes().setBits(64)));
and.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(and.getOutput());
sc.check(0xff00000000000000L, 0x2200000000000000L, 0x00ffffffffffffffL);
}
}

View File

@ -28,4 +28,15 @@ public class NotTest extends TestCase {
sc.check(2, 1);
sc.check(3, 0);
}
public void testNot64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
Model model = new Model();
Not out = model.add(new Not(new ElementAttributes().setBits(64)));
out.setInputs(a.asList());
TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(out.getOutputs());
sc.check(0xff00000000000000L, 0x00ffffffffffffffL);
}
}

View File

@ -34,4 +34,17 @@ public class OrTest extends TestCase {
sc.check(0, 1, 1);
sc.check(0, 0, 0);
}
public void testOr64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
FanIn and = model.add(new Or(new ElementAttributes().setBits(64)));
and.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(and.getOutput());
sc.check(0xff00000000000000L, 0x2200000000000000L, 0xff00000000000000L);
}
}

View File

@ -17,7 +17,7 @@ import static de.neemann.digital.core.ObservableValues.ovs;
*/
public class XNOrTest extends TestCase {
public void testXor() throws Exception {
public void testXNor() throws Exception {
ObservableValue a = new ObservableValue("a", 1);
ObservableValue b = new ObservableValue("b", 1);
@ -32,4 +32,18 @@ public class XNOrTest extends TestCase {
sc.check(0, 1, 0);
sc.check(1, 1, 1);
}
public void testXNor64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
XOr out = model.add(new XNOr(new ElementAttributes().setBits(64)));
out.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
sc.check(0x7e00000000000000L, 0x2200000000000000L, ~0x5c00000000000000L);
}
}

View File

@ -32,4 +32,17 @@ public class XOrTest extends TestCase {
sc.check(0, 1, 1);
sc.check(1, 1, 0);
}
public void testXor64() throws Exception {
ObservableValue a = new ObservableValue("a", 64);
ObservableValue b = new ObservableValue("b", 64);
Model model = new Model();
XOr out = model.add(new XOr(new ElementAttributes().setBits(64)));
out.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
sc.check(0x7e00000000000000L, 0x2200000000000000L, 0x5c00000000000000L);
}
}