   Speeding up Memory Reads and Writes with VectorC
  Comments for the article Speeding up Memory Reads and Writes with VectorC
  I'm using Visual Studio 2010 compiler, I've tried this code:inline float length(Vector3 &vec1, Vector3 &vec2){__hint__((prefetch (&vec1)));__hint__((prefetch (&vec2)));return sqrt((vec1.x-vec2.x)*(vec1.x-vec2.x)+(vec1.y-vec2.y)*(vec1.y-vec2.y)*(vec1.z-vec2.z)*(vec1.z-vec2.z));}However I get these errors:error C3861: '__hint__': identifier not founderror C3861: 'prefetch': identifier not foundI'm pretty sure I'm missing include, as I didn't include anything extra, but not sure which one, Google doesn't show any good results when I search for __hint__ neither prefetch().Thank you in advance.   ;  That's because you use a compiler-specific statement with a totally different compiler than the one in this (9 year old) article._mm_prefetch is what you want.   ;Quote:Original post by samothThat's because you use a compiler-specific statement with a totally different compiler than the one in this (9 year old) article.Wow, I didn't know it was even possible to post replies to 9 year old threads.   ;  Functions:inline float length(Vector3 &vec1, Vector3 &vec2){return sqrt((vec1.x-vec2.x)*(vec1.x-vec2.x)+(vec1.y-vec2.y)*(vec1.y-vec2.y)+(vec1.z-vec2.z)*(vec1.z-vec2.z));}inline float length_prefech(Vector3 &vec1, Vector3 &vec2){_mm_prefetch((char*)&vec1, _MM_HINT_T0);_mm_prefetch((char*)&vec2, _MM_HINT_T0);return sqrt((vec1.x-vec2.x)*(vec1.x-vec2.x)+(vec1.y-vec2.y)*(vec1.y-vec2.y)+(vec1.z-vec2.z)*(vec1.z-vec2.z));}Test code:CStopWatch *timer2=new CStopWatch();float time1, time2;Vector3 vec1(10,10,10), vec2(15,346,4834);timer2->startTimer();for(int i=0; i<=20000000; i++) length(vec1, vec2);timer2->stopTimer();time1=timer2->getElapsedTime();timer2->startTimer();for(int i=0; i<=20000000; i++) length_prefech(vec1, vec2);timer2->stopTimer();time2=timer2->getElapsedTime();time1 ends up being 0.2 seconds lower than time2 (without prefetch faster). Shouldn't prefetch make it faster, or I'm doing something wrong?   ;  It really depends on your CPU, and where vec1 and vec2 are in memory (if they're adjacent in a contiguous array shouldn't help much at all).The first CPUs (PIII  Tualatin) with hardware prefetch were released at about the time this article was published on Gamedev.Modern CPUs have only gotten better at it too, I believe the prefetch on Intel's Core2 (and to a lesser extent P4s), as well as AMD's Phenoms is actually pretty good.Also your benchmark isn't really the best as its likely once you've called the unprefetched length function once the vectors will remain in cache for the rest of the calls to length.(The compiler might even be optimising a lot out as you don't even use the return of length either)Prefetching is a bit of a micro-optimisation, although can make a world of difference on In-Order execution cpus (Xbox 360/PS3/Wii/iPhone) to avoid cache misses and pipeline stalls, but on the PC its probably worth leaving till you've ruled out some other possibilities.   