Follow

Today we added my optimised 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!

Thanks to @asie and @bd for inspiration and tips!

· · Web · 1 · 4 · 17

@eris @alderwick @asie @bd I have no idea what I'm talking about, I just wanted to give a more esoteric vibe to the conversation and failed.

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

1/2

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

2/2

Sign in to participate in the conversation
Merveilles

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.