* [PATCH] PARISC: Avoid undefined shift in cnv_float.h
@ 2012-04-01 16:57 John David Anglin
2012-04-01 17:06 ` James Bottomley
0 siblings, 1 reply; 3+ messages in thread
From: John David Anglin @ 2012-04-01 16:57 UTC (permalink / raw)
To: linux-parisc List; +Cc: James Bottomley
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
The attached change fixes a float conversion problem found running the
GCC testsuite with GCC configured with --with-arch=2.0.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
[-- Attachment #2: cnv-float-patch.txt --]
[-- Type: text/plain, Size: 1082 bytes --]
diff --git a/arch/parisc/math-emu/cnv_float.h b/arch/parisc/math-emu/cnv_float.h
index 9071e09..37299c7 100644
--- a/arch/parisc/math-emu/cnv_float.h
+++ b/arch/parisc/math-emu/cnv_float.h
@@ -347,16 +347,15 @@
Sgl_isinexact_to_fix(sgl_value,exponent)
#define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \
- {Sall(sgl_value) <<= SGL_EXP_LENGTH; /* left-justify */ \
+ {unsigned int val = Sall(sgl_value) << SGL_EXP_LENGTH; \
if (exponent <= 31) { \
Dintp1(dresultA) = 0; \
- Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \
+ Dintp2(dresultB) = val >> (31 - exponent); \
} \
else { \
- Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent); \
- Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31); \
+ Dintp1(dresultA) = val >> (63 - exponent); \
+ Dintp2(dresultB) = exponent <= 62 ? val << (exponent - 31) : 0; \
} \
- Sall(sgl_value) >>= SGL_EXP_LENGTH; /* return to original */ \
}
#define Duint_setzero(dresultA,dresultB) \
[-- Attachment #3: Type: text/plain, Size: 45 bytes --]
--
John David Anglin dave.anglin@bell.net
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] PARISC: Avoid undefined shift in cnv_float.h
2012-04-01 16:57 [PATCH] PARISC: Avoid undefined shift in cnv_float.h John David Anglin
@ 2012-04-01 17:06 ` James Bottomley
2012-04-01 17:25 ` John David Anglin
0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2012-04-01 17:06 UTC (permalink / raw)
To: John David Anglin; +Cc: linux-parisc List
On Sun, 2012-04-01 at 12:57 -0400, John David Anglin wrote:
> The attached change fixes a float conversion problem found running the
> GCC testsuite with GCC configured with --with-arch=2.0.
Could you describe the actual problem? (it helps enormously when people
look at the change logs a year later and try and work out what the
actual issue is).
Thanks,
James
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PARISC: Avoid undefined shift in cnv_float.h
2012-04-01 17:06 ` James Bottomley
@ 2012-04-01 17:25 ` John David Anglin
0 siblings, 0 replies; 3+ messages in thread
From: John David Anglin @ 2012-04-01 17:25 UTC (permalink / raw)
To: James Bottomley; +Cc: linux-parisc List
On 1-Apr-12, at 1:06 PM, James Bottomley wrote:
> On Sun, 2012-04-01 at 12:57 -0400, John David Anglin wrote:
>> The attached change fixes a float conversion problem found running
>> the
>> GCC testsuite with GCC configured with --with-arch=2.0.
>
> Could you describe the actual problem? (it helps enormously when
> people
> look at the change logs a year later and try and work out what the
> actual issue is).
The actual problem occurs for an exponent value of 63. This is the
maximum
exponent value that can be passed. This causes a left shift by 32 in
the else
hunk of the macro. This causes undefined behavior and the wrong value
is
returned for dresultB. The fix is the check "exponent <= 62". If the
exponent
is 63, dresultB is set to 0.
The patch also optimizes the operation a bit by copying
"Sall(sgl_value) << SGL_EXP_LENGTH" to val, so that sgl_value is not
modified.
Dave
--
John David Anglin dave.anglin@bell.net
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-01 17:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-01 16:57 [PATCH] PARISC: Avoid undefined shift in cnv_float.h John David Anglin
2012-04-01 17:06 ` James Bottomley
2012-04-01 17:25 ` John David Anglin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox