Bug 20131 – Bad codegen from inline asm LOCK CMPXCHG; possible REX prefix missing

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-15T07:40:55Z
Last change time
2019-08-16T02:35:31Z
Keywords
iasm, pull
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2019-08-15T07:40:55Z
Compile and dump using: > dmd asmtest.d -O -c -m64 && objdump asmtest.o -S asmtest.d --------- bool cas(byte*, byte*, byte) { asm pure nothrow @nogc @trusted { naked; mov AL, [RSI]; lock; cmpxchg [RDX], DIL; mov DL, AL; setz AL; je skip_writeback; mov [RSI], DL; skip_writeback: ret; } } Emits: Disassembly of section .text._D7asmtest3casFPgQcgZb: 0000000000000000 <_D7asmtest3casFPgQcgZb>: 0: 8a 06 mov (%rsi),%al 2: f0 0f b0 3a lock cmpxchg %bh,(%rdx) 6: 88 c2 mov %al,%dl 8: 0f 94 c0 sete %al b: 74 02 je f <_D7asmtest3casFPgQcgZb+0xf> d: 88 16 mov %dl,(%rsi) f: c3 retq Note: Src: lock; cmpxchg [RDX], DIL; Output: lock cmpxchg %bh,(%rdx) DIL turned into %bh. only 4 bytes including LOCK... REX prefix missing maybe? Blocks https://github.com/dlang/druntime/pull/2735
Comment #1 by bugzilla — 2019-08-15T09:04:14Z
Minimal test case: bool test() { asm { naked; cmpxchg [RDX], DIL; } }
Comment #2 by bugzilla — 2019-08-15T09:05:56Z
For the moment, until I fix it, you can use db to insert the exact bytes you need.
Comment #3 by dlang-bot — 2019-08-15T10:10:49Z
@WalterBright created dlang/dmd pull request #10312 "fix Issue 20131 - Bad codegen from inline asm LOCK CMPXCHG; possible …" fixing this issue: - fix Issue 20131 - Bad codegen from inline asm LOCK CMPXCHG; possible REX prefix missing https://github.com/dlang/dmd/pull/10312
Comment #4 by dlang-bot — 2019-08-16T02:35:31Z
dlang/dmd pull request #10312 "fix Issue 20131 - Bad codegen from inline asm LOCK CMPXCHG; possible …" was merged into master: - e26754056f0e671edbcdb80b9507780fa078907d by Walter Bright: fix Issue 20131 - Bad codegen from inline asm LOCK CMPXCHG; possible REX prefix missing https://github.com/dlang/dmd/pull/10312