use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Adder method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPortValue(IN0);
Value b = state.getPortValue(IN1);
Value c_in = state.getPortValue(C_IN);
Value[] outs = Adder.computeSum(dataWidth, a, b, c_in);
// propagate them
int delay = (dataWidth.getWidth() + 2) * PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(C_OUT, outs[1], delay);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Multiplier method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPortValue(IN0);
Value b = state.getPortValue(IN1);
Value c_in = state.getPortValue(C_IN);
Value[] outs = Multiplier.computeProduct(dataWidth, a, b, c_in);
// propagate them
int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(C_OUT, outs[1], delay);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Shifter method propagate.
@Override
public void propagate(InstanceState state) {
// compute output
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
int bits = dataWidth == null ? 32 : dataWidth.getWidth();
Value vx = state.getPortValue(IN0);
Value vd = state.getPortValue(IN1);
// y will by x shifted by d
Value vy;
if (vd.isFullyDefined() && vx.getWidth() == bits) {
int d = vd.toIntValue();
Object shift = state.getAttributeValue(ATTR_SHIFT);
if (d == 0) {
vy = vx;
} else if (vx.isFullyDefined()) {
int x = vx.toIntValue();
int y;
if (shift == SHIFT_LOGICAL_RIGHT) {
y = x >>> d;
} else if (shift == SHIFT_ARITHMETIC_RIGHT) {
if (d >= bits)
d = bits - 1;
y = x >> d | ((x << (32 - bits)) >> (32 - bits + d));
} else if (shift == SHIFT_ROLL_RIGHT) {
if (d >= bits)
d -= bits;
y = (x >>> d) | (x << (bits - d));
} else if (shift == SHIFT_ROLL_LEFT) {
if (d >= bits)
d -= bits;
y = (x << d) | (x >>> (bits - d));
} else {
// SHIFT_LOGICAL_LEFT
y = x << d;
}
vy = Value.createKnown(dataWidth, y);
} else {
Value[] x = vx.getAll();
Value[] y = new Value[bits];
if (shift == SHIFT_LOGICAL_RIGHT) {
if (d >= bits)
d = bits;
System.arraycopy(x, d, y, 0, bits - d);
Arrays.fill(y, bits - d, bits, Value.FALSE);
} else if (shift == SHIFT_ARITHMETIC_RIGHT) {
if (d >= bits)
d = bits;
System.arraycopy(x, d, y, 0, x.length - d);
Arrays.fill(y, bits - d, y.length, x[bits - 1]);
} else if (shift == SHIFT_ROLL_RIGHT) {
if (d >= bits)
d -= bits;
System.arraycopy(x, d, y, 0, bits - d);
System.arraycopy(x, 0, y, bits - d, d);
} else if (shift == SHIFT_ROLL_LEFT) {
if (d >= bits)
d -= bits;
System.arraycopy(x, x.length - d, y, 0, d);
System.arraycopy(x, 0, y, d, bits - d);
} else {
// SHIFT_LOGICAL_LEFT
if (d >= bits)
d = bits;
Arrays.fill(y, 0, d, Value.FALSE);
System.arraycopy(x, 0, y, d, bits - d);
}
vy = Value.create(y);
}
} else {
vy = Value.createError(dataWidth);
}
// propagate them
int delay = dataWidth.getWidth() * (3 * Adder.PER_DELAY);
state.setPort(OUT, vy, delay);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Subtractor method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPortValue(IN0);
Value b = state.getPortValue(IN1);
Value b_in = state.getPortValue(B_IN);
if (b_in == Value.UNKNOWN || b_in == Value.NIL)
b_in = Value.FALSE;
Value[] outs = Adder.computeSum(data, a, b.not(), b_in.not());
// propagate them
int delay = (data.getWidth() + 4) * Adder.PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(B_OUT, outs[1].not(), delay);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TtyInterface method displayTableRow.
private static void displayTableRow(ArrayList<Value> prevOutputs, ArrayList<Value> curOutputs) {
boolean shouldPrint = false;
if (prevOutputs == null) {
shouldPrint = true;
} else {
for (int i = 0; i < curOutputs.size(); i++) {
Value a = prevOutputs.get(i);
Value b = curOutputs.get(i);
if (!a.equals(b)) {
shouldPrint = true;
break;
}
}
}
if (shouldPrint) {
for (int i = 0; i < curOutputs.size(); i++) {
if (i != 0)
// OK
System.out.print("\t");
// OK
System.out.print(curOutputs.get(i));
}
// OK
System.out.println();
}
}
Aggregations