Community
cancel
Showing results for 
Search instead for 
Did you mean: 
andysem
New Contributor III
53 Views

Alignment requirement for pcmpistri

Hi,

I'm testing a custom implementation of strcmp() which involves SSE4.2 and this instruction in particular:

pcmpistri $0x18,(%rsi,%rax,1),%xmm1

I've made a test that passes unaligned pointers to the custom strcmp(), the test looks like this:

#include <string.h>

const char a[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
const char b[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";

int main()
{
    return strcmp(a + 1, b + 1);
}

I verified in the debugger that the pointers are actually not 16-byte aligned when the above instruction is executed. My expectation was that the instruction would crash, however it did not. In fact, the function works correctly, i.e. returns 0.

My question is, does pcmpistri not actually require the memory operand to be aligned? I looked in "Intel(R) 64 and IA-32 Architectures Software Developer Manual" and the instruction is documented as having an m128 operand, which is, as I understand, required to be aligned.

I'm running on a Sandy Bridge CPU.

 

0 Kudos
2 Replies
MarkC_Intel
Moderator
53 Views

The STTNI instructions (SSE4.2) do not have the usual SSE 16B alignment requirements. This is listed in the "Other Exceptions" section of volume 2 for each of these instructions. There is a footnote in section 2.4.4 of rev 54 of volume 2 (pdf page 59) of the Intel SDM. http://www.intel.com/sdm

 

andysem
New Contributor III
53 Views

Ah, I was reading an outdated version of the document that didn't have that footnote. Thanks, Mark.