Debian Codegraph @

debian/missing-sources/safe_arch/src/x86_x64/ssse3.rs

raw
1 #![cfg(target_feature = "ssse3")]
2
3 use super::*;
4
5 /// Lanewise absolute value with lanes as `i8`.
6 ///
7 /// This is a "wrapping" absolute value, so `i8::MIN` stays as `i8::MIN`.
8 ///
9 /// * **Intrinsic:** [`_mm_abs_epi8`]
10 /// * **Assembly:** `pabsb xmm, xmm`
11 #[must_use]
12 #[inline(always)]
13 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
14 pub fn abs_i8_m128i(a: m128i) -> m128i {
15 m128i(unsafe { _mm_abs_epi8(a.0) })
16 }
17
18 /// Lanewise absolute value with lanes as `i16`.
19 ///
20 /// This is a "wrapping" absolute value, so `i16::MIN` stays as `i16::MIN`.
21 ///
22 /// * **Intrinsic:** [`_mm_abs_epi16`]
23 /// * **Assembly:** `pabsw xmm, xmm`
24 #[must_use]
25 #[inline(always)]
26 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
27 pub fn abs_i16_m128i(a: m128i) -> m128i {
28 m128i(unsafe { _mm_abs_epi16(a.0) })
29 }
30
31 /// Lanewise absolute value with lanes as `i32`.
32 ///
33 /// This is a "wrapping" absolute value, so `i32::MIN` stays as `i32::MIN`.
34 ///
35 /// * **Intrinsic:** [`_mm_abs_epi32`]
36 /// * **Assembly:** `pabsd xmm, xmm`
37 #[must_use]
38 #[inline(always)]
39 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
40 pub fn abs_i32_m128i(a: m128i) -> m128i {
41 m128i(unsafe { _mm_abs_epi32(a.0) })
42 }
43
44 /// Counts `$a` as the high bytes and `$b` as the low bytes then performs a
45 /// **byte** shift to the right by the immediate value.
46 ///
47 /// Remember that this is all little-endian data.
48 ///
49 /// * **Intrinsic:** [`_mm_alignr_epi8`]
50 /// * **Assembly:** `palignr xmm, xmm, imm8`
51 #[must_use]
52 #[inline(always)]
53 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
54 pub fn combined_byte_shr_imm_m128i<const IMM: i32>(
55 a: m128i, b: m128i,
56 ) -> m128i {
57 m128i(unsafe { _mm_alignr_epi8(a.0, b.0, IMM) })
58 }
59
60 /// Add horizontal pairs of `i16` values, pack the outputs as `a` then `b`.
61 ///
62 /// * **Intrinsic:** [`_mm_hadd_epi16`]
63 /// * **Assembly:** `phaddw xmm, xmm`
64 #[must_use]
65 #[inline(always)]
66 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
67 pub fn add_horizontal_i16_m128i(a: m128i, b: m128i) -> m128i {
68 m128i(unsafe { _mm_hadd_epi16(a.0, b.0) })
69 }
70
71 /// Add horizontal pairs of `i32` values, pack the outputs as `a` then `b`.
72 ///
73 /// * **Intrinsic:** [`_mm_hadd_epi32`]
74 /// * **Assembly:** `phaddd xmm, xmm`
75 #[must_use]
76 #[inline(always)]
77 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
78 pub fn add_horizontal_i32_m128i(a: m128i, b: m128i) -> m128i {
79 m128i(unsafe { _mm_hadd_epi32(a.0, b.0) })
80 }
81
82 /// Add horizontal pairs of `i16` values, saturating, pack the outputs as `a`
83 /// then `b`.
84 ///
85 /// * **Intrinsic:** [`_mm_hadds_epi16`]
86 /// * **Assembly:** `phaddsw xmm, xmm`
87 #[must_use]
88 #[inline(always)]
89 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
90 pub fn add_horizontal_saturating_i16_m128i(a: m128i, b: m128i) -> m128i {
91 m128i(unsafe { _mm_hadds_epi16(a.0, b.0) })
92 }
93
94 /// Subtract horizontal pairs of `i16` values, pack the outputs as `a` then `b`.
95 ///
96 /// * **Intrinsic:** [`_mm_hsub_epi16`]
97 /// * **Assembly:** `phsubw xmm, xmm`
98 #[must_use]
99 #[inline(always)]
100 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
101 pub fn sub_horizontal_i16_m128i(a: m128i, b: m128i) -> m128i {
102 m128i(unsafe { _mm_hsub_epi16(a.0, b.0) })
103 }
104
105 /// Subtract horizontal pairs of `i32` values, pack the outputs as `a` then `b`.
106 ///
107 /// * **Intrinsic:** [`_mm_hsub_epi32`]
108 /// * **Assembly:** `phsubd xmm, xmm`
109 #[must_use]
110 #[inline(always)]
111 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
112 pub fn sub_horizontal_i32_m128i(a: m128i, b: m128i) -> m128i {
113 m128i(unsafe { _mm_hsub_epi32(a.0, b.0) })
114 }
115
116 /// Subtract horizontal pairs of `i16` values, saturating, pack the outputs as
117 /// `a` then `b`.
118 ///
119 /// * **Intrinsic:** [`_mm_hsubs_epi16`]
120 /// * **Assembly:** `phsubsw xmm, xmm`
121 #[must_use]
122 #[inline(always)]
123 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
124 pub fn sub_horizontal_saturating_i16_m128i(a: m128i, b: m128i) -> m128i {
125 m128i(unsafe { _mm_hsubs_epi16(a.0, b.0) })
126 }
127
128 /// This is dumb and weird.
129 ///
130 /// * Vertically multiplies each `u8` lane from `a` with an `i8` lane from `b`,
131 /// producing an `i16` intermediate value.
132 /// * These intermediate `i16` values are horizontally added with saturation.
133 ///
134 /// * **Intrinsic:** [`_mm_maddubs_epi16`]
135 /// * **Assembly:** `pmaddubsw xmm, xmm`
136 #[must_use]
137 #[inline(always)]
138 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
139 pub fn mul_u8i8_add_horizontal_saturating_m128i(a: m128i, b: m128i) -> m128i {
140 m128i(unsafe { _mm_maddubs_epi16(a.0, b.0) })
141 }
142
143 /// Multiply `i16` lanes into `i32` intermediates, keep the high 18 bits, round
144 /// by adding 1, right shift by 1.
145 ///
146 /// This is `_mm_mulhrs_epi16`, which I can only assume is named for something
147 /// like "high bits rounded and scaled".
148 ///
149 /// * **Intrinsic:** [`_mm_mulhrs_epi16`]
150 /// * **Assembly:** `pmulhrsw xmm, xmm`
151 #[must_use]
152 #[inline(always)]
153 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
154 pub fn mul_i16_scale_round_m128i(a: m128i, b: m128i) -> m128i {
155 m128i(unsafe { _mm_mulhrs_epi16(a.0, b.0) })
156 }
157
158 /// Shuffle `i8` lanes in `a` using `i8` values in `v`.
159 ///
160 /// If a lane in `v` is negative, that output is zeroed.
161 ///
162 /// * **Intrinsic:** [`_mm_shuffle_epi8`]
163 /// * **Assembly:** `pshufb xmm, xmm`
164 #[must_use]
165 #[inline(always)]
166 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
167 pub fn shuffle_av_i8z_all_m128i(a: m128i, v: m128i) -> m128i {
168 m128i(unsafe { _mm_shuffle_epi8(a.0, v.0) })
169 }
170
171 /// Applies the sign of `i8` values in `b` to the values in `a`.
172 ///
173 /// * If `b` is negative: the `a` value is negated.
174 /// * Else If `b` is 0: the `a` value becomes 0.
175 /// * Else the `a` value is unchanged.
176 ///
177 /// * **Intrinsic:** [`_mm_sign_epi8`]
178 /// * **Assembly:** `psignb xmm, xmm`
179 #[must_use]
180 #[inline(always)]
181 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
182 pub fn sign_apply_i8_m128i(a: m128i, b: m128i) -> m128i {
183 m128i(unsafe { _mm_sign_epi8(a.0, b.0) })
184 }
185
186 /// Applies the sign of `i16` values in `b` to the values in `a`.
187 ///
188 /// * If `b` is negative: the `a` value is negated.
189 /// * Else If `b` is 0: the `a` value becomes 0.
190 /// * Else the `a` value is unchanged.
191 ///
192 /// * **Intrinsic:** [`_mm_sign_epi16`]
193 /// * **Assembly:** `psignw xmm, xmm`
194 #[must_use]
195 #[inline(always)]
196 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
197 pub fn sign_apply_i16_m128i(a: m128i, b: m128i) -> m128i {
198 m128i(unsafe { _mm_sign_epi16(a.0, b.0) })
199 }
200
201 /// Applies the sign of `i32` values in `b` to the values in `a`.
202 ///
203 /// * If `b` is negative: the `a` value is negated.
204 /// * Else If `b` is 0: the `a` value becomes 0.
205 /// * Else the `a` value is unchanged.
206 ///
207 /// * **Intrinsic:** [`_mm_sign_epi32`]
208 /// * **Assembly:** `psignd xmm, xmm`
209 #[must_use]
210 #[inline(always)]
211 #[cfg_attr(docsrs, doc(cfg(target_feature = "ssse3")))]
212 pub fn sign_apply_i32_m128i(a: m128i, b: m128i) -> m128i {
213 m128i(unsafe { _mm_sign_epi32(a.0, b.0) })
214 }
215