3 ms·
72 bytes. I don't think that's correct; assuming RIP-relative for all the global variables, the first 9 instructions are 7 bytes each and the last one 4, givin
by userbinator 10y ago
72 bytes.
I don't think that's correct; assuming RIP-relative for all the global variables, the first 9 instructions are 7 bytes each and the last one 4, giving a total of 67 bytes.
You can cherry-pick examples all you want, but I think this is a great example of why you should use Asm: It's not even trying to be optimised, and it still somehow manages to be smaller overall!
Try to optimise it, however, and you can definitely beat GCC...
lea rcx, [copyxe]
imul rax, [rcx], 3
add r9, rax
imul rax, [rcx+copyx-copyxe], -3
add r9, rax
imul rax, [rcx+sizex-copyxe], 3
add r10, rax
inc r14
...with 32 bytes. This human gives, for "-O2", the following 41-byte snippet:
lea rcx, [copyxe]
mov rax, [rcx]
lea rax, [rax+rax*2]
add r9, rax
mov rax, [rcx+copyx-copyxe]
lea rax, [rax+rax*2]
sub r9, rax
mov rax, [rcx+sizex-copyxe]
lea rax, [rax+rax*2]
add r10, rax
inc r14
GCC may be clever to turn (-3) * x into x - 4 * x, but not clever enough to realise that turning 3 * x into x + 2 * x like it did for the other two "statements" and a subtraction would be shorter and faster because it means one less operation on the critical path.