BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
Value en = enable ? state.getPort(outputs + 1) : Value.TRUE;
// determine output values
Value others; // the default output
if (threeState.booleanValue()) {
others = Value.createUnknown(data);
} else {
others = Value.createKnown(data, 0);
}
int outIndex = -1; // the special output
Value out = null;
if (en == Value.FALSE) {
Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
others = Value.repeat(base, data.getWidth());
} else if (en == Value.ERROR && state.isPortConnected(outputs + 1)) {
others = Value.createError(data);
} else {
Value sel = state.getPort(outputs);
if (sel.isFullyDefined()) {
outIndex = sel.toIntValue();
out = state.getPort(outputs + (enable ? 2 : 1));
} else if (sel.isErrorValue()) {
others = Value.createError(data);
} else {
others = Value.createUnknown(data);
}
}