[Slackers] conditional performance

Steve Judd sjudd at ffd2.com
Mon Apr 17 20:49:50 CDT 2006


On Tue, 18 Apr 2006, Jaymz Julian wrote:

> One interesting thing, is that the following:
>
> if+(foo)
> if+(bar)
> endif
> endif
>
> seems faster than:
>
> if(foo and bar)
> endif
>

Shouldn't be.  Yeah, check it out:

Compiling...
:1000
:1000             ubyte    a,b
:1000
:1000 ad 18 10 f0
:1004 08          if+      a
:1005 ad 19 10 f0
:1009 03                       if+ b
:100a ee 20 d0                   inc $d020
:100d                          endif+
:100d             endif+
:100d
:100d ad 18 10 2d
:1011 19 10 f0 03 if+      a   and b
:1015 ee 20 d0                 inc $d020
:1018             endif+

The first one assembles to

	lda a
	bne :skip
	lda b
	bne :skip
	inc $d020
:skip

while the first one is

	lda a
	and b
	bne :skip

(which assumes a and b are logical 1 or 0 -- if a=1 and b=2 the branch
won't be taken, for example.)

(Note, by the way, that parethesis aren't required.)

-S


More information about the Slackers mailing list