1#![expect(
5 missing_docs,
6 reason = "TODO: https://github.com/linebender/fearless_simd/issues/40"
7)]
8use crate::{Level, Simd, SimdBase};
9
10pub trait Select<T> {
12 fn select(self, if_true: T, if_false: T) -> T;
18}
19
20pub trait WithSimd {
22 type Output;
23
24 fn with_simd<S: Simd>(self, simd: S) -> Self::Output;
25}
26
27impl<R, F: FnOnce(Level) -> R> WithSimd for F {
28 type Output = R;
29
30 #[inline(always)]
31 fn with_simd<S: Simd>(self, simd: S) -> Self::Output {
32 self(simd.level())
33 }
34}
35
36pub trait Bytes: Sized {
38 type Bytes;
39
40 fn to_bytes(self) -> Self::Bytes;
42
43 fn from_bytes(value: Self::Bytes) -> Self;
45
46 fn bitcast<U: Bytes<Bytes = Self::Bytes>>(self) -> U {
48 U::from_bytes(self.to_bytes())
49 }
50}
51
52pub(crate) mod seal {
53 #[expect(
54 unnameable_types,
55 reason = "This is a sealed trait, so being unnameable is the entire point"
56 )]
57 pub trait Seal {}
58}
59
60pub trait SimdFrom<T, S: Simd> {
69 fn simd_from(simd: S, value: T) -> Self;
70}
71
72pub trait SimdInto<T, S> {
80 fn simd_into(self, simd: S) -> T;
81}
82
83impl<F, T: SimdFrom<F, S>, S: Simd> SimdInto<T, S> for F {
84 fn simd_into(self, simd: S) -> T {
85 SimdFrom::simd_from(simd, self)
86 }
87}
88
89impl<T, S: Simd> SimdFrom<T, S> for T {
90 fn simd_from(_simd: S, value: T) -> Self {
91 value
92 }
93}
94
95pub trait SimdElement {
97 type Mask: SimdElement;
99}
100
101impl SimdElement for f32 {
102 type Mask = i32;
103}
104
105impl SimdElement for f64 {
106 type Mask = i64;
107}
108
109impl SimdElement for u8 {
110 type Mask = i8;
111}
112
113impl SimdElement for i8 {
114 type Mask = Self;
115}
116
117impl SimdElement for u16 {
118 type Mask = i16;
119}
120
121impl SimdElement for i16 {
122 type Mask = Self;
123}
124
125impl SimdElement for u32 {
126 type Mask = i32;
127}
128
129impl SimdElement for i32 {
130 type Mask = Self;
131}
132
133impl SimdElement for i64 {
134 type Mask = Self;
135}
136
137pub trait SimdCvtTruncate<T> {
139 fn truncate_from(x: T) -> Self;
140 fn truncate_from_precise(x: T) -> Self;
141}
142
143pub trait SimdCvtFloat<T> {
145 fn float_from(x: T) -> Self;
146}
147
148pub trait SimdCombine<S: Simd>: SimdBase<S> {
152 type Combined: SimdBase<S, Element = Self::Element, Block = Self::Block>;
153
154 fn combine(self, rhs: impl SimdInto<Self, S>) -> Self::Combined;
156}
157
158pub trait SimdSplit<S: Simd>: SimdBase<S> {
162 type Split: SimdBase<S, Element = Self::Element, Block = Self::Block>;
163
164 fn split(self) -> (Self::Split, Self::Split);
166}