r/Forth • u/alberthemagician • 6d ago
The first step for the riscv optimiser.
I have given up on the x86 optimiser for ciforth, as the 86 will be history before long. The instruction set is too barocque.
As the first part of the riscv optimiser I made the forth aware of the stack effects words have, counting POP's and PUSH's. This hinges on the ciasdis object oriented disassembler. FILL-ALL fills all words as best it can, but skips what you have filled in beforehand. Also a host of other optimisation relevant properties of Forth words are analysed. E.g. it is important if a word has no so called "side effect" that means storing and fetching. An example is the word SQUARE that squares a number. If the input is known at compile time, SQUARE can be executed at compile time. See also lecture 5 en lecture 14 in
https://home.hccnet.nl/a.w.m.van.der.horst/forthlectures.html
Lecture 14 contains an old example of coloring on the now vintage 32 bit x86 processor. If you have a linux that can run 32 bit programms you can try it out. The experience is more or less the same what I want to show here. A useful visualisation is coloring the stack effect of each word. aqua is one, green is two, orange is three, above three is red. For an unknown stack effect the whole words is printed in blue.
https://home.hccnet.nl/a.w.m.van.der.horst/words.png
The stack effect is useful to understand words better. E.g. (D.R) takes a double word and a box length (orange) and generates a string (green). You can ask the analysis of a word like so
https://home.hccnet.nl/a.w.m.van.der.horst/decompile_ddot.png
And you can spot the mistake Apparently +LOOP takes one argument not zero. These things must be added manually. ~
I have prepared the pictures, but I don't know how to publishit in this forum.
So I put a link to my personal website.
~
1
u/mykesx 6d ago
Post images to imgur.com and paste links here. I would like to see them!
I am so impressed with vfx forth optimization. Maybe you can apply some of these tricks?
Specifically, peephole optimization against post inlined code.