Skip to content
Permalink
Browse files

Remove packing constraints (more changes)

  • Loading branch information...
akosba committed Feb 19, 2019
1 parent 391d0e7 commit d12b6d93a0ec1760ffe34b7f36e4fb4d8562ca93
@@ -36,5 +36,4 @@
public static boolean hexOutputEnabled = properties.getProperty("PRINT_HEX").equals("1");
public static boolean outputVerbose = properties.getProperty("OUTPUT_VERBOSE").equals("1");
public static boolean debugVerbose = properties.getProperty("DEBUG_VERBOSE").equals("1");
public static boolean promotePackOutput = false;
}
@@ -175,10 +175,11 @@ public Wire createProverWitnessWire(String... desc) {
public Wire makeOutput(Wire wire, String... desc) {
Wire outputWire = wire;
if (!(wire instanceof VariableWire || wire instanceof VariableBitWire) || inWires.contains(wire)) {
wire.packIfNeeded();
outputWire = makeVariable(wire, desc);
} else if (inWires.contains(wire) || proverWitnessWires.contains(wire)) {
outputWire = makeVariable(wire, desc);
} else if (wire instanceof VariableWire) {
} else {
wire.packIfNeeded();
}

@@ -214,17 +215,13 @@ protected Wire makeVariable(Wire wire, String... desc) {
}

public void addDebugInstruction(Wire w, String... desc) {
if (w instanceof VariableWire) {
w.packIfNeeded();
}
w.packIfNeeded();
addToEvaluationQueue(new WireLabelInstruction(LabelType.debug, w, desc));
}

public void addDebugInstruction(Wire[] wires, String... desc) {
for (int i = 0; i < wires.length; i++) {
if (wires[i] instanceof VariableWire) {
wires[i].packIfNeeded();
}
wires[i].packIfNeeded();
addToEvaluationQueue(
new WireLabelInstruction(LabelType.debug, wires[i], desc.length > 0 ? (desc[0] + " - " + i) : ""));
}
@@ -369,12 +366,9 @@ public void addAssertion(Wire w1, Wire w2, Wire w3, String... desc) {
throw new RuntimeException("Assertion failed on the provided constant wires .. ");
}
} else {
if(w1 instanceof VariableWire)
w1.packIfNeeded();
if(w2 instanceof VariableWire)
w2.packIfNeeded();
if(w3 instanceof VariableWire)
w3.packIfNeeded();
w1.packIfNeeded();
w2.packIfNeeded();
w3.packIfNeeded();
Instruction op = new AssertBasicOp(w1, w2, w3, desc);
addToEvaluationQueue(op);
}
@@ -258,7 +258,7 @@ public Wire xorBitwise(Wire w, int numBits, String... desc) {
WireArray result = bits1.xorWireArray(bits2, numBits, desc);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -278,7 +278,7 @@ public Wire andBitwise(Wire w, int numBits, String... desc) {
WireArray result = bits1.andWireArray(bits2, numBits, desc);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -298,7 +298,7 @@ public Wire orBitwise(Wire w, int numBits, String... desc) {
WireArray result = bits1.orWireArray(bits2, numBits, desc);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -412,7 +412,7 @@ public Wire rotateLeft(int numBits, int s, String... desc) {
WireArray result = new WireArray(rotatedBits);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -430,7 +430,7 @@ public Wire rotateRight(int numBits, int s, String... desc) {
WireArray result = new WireArray(rotatedBits);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -448,7 +448,7 @@ public Wire shiftLeft(int numBits, int s, String... desc) {
WireArray result = new WireArray(shiftedBits);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -466,7 +466,7 @@ public Wire shiftRight(int numBits, int s, String... desc) {
WireArray result = new WireArray(shiftedBits);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -478,15 +478,15 @@ public Wire invBits(int bitwidth, String... desc) {
for (int i = 0; i < resultBits.length; i++) {
resultBits[i] = bits[i].invAsBit(desc);
}
return new VariableWire(new WireArray(resultBits));
return new LinearCombinationWire(new WireArray(resultBits));
}

public Wire trimBits(int currentNumOfBits, int desiredNumofBits, String... desc) {
WireArray bitWires = getBitWires(currentNumOfBits, desc);
WireArray result = bitWires.adjustLength(desiredNumofBits);
BigInteger v = result.checkIfConstantBits(desc);
if (v == null) {
return new VariableWire(result);
return new LinearCombinationWire(result);
} else {
return generator.createConstantWire(v);
}
@@ -10,7 +10,6 @@
import circuit.eval.Instruction;
import circuit.operations.primitive.AddBasicOp;
import circuit.operations.primitive.PackBasicOp;
import circuit.config.Config;

public class WireArray {

@@ -258,11 +257,7 @@ else if (!v.equals(BigInteger.ZERO)){
Instruction op = new PackBasicOp(bits, out, desc);
Wire[] cachedOutputs = generator.addToEvaluationQueue(op);
if(cachedOutputs == null){
if(Config.promotePackOutput){
return CircuitGenerator.getActiveCircuitGenerator().makeVariable(out);
} else{
return out;
}
return out;
}
else{
generator.currentWireId--;

0 comments on commit d12b6d9

Please sign in to comment.
You can’t perform that action at this time.