Skip to contentSkip to conversation

Avoid a build warning on 32-bit platforms

PATCH In review Mikael Pettersson 4 participants 5 messages Oct 20, 2004 Random number driver

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · On Tue, 19 Oct 2004 19:37:16 -0700, [email protected] (Chris Wedgwood) wrote:
(quoted diff) +0 -0
@@ -818,11 +818,12 @@
 	 * jiffies.
 	 */
 	time = get_cycles();

Review line 826

Quoted 10 lines
(quoted diff) +5 -4
-	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

#1 lore raw

PATCH 1/1 Avoid annoying build warning on 32-bit platforms

Quoted 2 lines · Mikael Pettersson

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)

Quoted 1 line

Definitely preferable over #ifdef:s.

indeed

Avoid annoying gcc warning on 32-bit platforms.

Signed-off-by [email protected]

===== drivers/char/random.c 1.57 vs edited =====

drivers/char/random.c +3 -5
@@ -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.
#2 lore raw

Re: [PATCH (updated)] Avoid annoying build warning on 32-bit platforms

Quoted 8 lines · Chris Wedgwood

Avoid annoying gcc warning on 32-bit platforms.

Signed-off-by [email protected]

===== drivers/char/random.c 1.57 vs edited =====

drivers/char/random.c static void add_timer_randomness(struct · line 822

Quoted 9 lines
drivers/char/random.c +2 -4
@@ -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.

drivers/char/random.c static void add_timer_randomness(struct · line 826

Quoted 3 lines
drivers/char/random.c +1 -1
+	else
 		time = jiffies;
-	}

Jakub

#3 lore raw

Re: [PATCH (updated)] Avoid annoying build warning on 32-bit platforms

In reply to Chris Wedgwood

On Wed, 20 Oct 2004 03:23:43 -0700
Chris Wedgwood <[email protected]> bubbled:

Quoted 22 lines · Mikael Pettersson
Quoted 3 lines

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)

Quoted 1 line

Definitely preferable over #ifdef:s.

indeed

Avoid annoying gcc warning on 32-bit platforms.

Signed-off-by [email protected]

===== drivers/char/random.c 1.57 vs edited =====

drivers/char/random.c static void add_timer_randomness(struct · line 822

Quoted 9 lines
drivers/char/random.c +2 -4
@@ -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 ?!?!
Quoted 11 lines
drivers/char/random.c +1 -2
+	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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 7 lines
MyExcuse:
We've run out of licenses

Martin Zwickel <[email protected]>
Research & Development

TechnoTrend AG <http://www.technotrend.de>
#4 lore raw

Re: [PATCH (updated)] Avoid annoying build warning on 32-bit platforms

Quoted 3 lines · Martin Zwickel

drivers/char/random.c static void add_timer_randomness(struct · line 822

Quoted 2 lines
drivers/char/random.c +2 -0
+	if (time)
+		num ^= (u32)((time >> 32) >> 1);
                                      ^^ errr ... should be 31 ?!?!

yeah, i'm retarded, sorry about that :)