6 comments

[ 2.1 ms ] story [ 40.2 ms ] thread
If you're wondering why this is useful, the reason is buffer overflow exploits. Strings in C are null-terminated, so having a null in your code may stop it from getting copied.
I think obfuscation is another reason, since the classic "xor reg, reg" (31 C0 is xor eax, eax) does not have any nulls either.
yeah, nor it does on x64_64 since it's the same encoding but prefixed by a REX: `48 31 c0 xor %rax,%rax`
I've used this in the past, in high performance math.

If you have data (vectors, matrices, etc.) that doesn't fit neatly into a SIMD block size, you'll have to zero out fields after the calculation. At this point, it's cheaper to generate a zero on the register than load via memory (cheaper as in the number of CPU instructions.)

It began as an obsfucation method then I realized more implications.