You never published your source code, Dr. Brad? I would love to see it sometime, as a non-trivial example of proper technique for a novice like myself.
Mike B.
Split stack vs. other approaches
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Split stack vs. other approaches
The oversight has now been rectified. Source code is here. Be warned that it was originally written in Forth 'screens' using 'shadow screens' for documentation; when converted to an ASCII text file, all the shadow screens got put at the end. Someday I should reformat it into 128-character lines with the comments alongside the text, or perhaps interleave the shadow screens with the source screens. There's also a lot of white space from empty screens.
You will probably find the glossary useful, as well. And a lot of it was written in assembly-language CODE words (for the 80x86).
You will probably find the glossary useful, as well. And a lot of it was written in assembly-language CODE words (for the 80x86).
Because there are never enough Forth implementations: http://www.camelforth.com
Re: Split stack vs. other approaches
Dragging out an older post.
On TOS optimizing.
I wrote a optimizing compiler for a DSP chip. Words that used value on
top of the stack had two entries. One that assumed the TOS was
in the TOS location and the other that it was not.
The compiler kept track of the state of TOS. If it was empty the
consuming word would be compiled at the earlier address that
popped the value.
This was only for low level words. Most high level words kept the stack
balanced.
Dwight
On TOS optimizing.
I wrote a optimizing compiler for a DSP chip. Words that used value on
top of the stack had two entries. One that assumed the TOS was
in the TOS location and the other that it was not.
The compiler kept track of the state of TOS. If it was empty the
consuming word would be compiled at the earlier address that
popped the value.
This was only for low level words. Most high level words kept the stack
balanced.
Dwight
Re: Split stack vs. other approaches
barrym95838 wrote:
That's Charlie's deal with his Pettil implementation. It involves some trade-offs. A favorable example: NIP becomes INX. There are pros and cons to any decision like that. For my 65m32 DTC Forth, I keep TOS in the accumulator, but that would be impossible for a 6502, and a dubious optimization for an '802/'816. Perhaps Charlie did some benchmarks that led to his design decision, and would be able to share them briefly with us, here or in a fresh thread?
Code: Select all
plus ; split stack with separate tos
clc ;[2]
lda tos ;[3]
adc stackl,x ;[4]
sta tos ;[3]
lda tos+1 ;[3]
adc stackh,x ;[4]
sta tos+1 ;[3]
inx ;[2]
jmp next ;[3] =27 clocks
vs.
plus ; split stack only
clc ;[2]
lda stackl,x ;[4]
adc stackl+1,x ;[4]
sta stackl+1,x ;[4]
lda stackh+1,x ;[4]
adc stackh,x ;[4]
sta stackh+1,x ;[4]
inx ;[2]
jmp next ;[3] =31 clocksRe: Split stack vs. other approaches
Arrays also benefit from LSB/MSB splittng.
In the programming section I use this a bunch, in my
distribution sort code, but it does chew up page zero pointers faster.
Dwight
In the programming section I use this a bunch, in my
distribution sort code, but it does chew up page zero pointers faster.
Dwight
Re: Split stack vs. other approaches
Brad R wrote:
_________________
Because there are never enough Forth implementations: http://www.camelforth.com
Because there are never enough Forth implementations: http://www.camelforth.com
Re: Split stack vs. other approaches
chitselb wrote:
Garth has gently suggested that the split stack might not be very good.There are two 48-byte regions of zero page called 'stackl' and 'stackh', with 'tos' being stored in a separate 2-bytes contiguous region of zero page. The X register is the stack pointer
GARTHWILSON wrote:
It would take some convincing for me to believe that splitting the stack and having to keep moving things in and out of a fixed-address TOS pair of ZP bytes would be more efficient than keeping byte pairs together in every cell and doing indexing and doing the INX or DEX twice to add or drop stack cells.
It just seems that PETTIL's split stack approach with TOS in a dedicated zero page location would make implementing multitasking more difficult.