]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.52/mips-math-emu-max-min-.-d-s-fix-cases-of-both-inputs-negative.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.52 / mips-math-emu-max-min-.-d-s-fix-cases-of-both-inputs-negative.patch
1 From aabf5cf02e22ebc4e541adf835910f388b6c3e65 Mon Sep 17 00:00:00 2001
2 From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
3 Date: Thu, 27 Jul 2017 18:08:50 +0200
4 Subject: MIPS: math-emu: <MAX|MIN>.<D|S>: Fix cases of both inputs negative
5
6 From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
7
8 commit aabf5cf02e22ebc4e541adf835910f388b6c3e65 upstream.
9
10 Fix the value returned by <MAX|MIN>.<D|S>, if both inputs are negative
11 normal fp numbers. The previous logic did not take into account that
12 if both inputs have the same sign, there should be separate treatment
13 of the cases when both inputs are negative and when both inputs are
14 positive.
15
16 A relevant example:
17
18 MAX.S fd,fs,ft:
19 If fs contains -5.0, and ft contains -7.0, fd is going to contain
20 -5.0 (without this patch, it used to contain -7.0).
21
22 Fixes: a79f5f9ba508 ("MIPS: math-emu: Add support for the MIPS R6 MAX{, A} FPU instruction")
23 Fixes: 4e9561b20e2f ("MIPS: math-emu: Add support for the MIPS R6 MIN{, A} FPU instruction")
24
25 Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
26 Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
27 Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
28 Reviewed-by: James Hogan <james.hogan@imgtec.com>
29 Cc: Bo Hu <bohu@google.com>
30 Cc: Douglas Leung <douglas.leung@imgtec.com>
31 Cc: Jin Qian <jinqian@google.com>
32 Cc: Paul Burton <paul.burton@imgtec.com>
33 Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
34 Cc: Raghu Gandham <raghu.gandham@imgtec.com>
35 Cc: linux-mips@linux-mips.org
36 Cc: linux-kernel@vger.kernel.org
37 Patchwork: https://patchwork.linux-mips.org/patch/16882/
38 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
39 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
40
41 ---
42 arch/mips/math-emu/dp_fmax.c | 32 ++++++++++++++++++++++++--------
43 arch/mips/math-emu/dp_fmin.c | 32 ++++++++++++++++++++++++--------
44 arch/mips/math-emu/sp_fmax.c | 32 ++++++++++++++++++++++++--------
45 arch/mips/math-emu/sp_fmin.c | 32 ++++++++++++++++++++++++--------
46 4 files changed, 96 insertions(+), 32 deletions(-)
47
48 --- a/arch/mips/math-emu/dp_fmax.c
49 +++ b/arch/mips/math-emu/dp_fmax.c
50 @@ -116,16 +116,32 @@ union ieee754dp ieee754dp_fmax(union iee
51 else if (xs < ys)
52 return x;
53
54 - /* Compare exponent */
55 - if (xe > ye)
56 - return x;
57 - else if (xe < ye)
58 - return y;
59 + /* Signs of inputs are equal, let's compare exponents */
60 + if (xs == 0) {
61 + /* Inputs are both positive */
62 + if (xe > ye)
63 + return x;
64 + else if (xe < ye)
65 + return y;
66 + } else {
67 + /* Inputs are both negative */
68 + if (xe > ye)
69 + return y;
70 + else if (xe < ye)
71 + return x;
72 + }
73
74 - /* Compare mantissa */
75 + /* Signs and exponents of inputs are equal, let's compare mantissas */
76 + if (xs == 0) {
77 + /* Inputs are both positive, with equal signs and exponents */
78 + if (xm <= ym)
79 + return y;
80 + return x;
81 + }
82 + /* Inputs are both negative, with equal signs and exponents */
83 if (xm <= ym)
84 - return y;
85 - return x;
86 + return x;
87 + return y;
88 }
89
90 union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
91 --- a/arch/mips/math-emu/dp_fmin.c
92 +++ b/arch/mips/math-emu/dp_fmin.c
93 @@ -116,16 +116,32 @@ union ieee754dp ieee754dp_fmin(union iee
94 else if (xs < ys)
95 return y;
96
97 - /* Compare exponent */
98 - if (xe > ye)
99 - return y;
100 - else if (xe < ye)
101 - return x;
102 + /* Signs of inputs are the same, let's compare exponents */
103 + if (xs == 0) {
104 + /* Inputs are both positive */
105 + if (xe > ye)
106 + return y;
107 + else if (xe < ye)
108 + return x;
109 + } else {
110 + /* Inputs are both negative */
111 + if (xe > ye)
112 + return x;
113 + else if (xe < ye)
114 + return y;
115 + }
116
117 - /* Compare mantissa */
118 + /* Signs and exponents of inputs are equal, let's compare mantissas */
119 + if (xs == 0) {
120 + /* Inputs are both positive, with equal signs and exponents */
121 + if (xm <= ym)
122 + return x;
123 + return y;
124 + }
125 + /* Inputs are both negative, with equal signs and exponents */
126 if (xm <= ym)
127 - return x;
128 - return y;
129 + return y;
130 + return x;
131 }
132
133 union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
134 --- a/arch/mips/math-emu/sp_fmax.c
135 +++ b/arch/mips/math-emu/sp_fmax.c
136 @@ -116,16 +116,32 @@ union ieee754sp ieee754sp_fmax(union iee
137 else if (xs < ys)
138 return x;
139
140 - /* Compare exponent */
141 - if (xe > ye)
142 - return x;
143 - else if (xe < ye)
144 - return y;
145 + /* Signs of inputs are equal, let's compare exponents */
146 + if (xs == 0) {
147 + /* Inputs are both positive */
148 + if (xe > ye)
149 + return x;
150 + else if (xe < ye)
151 + return y;
152 + } else {
153 + /* Inputs are both negative */
154 + if (xe > ye)
155 + return y;
156 + else if (xe < ye)
157 + return x;
158 + }
159
160 - /* Compare mantissa */
161 + /* Signs and exponents of inputs are equal, let's compare mantissas */
162 + if (xs == 0) {
163 + /* Inputs are both positive, with equal signs and exponents */
164 + if (xm <= ym)
165 + return y;
166 + return x;
167 + }
168 + /* Inputs are both negative, with equal signs and exponents */
169 if (xm <= ym)
170 - return y;
171 - return x;
172 + return x;
173 + return y;
174 }
175
176 union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
177 --- a/arch/mips/math-emu/sp_fmin.c
178 +++ b/arch/mips/math-emu/sp_fmin.c
179 @@ -116,16 +116,32 @@ union ieee754sp ieee754sp_fmin(union iee
180 else if (xs < ys)
181 return y;
182
183 - /* Compare exponent */
184 - if (xe > ye)
185 - return y;
186 - else if (xe < ye)
187 - return x;
188 + /* Signs of inputs are the same, let's compare exponents */
189 + if (xs == 0) {
190 + /* Inputs are both positive */
191 + if (xe > ye)
192 + return y;
193 + else if (xe < ye)
194 + return x;
195 + } else {
196 + /* Inputs are both negative */
197 + if (xe > ye)
198 + return x;
199 + else if (xe < ye)
200 + return y;
201 + }
202
203 - /* Compare mantissa */
204 + /* Signs and exponents of inputs are equal, let's compare mantissas */
205 + if (xs == 0) {
206 + /* Inputs are both positive, with equal signs and exponents */
207 + if (xm <= ym)
208 + return x;
209 + return y;
210 + }
211 + /* Inputs are both negative, with equal signs and exponents */
212 if (xm <= ym)
213 - return x;
214 - return y;
215 + return y;
216 + return x;
217 }
218
219 union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)