190f3df4fSAlexandre Courbot // SPDX-License-Identifier: GPL-2.0 290f3df4fSAlexandre Courbot 390f3df4fSAlexandre Courbot //! Additional numerical features for the kernel. 490f3df4fSAlexandre Courbot 590f3df4fSAlexandre Courbot use core::ops; 690f3df4fSAlexandre Courbot 7*01e345e8SAlexandre Courbot pub mod bounded; 8*01e345e8SAlexandre Courbot pub use bounded::*; 9*01e345e8SAlexandre Courbot 1090f3df4fSAlexandre Courbot /// Designates unsigned primitive types. 1190f3df4fSAlexandre Courbot pub enum Unsigned {} 1290f3df4fSAlexandre Courbot 1390f3df4fSAlexandre Courbot /// Designates signed primitive types. 1490f3df4fSAlexandre Courbot pub enum Signed {} 1590f3df4fSAlexandre Courbot 1690f3df4fSAlexandre Courbot /// Describes core properties of integer types. 1790f3df4fSAlexandre Courbot pub trait Integer: 1890f3df4fSAlexandre Courbot Sized 1990f3df4fSAlexandre Courbot + Copy 2090f3df4fSAlexandre Courbot + Clone 2190f3df4fSAlexandre Courbot + PartialEq 2290f3df4fSAlexandre Courbot + Eq 2390f3df4fSAlexandre Courbot + PartialOrd 2490f3df4fSAlexandre Courbot + Ord 2590f3df4fSAlexandre Courbot + ops::Add<Output = Self> 2690f3df4fSAlexandre Courbot + ops::AddAssign 2790f3df4fSAlexandre Courbot + ops::Sub<Output = Self> 2890f3df4fSAlexandre Courbot + ops::SubAssign 2990f3df4fSAlexandre Courbot + ops::Mul<Output = Self> 3090f3df4fSAlexandre Courbot + ops::MulAssign 3190f3df4fSAlexandre Courbot + ops::Div<Output = Self> 3290f3df4fSAlexandre Courbot + ops::DivAssign 3390f3df4fSAlexandre Courbot + ops::Rem<Output = Self> 3490f3df4fSAlexandre Courbot + ops::RemAssign 3590f3df4fSAlexandre Courbot + ops::BitAnd<Output = Self> 3690f3df4fSAlexandre Courbot + ops::BitAndAssign 3790f3df4fSAlexandre Courbot + ops::BitOr<Output = Self> 3890f3df4fSAlexandre Courbot + ops::BitOrAssign 3990f3df4fSAlexandre Courbot + ops::BitXor<Output = Self> 4090f3df4fSAlexandre Courbot + ops::BitXorAssign 4190f3df4fSAlexandre Courbot + ops::Shl<u32, Output = Self> 4290f3df4fSAlexandre Courbot + ops::ShlAssign<u32> 4390f3df4fSAlexandre Courbot + ops::Shr<u32, Output = Self> 4490f3df4fSAlexandre Courbot + ops::ShrAssign<u32> 4590f3df4fSAlexandre Courbot + ops::Not 4690f3df4fSAlexandre Courbot { 4790f3df4fSAlexandre Courbot /// Whether this type is [`Signed`] or [`Unsigned`]. 4890f3df4fSAlexandre Courbot type Signedness; 4990f3df4fSAlexandre Courbot 5090f3df4fSAlexandre Courbot /// Number of bits used for value representation. 5190f3df4fSAlexandre Courbot const BITS: u32; 5290f3df4fSAlexandre Courbot } 5390f3df4fSAlexandre Courbot 5490f3df4fSAlexandre Courbot macro_rules! impl_integer { 5590f3df4fSAlexandre Courbot ($($type:ty: $signedness:ty), *) => { 5690f3df4fSAlexandre Courbot $( 5790f3df4fSAlexandre Courbot impl Integer for $type { 5890f3df4fSAlexandre Courbot type Signedness = $signedness; 5990f3df4fSAlexandre Courbot 6090f3df4fSAlexandre Courbot const BITS: u32 = <$type>::BITS; 6190f3df4fSAlexandre Courbot } 6290f3df4fSAlexandre Courbot )* 6390f3df4fSAlexandre Courbot }; 6490f3df4fSAlexandre Courbot } 6590f3df4fSAlexandre Courbot 6690f3df4fSAlexandre Courbot impl_integer!( 6790f3df4fSAlexandre Courbot u8: Unsigned, 6890f3df4fSAlexandre Courbot u16: Unsigned, 6990f3df4fSAlexandre Courbot u32: Unsigned, 7090f3df4fSAlexandre Courbot u64: Unsigned, 7190f3df4fSAlexandre Courbot u128: Unsigned, 7290f3df4fSAlexandre Courbot usize: Unsigned, 7390f3df4fSAlexandre Courbot i8: Signed, 7490f3df4fSAlexandre Courbot i16: Signed, 7590f3df4fSAlexandre Courbot i32: Signed, 7690f3df4fSAlexandre Courbot i64: Signed, 7790f3df4fSAlexandre Courbot i128: Signed, 7890f3df4fSAlexandre Courbot isize: Signed 7990f3df4fSAlexandre Courbot ); 80