+
+ /**
+ *
+ * Fuses two wires together. If the bits change in one Wire, the other is changed accordingly immediately. Warning: The bits are
+ * permanently fused together.
+ *
+ * @param a The {@link Wire} to be fused with b
+ * @param b The {@link Wire} to be fused with a
+ */
+ public static void fuse(Wire a, Wire b)
+ {
+ fuse(a, b, 0, 0, a.width);
+ }
+
+ /**
+ * Fuses the selected bits of two wires together. If the bits change in one Wire, the other is changed accordingly immediately. Warning:
+ * The bits are permanently fused together.
+ *
+ * @param a The {@link Wire} to be (partially) fused with b
+ * @param b The {@link Wire} to be (partially) fused with a
+ * @param fromA The first bit of {@link Wire} a to be fused
+ * @param fromB The first bit of {@link Wire} b to be fused
+ * @param width The amount of bits to fuse
+ */
+ public static void fuse(Wire a, Wire b, int fromA, int fromB, int width)
+ {
+ ReadWriteEnd rA = a.createReadWriteEnd(), rB = b.createReadWriteEnd();
+ rA.registerObserver(x -> rB.feedSignals(fromB, rA.wireValuesExcludingMe().subVector(fromA, fromA + width)));
+ rB.registerObserver(x -> rA.feedSignals(fromA, rB.wireValuesExcludingMe().subVector(fromB, fromB + width)));
+
+ rA.setValues(0, BitVector.of(Bit.Z, fromA));
+ rB.setValues(0, BitVector.of(Bit.Z, fromB));
+ rA.setValues(fromA + width, BitVector.of(Bit.Z, a.width - width - fromA));
+ rB.setValues(fromB + width, BitVector.of(Bit.Z, b.width - width - fromB));
+
+ rA.notifyObservers();
+ rB.notifyObservers();
+ }