Skip to content

Commit 322bf69

Browse files
aleksandar-markovicgregkh
authored andcommitted
MIPS: math-emu: <MAXA|MINA>.<D|S>: Fix cases of input values with opposite signs
commit 1a41b3b441508ae63b1a9ec699ec94065739eb60 upstream. Fix the value returned by <MAXA|MINA>.<D|S>, if the inputs are normal fp numbers of the same absolute value, but opposite signs. A relevant example: MAXA.S fd,fs,ft: If fs contains -3.0, and ft contains +3.0, fd is going to contain +3.0 (without this patch, it used to contain -3.0). Fixes: a79f5f9 ("MIPS: math-emu: Add support for the MIPS R6 MAX{, A} FPU instruction") Fixes: 4e9561b ("MIPS: math-emu: Add support for the MIPS R6 MIN{, A} FPU instruction") Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com> Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Reviewed-by: James Hogan <james.hogan@imgtec.com> Cc: Bo Hu <bohu@google.com> Cc: Douglas Leung <douglas.leung@imgtec.com> Cc: Jin Qian <jinqian@google.com> Cc: Paul Burton <paul.burton@imgtec.com> Cc: Petar Jovanovic <petar.jovanovic@imgtec.com> Cc: Raghu Gandham <raghu.gandham@imgtec.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/16883/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a83ffb5 commit 322bf69

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

arch/mips/math-emu/dp_fmax.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
243243
return y;
244244

245245
/* Compare mantissa */
246-
if (xm <= ym)
246+
if (xm < ym)
247247
return y;
248-
return x;
248+
else if (xm > ym)
249+
return x;
250+
else if (xs == 0)
251+
return x;
252+
return y;
249253
}

arch/mips/math-emu/dp_fmin.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
243243
return x;
244244

245245
/* Compare mantissa */
246-
if (xm <= ym)
246+
if (xm < ym)
247+
return x;
248+
else if (xm > ym)
249+
return y;
250+
else if (xs == 1)
247251
return x;
248252
return y;
249253
}

arch/mips/math-emu/sp_fmax.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
243243
return y;
244244

245245
/* Compare mantissa */
246-
if (xm <= ym)
246+
if (xm < ym)
247247
return y;
248-
return x;
248+
else if (xm > ym)
249+
return x;
250+
else if (xs == 0)
251+
return x;
252+
return y;
249253
}

arch/mips/math-emu/sp_fmin.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
243243
return x;
244244

245245
/* Compare mantissa */
246-
if (xm <= ym)
246+
if (xm < ym)
247+
return x;
248+
else if (xm > ym)
249+
return y;
250+
else if (xs == 1)
247251
return x;
248252
return y;
249253
}

0 commit comments

Comments
 (0)