[PicForth] optimisation issue #2
David McNab
david at rebirthing.co.nz
Tue Nov 30 01:50:39 CET 2004
Hi,
Thanks to Samuel for earlier enlightening reply.
Now, a more challenging scenario. Here's a function from my 5-button
keypad driver:
\ return currently pressed button in W, or 5key.NONE if
\ no key currently pressed
code 5key.getc-raw ( -- W:keycode )
return-in-w
5key.pin-MENU btfss
5key.MENU retlw
5key.pin-UP btfss
5key.UP retlw
5key.pin-DOWN btfss
5key.DOWN retlw
5key.pin-OK btfss
5key.OK retlw
5key.pin-STARTSTOP btfss
5key.STARTSTOP retlw
5key.NONE retlw
end-code
I tried recoding this in pure PicForth, as:
: 5key.getc-raw
forth> return-in-w
5key.pin-MENU high? if 5key.MENU exit then
5key.pin-UP high? if 5key.UP exit then
5key.pin-DOWN high? if 5key.DOWN exit then
5key.pin-OK high? if 5key.OK exit then
5key.pin-STARTSTOP high? if 5key.STARTSTOP exit then
5key.NONE
;
However, this is generating:
; name: 5key.getc-raw
; max return-stack depth: 0
0x045F 1C07 btfss 0x07,0
0x0460 2C64 goto 0x464 ; 5key.getc-raw + 0x005
0x0461 0384 decf 0x04,f
0x0462 0180 clrf 0x00
0x0463 0008 return
0x0464 1C87 btfss 0x07,1
0x0465 2C6A goto 0x46A ; 5key.getc-raw + 0x00B
0x0466 3001 movlw 0x01
0x0467 0384 decf 0x04,f
0x0468 0080 movwf 0x00
0x0469 0008 return
...
This is using 5 words per test, instead of 2 as with the assembler example.
As I (mis)understand PicForth, the 'return-in-w' command flags a word,
such that when another word calls it, the calling word knows to look in
W instead of TOS for the return value.
So my (hopefully small) feature request is:
- expose 'return-in-w' in 'target' wordspace
- extend the PicForth optimiser to take advantage of 'return-in-w'
and generate code which makes full use of this.
--
Cheers
David
More information about the PicForth
mailing list