Skip to content

Instantly share code, notes, and snippets.

@jbarczak
Created April 14, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarczak/04e4ab898edf2e335917 to your computer and use it in GitHub Desktop.
Save jbarczak/04e4ab898edf2e335917 to your computer and use it in GitHub Desktop.
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