optimizing the cache

Brian Hurt bhurt at spnz.org
Mon Jan 30 20:47:48 CET 2006

On Mon, 30 Jan 2006, Bernhard Helmes wrote:

>> A nice day,
>> I would like to store some variables in the cache of the prozessor and not
>> in the Ram. Is there a possibility to say to gmp or / and gcc where it
>> stores the variables. I hope that i can speed up the program by a factor
>> 20.
> I found a method to prefetch the variable into the cache by
> __builtin_prefetch (&variable, 0, 3)
> But I am not sure, how i can prefetch a mpz_t-variable by this construction
> in the cache. Has anyone experience with a prefetch and gmp-variable ?
> Do you know whether i have to switch on gcc by -fbuiltin ?


You are, however, making another mistake: premature optimization.  Do you 
know what your cache miss rate is?  Yes, I've seen 10-fold or more 
improvements in code by better cache utilization- but this generally tends 
to be badly structured code in the first place.  In most cases the default 
caching policy is about as good as you're going to get, and you're not 
going to get much better.


More information about the gmp-discuss mailing list