use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Buffer method repair.
//
// static methods - shared with other classes
//
static Value repair(InstanceState state, Value v) {
AttributeSet opts = state.getProject().getOptions().getAttributeSet();
Object onUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED);
boolean errorIfUndefined = onUndefined.equals(Options.GATE_UNDEFINED_ERROR);
Value repaired;
if (errorIfUndefined) {
int vw = v.getWidth();
BitWidth w = state.getAttributeValue(StdAttr.WIDTH);
int ww = w.getWidth();
if (vw == ww && v.isFullyDefined())
return v;
Value[] vs = new Value[w.getWidth()];
for (int i = 0; i < vs.length; i++) {
Value ini = i < vw ? v.get(i) : Value.ERROR;
vs[i] = ini.isFullyDefined() ? ini : Value.ERROR;
}
repaired = Value.create(vs);
} else {
repaired = v;
}
Object outType = state.getAttributeValue(GateAttributes.ATTR_OUTPUT);
return AbstractGate.pullOutput(repaired, outType);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Comparator method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value gt = Value.FALSE;
Value eq = Value.TRUE;
Value lt = Value.FALSE;
Value a = state.getPortValue(IN0);
Value b = state.getPortValue(IN1);
Value[] ax = a.getAll();
Value[] bx = b.getAll();
int maxlen = Math.max(ax.length, bx.length);
for (int pos = maxlen - 1; pos >= 0; pos--) {
Value ab = pos < ax.length ? ax[pos] : Value.ERROR;
Value bb = pos < bx.length ? bx[pos] : Value.ERROR;
if (pos == ax.length - 1 && ab != bb) {
Object mode = state.getAttributeValue(MODE_ATTRIBUTE);
if (mode != UNSIGNED_OPTION) {
Value t = ab;
ab = bb;
bb = t;
}
}
if (ab == Value.ERROR || bb == Value.ERROR) {
gt = Value.ERROR;
eq = Value.ERROR;
lt = Value.ERROR;
break;
} else if (ab == Value.UNKNOWN || bb == Value.UNKNOWN) {
gt = Value.UNKNOWN;
eq = Value.UNKNOWN;
lt = Value.UNKNOWN;
break;
} else if (ab != bb) {
eq = Value.FALSE;
if (ab == Value.TRUE)
gt = Value.TRUE;
else
lt = Value.TRUE;
break;
}
}
// propagate them
int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
state.setPort(GT, gt, delay);
state.setPort(EQ, eq, delay);
state.setPort(LT, lt, delay);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Divider 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 upper = state.getPortValue(UPPER);
Value[] outs = Divider.computeResult(dataWidth, a, b, upper);
// propagate them
int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(REM, outs[1], delay);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Negator method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value in = state.getPortValue(IN);
Value out;
if (in.isFullyDefined()) {
out = Value.createKnown(in.getBitWidth(), -in.toIntValue());
} else {
Value[] bits = in.getAll();
Value fill = Value.FALSE;
int pos = 0;
while (pos < bits.length) {
if (bits[pos] == Value.FALSE) {
bits[pos] = fill;
} else if (bits[pos] == Value.TRUE) {
if (fill != Value.FALSE)
bits[pos] = fill;
pos++;
break;
} else if (bits[pos] == Value.ERROR) {
fill = Value.ERROR;
} else {
if (fill == Value.FALSE)
fill = bits[pos];
else
bits[pos] = fill;
}
pos++;
}
while (pos < bits.length) {
if (bits[pos] == Value.TRUE) {
bits[pos] = Value.FALSE;
} else if (bits[pos] == Value.FALSE) {
bits[pos] = Value.TRUE;
}
pos++;
}
out = Value.create(bits);
}
// propagate them
int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
state.setPort(OUT, out, delay);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Shifter method configurePorts.
private void configurePorts(Instance instance) {
BitWidth dataWid = instance.getAttributeValue(StdAttr.WIDTH);
int data = dataWid == null ? 32 : dataWid.getWidth();
int shift = 1;
while ((1 << shift) < data) shift++;
Port[] ps = new Port[3];
ps[IN0] = new Port(-40, -10, Port.INPUT, data);
ps[IN1] = new Port(-40, 10, Port.INPUT, shift);
ps[OUT] = new Port(0, 0, Port.OUTPUT, data);
ps[IN0].setToolTip(Strings.getter("shifterInputTip"));
ps[IN1].setToolTip(Strings.getter("shifterDistanceTip"));
ps[OUT].setToolTip(Strings.getter("shifterOutputTip"));
instance.setPorts(ps);
}
Aggregations