Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FMA Unit and DivSqrter with fflags #98

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
refactor: modify the comment related to the addend of FMA
  • Loading branch information
reo-pon committed Dec 21, 2024
commit 36f86021decf763d2daef7c8b9fa900268ca2eac
16 changes: 12 additions & 4 deletions Processor/Src/Pipeline/FPBackEnd/FPExecutionStage.sv
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,18 @@ module FPExecutionStage(
fmaMulLHS[i] = fpuCode[i] inside {FC_FNMSUB, FC_FNMADD} ? {~fuOpA[i].data[31], fuOpA[i].data[30:0]} : fuOpA[i].data;
fmaMulRHS[i] = fpuCode[i] inside {FC_ADD, FC_SUB} ? 32'h3f800000 : fuOpB[i].data;
if(fpuCode[i] == FC_MUL) begin
// Hack: set sign bit considering rounding mode
// +a * +0.0 should return +0.0 regardless of rounding mode,
// However, when implemented with fma(+a, +0.0, -0.0),
// it returns -0.0 when round_mode = 2
// If the arithmetical result is not zero,
// adding either -0.0 or +0.0 will produce the same result as the multiplication result.
// If the arithmetical result is zero,
// adding a zero with the same sign ensures that the result matches the multiplication result.
// Therefore, this approach is valid.
//
// Always adding +0.0 is incorrect:
// when the round_mode != 2 (downward) and the multiplication result is -0.0,
// the output will incorrectly become +0.0.
// Similarly, always adding -0.0 is also incorrect:
// when the round_mode == 2 (downward) and the multiplication result is +0.0,
// the output will incorrectly become -0.0.
fmaAddend[i] = { fmaMulLHS[i][31] ^ fmaMulRHS[i][31] , 31'h0 };
end
else if (fpuCode[i] == FC_ADD) begin
Expand Down