Re: [cc65] comparing int iterators in loops

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2012-04-02 10:59:12
On Mon, Apr 02, 2012 at 09:20:57AM +0200, Johan Kotlinski wrote:
> Hi, just one thought here. When I make a loop like this:
>
> 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. 

What I want to say is that it depends heavily on the actual circumstances,
which strategy is better.

I will have a more thoroughful look at it when I'm at home again.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
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 10:59:18 2012

This archive was generated by hypermail 2.1.8 : 2012-04-02 10:59:21 CEST