News for hackers. Stuff that matters.
Re:Writing C software without the standard library by dispose13432 on Tuesday November 29, 2016 @03:03AM (#13061594)
> xor rbp,rbp /* xoring a value with itself = 0 */

Is this faster than a (const) mov ?

Re:Writing C software without the standard library by vram22 on Tuesday November 29, 2016 @10:20AM (#13063526)
Apart from the replies to your question here, there was another interesting sub-thread on HN on this topic recently:

"Also, I like how returning 0 is "xor eax, eax"."

https://news.ycombinator.com/item?id=13052503

That led to multiple replies on it.

Re:Writing C software without the standard library by capnfantasic on Tuesday November 29, 2016 @03:09AM (#13061615)
Traditionally yes. On the latest CPUs - who knows.
Re:Writing C software without the standard library by SonOfLilit on Tuesday November 29, 2016 @03:34AM (#13061704)
Probably yes, because Intel knows this is the code every compiler outputs for zeroing a register.

Also, the reason it is "faster" is that the encoding is 1 byte, vs. 9 bytes (in 64 bit) for "mov rbp, 0" - roughly, 1 for "mov rbp,", 8 more for a 64 bit "0".

Re:Writing C software without the standard library by bonzini on Tuesday November 29, 2016 @04:18AM (#13061864)
Technically you could get by with 5 bytes for "mov ebp, 0".

Another reason why it was faster was that the processor recognized it and avoided partial flags stalls after an "inc". But in 64-bit code you rarely have "inc" at all, so it matters less. On the other hand, a few years ago XOR had a false dependency on the register you're clearing; I'm not sure it is still that way on more recent processors.

Re:Writing C software without the standard library by SonOfLilit on Tuesday November 29, 2016 @06:49AM (#13062434)
I tip my hat to you, your analysis is far more interesting than mine.
Re:Writing C software without the standard library by bonzini on Wednesday November 30, 2016 @02:15AM (#13069054)
Wrong too, it's partial register stalls not partial flags stalls.