* Re: [PATCH] Avoid a build warning on 32-bit platforms
@ 2004-10-20 9:56 Mikael Pettersson
2004-10-20 10:23 ` [PATCH (updated)] Avoid annoying " Chris Wedgwood
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Pettersson @ 2004-10-20 9:56 UTC (permalink / raw)
To: cw, linux-kernel
On Tue, 19 Oct 2004 19:37:16 -0700, cw@f00f.org (Chris Wedgwood) wrote:
>@@ -818,11 +818,12 @@
> * jiffies.
> */
> time = get_cycles();
>- if (time != 0) {
>- if (sizeof(time) > 4)
>- num ^= (u32)(time >> 32);
>- } else {
>+ if (!time)
> time = jiffies;
>+ else {
>+#if (BITS_PER_LONG > 32)
>+ num ^= (u32)(time >> 32);
>+#endif /* (BITS_PER_LONG > 32) */
There's a coding idiom for doing this: just break up
the ">> 32" in two steps, like: ((time >> 31) >> 1).
Definitely preferable over #ifdef:s.
/Mikael
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH (updated)] Avoid annoying build warning on 32-bit platforms
2004-10-20 9:56 [PATCH] Avoid a build warning on 32-bit platforms Mikael Pettersson
@ 2004-10-20 10:23 ` Chris Wedgwood
2004-10-20 10:42 ` Jakub Jelinek
2004-10-20 10:53 ` Martin Zwickel
0 siblings, 2 replies; 5+ messages in thread
From: Chris Wedgwood @ 2004-10-20 10:23 UTC (permalink / raw)
To: Mikael Pettersson; +Cc: linux-kernel, Linus Torvalds, Andrew Morton
On Wed, Oct 20, 2004 at 11:56:45AM +0200, Mikael Pettersson wrote:
> There's a coding idiom for doing this: just break up
> the ">> 32" in two steps, like: ((time >> 31) >> 1).
i assumed gcc would complain there too but it doesn't and it does
optimize this away (i checked)
> Definitely preferable over #ifdef:s.
indeed
Avoid annoying gcc warning on 32-bit platforms.
Signed-off-by: cw@f00f.org
===== drivers/char/random.c 1.57 vs edited =====
--- 1.57/drivers/char/random.c 2004-10-05 14:21:53 -07:00
+++ edited/drivers/char/random.c 2004-10-20 03:19:17 -07:00
@@ -818,12 +818,10 @@ static void add_timer_randomness(struct
* jiffies.
*/
time = get_cycles();
- if (time != 0) {
- if (sizeof(time) > 4)
- num ^= (u32)(time >> 32);
- } else {
+ if (time)
+ num ^= (u32)((time >> 32) >> 1);
+ else
time = jiffies;
- }
/*
* Calculate number of bits of randomness we probably added.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH (updated)] Avoid annoying build warning on 32-bit platforms
2004-10-20 10:23 ` [PATCH (updated)] Avoid annoying " Chris Wedgwood
@ 2004-10-20 10:42 ` Jakub Jelinek
2004-10-20 10:53 ` Martin Zwickel
1 sibling, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2004-10-20 10:42 UTC (permalink / raw)
To: Chris Wedgwood
Cc: Mikael Pettersson, linux-kernel, Linus Torvalds, Andrew Morton
On Wed, Oct 20, 2004 at 03:23:43AM -0700, Chris Wedgwood wrote:
> Avoid annoying gcc warning on 32-bit platforms.
>
> Signed-off-by: cw@f00f.org
>
> ===== drivers/char/random.c 1.57 vs edited =====
> --- 1.57/drivers/char/random.c 2004-10-05 14:21:53 -07:00
> +++ edited/drivers/char/random.c 2004-10-20 03:19:17 -07:00
> @@ -818,12 +818,10 @@ static void add_timer_randomness(struct
> * jiffies.
> */
> time = get_cycles();
> - if (time != 0) {
> - if (sizeof(time) > 4)
> - num ^= (u32)(time >> 32);
> - } else {
> + if (time)
> + num ^= (u32)((time >> 32) >> 1);
^^
32 + 1 != 32.
> + else
> time = jiffies;
> - }
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH (updated)] Avoid annoying build warning on 32-bit platforms
2004-10-20 10:23 ` [PATCH (updated)] Avoid annoying " Chris Wedgwood
2004-10-20 10:42 ` Jakub Jelinek
@ 2004-10-20 10:53 ` Martin Zwickel
2004-10-20 19:18 ` Chris Wedgwood
1 sibling, 1 reply; 5+ messages in thread
From: Martin Zwickel @ 2004-10-20 10:53 UTC (permalink / raw)
To: Chris Wedgwood
Cc: Mikael Pettersson, linux-kernel, Linus Torvalds, Andrew Morton
[-- Attachment #1: Type: text/plain, Size: 1537 bytes --]
On Wed, 20 Oct 2004 03:23:43 -0700
Chris Wedgwood <cw@f00f.org> bubbled:
> On Wed, Oct 20, 2004 at 11:56:45AM +0200, Mikael Pettersson wrote:
>
> > There's a coding idiom for doing this: just break up
> > the ">> 32" in two steps, like: ((time >> 31) >> 1).
>
> i assumed gcc would complain there too but it doesn't and it does
> optimize this away (i checked)
>
> > Definitely preferable over #ifdef:s.
>
> indeed
>
>
>
> Avoid annoying gcc warning on 32-bit platforms.
>
> Signed-off-by: cw@f00f.org
>
> ===== drivers/char/random.c 1.57 vs edited =====
> --- 1.57/drivers/char/random.c 2004-10-05 14:21:53 -07:00
> +++ edited/drivers/char/random.c 2004-10-20 03:19:17 -07:00
> @@ -818,12 +818,10 @@ static void add_timer_randomness(struct
> * jiffies.
> */
> time = get_cycles();
> - if (time != 0) {
> - if (sizeof(time) > 4)
> - num ^= (u32)(time >> 32);
> - } else {
> + if (time)
> + num ^= (u32)((time >> 32) >> 1);
^^ errr ... should be 31 ?!?!
> + else
> time = jiffies;
> - }
>
> /*
> * Calculate number of bits of randomness we probably added.
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
MyExcuse:
We've run out of licenses
Martin Zwickel <martin.zwickel@technotrend.de>
Research & Development
TechnoTrend AG <http://www.technotrend.de>
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-10-20 19:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-20 9:56 [PATCH] Avoid a build warning on 32-bit platforms Mikael Pettersson
2004-10-20 10:23 ` [PATCH (updated)] Avoid annoying " Chris Wedgwood
2004-10-20 10:42 ` Jakub Jelinek
2004-10-20 10:53 ` Martin Zwickel
2004-10-20 19:18 ` Chris Wedgwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox