Bug 50994 - wanted: interface for querying cache size
Summary: wanted: interface for querying cache size
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-04 23:01 UTC by Benjamin Kosnik
Modified: 2011-11-04 23:13 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Kosnik 2011-11-04 23:01:33 UTC
GCC is missing a way to query cache line size. This could be provided as a compile-time constant, in the form of predefined macros in a form similar to the existing sizeof macros via something like __SIZEOF_L1_CACHE_LINE__. Or, it could be via a __builtin, like __builtin_l1_cache_line_size(). 

Results would be consistent with existing --param flags, such that

--param l1-cache-line-size=64

meant that

__builtin_l1_cache_line_size() == 64.

I notice that intel provides the following interface, via:
http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011Update/compiler_c/index.htm


unsigned int __cacheSize(unsigned int cacheLevel)

"__cacheSize(n) returns the size in kilobytes of the cache at level n. 1 represents the first-level cache. 0 is returned for a non-existent cache level. For example, an application may query the cache size and use it to select block sizes in algorithms that operate on matrices."

ding ding ding!!
Comment 1 Andrew Pinski 2011-11-04 23:12:51 UTC
The cache block/line size could be different on two different machines so it cannot be constant.  Also there is no portable way of figuring out the cache size.