Sujet : Re: Computer architects leaving Intel...
De : bl1-thispartdoesnotbelonghere (at) *nospam* gmx.com (Bernd Linsel)
Groupes : comp.archDate : 05. Sep 2024, 22:07:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbd6ia$e0ld$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
User-Agent : Betterbird (Linux)
On 05.09.24 19:04, Terje Mathisen wrote:
One of my alternatives are
unsigned u = start; // Cannot be less than zero
if (u) {
u++;
do {
u--;
data[u]...
while (u);
}
This typically results in effectively the same asm code as the signed
version, except for a bottom JGE (Jump (signed) Greater or Equal instead
of JA (Jump Above or Equal, but my version is far more verbose.
Alternatively, if you don't need all N bits of the unsigned type, then
you can subtract and check if the top bit is set in the result:
for (unsigned u = start; (u & TOPBIT) == 0; u--)
Terje
What about:
for (unsigned u = start; u != ~0u; --u)
...
or even
for (unsigned u = start; (int)u >= 0; --u)
...
?
I've compared all variants for x86_64 with -O3 -fexpensive-optimizations
on godbolt.org:
- 32 bit version:
https://godbolt.org/z/TMhhx3nch
- 64 bit version:
https://godbolt.org/z/8oxzTf5Gf
-- Bernd Linsel