2 Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
3 Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
8 #[rustfmt::skip] // work around for https://github.com/rust-lang/rustfmt/issues/4823
9 macro_rules! make_float_type {
30 #[float(prim = $float_prim:ident $(, scalar = $float_scalar:ident)?)]
46 type $float: Float<Self::$u32, BitsType = Self::$uint>
47 $(+ From<Self::$float_scalar>)?
48 + Compare<Bool = Self::$bool>
49 + Make<Self, Prim = $float_prim>
50 $(+ ConvertTo<Self::$uint_smaller>)*
51 $(+ ConvertTo<Self::$int_smaller>)*
52 $($(+ ConvertTo<Self::$float_smaller>)?)*
53 + ConvertTo<Self::$uint>
54 + ConvertTo<Self::$int>
55 $(+ ConvertTo<Self::$uint_larger>)*
56 $(+ ConvertTo<Self::$int_larger>)*
57 $($(+ Into<Self::$float_larger>)?)*;
73 #[rustfmt::skip] // work around for https://github.com/rust-lang/rustfmt/issues/4823
74 macro_rules! make_uint_int_float_type {
80 #[uint($($uint_smaller_traits:tt)*)]
82 #[int($($int_smaller_traits:tt)*)]
85 #[float($($float_smaller_traits:tt)*)]
91 #[uint(prim = $uint_prim:ident $(, scalar = $uint_scalar:ident)?)]
93 #[int(prim = $int_prim:ident $(, scalar = $int_scalar:ident)?)]
96 #[float(prim = $float_prim:ident $(, scalar = $float_scalar:ident)?)]
102 #[uint($($uint_larger_traits:tt)*)]
104 #[int($($int_larger_traits:tt)*)]
107 #[float($($float_larger_traits:tt)*)]
113 type $uint: UInt<Self::$u32>
114 $(+ From<Self::$uint_scalar>)?
115 + Compare<Bool = Self::$bool>
116 + Make<Self, Prim = $uint_prim>
117 $(+ ConvertTo<Self::$uint_smaller>)*
118 $(+ ConvertTo<Self::$int_smaller>)*
119 $($(+ ConvertTo<Self::$float_smaller>)?)*
120 + ConvertTo<Self::$int>
121 $(+ ConvertTo<Self::$float>)?
122 $(+ Into<Self::$uint_larger>)*
123 $(+ Into<Self::$int_larger>)*
124 $($(+ Into<Self::$float_larger>)?)*;
125 type $int: SInt<Self::$u32>
126 $(+ From<Self::$int_scalar>)?
127 + Compare<Bool = Self::$bool>
128 + Make<Self, Prim = $int_prim>
129 $(+ ConvertTo<Self::$uint_smaller>)*
130 $(+ ConvertTo<Self::$int_smaller>)*
131 $($(+ ConvertTo<Self::$float_smaller>)?)*
132 + ConvertTo<Self::$uint>
133 $(+ ConvertTo<Self::$float>)?
134 $(+ ConvertTo<Self::$uint_larger>)*
135 $(+ Into<Self::$int_larger>)*
136 $($(+ Into<Self::$float_larger>)?)*;
158 #[float(prim = $float_prim $(, scalar = $float_scalar)?)]
178 macro_rules! make_uint_int_float_types {
181 #[bool = $bool:ident]
184 [$first_larger:tt, $($larger:tt,)*]
186 make_uint_int_float_type! {
191 [$first_larger, $($larger,)*]
193 make_uint_int_float_types! {
196 [$($smaller,)* $current,],
203 #[bool = $bool:ident]
208 make_uint_int_float_type! {
218 #[rustfmt::skip] // work around for https://github.com/rust-lang/rustfmt/issues/4823
219 macro_rules! make_types {
222 $(#[scalar = $ScalarBool:ident])?
226 $(#[scalar = $ScalarU8:ident])?
230 $(#[scalar = $ScalarU16:ident])?
234 $(#[scalar = $ScalarU32:ident])?
238 $(#[scalar = $ScalarU64:ident])?
242 $(#[scalar = $ScalarI8:ident])?
246 $(#[scalar = $ScalarI16:ident])?
250 $(#[scalar = $ScalarI32:ident])?
254 $(#[scalar = $ScalarI64:ident])?
258 $(#[scalar = $ScalarF16:ident])?
262 $(#[scalar = $ScalarF32:ident])?
266 $(#[scalar = $ScalarF64:ident])?
270 $(+ From<Self::$ScalarBool>)?
271 + Make<Self, Prim = bool>
272 + Select<Self::$Bool>;
273 make_uint_int_float_types! {
278 #[uint(prim = u8 $(, scalar = $ScalarU8)?)]
280 #[int(prim = i8 $(, scalar = $ScalarI8)?)]
285 #[uint(prim = u16 $(, scalar = $ScalarU16)?)]
287 #[int(prim = i16 $(, scalar = $ScalarI16)?)]
289 #[float(prim = F16 $(, scalar = $ScalarF16)?)]
293 #[uint(prim = u32 $(, scalar = $ScalarU32)?)]
295 #[int(prim = i32 $(, scalar = $ScalarI32)?)]
297 #[float(prim = f32 $(, scalar = $ScalarF32)?)]
301 #[uint(prim = u64 $(, scalar = $ScalarU64)?)]
303 #[int(prim = i64 $(, scalar = $ScalarI64)?)]
305 #[float(prim = f64 $(, scalar = $ScalarF64)?)]
313 /// reference used to build IR for Kazan; an empty type for `core::simd`
314 pub trait Context: Copy {
401 fn make<T: Make<Self>>(self, v: T::Prim) -> T {
406 pub trait Make<Context>: Sized {
408 fn make(ctx: Context, v: Self::Prim) -> Self;
411 pub trait ConvertTo<T> {
415 macro_rules! impl_convert_to_using_as {
416 ($($src:ident -> [$($dest:ident),*];)*) => {
418 impl ConvertTo<$dest> for $src {
419 fn to(self) -> $dest {
425 ([$($src:ident),*] -> $dest:tt;) => {
426 impl_convert_to_using_as! {
432 ([$($src:ident),*];) => {
433 impl_convert_to_using_as! {
434 [$($src),*] -> [$($src),*];
439 impl_convert_to_using_as! {
440 [u8, i8, u16, i16, u32, i32, u64, i64, f32, f64];
458 impl<T> Number for T where
475 + BitAnd<Output = Self>
476 + BitOr<Output = Self>
477 + BitXor<Output = Self>
485 impl<T> BitOps for T where
487 + BitAnd<Output = Self>
488 + BitOr<Output = Self>
489 + BitXor<Output = Self>
497 pub trait Int<ShiftRhs>:
500 + Shl<ShiftRhs, Output = Self>
501 + Shr<ShiftRhs, Output = Self>
502 + ShlAssign<ShiftRhs>
503 + ShrAssign<ShiftRhs>
507 pub trait UInt<ShiftRhs>: Int<ShiftRhs> {}
509 pub trait SInt<ShiftRhs>: Int<ShiftRhs> + Neg<Output = Self> {}
511 macro_rules! impl_uint {
512 ($($ty:ident),*) => {
514 impl Int<u32> for $ty {}
515 impl UInt<u32> for $ty {}
520 impl_uint![u8, u16, u32, u64];
522 macro_rules! impl_int {
523 ($($ty:ident),*) => {
525 impl Int<u32> for $ty {}
526 impl SInt<u32> for $ty {}
531 impl_int![i8, i16, i32, i64];
533 pub trait Float<BitsShiftRhs>: Number + Neg<Output = Self> {
534 type BitsType: UInt<BitsShiftRhs>;
535 fn abs(self) -> Self;
536 fn trunc(self) -> Self;
537 fn ceil(self) -> Self;
538 fn floor(self) -> Self;
539 fn round(self) -> Self;
540 #[cfg(feature = "fma")]
541 fn fma(self, a: Self, b: Self) -> Self;
542 fn is_nan(self) -> Self::Bool;
543 fn is_infinite(self) -> Self::Bool;
544 fn is_finite(self) -> Self::Bool;
545 fn from_bits(v: Self::BitsType) -> Self;
546 fn to_bits(self) -> Self::BitsType;
549 macro_rules! impl_float {
550 ($ty:ty, $bits:ty) => {
551 impl Float<u32> for $ty {
552 type BitsType = $bits;
553 fn abs(self) -> Self {
554 #[cfg(feature = "std")]
556 #[cfg(not(feature = "std"))]
559 fn trunc(self) -> Self {
560 #[cfg(feature = "std")]
562 #[cfg(not(feature = "std"))]
565 fn ceil(self) -> Self {
566 #[cfg(feature = "std")]
568 #[cfg(not(feature = "std"))]
571 fn floor(self) -> Self {
572 #[cfg(feature = "std")]
574 #[cfg(not(feature = "std"))]
577 fn round(self) -> Self {
578 #[cfg(feature = "std")]
580 #[cfg(not(feature = "std"))]
583 #[cfg(feature = "fma")]
584 fn fma(self, a: Self, b: Self) -> Self {
587 fn is_nan(self) -> Self::Bool {
590 fn is_infinite(self) -> Self::Bool {
593 fn is_finite(self) -> Self::Bool {
596 fn from_bits(v: Self::BitsType) -> Self {
599 fn to_bits(self) -> Self::BitsType {
606 impl_float!(f32, u32);
607 impl_float!(f64, u64);
609 pub trait Bool: BitOps {}
611 impl Bool for bool {}
613 pub trait Select<T>: Bool {
614 fn select(self, true_v: T, false_v: T) -> T;
617 impl<T> Select<T> for bool {
618 fn select(self, true_v: T, false_v: T) -> T {
626 pub trait Compare: Copy {
627 type Bool: Bool + Select<Self>;
628 fn eq(self, rhs: Self) -> Self::Bool;
629 fn ne(self, rhs: Self) -> Self::Bool;
630 fn lt(self, rhs: Self) -> Self::Bool;
631 fn gt(self, rhs: Self) -> Self::Bool;
632 fn le(self, rhs: Self) -> Self::Bool;
633 fn ge(self, rhs: Self) -> Self::Bool;
636 macro_rules! impl_compare_using_partial_cmp {
639 impl Compare for $ty {
641 fn eq(self, rhs: Self) -> Self::Bool {
644 fn ne(self, rhs: Self) -> Self::Bool {
647 fn lt(self, rhs: Self) -> Self::Bool {
650 fn gt(self, rhs: Self) -> Self::Bool {
653 fn le(self, rhs: Self) -> Self::Bool {
656 fn ge(self, rhs: Self) -> Self::Bool {
664 impl_compare_using_partial_cmp![u8, i8, u16, i16, F16, u32, i32, f32, u64, i64, f64];