www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6877] New: [XMM] regression, clobbered float value

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

           Summary: [XMM] regression, clobbered float value
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



struct Matrix
{
    float[3][3] data;

    ref float[3] opIndex(size_t idx)
    {
        assert(0 <= idx && idx <= 2);
        return this.data[idx];
    }

    static Matrix identityMatrix()
    {
        Matrix id;
        id.data[0][0] = 1.0f; id.data[0][1] = 0.0f; id.data[0][2] = 0.0f;
        id.data[1][0] = 0.0f; id.data[1][1] = 1.0f; id.data[1][2] = 0.0f;
        id.data[2][0] = 0.0f; id.data[2][1] = 0.0f; id.data[2][2] = 1.0f;
        return id;
    }

    void setRotate(float deg)
    {
        this = identityMatrix();
        setSinCos(0.5f * deg, 0.2f * deg);
    }

    void setSinCos(float sinV, float cosV)
    {
        this[0][0] = cosV;
        this[0][1] = -sinV; // <- !!! BUG HERE BUG !!!

        // alternatively with this
        // *(cast(uint*)&(this[0][1])) = (*cast(uint*)&sinV) ^ 0x80000000;
        // thus it is not the OPneg that fails

        this[1][0] = sinV;
        this[1][1] = cosV;
    }
}

extern(C) int printf(in char* format, ...);

void main()
{
    Matrix m;
    m.setRotate(4);

    // should be -2
    printf("%g\n", m.data[0][1]);
}

---

Needed Flags: -O -inline, NOT -release, compilation with config.fpxmmregs

The is NaN where it should have been -2.
I could not reduce this test case any further.

This regression was introduced with:
https://github.com/D-Programming-Language/dmd/commit/82b5c12653c16097426ce990ecacc97525666302

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6877




struct Matrix
{
    void setSinCos(float sinV)
    {
        // use parameter, so it becomes a register veriable
        a = sinV * sinV;

        // refer to value of parameter
        version (none)
            val = -sinV;
        else // which 'eleq' optimizes to
            *cast(uint*)&val = (*cast(uint*)&sinV) ^ 0x80000000;
    }
    float a, val;
}

extern(C) int printf(in char* format, ...);

void main()
{
    Matrix m;
    printf("%g\n", m.val);
    // indirect to prevent CTFE
    auto dg = &m.setSinCos;
    dg(2.0);
    printf("%g\n", m.val);
}

-----------------------------------------------------

sinV is a register variable residing in xmm2.
The load for the left xor operand is done with
  mov   %edx, %eax
which should be
  movd %xmm2, %eax
instead, same modrm though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6877


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



21:19:12 PDT ---
https://github.com/D-Programming-Language/dmd/commit/9d68b00cb299a6abdcd2e79b4d4cddf5dd8b28c2

https://github.com/D-Programming-Language/dmd/commit/bcb742282c6a1ac36480e38e505d8b666dcf610a

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2011