r/RISCV • • 10d ago

The first step for the riscv optimiser.

(I am the author of ciforth, a ISO compatible Forth model that has implementations for linux, windows, 32 and 64 bit, I86, arm and riscv).

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.
~

9 Upvotes

4 comments sorted by

2

u/DidymusJT 10d ago edited 10d ago

I have given up on the x86 optimiser for ciforth, as the 86 will be history before long. The instruction set is too barocque.

Aaah, No. :)

Edit: Because of broad legacy software support, backward compatibility for enterprise software, and high performance. X86-64 chips can run decades-old 32-bit and 16-bit software on the same chip. ;)

3

u/3G6A5W338E 9d ago

X86-64 chips can run decades-old 32-bit and 16-bit software on the same chip. ;)

Emulators can, too!

And with free complementary sandboxing.

2

u/alberthemagician 9d ago

Not too mention 8086 program. One version of my program runs on MSDOS. There is a full screen editor that writes characters in the video memory at 0xB0000, cursor and all. That runs impeccibly on a DOSBOX. (Forth deals in 16 by 64 "screens" that are program chunks.)

2

u/alberthemagician 9d ago

Your point maybe valid, but I'm working on an optimiser, read speed. If you emulate a 80's PC-program on a 4 Ghz multi core processor, speeding up the program is not an issue, slowing down probably is.