rich_sdl2_rust/
system.rs

1//! Querying some system information.
2
3use crate::bind;
4
5/// Returns the size of the system RAM.
6#[must_use]
7pub fn ram_size() -> usize {
8    unsafe { bind::SDL_GetSystemRAM() as usize }
9}
10
11pub mod simd_alloc;
12
13/// System CPU information.
14pub mod cpu {
15    use crate::bind;
16
17    /// Counts the system CPU.
18    #[must_use]
19    pub fn count() -> u32 {
20        unsafe { bind::SDL_GetCPUCount() as u32 }
21    }
22
23    /// Returns the cache line size of the system CPU.
24    #[must_use]
25    pub fn cache_line_size() -> usize {
26        unsafe { bind::SDL_GetCPUCacheLineSize() as usize }
27    }
28
29    /// Returns the SIMD alignment of the system CPU.
30    #[must_use]
31    #[allow(clippy::unnecessary_cast)]
32    pub fn simd_alignment() -> usize {
33        unsafe { bind::SDL_SIMDGetAlignment() as usize }
34    }
35
36    /// Returns whether the system CPU has RDTSC.
37    #[must_use]
38    pub fn has_rdtsc() -> bool {
39        unsafe { bind::SDL_HasRDTSC() == bind::SDL_TRUE }
40    }
41    /// Returns whether the system CPU has AltiVec.
42    #[must_use]
43    pub fn has_alti_vec() -> bool {
44        unsafe { bind::SDL_HasAltiVec() == bind::SDL_TRUE }
45    }
46    /// Returns whether the system CPU has MMX.
47    #[must_use]
48    pub fn has_mmx() -> bool {
49        unsafe { bind::SDL_HasMMX() == bind::SDL_TRUE }
50    }
51    /// Returns whether the system CPU has 3DNow!.
52    #[must_use]
53    pub fn has_3d_now() -> bool {
54        unsafe { bind::SDL_Has3DNow() == bind::SDL_TRUE }
55    }
56    /// Returns whether the system CPU has SSE.
57    #[must_use]
58    pub fn has_sse() -> bool {
59        unsafe { bind::SDL_HasSSE() == bind::SDL_TRUE }
60    }
61    /// Returns whether the system CPU has SSE2.
62    #[must_use]
63    pub fn has_sse2() -> bool {
64        unsafe { bind::SDL_HasSSE2() == bind::SDL_TRUE }
65    }
66    /// Returns whether the system CPU has SSE3.
67    #[must_use]
68    pub fn has_sse3() -> bool {
69        unsafe { bind::SDL_HasSSE3() == bind::SDL_TRUE }
70    }
71    /// Returns whether the system CPU has SSE4.1.
72    #[must_use]
73    pub fn has_sse41() -> bool {
74        unsafe { bind::SDL_HasSSE41() == bind::SDL_TRUE }
75    }
76    /// Returns whether the system CPU has SSE4.2.
77    #[must_use]
78    pub fn has_sse42() -> bool {
79        unsafe { bind::SDL_HasSSE42() == bind::SDL_TRUE }
80    }
81    /// Returns whether the system CPU has AVX.
82    #[must_use]
83    pub fn has_avx() -> bool {
84        unsafe { bind::SDL_HasAVX() == bind::SDL_TRUE }
85    }
86    /// Returns whether the system CPU has AVX2.
87    #[must_use]
88    pub fn has_avx2() -> bool {
89        unsafe { bind::SDL_HasAVX2() == bind::SDL_TRUE }
90    }
91    /// Returns whether the system CPU has AVX-512F.
92    #[must_use]
93    pub fn has_avx512f() -> bool {
94        unsafe { bind::SDL_HasAVX512F() == bind::SDL_TRUE }
95    }
96    /// Returns whether the system CPU has ARM SIMD.
97    #[must_use]
98    pub fn has_arm_simd() -> bool {
99        unsafe { bind::SDL_HasARMSIMD() == bind::SDL_TRUE }
100    }
101    /// Returns whether the system CPU has NEON, Advanced SIMD.
102    #[must_use]
103    pub fn has_neon() -> bool {
104        unsafe { bind::SDL_HasNEON() == bind::SDL_TRUE }
105    }
106}