3 ms·
I’ve printed his entry and there are some neat tricks I learned, but ‘stage 3’, where, according to his comments, a bytecode interpreter is used, is still beyon
by rustybolt 5y ago
I’ve printed his entry and there are some neat tricks I learned, but ‘stage 3’, where, according to his comments, a bytecode interpreter is used, is still beyond my understanding. Also not sure why this helps, a bytecode interpreter sounds like a lot of overhead to me…
- saagarjha 5y agoThe bytecode is specifically designed so that it maps directly to the output. // The third phase operates primarily using a bytecode interpreter; it // generates a program in "FizzBuzz bytecode", for which each byte of // bytecode generates one byte of output. The bytecode language is // designed so that it can be interpreted using SIMD instructions; 32 // bytes of bytecode can be loaded from memory, interpreted, and have // its output stored back into memory using just four machine // instructions. // The bytecode format is very simple (in order to allow it to be // interpreted in just a couple of machine instructions): // - A negative byte represents a literal character (e.g. to produce // a literal 'F', you use the bytecode -'F', i.e. -70 = 0xba) // - A byte 0..7 represents the hundreds..billions digit of the line // number respectively, and asserts that the hundreds digit of the // line number is even // - A byte 8..15 represents the hundreds..billions digit of the line // number respectively, and asserts that the hundreds digit of the // line number is odd // %ymm2 holds the bytecode for outputting the hundreds and more // significant digits of a line number. The most significant digits of // this can be obtained by converting LINENO_TOP from high-decimal to // the corresponding bytecode, which is accomplished by subtracting // from 198 (i.e. 256 - 10 - '0'). The constant parts of LINENO_TOP // are 198 minus the bytecode for outputting the hundreds to billions // digit of a number; this makes it possible for a single endian // shuffle to deal with all 16 of the mid and high digits at once.