applyLdpcMessageSign function
Applies sign to an unsigned LDPC message magnitude.
Implementation
Logic applyLdpcMessageSign(Logic magnitude, Logic sign, String name) {
final maximumPositive = Const(
(BigInt.one << (magnitude.width - 1)) - BigInt.one,
width: magnitude.width,
);
final positiveMagnitude =
mux(magnitude.gt(maximumPositive), maximumPositive, magnitude);
final negative = ((~magnitude) + Const(1, width: magnitude.width))
.getRange(0, magnitude.width);
return mux(sign, negative, positiveMagnitude).named(name);
}