Jump to page: 1 2
Thread overview
[Issue 19443] core.simd generates incorrect code
Oct 08, 2020
Nathan S.
Dec 22, 2020
Walter Bright
Dec 28, 2020
Walter Bright
Dec 28, 2020
Walter Bright
Jan 07, 2021
ponce
[Issue 19443] core.simd generates incorrect code for MOVHLPS
Mar 20, 2021
Nathan S.
Mar 21, 2021
Walter Bright
Mar 21, 2021
Walter Bright
[Issue 19443] core.simd generates MOVLPS instead of MOVHLPS
Mar 21, 2021
Walter Bright
Mar 21, 2021
Dlang Bot
Mar 21, 2021
Dlang Bot
October 08, 2020
https://issues.dlang.org/show_bug.cgi?id=19443

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |n8sh.secondary@hotmail.com
          Component|phobos                      |dmd
           Severity|minor                       |normal

--- Comment #1 from Nathan S. <n8sh.secondary@hotmail.com> ---
I ran into MOVHLPS not working today. I spent some time looking through DMD but couldn't find anything different between the way it treats MOVHLPS and MOVLHPS (the latter of which as j.kulaviir said works fine) aside from them having different opcodes.

--
December 22, 2020
https://issues.dlang.org/show_bug.cgi?id=19443

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend, SIMD
                 CC|                            |bugzilla@digitalmars.com

--
December 28, 2020
https://issues.dlang.org/show_bug.cgi?id=19443

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
Here's the attachment:

/*dmd -m64 movhlps.d*/
import std.stdio;
import core.simd;

void main ()
{
        float4 a = [1, 2, 4, 8];
        float4 b = [2, 3, 5, 7];
        writefln ("expected result: [5, 7, 4, 8]");
        //Does not produce the expected result
        writefln ("core.simd: %s", simd!(XMM.MOVHLPS) (a, b));
        //But this does. How mysterious!
        float4 res;
        asm
        {
                movaps XMM0, a;
                movaps XMM1, b;
                movhlps XMM0, XMM1;
                movaps res, XMM0;
        }
        writefln ("asm: %s", res);
}

--
December 28, 2020
https://issues.dlang.org/show_bug.cgi?id=19443

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
I corrected the line:

  writefln ("core.simd: %s", simd!(XMM.MOVHLPS) (a, b));

to:

  writefln ("core.simd: %s", __simd(XMM.MOVHLPS, a, b));

Compiled with master and ran it, and the output is:

  expected result: [5, 7, 4, 8]
  core.simd: [0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 0, 65]
  asm: [5, 7, 4, 8]

which appears to be the expected behavior. Marking as resolved.

--
January 07, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

ponce <aliloko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |aliloko@gmail.com
         Resolution|WORKSFORME                  |---

--- Comment #4 from ponce <aliloko@gmail.com> ---
Unfortunately it isn't resolved.

Consider this test case, built with DMD from 7 jan 2021 at commit 4f18b2798ad8fa337b8b71e4d2dd0d983adf9868 (with digger)

void main()
{
    float4 a = [1.0f, 2.0f, 3.0f, 4.0f];
    float4 b = [5.0f, 6.0f, 7.0f, 8.0f];
    float4 r = cast(float4) __simd(XMM.MOVHLPS, a, b);
    float[4] correct = [7.0f, 8.0f, 3.0f, 4.0f];
    assert(r.array == correct); // FAIL, produces [5, 6, 3, 4] instead
}

and indeed Godbolt can show how it generated MOVLPS instead of MOVHLPS: https://d.godbolt.org/z/43n5KP

--
March 20, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|core.simd generates         |core.simd generates
                   |incorrect code              |incorrect code for MOVHLPS

--
March 21, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
The MOVHLPS instruction is encoded:

NP 0F 12 /r MOVHLPS xmm1, xmm2

"Moves two packed single-precision floating-point values from the high quadword of the second XMM argument (second operand) to the low quadword of the first XMM register (first argument). The quadword at bits 127:64 of the destination operand is left unchanged. Bits (MAXVL-1:128) of the corresponding destination register remain unchanged."

The MOVLPS instruction is encoded:

NP 0F 12 /r MOVLPS xmm1, m64

"Moves two packed single-precision floating-point values from the source 64-bit memory operand and stores them in the low 64-bits of the destination XMM register. The upper 64bits of the XMM register are preserved. Bits (MAXVL-1:128) of the corresponding destination register are preserved."

https://www.felixcloutier.com/x86/movlps https://www.felixcloutier.com/x86/movhlps

Looking at the code:

    float4 a = [1.0f, 2.0f, 3.0f, 4.0f];
    float4 b = [5.0f, 6.0f, 7.0f, 8.0f];
    float4 r = cast(float4) __simd(XMM.MOVHLPS, a, b);
    float[4] correct = [7.0f, 8.0f, 3.0f, 4.0f];
    assert(r.array == correct); // FAIL, produces [5, 6, 3, 4] instead

The problem appears to be that the second operand needs to be forced into an XMM register rather than remaining in memory.

--
March 21, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---
Another problem is that MOVHLPS and LODLPS have the same opcode (!) in
core.simd.

--
March 21, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|core.simd generates         |core.simd generates MOVLPS
                   |incorrect code for MOVHLPS  |instead of MOVHLPS

--
March 21, 2021
https://issues.dlang.org/show_bug.cgi?id=19443

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #12293 "fix Issue 19443 - core.simd generates MOVLPS instead of MOVHLPS" fixing this issue:

- fix Issue 19443 - core.simd generates MOVLPS instead of MOVHLPS

https://github.com/dlang/dmd/pull/12293

--
« First   ‹ Prev
1 2