Re: [cc65] comparing int iterators in loops

From: Johan Kotlinski <kotlinski1gmail.com>
Date: 2012-04-02 12:03:33
>> for (char* ptr = 0xd800; ptr != 0xdbe8; ++ptr) { ... }
>>
>> ...the check for exit condition will be done MSB first. I.e., it would
>> compare with 0xdb before comparing 0xe8.
>>
>> Wouldn't it be so much more efficient if it checks LSB first? Roughly
>> MSB will match one out of four times, while LSB only matches one out
>> of 256 times. So those second checks could be avoided a lot of times.
>
> Ok, but what is with
>
>    for (I = 0x0000; I != 0xFF00; I += 0x100) { ... }
>
> In this case comparing LSB is useless, because the condition is never true.

That is indeed true... but increasing by one is so much more common
(at least for me).
I have just sort of noted this optimization opportunity over and over,
now eventually I made the post ;-)

Cheers,
Johan
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Apr 2 12:04:07 2012

This archive was generated by hypermail 2.1.8 : 2012-04-02 12:04:09 CEST