www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 234] New: dynamic arrays in combination with SSE instructions cause segment faults

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

           Summary: dynamic arrays in combination with SSE instructions
                    cause segment faults
           Product: D
           Version: 0.162
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: thomas-dloop kuehne.cn


If compiled with -version=dynamic, the code below segmentfaults.

import std.stdio;

int main(){
        version(dynamic){
                double[] a = new double[2];
                double[] b = new double[2];
        }else{
                double[2] a;
                double[2] b;
        }

        a[0] = 4.0;
        a[1] = 2.0;

        b[0] = -0.5;
        b[1] = -0.25;

        writefln("a:\t%s\t%s", a[0], a[1]);
        writefln("b:\t%s\t%s", b[0], b[1]);

        asm{
                movupd XMM0, a;
                movupd b, XMM0;
                emms;
        }
        writefln("-- asm finished --");

        writefln("a:\t%s\t%s", a[0], a[1]);
        writefln("b:\t%s\t%s", b[0], b[1]);

        return 0;
}

test cases:
http://dstress.kuehne.cn/run/o/odd_bug_05_A.d
http://dstress.kuehne.cn/run/o/odd_bug_05_B.d
http://dstress.kuehne.cn/run/o/odd_bug_05_C.d
http://dstress.kuehne.cn/run/o/odd_bug_05_D.d


-- 
Jul 02 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=234


bugzilla digitalmars.com changed:

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





It segment faults because dynamic arrays are stored differently than static
arrays. When using inline asm, one must account for this. For the dynamic
arrays, using the following will work:

asm{
        mov EAX,a+4;
        movupd XMM0, [EAX];
        mov EAX,b+4;
        movupd [EAX], XMM0;
        emms;
}


-- 
Dec 12 2006