News for hackers. Stuff that matters.
Re:Web server for Linux written in amd64 assembly by Luyt on Monday February 03, 2014 @06:48AM (#7170131)

    xor rax,rax
I used this construct often to zero a register, in the time that memory and CPU cycles were scarce. But nowadays, my time is a more valuable resource, and I tend to write:

    mov rax, 0
It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.
Re:Web server for Linux written in amd64 assembly by sneak on Monday February 03, 2014 @07:03AM (#7170169)
> It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.

So do webservers written in Python. I don't think that was the point of this project.

Re:Web server for Linux written in amd64 assembly by xyzzy123 on Monday February 03, 2014 @07:10AM (#7170197)
Personally I find the xor form easier to follow, it's SUCH a long-standing convention that if I saw a mov rax, 0 I would wonder what was going on.
Re:Web server for Linux written in amd64 assembly by rjzzleep on Monday February 03, 2014 @02:04PM (#7172737)
same here. _but_ if you weren't proficient in writing and reading asm the statement would no longer be true.

now, you could argue if that were that the case, wth is that person doing there anyway.

also if you compile something like `return 0;` it used to be compiled down to `xor eax,eax; ret;`, but meh barely anyone i know coding these days even knew this to begin with.

Re:Web server for Linux written in amd64 assembly by XorNot on Monday February 03, 2014 @07:05AM (#7170175)
Couldn't you just find-replace this in a makefile?

Then again almost everything about assembly gets a bit "isn't that what we made other languages for?"

Re:Web server for Linux written in amd64 assembly by csmithuk on Monday February 03, 2014 @07:28AM (#7170270)
xoring something with itself is a common idiom in ASM. Been doing it since the Z80 (XOR A). Not sure that meaning is enhanced at all.
Re:Web server for Linux written in amd64 assembly by lttlrck on Monday February 03, 2014 @07:24AM (#7170261)
A few more instruction cycles? Which architecture and which decade?
Re:Web server for Linux written in amd64 assembly by ksk on Monday February 03, 2014 @08:25AM (#7170471)
This decade :)

For modern out-of-order CPUs - xor reg1,reg2 is problematic because the result depends on the previous contents of the register. Hence it cannot be executed out of order.

However as a special case xor reg1,reg1 (along with sub reg1,reg1) will be detected by the cpu (intel anyway) as a 'zero idiom' instruction and because it has a smaller opcode than mov reg,0 its preferred.

There are also other complex reasons - for detailed info see 3.5.1.8 in the Intel optimization manual.

Re:Web server for Linux written in amd64 assembly by Dylan16807 on Monday February 03, 2014 @12:14PM (#7171907)
>This decade :)

The initial claim was that mov reg,0 was slower to execute.

Re:Web server for Linux written in amd64 assembly by ksk on Monday February 03, 2014 @02:27PM (#7172885)
A CPU cycle is Fetch,Decode,Execute,Writeback. The 'zero idiom' instructions do not consume any 'Execute' resources. Apart from this.. as the other poster said, smaller opcodes means more instructions can fit inside the caches.
Re:Web server for Linux written in amd64 assembly by teraflop on Monday February 03, 2014 @01:05PM (#7172359)
Smaller opcodes will, all else being equal, take up fewer instruction decide cycles and less space in the CPU cache.