Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular stacks #71

Open
massung opened this issue Aug 3, 2018 · 6 comments
Open

Circular stacks #71

massung opened this issue Aug 3, 2018 · 6 comments

Comments

@massung
Copy link
Member

massung commented Aug 3, 2018

For those of you who have had the pleasure of working with some of Chuck's hardware, I'm generally curious: did/do you still actively work to keep the parameter stack balanced or did you just ignore it to save cycles?

Specifically, I'm thinking of instructions like if and -if that don't pop S into T. Unless there was a specific reason to do so, would you waste the memory+cycles to drop? Did you ever run into situations where the circular stack came back to haunt you if you weren't careful about balancing your work (and perhaps even would have preferred the hardware halt)?

@RickCarlino
Copy link
Member

RickCarlino commented Aug 3, 2018

@massung I've never worked with any of Chuck's hardware and actually this is the first time I've ever heard of anyone using a Forth with a circular stack.

Is there any literature out there about this? I'd like to learn more.

@massung
Copy link
Member Author

massung commented Aug 3, 2018

http://www.greenarraychips.com/

Most of Chuck's chips have used circular stacks - for both parameter and return stacks - for quite some time. The F18A is a personal favorite as far as the spec goes (I haven't actually had the pleasure of working with one): http://www.greenarraychips.com/home/documents/index.html#F18A

@CharleyShattuck
Copy link

I've used the circular stacks on an F18A quite a bit and I'm completely sold on the idea. If you need to keep track you can. If you don't need to, don't bother. Also you can fill up the circular stack(s) and pop values repeatedly to save code and time. I think they're a great idea.

@mschuldt
Copy link

mschuldt commented Aug 6, 2018

Definite use them! Doing tricks with the circular stacks is one of the fun parts of programming the f18/ga144, but really I think it's often more about saving memory than it is about saving cycles. Remember each f18 computer has only 64 words of memory.

Filling the circular stacks like Charley mentioned is super cool! An example of this is their code to find the resonant frequency of a watch crystal and continuously pump it to maintain oscillation. It's often used as a low duty cycle signal source for low powered applications.

Once the code is done initializing oscillation and setting up the stack it can just spin in a tight loop writing values from the stack to the io port.

you can read about it and see the code on page 8 of this application note

@mschuldt
Copy link

mschuldt commented Aug 6, 2018

@RickCarlino Greenarray's download index has just about everything on the f18 and ga144.

Chuck's site colorforth.com was another resource and also had a bunch of interesting info about the tools and process of designing the chips. It's down now but I have a mirrored version hosted on github pages here and collected some links to the pages relevant to programming the ga144 here.

@rdrop-exit
Copy link
Member

rdrop-exit commented Aug 7, 2018

One nifty 'feature' of a circular stack is that it makes it more attractive for a processor's ISA to include all 16 dyadic bitwise boolean operators (implemented as a Word-Width x 4-1 mux). For example drop is actually a bitwise logical operation when you're using a circular stack.

The following snippet is actually from a byte-coded (i.e. token threaded) Forth virtual machine rather than a real processor, but it should illustrate the concept.

0 preamble  Host VM Bytecodes $ f0 .. $ ff
1
2 Low nibble of bytecode corresponds to dyadic bitwise boolean
3 function number:
4
5           drop               or nor               dropc
6         andc  \           xor |  | eqv           /  cor
7        and  \  \       nip |  |  |  | nipc      /  /  nand
8       0d  \  \  \  cand |  |  |  |  |  | orc   /  /  /  -1d
9    x t  \  \  \  \   |  |  |  |  |  |  |  |   /  /  /  /
a    0 0 | 0| 0| 0| 0| 0| 0| 0| 0| 1| 1| 1| 1| 1| 1| 1| 1|
b    0 1 | 0| 0| 0| 0| 1| 1| 1| 1| 0| 0| 0| 0| 1| 1| 1| 1|
c    1 0 | 0| 0| 1| 1| 0| 0| 1| 1| 0| 0| 1| 1| 0| 0| 1| 1|
d    1 1 | 0| 1| 0| 1| 0| 1| 0| 1| 0| 1| 0| 1| 0| 1| 0| 1|
e     f#   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
f
0 shadow  Host VM Bytecodes $ f0 .. $ f7
1
2 0d   Dyadic zero.
3 and  Bitwise and.
4 andc Bitwise and with complement - AKA nimp.
5 drop Discard top of stack.
6 cand Bitwise complement then and - AKA nif, bic.
7 nip  Discard second entry of stack.
8 xor  Bitwise exclusive-or - AKA neq.
9 or   Bitwise inclusive-or.
a
b
c
d
e
f
0 source  Host VM Bytecodes $ f0 .. $ f7
1
2 $ f0 bytecode 0d   ( x1 x2 -- 0 )
3 $ f1 bytecode and  ( x1 x2 -- x1&x2 )
4 $ f2 bytecode andc ( x1 x2 -- x1&~x2 )
5 $ f3 bytecode drop ( x -- ) \ i.e. x1 x2 -- x1  (circular stack)
6 $ f4 bytecode cand ( x1 x2 -- ~x1&x2 )
7 $ f5 bytecode nip  ( x1 x2 -- x2 )
8 $ f6 bytecode xor  ( x1 x2 -- x1^x2 )
9 $ f7 bytecode or   ( x1 x2 -- x1|x2 )
a
b
c
d
e
f
0 shadow  Host VM Bytecodes $ f8 .. $ ff
1
2 nor   Bitwise nor.
3 eqv   Bitwise equivalence - AKA xnor.
4 nipc  Nip then complement.
5 orc   Bitwise or with complement - AKA bitwise if.
6 dropc Drop then complement.
7 cor   Bitwise complement then or - AKA imp.
8 nand  Bitwise nand.
9 -1d   Dyadic -1.
a
b
c
d
e
f
0 source  Host VM Bytecodes $ f8 .. $ ff
1
2 $ f8 bytecode nor   ( x1 x2 -- x1~|x2 )
3 $ f9 bytecode eqv   ( x1 x2 -- x1~^x2 )
4 $ fa bytecode nipc  ( x1 x2 -- ~x2 )
5 $ fb bytecode orc   ( x1 x2 -- x1|~x2 )
6 $ fc bytecode dropc ( x1 x2 -- ~x1 )
7 $ fd bytecode cor   ( x1 x2 -- ~x1|x2 )
8 $ fe bytecode nand  ( x1 x2 -- x1~&x2 )
9 $ ff bytecode -1d   ( x1 x2 -- -1 )
a
b
c
d
e
f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants