Thread: MMX/SSE2 instrinsic crashes on function exit

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    MMX/SSE2 instrinsic crashes on function exit

    I am trying to use the SSE2 intrinsics to access the XMM registers but I'm having a problem. The intrinsic commands are calculating and returning the correct values on the first call to the function, but it crashes on the second call with an access violation.

    Here is the code in question:
    Code:
    __m128i lsXMM0,lsXMM1,lsTotal;
    	
    __declspec(align(16)) unsigned __int16 laData[8]; // use to hold result
    
    // Get row 0
    lsXMM0 = _mm_load_si128((__m128i*)&gaRefFrame[anSampleYPos][anSampleXPos]);
    lsXMM1 = _mm_load_si128((__m128i*)&gaCurFrame[anBlockYPos][anBlockXPos]);
    // SAD Row 0 
    lsTotal = _mm_sad_epu8(lsXMM0, lsXMM1);
    // Get SAD results
    _mm_store_si128((__m128i*)laData, lsTotal);
    
    return laData[0]+laData[4];
    On the second call to this code, the access violation occurs on the first mm_load with this:
    Code:
    Unhandled exception at 0x00402cd8 in findmv.exe: 0xC0000005: Access violation reading location 0xffffffff.
    Is there something I must do to clear out the lsXMM0 structure to use it again? I would think it goes out of scope on exiting the function and gets redeclared on the next call.

    Jason

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > _mm_load_si128((__m128i*)&gaRefFrame[anSampleYPos][anSampleXPos])
    My guess is that this data isn't aligned properly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    I have it aligned by using the _mm_malloc function to align it to 16-bytes. If it's not aligned, it wont even get past the first load instruction on the first loop iteration.

    Jason

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Show us.

    > gaRefFrame[anSampleYPos][anSampleXPos]
    Unless each element of this array is a multiple of 16 bytes, then taking the address of an element of the array (except the first one) will NOT be aligned on a 16-byte boundary.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM