sdl3_sys/generated/bits.rs
1//! Functions for fiddling with bits and bitmasks.
2
3use super::stdinc::*;
4
5/// Get the index of the most significant (set) bit in a 32-bit number.
6///
7/// Result is undefined when called with 0. This operation can also be stated
8/// as "count leading zeroes" and "log base 2".
9///
10/// Note that this is a forced-inline function in a header, and not a public
11/// API function available in the SDL library (which is to say, the code is
12/// embedded in the calling program and the linker and dynamic loader will not
13/// be able to find this function inside SDL itself).
14///
15/// ## Parameters
16/// - `x`: the 32-bit value to examine.
17///
18/// ## Return value
19/// Returns the index of the most significant bit, or -1 if the value is 0.
20///
21/// ## Thread safety
22/// It is safe to call this function from any thread.
23///
24/// ## Availability
25/// This function is available since SDL 3.2.0.
26#[inline(always)]
27pub const fn SDL_MostSignificantBitIndex32(x: Uint32) -> ::core::ffi::c_int {
28 31 - (x.leading_zeros() as ::core::ffi::c_int)
29}
30
31/// Determine if a unsigned 32-bit value has exactly one bit set.
32///
33/// If there are no bits set (`x` is zero), or more than one bit set, this
34/// returns false. If any one bit is exclusively set, this returns true.
35///
36/// Note that this is a forced-inline function in a header, and not a public
37/// API function available in the SDL library (which is to say, the code is
38/// embedded in the calling program and the linker and dynamic loader will not
39/// be able to find this function inside SDL itself).
40///
41/// ## Parameters
42/// - `x`: the 32-bit value to examine.
43///
44/// ## Return value
45/// Returns true if exactly one bit is set in `x`, false otherwise.
46///
47/// ## Thread safety
48/// It is safe to call this function from any thread.
49///
50/// ## Availability
51/// This function is available since SDL 3.2.0.
52#[inline(always)]
53pub const fn SDL_HasExactlyOneBitSet32(x: Uint32) -> ::core::primitive::bool {
54 if ((x != 0) && !((x & (x - 1_u32)) != 0)) {
55 return true;
56 }
57 return false;
58}
59
60#[cfg(doc)]
61use crate::everything::*;