Source

Thread

1/ @NOTimothyLottes

Exploring minimum size compilers on x86-64, specifically branch-free logic (one predicted jnz to loop per input token). A minimum forth-like language can be built with a 17-instruction/token loop. Source uses {2-bit tag, 14-bit dictionary index}.

2/ @NOTimothyLottes

So the instructions of the compiler itself fits on one x86-64 cacheline, less than 64 bytes total.

3/ @NOTimothyLottes

From a data perspective, it’s 16384 entry dictionary that contains direct 32-bit chunks of pre-compiled instructions that can be spiced together.

4/ @NOTimothyLottes

2-bit tag/token,
00 : write value from dictionary ‘V’
01 : write V-nextInstructionPointer (for call/jmp)
02 : ignore (for comments)
03 : write instructionPointer into dictionary (for define)

So like a direct mapped tiny color-forth

5/ @NOTimothyLottes

Haven’t timed code generation speed, but it’s probably peaks around 1/2 GB/sec of code gen on a 2 GHz x86-64. Meaning fast enough to support recompiling the whole program each frame if you wanted to.

6/ @NOTimothyLottes

Designing the language around making something forth-like to be the macro assembler for GPU binary generation, but also fast enough to be the entire x86-64 code as well. Meaning can do x86-64 assembly too for important raw loops.

7/ @NOTimothyLottes

Apparently AMD’s Zen line doesn’t have sub-register stalls like Intel, so one can take advantage. Also used the 2-for-1 {SAR ax,15} trick, which produces a full 0/~0 mask along with putting the last shifted out bit 14 in CF. Quite useful for branch-free logic (like cmovCC ops).

8/ @NOTimothyLottes

x86-64 is actually really poor ISA for branch-free logic for many reasons, like cmovCC doesn’t have an IMM operand form so you burn registers for immediate constants, and not having a separate destination register means extra MOVs to duplicate, with some exceptions like LEA.

9/ @NOTimothyLottes

Anyway this whole system was another exploration of a minimal x86-64 based setup. Last I was trying a text interpretered one (with branches), and I think this new one is substantially better.

10/ @NOTimothyLottes

There is also a lot of nice things about working in Linux and having the easy ability to guarantee code/data in the lower 32-bit address space. This is for no-library execution (meaning only kernel interfaces, including for the GPU).

0 items under this folder.