Skip to contentSkip to conversation

sound/isa: use unsigned for loop index]

PATCH New Ricardo Martins 1 participant 1 message May 11, 2008 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 sound/isa: use unsigned for loop index]

Sorry, I forgot to CC the list.

----- Forwarded message from Ricardo Martins <[email protected]> -----

Date: Sun, 11 May 2008 18:16:52 +0100
From: Ricardo Martins <[email protected]>
To: Alexey Dobriyan <[email protected]>
Subject: Re: [PATCH 1/4] sound/isa: use unsigned for loop index
User-Agent: Mutt/1.5.17 (2007-11-01)

Quoted 15 lines · Alexey Dobriyan
Quoted 14 lines · Ricardo Martins
Quoted 5 lines · Alexey Dobriyan
Quoted 2 lines · Julia Lawall

A few more cases in the spirit of the patch "Trivial: Replacement of always

Quoted 1 line

0 ints with unsigned ints" submitted by Ricardo Martins <[email protected]>

And rationale for those would be ...?

Acccording to the kernel-janitors TODO [1], Jeff Garzik suggested the following:

2) "unsigned int" is preferred to "int", it generates better asm code on all platforms except sh5. This replacement needs to be done manually, because often 'int' is required due to negative values -Exxx commonly passed as error values.

Quoted 8 lines
Quoted 6 lines

Since (most) loop counters such as "int i" are always either zero or a positive number, they are perfect candidates for using unsigned int instead, imho. It goes without saying, that each case must be considered separately in case a negative value is indeed needed.

[1] http://kernelnewbies.org/KernelJanitors/Todo

So you've checked disassembly in both cases and saw it's better?

The generated assembly code in a very simple test case (two 'for' loops, one using an int and another using an unsigned int as the counter variable) is exactly the same in both cases.

However, since this was a very very simple test case, I supposed that Jeff Garzik's claim would hold true in more complex cases.

Comparing the output of "objdump -M intel -d drivers/video/nvidia/nvidia.o" before and after my patch, I reach the same conclusion: at least in my arch (x86_64), both versions are approximately the same. If anyone is interested, I can email or upload those dumps somewhere.

Now I feel like a fool. That teaches me to always doubt each and every claim I am exposed to.

Regards,

Signature · 3 lines
 Ricardo Martins  *  scarybox.net  *  GPG key: 0x1308F1B4

----- End forwarded message -----