| 400 | } |
| 401 | |
| 402 | int64_t CpuInfo::CacheSize(CacheLevel level) const { |
| 403 | constexpr auto kDefaultCacheSizes = std::array<int64_t, 3>{ |
| 404 | 32 * 1024, // Level 1: 32K |
| 405 | 256 * 1024, // Level 2: 256K |
| 406 | 3072 * 1024, // Level 3: 3M |
| 407 | }; |
| 408 | static_assert(kDefaultCacheSizes.size() == kCacheLevels); |
| 409 | |
| 410 | static_assert(static_cast<int>(CacheLevel::L1) == 0); |
| 411 | const int i = static_cast<int>(level); |
| 412 | if (cache_sizes_[i] > 0) return cache_sizes_[i]; |
| 413 | if (i == 0) return kDefaultCacheSizes[0]; |
| 414 | // l3 may be not available, return maximum of l2 or default size |
| 415 | return std::max(kDefaultCacheSizes[i], cache_sizes_[i - 1]); |
| 416 | } |
| 417 | |
| 418 | bool CpuInfo::IsSupported(int64_t flags) const { |
| 419 | return (hardware_flags_ & flags) == flags; |