ohmu
·
2026-10-15
1#pragma once
2
3#include "fastfetch.h"
4#include "modules/cpucache/option.h"
5
6typedef enum FFCPUCacheType: uint8_t {
7 FF_CPU_CACHE_TYPE_UNIFIED = 0,
8 FF_CPU_CACHE_TYPE_INSTRUCTION = 1,
9 FF_CPU_CACHE_TYPE_DATA = 2,
10 FF_CPU_CACHE_TYPE_TRACE = 3,
11} FFCPUCacheType;
12
13typedef struct FFCPUCache {
14 uint32_t size;
15 uint32_t num;
16 uint32_t lineSize;
17 FFCPUCacheType type;
18} FFCPUCache;
19
20typedef struct FFCPUCacheResult {
21 FFlist caches[4]; // L1, L2, L3, L4(?)
22} FFCPUCacheResult;
23
24const char* ffDetectCPUCache(FFCPUCacheResult* result);
25
26static inline FFCPUCache* ffCPUCacheAddItem(FFCPUCacheResult* result, uint32_t level, uint32_t size, uint32_t lineSize, FFCPUCacheType type) {
27 FFlist* cacheLevel = &result->caches[level - 1];
28
29 FF_LIST_FOR_EACH (FFCPUCache, item, *cacheLevel) {
30 if (item->type == type && item->size == size && item->lineSize == lineSize) {
31 item->num++;
32 return item;
33 }
34 }
35
36 FFCPUCache* item = FF_LIST_ADD(FFCPUCache, *cacheLevel);
37 *item = (FFCPUCache) {
38 .size = size,
39 .num = 1,
40 .lineSize = lineSize,
41 .type = type,
42 };
43 return item;
44}