Writing a BitStream in pure JS I tried the following operation:
// Calculate the number of bits to write in this var bitsToWrite = bitsLeftInByte < bitLength ? bitsLeftInByte : bitLength;
On my first round of optimisation, this seemed like a possible candidate.
Nope, 10% slower.
var xmy = bitsLeftInByte - bitLength; var bitsToWrite = bitLength + (xmy & (xmy >> 31));
Aha, bit twiddling hacks! About 5% slower.
I think I need to see some assembly to make any sense of this.
I'd like to say I will do some command-line fu, but more likely is I will attach OllyDbg in a Windows build of NodeJS.