Last active
July 21, 2016 09:34
-
-
Save rwg/9c2de9ea02bc216b764625a92a0e87e0 to your computer and use it in GitHub Desktop.
gcc and clang vs. https://randomascii.wordpress.com/2016/07/17/zeroing-memory-is-hard-vc-2015-arrays/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - Host is OS X 10.11.5 (Darwin 15.5.0) | |
# - clang is the version shipped with XCode 7.3.1: "Apple LLVM version 7.3.0 (clang-703.0.31)" | |
# - gcc-6.1.0 was compiled from source | |
% cat z.c | |
extern void do_something(char *); | |
main() { | |
char buffer[32] = { 0 }; | |
do_something(buffer); | |
} | |
% gcc-6.1.0 -m64 -march=x86-64 -mtune=generic -O0 -S -o - z.c | |
[snip] | |
movq $0, -32(%rbp) | |
movq $0, -24(%rbp) | |
movq $0, -16(%rbp) | |
movq $0, -8(%rbp) | |
[snip] | |
% gcc-6.1.0 -m64 -march=x86-64 -mtune=generic -O1 -S -o - z.c | |
[snip] | |
movq $0, (%rsp) | |
movq $0, 8(%rsp) | |
movq $0, 16(%rsp) | |
movq $0, 24(%rsp) | |
[snip] | |
# NOTE: -O2 and -O3 generate the same assembly code as -O1 | |
% gcc-6.1.0 -m64 -march=x86-64 -mtune=generic -Os -S -o - z.c | |
[snip] | |
xorl %eax, %eax | |
movl $8, %ecx | |
movq %rsp, %rdi | |
rep stosl | |
[snip] | |
% clang -m64 -march=x86-64 -mtune=generic -fno-stack-protector -O0 -S -o - z.c | |
[snip] | |
xorl %esi, %esi | |
movl $32, %ecx | |
movl %ecx, %edx | |
movq %rax, %rdi | |
movq %rax, -40(%rbp) ## 8-byte Spill | |
callq _memset | |
[snip] | |
% clang -m64 -march=x86-64 -mtune=generic -fno-stack-protector -O1 -S -o - z.c | |
[snip] | |
xorps %xmm0, %xmm0 | |
movaps %xmm0, -16(%rbp) | |
movaps %xmm0, -32(%rbp) | |
[snip] | |
# NOTE: -O2, -O3, and -Os generate the same assembly code as -O1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment