I have a class which I am using _mm_prefetch()
to pre-request the cacheline containing a class member, of type double:
class MyClass{
double getDouble(){
return dbl;
}
//other members
double dbl;
//other members
};
_mm_prefetch()
signature is:
void _mm_prefetch (char const* p, int i)
But when I do:
_mm_prefetch((char*)(myOb.getDouble()), _MM_HINT_T0);
GCC complains:
error: invalid cast from type 'double' to type 'char*'
So how do I prefetch this class member?
If you read the description for _mm_prefetch()
from the site you linked to it has :
void _mm_prefetch (char const* p, int i)
Fetch the line of data from memory that contains address p to a location in the cache heirarchy specified by the locality hint i.
So you need to pass the address of the variable that you want. In order for you to do that you need to pass to the function either the address of a reference to the class member or a pointer to it.
The simplest solution woul be to change getDouble()
to return a reference and then you can use:
_mm_prefetch((char*)(&myOb.getDouble()), _MM_HINT_T0);