- ReadWriteEnd source = (ReadWriteEnd) initiator;
- if (source.getWire().inputs.size() - (source.isWriting() ? 1 : 0) == 0)
- target.setWriting(false);
- else
- {
- target.setWriting(true);
- BitVector targetInput = source.wireValuesExcludingMe().subVector(fromSource, fromSource + width);
- target.setValues(fromTarget, targetInput);
- }
+ addParticipatingWireBit(new WireBit(w, bit));
+ }
+
+ private void addParticipatingWireBit(WireBit wb)
+ {
+ wb.wire.fusedBits[wb.bit] = this;
+ participatingWireBits.add(wb);
+ wb.wire.invalidateCachedValuesForAllFusedWires();
+ }
+
+ public void mergeOtherIntoThis(FusedBit other)
+ {
+ for (WireBit wb : other.participatingWireBits)
+ addParticipatingWireBit(wb);
+ }
+
+ public void invalidateCachedValuesForAllParticipatingWires()
+ {
+ for (WireBit wb : participatingWireBits)
+ wb.wire.invalidateCachedValues();
+ }
+
+ public Bit getValue()
+ {
+ Bit result = null;
+ for (WireBit wb : participatingWireBits)
+ if (!wb.wire.inputs.isEmpty())
+ {
+ Bit bit = wb.wire.bitsWithoutFusions[wb.bit];
+ result = result == null ? bit : result.join(bit);
+ }
+ return result == null ? U : result;
+ }
+ }
+
+ private static class WireBit
+ {
+ public final Wire wire;
+ public final int bit;
+
+ public WireBit(Wire wire, int bit)
+ {
+ this.wire = wire;
+ this.bit = bit;