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

See Also:
Known to work:
Known to fail:
Last reconfirmed:


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:

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.