[cc65] How to force a pointer optimization?

From: Jakub <debski.jakub1wp.pl>
Date: 2009-04-14 19:27:50
Hi,



Addressing the known table generates a fast and compact code 
(cl65 -Osi -Cl -l test.c):



unsigned char a[255];

void main(void)

{

  unsigned char i;

  for (i=1;i;++i)

    a[i] = 0x02;

}



000000r 1  A9 01             lda     #$01

000002r 1  8D rr rr          sta     L0004

000005r 1  AD rr rr     L0005:     lda     L0004

000008r 1  F0 0E             beq     L0006

00000Ar 1  AC rr rr          ldy     L0004

00000Dr 1  A9 02             lda     #$02

00000Fr 1  99 rr rr          sta     _a,y

000012r 1  EE rr rr          inc     L0004

000015r 1  4C rr rr          jmp     L0005

000018r 1  60           L0006:     rts



(I know about memset, this is just an example).



However when I use a constant pointer, the generated code is much less 
efficient, even with zero-page indexer.

Is there a way to write constant+index ((unsigned char*)a)[i] somehow to 
make it optimized by CC65?



//// test.c

#define a 0x9C68

extern unsigned char i;

#pragma zpsym ("i");

void main(void)

{

for (i=1;i;++i)

((unsigned char*)a)[i] = 0x02;

}

//// zero.asm

.export _i

.segment "ZEROPAGE"

_i: .byte 0

////



lda #$01

sta _i

L0003: lda _i

beq L0004

ldx #$9C

lda #$68

clc

adc _i

bcc L000E

inx

L000E: sta sreg

stx sreg+1

lda #$02

ldy #$00

sta (sreg),y

inc _i

jmp L0003

L0004: rts



Btw, do you still prefer not to add the zstatic keyword?

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Apr 14 19:27:57 2009

This archive was generated by hypermail 2.1.8 : 2009-04-14 19:28:00 CEST