2 ms·
Question for PL implementation folks: How practical is it to implement a keyword/type that (portably) represents the L1/L2/LN cache size? Suppose I am implemen
by pphysch 4y ago
Question for PL implementation folks:
How practical is it to implement a keyword/type that (portably) represents the L1/L2/LN cache size? Suppose I am implementing an algorithm or data structure and I really don't care what the $BLOCK_SIZE is, as long as it fits reasonably nicely in one of the lower caches as a sane default. It would be nice if I could do this with a magic keyword rather than hardcoding a default (1KiB) and forcing the end user to tune runtime params according to their hardware. Bonus if this can be used for static/stack allocations too.
- 0xffff2 4y agoFor compiled languages, you would only every be able to do this for code compiled specifically for the target machine. I wonder if there are numbers out there for what percentage of code that applies to in the real world? My naive assumption is that it's a single digit percentage.
- kllrnohj 4y agoThe `cpuid` instruction would tell you things like cache line size (and can enumerate cache topology). But you're then paying a cost for the value not being known at compile time, so you'd need to weigh the tradeoffs that may result from that.