CPU cache chunks and gcc function align flag

Started by
1 comment, last by 3Dgonewild 14 years, 11 months ago
Haven't asked stuff for a while , but here it goes :)... I've been doing a little research on gcc optimization options , and i've been wondering what exactly happens when i set a custom function align level. For example , if we had a cpu with 256kb cache divided into 32byte cache chunks(lines) , it would be efficient to set function align flag to 32 ? Also , are there any other cpu cache specific optimization flags that i should know? Thanks for your time :).
Advertisement
I guess it won't make any difference, but if you want to know for sure you'll have to profile.

Furthermore, I doubt that you'll find any magic optimization flags, besides the basic ones, that will give you noticable performance gains. It's much more efficient to find the hotspots through profiling and then optimising the code there.

Some (most?) CPUs have a set of cache control instructions which may or may not be exposed as compiler intrinsics. So if you have a piece of code that would benefit from better use of the caches, use those instructions. It's most likely not worth it though...


Well you're right about profiling the code , but i was just asking for some more information on the subject , but it seems that no one actually did some research before.

I haven't found a document that explains how a function is aligned.
Eg: the variable members get aligned by N bytes ?
If that's the case , then obviously on some platforms its possible to get interesting results(especially when dealing with large objects).
In my experience, any playing around with alignments and cache prefetching makes your code run equally fast in the best case and slower in the average case.
There may be cases where your code will perform better, but like Rattenhirn already said, you won't find those without profiling.

This topic is closed to new replies.

Advertisement