Re: [cc65] Own parameter call stack?

From: Christian Krüger <Christian.Krueger1pace.de>
Date: 2009-09-01 16:46:20
>Now, if you remove the high byte handling, all you gain are three cycles for the bcc!
>Ok, decsp4 may be inlined more aggressively if it is smaller, giving another 6+6 cycles
>for jsr/rts. But as can be easily seen from the above, this is just a small precentage
>of the execution time when pushing the parameters.

The gain would be a little bigger since you could use an other addressing mode:

actual pushax:

	pha                     ; (3)
	lda	sp              ; (6)
	sec                     ; (8)
	sbc	#2              ; (10)
	sta	sp		; (13)
	bcs	@L1             ; (17)
	dec	sp+1            ; (+5)
@L1:	ldy	#1              ; (19)
	txa			; (21)
	sta	(sp),y          ; (27)
	pla                     ; (31)
	dey                     ; (33)
	sta	(sp),y		; (38)
	rts                     ; (44)  


could be:

	ldy SP		; (3)
	dey			; (5)
	pha			; (8)
	txa			; (10)
	sta STACK, Y	; (15)
	dey			; (17)
	pla			; (21)
	sta STACK, Y	; (26)
	sty SP		; (29)
	rts			; (35)

pop operations would be faster, since an 'ldx abs,Y' is supported by the 6502.


>Yes, we can gain a few cycles by this method, but the drawback is big: Some programs will compile
>into invalid code and the compiler cannot tell.

But today I could also ran into a stack overflow without a warning?

>You can use a struct and pass a pointer to it. This is as fast as using the stack and just one >__fastcall__ parameter is passed:

Yes, good hint (and also a little bit more object orientated) I make already use of this, but
sometimes I need to 'shuffle' parameter structs for calls and building a separate structure
with encapsulates other structures only for the sake of a cheapter function call is not so
'beautiful'...

I fully understand that this is a spare time eater and your intentions not to do it.
It's just that I'm using the assembler at 99% of my retro coding time and like the framework
in general. I just don't need bigger stacks than 256 bytes in all my projects.
A general switch would be nice - didn't know that the stack accesses are so scattered.


Anyhow, I like to thank you for your great work and the permanently support
Chris

----------------------------------------------------------------------
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 Sep 1 16:46:31 2009

This archive was generated by hypermail 2.1.8 : 2009-09-01 16:46:34 CEST