Skip to main content

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