use of com.cburch.logisim.data.BitWidth 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.BitWidth 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.BitWidth 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.BitWidth in project logisim-evolution by reds-heig.
the class bin2bcd method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
BitWidth nrofbits = attrs.getValue(bin2bcd.ATTR_BinBits);
int NrOfPorts = (int) (Math.log10(1 << nrofbits.getWidth()) + 1.0);
return Bounds.create((int) (-0.5 * InnerDistance), -20, NrOfPorts * InnerDistance, 40);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class bin2bcd method propagate.
@Override
public void propagate(InstanceState state) {
int bin_value = (state.getPortValue(BINin).isFullyDefined() & !state.getPortValue(BINin).isUnknown() & !state.getPortValue(BINin).isErrorValue() ? state.getPortValue(BINin).toIntValue() : -1);
BitWidth NrOfBits = state.getAttributeValue(bin2bcd.ATTR_BinBits);
int NrOfPorts = (int) (Math.log10(Math.pow(2.0, NrOfBits.getWidth())) + 1.0);
for (int i = NrOfPorts; i > 0; i--) {
int value = (int) (Math.pow(10, i - 1));
int number = bin_value / value;
state.setPort(i, Value.createKnown(BitWidth.create(4), number), PER_DELAY);
bin_value -= number * value;
}
}
Aggregations