BigInteger intResult = null;
Precision precision = new Precision(
((Parameter) getAttribute("outputPrecision"))
.getExpression());
if (A.hasToken(0) && B.hasToken(0)) {
FixPoint valueA = ((FixToken) A.get(0)).fixValue();
FixPoint valueB = ((FixToken) B.get(0)).fixValue();
if (valueA.getPrecision().getNumberOfBits() != precision
.getNumberOfBits()) {
throw new IllegalActionException(this,
"Input A has different width than the output port");
}
if (valueB.getPrecision().getNumberOfBits() != precision
.getNumberOfBits()) {
throw new IllegalActionException(this,
"Input B has different width than the output port");
}
BigInteger bigIntA = valueA.getUnscaledValue();
BigInteger bigIntB = valueB.getUnscaledValue();
if (operation.getExpression().equals("AND")) {
intResult = bigIntA.and(bigIntB);
} else if (operation.getExpression().equals("OR")) {
intResult = bigIntA.or(bigIntB);
} else if (operation.getExpression().equals("NAND")) {
intResult = bigIntA.and(bigIntB).not();
} else if (operation.getExpression().equals("NOR")) {
intResult = bigIntA.or(bigIntB).not();
} else if (operation.getExpression().equals("XOR")) {
intResult = bigIntA.xor(bigIntB);
} else if (operation.getExpression().equals("XNOR")) {
intResult = bigIntA.xor(bigIntB).not();
}
}
if (intResult != null) {
Overflow overflow = Overflow
.getName(((Parameter) getAttribute("outputOverflow"))
.getExpression().toLowerCase());
Rounding rounding = Rounding
.getName(((Parameter) getAttribute("outputRounding"))
.getExpression().toLowerCase());
FixPoint result = new FixPoint(intResult.doubleValue(),
new FixPointQuantization(precision, overflow, rounding));
sendOutput(output, 0, new FixToken(result));
}
} else {
output.resend(0);