Sign in to follow this  
3Dgonewild

CPU cache chunks and gcc function align flag

Recommended Posts

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 :).

Share this post


Link to post
Share on other sites
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...


Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this