Threaded Code
Forththreaded code
2022-9-26 0:18 JST

スレッデッドコードの研究。Gforth は特別な直接スレッデッドコードだってどっかに書いてあったんだけど、見失った。

まずは情報集め

threaded codeの説明によると直接スレッディングの方が若干スピードが速いみたいね。「Pentium、K5そしてK6(-2)」の話をしているみたいなので、現在はどうなのよ?というのは気になる。また、間接スレッドのほうがソースがコンパクトになる(はず)なのも気になる。コンパクトのほうが良い。

スレッデッド・コードについてはここの情報も役に立つよね。

FPGA の Forth では深堀しても意味がないかな。スピードよりコンパクトさが重要だし。

自分が前に作ったVMは(Forthじゃない)直接スレッディングだったなぁ。32bit の値をロードするのにどうしようか迷った記憶がある。

immu の threaded code

immu.s_next:

jonesforth の threaded code

jonesforth.S
/* NEXT macro. */
.macro NEXT
lodsl
jmp *(%eax)
.endm

/* The macro is called NEXT.  That's a FORTH-ism.  It expands to those two instructions.
Every FORTH primitive that we write has to be ended by NEXT.  Think of it kind of like
a return.
The above describes what is known as direct threaded code.

リンク集