[Issue 20838] on modern (x86_64) CPUs, dmd emit cmpxchg8b instead of CMPXCHG16B
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 18 21:37:46 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20838
--- Comment #11 from mw <mingwu at gmail.com> ---
> this is solely an issue with your 'workflow' involving obj2asm.
Thank you. It's indeed the problem of obj2asm, with gnu's tool objdump:
--------------------------------------------------------------------------------
$ ldc2 -m64 c.d
$ objdump -S --disassemble c > c.asm
$ grep -i cmpxch c.asm
f5b3: f0 48 0f c7 0e lock cmpxchg16b (%rsi)
1ecc3: f0 48 0f b1 3a lock cmpxchg %rdi,(%rdx)
1ed32: f0 40 0f b0 3a lock cmpxchg %dil,(%rdx)
1ed42: 66 f0 0f b1 3a lock cmpxchg %di,(%rdx)
30563: 48 8d 15 ba ea 01 00 lea 0x1eaba(%rip),%rdx #
4f024 <_D4core5cpuid13_hasCmpxchg8byb>
30573: 48 8d 15 ab ea 01 00 lea 0x1eaab(%rip),%rdx #
4f025 <_D4core5cpuid14_hasCmpxchg16byb>
30da6: f0 48 0f b1 3c ce lock cmpxchg %rdi,(%rsi,%rcx,8)
--------------------------------------------------------------------------------
I found the cmpxchg16b instruction.
But I'm not sure what the other 'cmpxchg' is. Can some asm expert help explain?
BTW: I find another issue with LDC: with this code on
https://d.godbolt.org/z/HesA24
i.e. remove the import std.stdio and writeln
--------------------------------------------------------------------------------
$ cat c.d
//import std.stdio;
import core.atomic;
struct N {
N* prev;
N* next;
}
shared(N) n;
void main() {
cas(&n, n, n);
//writeln(size_t.sizeof*2, N.sizeof);
}
$ ldc2 -m64 c.d
$ ./c
Segmentation fault (core dumped)
$ ldc2 --version
LDC - the LLVM D compiler (1.20.0):
based on DMD v2.090.1 and LLVM 9.0.1
built with LDC - the LLVM D compiler (1.20.0)
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake
http://dlang.org - http://wiki.dlang.org/LDC
--------------------------------------------------------------------------------
Although on https://d.godbolt.org/z/HesA24
the "Output" dropdown has an option "Run the compiled binary", I select that,
but didn't see the result.
With import std.stdio and writeln, the LDC output behave normally (no
segfault):
--------------------------------------------------------------------------------
$ ldc2 -m64 c.d
$ ./c
1616
--------------------------------------------------------------------------------
Can you try if you can reproduce this segfault on a local Linux box?
--
More information about the Digitalmars-d-bugs
mailing list