News for hackers. Stuff that matters.

inolen1

Re:Compiling Quake 3 Virtual Machines To JavaScript on Sunday February 16, 2014 @03:26PM (#7249112)
Right. Pulling from JC's August 16, 1999 .plan (http://floodyberry.com/carmack/johnc_plan_1999.html#d1999081...) when he first wrote the x86 compiler:

Q3demo1 dll: 52.9 Compiled: 50.2 Interpreted: 43.9

Q3demo2 dll: 50.1 Compiled: 46.5 Interpreted: 38.7

Re:Compiling Quake 3 Virtual Machines To JavaScript on Sunday February 16, 2014 @01:26PM (#7248553)
I actually did that first: https://github.com/inolen/qvmc

It worked, but the main issue was related to object file generation.

Basically, you have to allocate one big i8 array to represent all of the QVM's data segments (including its bss segment). This doesn't translate well once compiled with Emscripten, as bss relocation is on a per-variable basis. For one of the Quake 3 Fortress QVMs which was only a few hundred kb it output a ~50mb .bc file and a ~70mb .js file of mostly 0s.

I experimented with storing each segment as its own i8 array (which could be 0 initialized for the bss segment) in a packed struct, which significantly lowered the .bc file size. However, while I was looking into what I'd need to change in Emscripten to support this, I instead decided to go the route of writing the runtime compiler.

Fun fact: Quake 3 mods didn't have access to malloc / free, so it wasn't uncommon to have large amounts of static, 0 initialized data.