www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8778] New: Struct with core.simd type has wrong size and gives Segmentation fault

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

           Summary: Struct with core.simd type has wrong size and gives
                    Segmentation fault
           Product: D
           Version: 2.041
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: malteskarupke web.de



PDT ---
I have this problem in version 2.060 (but I had to select 2.041 because that's
the newest version in the bug tracker)

I'm also not sure whether this should be two bugs or one, but they seem related
so I'm posting them as one.

I wanted to write a Vector4 struct which gives operator overloads for simple
SIMD instructions. But the compiler behaves weird in that a) the struct has the
wrong size, and b) it gives me segmentation faults if I make the struct pure
nothrow  safe.

void main()
{
    import core.simd;

    struct PureVector4
    {
        pure:
        nothrow:
         safe:
        PureVector4 opAdd(in PureVector4 rhs) const
        {
            PureVector4 toReturn;
            toReturn.xyzw = __simd(XMM.ADDPS, xyzw, rhs.xyzw);
            return toReturn;
        }
        float4 xyzw;
    }
    struct Vector4
    {
        Vector4 opAdd(in Vector4 rhs) const
        {
            Vector4 toReturn;
            toReturn.xyzw = __simd(XMM.ADDPS, xyzw, rhs.xyzw);
            return toReturn;
        }
        float4 xyzw;
    }
    static assert(PureVector4.sizeof == Vector4.sizeof); // doesn't compile the
pure one is size 16 (correct), the other one is size 32 (incorrect)

    PureVector4 vec; // Segmentation fault. would work with the non-pure one
    vec.xyzw.array = [1, 2, 3, 1]; // just need to use the vector from the
previous line, otherwise there is no Segmentation fault
}

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|2.041                       |D2




 I have this problem in version 2.060 (but I had to select 2.041 because that's
 the newest version in the bug tracker)
Those specific version numbers are obsolete. Just use "D1", "D2", or "D1 & D2". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 08 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8778




PDT ---
One more comment:
I can also get the non-pure Vector4 to segfault by doing this for example:
Vector4 a;
a.xyzw.array = [1, 2, 3, 4];
Vector4 b = a + a + a + a + a + a; // segfault. probably alignment issue for
one of the temporaries

Should I create a separate bug for this or should I keep these as one ticket?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 08 2012