3 ms·
FWIW, __int128 and the optimizations mentioned works in clang too, my guess is that the author just runs an old version. #include <stdio.h> int ma
by sebcat 11y ago
FWIW, __int128 and the optimizations mentioned works in clang too, my guess is that the author just runs an old version.
#include <stdio.h>
int main() {
FILE *fp;
__int128 v=1234;
fp = fopen("foo12", "w");
fwrite(&v, sizeof(v), 1, fp);
fclose(fp);
return 0;
}
with -O2 -march=native -ffinite-math-only -fno-math-errno, for clang 3.5.0, linux/amd64, gives me:
4005d0: 53 push %rbx
4005d1: 48 83 ec 10 sub $0x10,%rsp
4005d5: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp)
4005dc: 00 00
4005de: 48 c7 04 24 d2 04 00 movq $0x4d2,(%rsp)
4005e5: 00
4005e6: bf b0 06 40 00 mov $0x4006b0,%edi
4005eb: be b6 06 40 00 mov $0x4006b6,%esi
4005f0: e8 bb fe ff ff callq 4004b0 <fopen@plt>
4005f5: 48 89 c3 mov %rax,%rbx
4005f8: 48 8d 3c 24 lea (%rsp),%rdi
4005fc: be 10 00 00 00 mov $0x10,%esi
400601: ba 01 00 00 00 mov $0x1,%edx
400606: 48 89 d9 mov %rbx,%rcx
400609: e8 b2 fe ff ff callq 4004c0 <fwrite@plt>
40060e: 48 89 df mov %rbx,%rdi
400611: e8 6a fe ff ff callq 400480 <fclose@plt>
400616: 31 c0 xor %eax,%eax
400618: 48 83 c4 10 add $0x10,%rsp
40061c: 5b pop %rbx
40061d: c3 retq
40061e: 66 90 xchg %ax,%ax
- cnvogel 11y ago...and both compile a 128=64×64 multiplication into a single imul. __int128 mult128(int64_t a, int64_t b) { return (__int128)a * (__int128)b; a0: 48 89 f0 mov %rsi,%rax a3: 48 f7 ef imul %rdi a6: c3 retq
- nanis 11y agoI have: Apple LLVM version 7.0.0 (clang-700.1.76) Target: x86_64-apple-darwin15.0.0 Thread model: posix I did mention that the same source code when compiled with gcc runs faster in a Linux VM than when it is compiled with clang and run in OSX. That means, some of those optimization options either do not mean anything or do not work as well when using clang.