Today we added my optimised #uxn core to the repo! uxn-fast.c is over three times faster than the standard uxn.c.
The best thing is that it's generated by a script that works on uxn.c, so when you need to change how Uxn works you can edit the concise, human-readable uxn.c and re-run the script to get high performance!
@eris Let's take DUP2 as an example: in the Uxn docs that opcode pops two bytes from the stack, pushes them back and pushes them again. The C code in uxn.c writes out those operations verbatim.
The script takes all those effects and just sets what is necessary for the end result: setting the contents of two bytes in the stack and adds two to the length. We only need to check the stack for under/overflow once, too - the original uxn.c would check for every pop and push.
@eris The other big thing is the tried-and-tested huge switch statement where all 256 opcodes are spelt out as unrolled code rather than just defining 32 basic opcode functions and varying how they work.
There's no assembly magic yet (sorry @thomasorus!) 😅 but we also rearrange some bits of C code so that compilers have an easy job of doing the rest of the optimisation for us.
@eris @alderwick It's easy to understand when you see the source I think, here: https://git.sr.ht/~rabbits/uxn/tree/master/item/src/uxn-fast.c
Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.