www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9200] New: Wrong SIMD cod generated

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200

           Summary: Wrong SIMD cod generated
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jerro.public gmail.com


--- Comment #0 from jerro.public gmail.com 2012-12-23 10:38:26 PST ---
When compiled with no flags, the following program gives wrong results:

import std.stdio;
import core.simd;

double2 * v(double* a)
{
    return cast(double2*)a;
}

void main()
{
    double2 a;
    auto p = cast(double*) &a;
    p[0] = 1;
    p[1] = 2;

    double2 b = v(p)[0];
    v(p)[0] = b;

    writeln(p[0 .. 2]); // prints [1, 0]
}

Disassembly of the relevant part of the code:


call   426344 <_D3tmp1vFPdZPNhG2d>
movapd xmm0,XMMWORD PTR [rax]
movapd XMMWORD PTR [rbp-0x10],xmm0
movapd xmm1,XMMWORD PTR [rbp-0x10]
movsd  QWORD PTR [rbp-0x40],xmm1        ; should be movapd
mov    rdi,QWORD PTR [rbp-0x20]
call   426344 <_D3tmp1vFPdZPNhG2d>
movsd  xmm1,QWORD PTR [rbp-0x40]        ; should be movapd
movapd XMMWORD PTR [rax],xmm1

This happens with both DMD 2.060 and the latest version of 2.061 from github.
It doesn't happen if I use either -O flag or -inline. It doesn't happen with
LDC or GDC.

I have only tested this on linux.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200



--- Comment #1 from jerro.public gmail.com 2012-12-23 10:49:42 PST ---
I managed to reduce it a bit further:

import std.stdio;
import core.simd;

double2 * v(double2* a)
{
    return a;
}

void main()
{
    double2 a = [1, 2];

    *v(&a) = a;

    writeln(a.array);
}

And the disassembly:


movsd  QWORD PTR [rbp-0x20],xmm1
lea    rdi,[rbp-0x10]
call   4263f4 <_D3tmp1vFPNhG2dZPNhG2d>
movsd  xmm1,QWORD PTR [rbp-0x20]
movapd XMMWORD PTR [rax],xmm1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2012-12-23
21:10:51 PST ---
This is happening in cod3.c REGSAVE::save() and REGSAVE::restore().
Unfortunately, just changing the opcodes doesn't work because MOVAPD requires
16 bit alignment of the operands. Fixing that exposes further problems.

Essentially, it'll have to wait a bit.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200



--- Comment #3 from jerro.public gmail.com 2012-12-24 16:24:04 PST ---
(In reply to comment #2)
 This is happening in cod3.c REGSAVE::save() and REGSAVE::restore().
 Unfortunately, just changing the opcodes doesn't work because MOVAPD requires
 16 bit alignment of the operands. Fixing that exposes further problems.
 
 Essentially, it'll have to wait a bit.

I know nothing about the DMD back end, so this may be an obviously bad idea, but if alignment is the main problem, wouldn't using MOVUPD work in the meantime? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200



--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2012-12-24
19:00:01 PST ---
MOVUPD is terribly slow.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |yebblies gmail.com
           Severity|major                       |critical


--- Comment #5 from yebblies <yebblies gmail.com> 2013-01-14 22:08:27 EST ---
(In reply to comment #4)
 MOVUPD is terribly slow.

Terribly slow is still much better than wrong-code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 14 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9200


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |SIMD
             Status|NEW                         |RESOLVED
           Platform|x86_64                      |All
         Resolution|                            |FIXED
         OS/Version|Linux                       |All


--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2013-01-14
12:44:51 PST ---
Fixed here:

https://github.com/D-Programming-Language/dmd/commit/c33809cc201b4697b384209eb3a7a623e8e871e9#src/backend/cod3.c

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 14 2013