Skip to content

Commit 6acd1d2

Browse files
aleksandar-markovicgregkh
authored andcommitted
MIPS: math-emu: <MAX|MAXA|MIN|MINA>.<D|S>: Fix cases of both inputs zero
commit 15560a58bfd4ff82cdd16b2270d4ef9b06d2cc4d upstream. Fix the value returned by <MAX|MAXA|MIN|MINA>.<D|S>, if both inputs are zeros. The right behavior in such cases is stated in instruction reference manual and is as follows: fs ft MAX MIN MAXA MINA --------------------------------------------- 0 0 0 0 0 0 0 -0 0 -0 0 -0 -0 0 0 -0 0 -0 -0 -0 -0 -0 -0 -0 Prior to this patch, some of the above cases were yielding correct results. However, for the sake of code consistency, all such cases are rewritten in this patch. A relevant example: MAX.S fd,fs,ft: If fs contains +0.0, and ft contains -0.0, fd is going to contain +0.0 (without this patch, it used to contain -0.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/16881/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b6c818d commit 6acd1d2

4 files changed

Lines changed: 8 additions & 24 deletions

File tree

arch/mips/math-emu/dp_fmax.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
9292
return ys ? x : y;
9393

9494
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
95-
if (xs == ys)
96-
return x;
97-
return ieee754dp_zero(1);
95+
return ieee754dp_zero(xs & ys);
9896

9997
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
10098
DPDNORMX;
@@ -204,9 +202,7 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
204202
return y;
205203

206204
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
207-
if (xs == ys)
208-
return x;
209-
return ieee754dp_zero(1);
205+
return ieee754dp_zero(xs & ys);
210206

211207
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
212208
DPDNORMX;

arch/mips/math-emu/dp_fmin.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
9292
return ys ? y : x;
9393

9494
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
95-
if (xs == ys)
96-
return x;
97-
return ieee754dp_zero(1);
95+
return ieee754dp_zero(xs | ys);
9896

9997
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
10098
DPDNORMX;
@@ -204,9 +202,7 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
204202
return y;
205203

206204
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
207-
if (xs == ys)
208-
return x;
209-
return ieee754dp_zero(1);
205+
return ieee754dp_zero(xs | ys);
210206

211207
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
212208
DPDNORMX;

arch/mips/math-emu/sp_fmax.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
9292
return ys ? x : y;
9393

9494
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
95-
if (xs == ys)
96-
return x;
97-
return ieee754sp_zero(1);
95+
return ieee754sp_zero(xs & ys);
9896

9997
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
10098
SPDNORMX;
@@ -204,9 +202,7 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
204202
return y;
205203

206204
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
207-
if (xs == ys)
208-
return x;
209-
return ieee754sp_zero(1);
205+
return ieee754sp_zero(xs & ys);
210206

211207
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
212208
SPDNORMX;

arch/mips/math-emu/sp_fmin.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
9292
return ys ? y : x;
9393

9494
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
95-
if (xs == ys)
96-
return x;
97-
return ieee754sp_zero(1);
95+
return ieee754sp_zero(xs | ys);
9896

9997
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
10098
SPDNORMX;
@@ -204,9 +202,7 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
204202
return y;
205203

206204
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
207-
if (xs == ys)
208-
return x;
209-
return ieee754sp_zero(1);
205+
return ieee754sp_zero(xs | ys);
210206

211207
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
212208
SPDNORMX;

0 commit comments

Comments
 (0)