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:
On the second call to this code, the access violation occurs on the first mm_load with this:Code:__m128i lsXMM0,lsXMM1,lsTotal; __declspec(align(16)) unsigned __int16 laData; // 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+laData;
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.Code:Unhandled exception at 0x00402cd8 in findmv.exe: 0xC0000005: Access violation reading location 0xffffffff.