cache_size/
blanket.rs

1/// Info about a what a given cache caches (instructions, data, etc.)
2#[derive(PartialEq, Eq, Debug)]
3pub enum CacheType {
4    /// Null - No more caches
5    Null = 0,
6    /// Data cache
7    Data,
8    /// Instruction cache
9    Instruction,
10    /// Data and Instruction cache
11    Unified,
12    /// 4-31 = Reserved
13    Reserved,
14}
15
16/// Returns the total size in bytes of `level` cache with type `cache_type`.
17///
18/// This is the implementation for unsupported architectures, and always returns None.
19#[inline]
20pub fn cache_size(_level: u8, _cache_type: CacheType) -> Option<usize> {
21    None
22}
23
24/// Returns the line size in bytes of `level` cache with type `cache_type`.
25///
26/// This is the implementation for unsupported architectures, and always returns None.
27#[inline]
28pub fn cache_line_size(_level: u8, _cache_type: CacheType) -> Option<usize> {
29    None
30}
31
32/// Returns the total size in bytes of of the L1 data cache.
33///
34/// This is the implementation for unsupported architectures, and always returns None.
35#[inline]
36pub fn l1_cache_size() -> Option<usize> {
37    None
38}
39
40/// Returns the line size in bytes of the L1 data cache.
41///
42/// This is the implementation for unsupported architectures, and always returns None.
43#[inline]
44pub fn l1_cache_line_size() -> Option<usize> {
45    cache_line_size(1, CacheType::Data)
46}
47
48/// Returns the total size in bytes of the unified L2 cache.
49///
50/// This is the implementation for unsupported architectures, and always returns None.
51#[inline]
52pub fn l2_cache_size() -> Option<usize> {
53    cache_size(2, CacheType::Unified)
54}
55
56/// Returns the line size in bytes of the unified L2 cache.
57///
58/// This is the implementation for unsupported architectures, and always returns None.
59#[inline]
60pub fn l2_cache_line_size() -> Option<usize> {
61    cache_line_size(2, CacheType::Unified)
62}
63
64/// Returns the total size in bytes of the unified L3 cache.
65///
66/// This is the implementation for unsupported architectures, and always returns None.
67#[inline]
68pub fn l3_cache_size() -> Option<usize> {
69    cache_size(3, CacheType::Unified)
70}
71
72/// Returns the line size in bytes of the unified L3 cache.
73///
74/// This is the implementation for unsupported architectures, and always returns None.
75#[inline]
76pub fn l3_cache_line_size() -> Option<usize> {
77    cache_line_size(3, CacheType::Unified)
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83    #[test]
84    fn test_l1_cache_size() {
85        assert_eq!(l1_cache_size(), None);
86    }
87    #[test]
88    fn test_l1_cache_line_size() {
89        assert_eq!(l1_cache_line_size(), None)
90    }
91    #[test]
92    fn test_l2_cache_size() {
93        assert_eq!(l2_cache_size(), None);
94    }
95    #[test]
96    fn test_l2_cache_line_size() {
97        assert_eq!(l2_cache_line_size(), None);
98    }
99    #[test]
100    fn test_l3_cache_size() {
101        assert_eq!(l3_cache_size(), None);
102    }
103    #[test]
104    fn test_l3_cache_line_size() {
105        assert_eq!(l3_cache_line_size(), None);
106    }
107}