Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Microsoft compiler appears to ignore prefetches inside a loop.
Tested this on MSVC 2013 express edition. Microsoft's connect site says I am not authorized to submit feedback for who knows what reason, or else I'd send it there directly......
Code I used:
void Foo( char* p, int* q )
{
for( size_t i=0; i<8; i++ )
_mm_prefetch(p+q[i], _MM_HINT_T0 );
}
ASM I got:
movsxd rax, DWORD PTR [rdx]
prefetcht0 BYTE PTR [rax+rcx]
ret 0
Hmmm, not quite what I wanted.... Tweaking the loop makes it even more obvious.
code:
int Foo( char* p, int* q )
{
int j=0;
for( size_t i=0; i<8; i++ )
{
_mm_prefetch(p+q[i], _MM_HINT_T0 );
j += q[i];
}
return j;
}
asm:
movsxd rax, DWORD PTR [rdx]
prefetcht0 BYTE PTR [rax+rcx]
add eax, DWORD PTR [rdx+4]
add eax, DWORD PTR [rdx+8]
add eax, DWORD PTR [rdx+12]
add eax, DWORD PTR [rdx+16]
add eax, DWORD PTR [rdx+20]
add eax, DWORD PTR [rdx+24]
add eax, DWORD PTR [rdx+28]
ret 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.