www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20838] New: on modern (x86_64) CPUs, dmd emit cmpxchg8b


          Issue ID: 20838
           Summary: on modern (x86_64) CPUs, dmd emit cmpxchg8b instead of
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mingwu gmail.com

Created attachment 1788
  --> https://issues.dlang.org/attachment.cgi?id=1788&action=edit
on modern (x86_64) CPUs, dmd emit cmpxchg8b instead of CMPXCHG16B

$ 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);  // output 16 16

$ dmd -m64 c.d
$ /usr/bin/obj2asm c.o > c.o.asm
$ grep -i xchg  c.o.asm
                cmpxchg8b       [R8]


$ grep flags /proc/cpuinfo | head -1 | grep 16
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb
rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology
nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl
vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe
popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch
cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi
flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx
rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida
arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

in particular, the flag cx16 is there:

CX16            *       Supports CMPXCHG16B instruction


$ uname -a

x86_64 x86_64 x86_64 GNU/Linux

$ dmd --version
DMD64 D Compiler v2.092.0
Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved
written by Walter Bright

May 17 2020