]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.52/mips-math-emu-max-maxa-min-mina-.-d-s-fix-cases-of-both-inputs-zero.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.52 / mips-math-emu-max-maxa-min-mina-.-d-s-fix-cases-of-both-inputs-zero.patch
CommitLineData
dbfa5f4f
GKH
1From 15560a58bfd4ff82cdd16b2270d4ef9b06d2cc4d Mon Sep 17 00:00:00 2001
2From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
3Date: Thu, 27 Jul 2017 18:08:49 +0200
4Subject: MIPS: math-emu: <MAX|MAXA|MIN|MINA>.<D|S>: Fix cases of both inputs zero
5
6From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
7
8commit 15560a58bfd4ff82cdd16b2270d4ef9b06d2cc4d upstream.
9
10Fix the value returned by <MAX|MAXA|MIN|MINA>.<D|S>, if both inputs
11are zeros. The right behavior in such cases is stated in instruction
12reference manual and is as follows:
13
14 fs ft MAX MIN MAXA MINA
15 ---------------------------------------------
16 0 0 0 0 0 0
17 0 -0 0 -0 0 -0
18 -0 0 0 -0 0 -0
19 -0 -0 -0 -0 -0 -0
20
21Prior to this patch, some of the above cases were yielding correct
22results. However, for the sake of code consistency, all such cases
23are rewritten in this patch.
24
25A relevant example:
26
27MAX.S fd,fs,ft:
28 If fs contains +0.0, and ft contains -0.0, fd is going to contain
29 +0.0 (without this patch, it used to contain -0.0).
30
31Fixes: a79f5f9ba508 ("MIPS: math-emu: Add support for the MIPS R6 MAX{, A} FPU instruction")
32Fixes: 4e9561b20e2f ("MIPS: math-emu: Add support for the MIPS R6 MIN{, A} FPU instruction")
33
34Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
35Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
36Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
37Reviewed-by: James Hogan <james.hogan@imgtec.com>
38Cc: Bo Hu <bohu@google.com>
39Cc: Douglas Leung <douglas.leung@imgtec.com>
40Cc: Jin Qian <jinqian@google.com>
41Cc: Paul Burton <paul.burton@imgtec.com>
42Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
43Cc: Raghu Gandham <raghu.gandham@imgtec.com>
44Cc: linux-mips@linux-mips.org
45Cc: linux-kernel@vger.kernel.org
46Patchwork: https://patchwork.linux-mips.org/patch/16881/
47Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
48Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
49
50---
51 arch/mips/math-emu/dp_fmax.c | 8 ++------
52 arch/mips/math-emu/dp_fmin.c | 8 ++------
53 arch/mips/math-emu/sp_fmax.c | 8 ++------
54 arch/mips/math-emu/sp_fmin.c | 8 ++------
55 4 files changed, 8 insertions(+), 24 deletions(-)
56
57--- a/arch/mips/math-emu/dp_fmax.c
58+++ b/arch/mips/math-emu/dp_fmax.c
59@@ -92,9 +92,7 @@ union ieee754dp ieee754dp_fmax(union iee
60 return ys ? x : y;
61
62 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
63- if (xs == ys)
64- return x;
65- return ieee754dp_zero(1);
66+ return ieee754dp_zero(xs & ys);
67
68 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
69 DPDNORMX;
70@@ -204,9 +202,7 @@ union ieee754dp ieee754dp_fmaxa(union ie
71 return y;
72
73 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
74- if (xs == ys)
75- return x;
76- return ieee754dp_zero(1);
77+ return ieee754dp_zero(xs & ys);
78
79 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
80 DPDNORMX;
81--- a/arch/mips/math-emu/dp_fmin.c
82+++ b/arch/mips/math-emu/dp_fmin.c
83@@ -92,9 +92,7 @@ union ieee754dp ieee754dp_fmin(union iee
84 return ys ? y : x;
85
86 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
87- if (xs == ys)
88- return x;
89- return ieee754dp_zero(1);
90+ return ieee754dp_zero(xs | ys);
91
92 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
93 DPDNORMX;
94@@ -204,9 +202,7 @@ union ieee754dp ieee754dp_fmina(union ie
95 return y;
96
97 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
98- if (xs == ys)
99- return x;
100- return ieee754dp_zero(1);
101+ return ieee754dp_zero(xs | ys);
102
103 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
104 DPDNORMX;
105--- a/arch/mips/math-emu/sp_fmax.c
106+++ b/arch/mips/math-emu/sp_fmax.c
107@@ -92,9 +92,7 @@ union ieee754sp ieee754sp_fmax(union iee
108 return ys ? x : y;
109
110 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
111- if (xs == ys)
112- return x;
113- return ieee754sp_zero(1);
114+ return ieee754sp_zero(xs & ys);
115
116 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
117 SPDNORMX;
118@@ -204,9 +202,7 @@ union ieee754sp ieee754sp_fmaxa(union ie
119 return y;
120
121 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
122- if (xs == ys)
123- return x;
124- return ieee754sp_zero(1);
125+ return ieee754sp_zero(xs & ys);
126
127 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
128 SPDNORMX;
129--- a/arch/mips/math-emu/sp_fmin.c
130+++ b/arch/mips/math-emu/sp_fmin.c
131@@ -92,9 +92,7 @@ union ieee754sp ieee754sp_fmin(union iee
132 return ys ? y : x;
133
134 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
135- if (xs == ys)
136- return x;
137- return ieee754sp_zero(1);
138+ return ieee754sp_zero(xs | ys);
139
140 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
141 SPDNORMX;
142@@ -204,9 +202,7 @@ union ieee754sp ieee754sp_fmina(union ie
143 return y;
144
145 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
146- if (xs == ys)
147- return x;
148- return ieee754sp_zero(1);
149+ return ieee754sp_zero(xs | ys);
150
151 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
152 SPDNORMX;