Debian Codegraph @

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

raw
1 #![cfg(target_feature = "fma")]
2
3 use super::*;
4
5 // Note(Lokathor): There's only a few significant operations here but each
6 // operation has variants for each of the four floating SIMD types (m128, m128d,
7 // m256, and m256d), as well as possibly working on the scalar forms. We should
8 // try to keep each operation grouping sorted into the order: m128, m128_s,
9 // m128d, m128d_s, m256, m256d
10
11 //
12 // MUL ADD
13 //
14
15 /// Lanewise fused `(a * b) + c`
16 /// ```
17 /// # use safe_arch::*;
18 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
19 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
20 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
21 /// let d = fused_mul_add_m128(a, b, c).to_array();
22 /// assert_eq!(d, [9.0, 16.0, 25.0, 36.0]);
23 /// ```
24 /// * **Intrinsic:** [`_mm_fmadd_ps`]
25 /// * **Assembly:** one of
26 /// * `vfmadd132ps xmm, xmm, xmm`
27 /// * `vfmadd213ps xmm, xmm, xmm`
28 /// * `vfmadd231ps xmm, xmm, xmm`
29 #[must_use]
30 #[inline(always)]
31 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
32 pub fn fused_mul_add_m128(a: m128, b: m128, c: m128) -> m128 {
33 m128(unsafe { _mm_fmadd_ps(a.0, b.0, c.0) })
34 }
35
36 /// Low lane fused `(a * b) + c`, other lanes unchanged
37 /// ```
38 /// # use safe_arch::*;
39 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
40 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
41 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
42 /// let d = fused_mul_add_m128_s(a, b, c).to_array();
43 /// assert_eq!(d, [9.0, 3.0, 4.0, 5.0]);
44 /// ```
45 /// * **Intrinsic:** [`_mm_fmadd_ss`]
46 /// * **Assembly:** one of
47 /// * `vfmadd132ss xmm, xmm, xmm`
48 /// * `vfmadd213ss xmm, xmm, xmm`
49 /// * `vfmadd231ss xmm, xmm, xmm`
50 #[must_use]
51 #[inline(always)]
52 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
53 pub fn fused_mul_add_m128_s(a: m128, b: m128, c: m128) -> m128 {
54 m128(unsafe { _mm_fmadd_ss(a.0, b.0, c.0) })
55 }
56
57 /// Lanewise fused `(a * b) + c`
58 /// ```
59 /// # use safe_arch::*;
60 /// let a = m128d::from_array([2.0, 3.0]);
61 /// let b = m128d::from_array([4.0, 5.0]);
62 /// let c = m128d::from_array([1.0, 1.0]);
63 /// let d = fused_mul_add_m128d(a, b, c).to_array();
64 /// assert_eq!(d, [9.0, 16.0]);
65 /// ```
66 /// * **Intrinsic:** [`_mm_fmadd_pd`]
67 /// * **Assembly:** one of
68 /// * `vfmadd132pd xmm, xmm, xmm`
69 /// * `vfmadd213pd xmm, xmm, xmm`
70 /// * `vfmadd231pd xmm, xmm, xmm`
71 #[must_use]
72 #[inline(always)]
73 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
74 pub fn fused_mul_add_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
75 m128d(unsafe { _mm_fmadd_pd(a.0, b.0, c.0) })
76 }
77
78 /// Low lane fused `(a * b) + c`, other lanes unchanged
79 /// ```
80 /// # use safe_arch::*;
81 /// let a = m128d::from_array([2.0, 3.0]);
82 /// let b = m128d::from_array([4.0, 5.0]);
83 /// let c = m128d::from_array([1.0, 1.0]);
84 /// let d = fused_mul_add_m128d_s(a, b, c).to_array();
85 /// assert_eq!(d, [9.0, 3.0]);
86 /// ```
87 /// * **Intrinsic:** [`_mm_fmadd_sd`]
88 /// * **Assembly:** one of
89 /// * `vfmadd132sd xmm, xmm, xmm`
90 /// * `vfmadd213sd xmm, xmm, xmm`
91 /// * `vfmadd231sd xmm, xmm, xmm`
92 #[must_use]
93 #[inline(always)]
94 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
95 pub fn fused_mul_add_m128d_s(a: m128d, b: m128d, c: m128d) -> m128d {
96 m128d(unsafe { _mm_fmadd_sd(a.0, b.0, c.0) })
97 }
98
99 /// Lanewise fused `(a * b) + c`
100 /// ```
101 /// # use safe_arch::*;
102 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
103 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
104 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
105 /// let d = fused_mul_add_m256(a, b, c).to_array();
106 /// assert_eq!(d, [6.0, 13.0, 22.0, 33.0, 6.0, 13.0, 22.0, 33.0]);
107 /// ```
108 /// * **Intrinsic:** [`_mm256_fmadd_ps`]
109 /// * **Assembly:** one of
110 /// * `vfmadd132ps ymm, ymm, ymm`
111 /// * `vfmadd213ps ymm, ymm, ymm`
112 /// * `vfmadd231ps ymm, ymm, ymm`
113 #[must_use]
114 #[inline(always)]
115 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
116 pub fn fused_mul_add_m256(a: m256, b: m256, c: m256) -> m256 {
117 m256(unsafe { _mm256_fmadd_ps(a.0, b.0, c.0) })
118 }
119
120 /// Lanewise fused `(a * b) + c`
121 /// ```
122 /// # use safe_arch::*;
123 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
124 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
125 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
126 /// let d = fused_mul_add_m256d(a, b, c).to_array();
127 /// assert_eq!(d, [6.0, 13.0, 22.0, 33.0]);
128 /// ```
129 /// * **Intrinsic:** [`_mm256_fmadd_pd`]
130 /// * **Assembly:** one of
131 /// * `vfmadd132pd ymm, ymm, ymm`
132 /// * `vfmadd213pd ymm, ymm, ymm`
133 /// * `vfmadd231pd ymm, ymm, ymm`
134 #[must_use]
135 #[inline(always)]
136 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
137 pub fn fused_mul_add_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
138 m256d(unsafe { _mm256_fmadd_pd(a.0, b.0, c.0) })
139 }
140
141 //
142 // MUL SUB
143 //
144
145 /// Lanewise fused `(a * b) - c`
146 /// ```
147 /// # use safe_arch::*;
148 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
149 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
150 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
151 /// let d = fused_mul_sub_m128(a, b, c).to_array();
152 /// assert_eq!(d, [7.0, 14.0, 23.0, 34.0]);
153 /// ```
154 /// * **Intrinsic:** [`_mm_fmsub_ps`]
155 /// * **Assembly:** one of
156 /// * `vfmsub132ps xmm, xmm, xmm`
157 /// * `vfmsub213ps xmm, xmm, xmm`
158 /// * `vfmsub231ps xmm, xmm, xmm`
159 #[must_use]
160 #[inline(always)]
161 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
162 pub fn fused_mul_sub_m128(a: m128, b: m128, c: m128) -> m128 {
163 m128(unsafe { _mm_fmsub_ps(a.0, b.0, c.0) })
164 }
165
166 /// Low lane fused `(a * b) - c`, other lanes unchanged.
167 /// ```
168 /// # use safe_arch::*;
169 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
170 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
171 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
172 /// let d = fused_mul_sub_m128_s(a, b, c).to_array();
173 /// assert_eq!(d, [7.0, 3.0, 4.0, 5.0]);
174 /// ```
175 /// * **Intrinsic:** [`_mm_fmsub_ss`]
176 /// * **Assembly:** one of
177 /// * `vfmsub132ss xmm, xmm, xmm`
178 /// * `vfmsub213ss xmm, xmm, xmm`
179 /// * `vfmsub231ss xmm, xmm, xmm`
180 #[must_use]
181 #[inline(always)]
182 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
183 pub fn fused_mul_sub_m128_s(a: m128, b: m128, c: m128) -> m128 {
184 m128(unsafe { _mm_fmsub_ss(a.0, b.0, c.0) })
185 }
186
187 /// Lanewise fused `(a * b) - c`
188 /// ```
189 /// # use safe_arch::*;
190 /// let a = m128d::from_array([2.0, 3.0]);
191 /// let b = m128d::from_array([4.0, 5.0]);
192 /// let c = m128d::from_array([1.0, 1.0]);
193 /// let d = fused_mul_sub_m128d(a, b, c).to_array();
194 /// assert_eq!(d, [7.0, 14.0]);
195 /// ```
196 /// * **Intrinsic:** [`_mm_fmsub_pd`]
197 /// * **Assembly:** one of
198 /// * `vfmsub132pd xmm, xmm, xmm`
199 /// * `vfmsub213pd xmm, xmm, xmm`
200 /// * `vfmsub231pd xmm, xmm, xmm`
201 #[must_use]
202 #[inline(always)]
203 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
204 pub fn fused_mul_sub_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
205 m128d(unsafe { _mm_fmsub_pd(a.0, b.0, c.0) })
206 }
207
208 /// Low lane fused `(a * b) - c`, other lanes unchanged.
209 /// ```
210 /// # use safe_arch::*;
211 /// let a = m128d::from_array([2.0, 3.0]);
212 /// let b = m128d::from_array([4.0, 5.0]);
213 /// let c = m128d::from_array([1.0, 1.0]);
214 /// let d = fused_mul_sub_m128d_s(a, b, c).to_array();
215 /// assert_eq!(d, [7.0, 3.0]);
216 /// ```
217 /// * **Intrinsic:** [`_mm_fmsub_sd`]
218 /// * **Assembly:** one of
219 /// * `vfmsub132sd xmm, xmm, xmm`
220 /// * `vfmsub213sd xmm, xmm, xmm`
221 /// * `vfmsub231sd xmm, xmm, xmm`
222 #[must_use]
223 #[inline(always)]
224 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
225 pub fn fused_mul_sub_m128d_s(a: m128d, b: m128d, c: m128d) -> m128d {
226 m128d(unsafe { _mm_fmsub_sd(a.0, b.0, c.0) })
227 }
228
229 /// Lanewise fused `(a * b) - c`
230 /// ```
231 /// # use safe_arch::*;
232 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
233 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
234 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
235 /// let d = fused_mul_sub_m256(a, b, c).to_array();
236 /// assert_eq!(d, [4.0, 11.0, 20.0, 31.0, 4.0, 11.0, 20.0, 31.0]);
237 /// ```
238 /// * **Intrinsic:** [`_mm256_fmsub_ps`]
239 /// * **Assembly:** one of
240 /// * `vfmsub132ps ymm, ymm, ymm`
241 /// * `vfmsub213ps ymm, ymm, ymm`
242 /// * `vfmsub231ps ymm, ymm, ymm`
243 #[must_use]
244 #[inline(always)]
245 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
246 pub fn fused_mul_sub_m256(a: m256, b: m256, c: m256) -> m256 {
247 m256(unsafe { _mm256_fmsub_ps(a.0, b.0, c.0) })
248 }
249
250 /// Lanewise fused `(a * b) - c`
251 /// ```
252 /// # use safe_arch::*;
253 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
254 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
255 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
256 /// let d = fused_mul_sub_m256d(a, b, c).to_array();
257 /// assert_eq!(d, [4.0, 11.0, 20.0, 31.0]);
258 /// ```
259 /// * **Intrinsic:** [`_mm256_fmsub_pd`]
260 /// * **Assembly:** one of
261 /// * `vfmsub132pd ymm, ymm, ymm`
262 /// * `vfmsub213pd ymm, ymm, ymm`
263 /// * `vfmsub231pd ymm, ymm, ymm`
264 #[must_use]
265 #[inline(always)]
266 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
267 pub fn fused_mul_sub_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
268 m256d(unsafe { _mm256_fmsub_pd(a.0, b.0, c.0) })
269 }
270
271 //
272 // MUL NEG ADD
273 //
274
275 /// Lanewise fused `-(a * b) + c`
276 /// ```
277 /// # use safe_arch::*;
278 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
279 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
280 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
281 /// let d = fused_mul_neg_add_m128(a, b, c).to_array();
282 /// assert_eq!(d, [-7.0, -14.0, -23.0, -34.0]);
283 /// ```
284 /// * **Intrinsic:** [`_mm_fnmadd_ps`]
285 /// * **Assembly:** one of
286 /// * `vfnmadd132ps xmm, xmm, xmm`
287 /// * `vfnmadd213ps xmm, xmm, xmm`
288 /// * `vfnmadd231ps xmm, xmm, xmm`
289 #[must_use]
290 #[inline(always)]
291 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
292 pub fn fused_mul_neg_add_m128(a: m128, b: m128, c: m128) -> m128 {
293 m128(unsafe { _mm_fnmadd_ps(a.0, b.0, c.0) })
294 }
295
296 /// Low lane `-(a * b) + c`, other lanes unchanged.
297 /// ```
298 /// # use safe_arch::*;
299 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
300 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
301 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
302 /// let d = fused_mul_neg_add_m128_s(a, b, c).to_array();
303 /// assert_eq!(d, [-7.0, 3.0, 4.0, 5.0]);
304 /// ```
305 /// * **Intrinsic:** [`_mm_fnmadd_ss`]
306 /// * **Assembly:** one of
307 /// * `vfnmadd132ss xmm, xmm, xmm`
308 /// * `vfnmadd213ss xmm, xmm, xmm`
309 /// * `vfnmadd231ss xmm, xmm, xmm`
310 #[must_use]
311 #[inline(always)]
312 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
313 pub fn fused_mul_neg_add_m128_s(a: m128, b: m128, c: m128) -> m128 {
314 m128(unsafe { _mm_fnmadd_ss(a.0, b.0, c.0) })
315 }
316
317 /// Lanewise fused `-(a * b) + c`
318 /// ```
319 /// # use safe_arch::*;
320 /// let a = m128d::from_array([2.0, 3.0]);
321 /// let b = m128d::from_array([4.0, 5.0]);
322 /// let c = m128d::from_array([1.0, 1.0]);
323 /// let d = fused_mul_neg_add_m128d(a, b, c).to_array();
324 /// assert_eq!(d, [-7.0, -14.0]);
325 /// ```
326 /// * **Intrinsic:** [`_mm_fnmadd_pd`]
327 /// * **Assembly:** one of
328 /// * `vfnmadd132pd xmm, xmm, xmm`
329 /// * `vfnmadd213pd xmm, xmm, xmm`
330 /// * `vfnmadd231pd xmm, xmm, xmm`
331 #[must_use]
332 #[inline(always)]
333 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
334 pub fn fused_mul_neg_add_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
335 m128d(unsafe { _mm_fnmadd_pd(a.0, b.0, c.0) })
336 }
337
338 /// Low lane `-(a * b) + c`, other lanes unchanged.
339 /// ```
340 /// # use safe_arch::*;
341 /// let a = m128d::from_array([2.0, 3.0]);
342 /// let b = m128d::from_array([4.0, 5.0]);
343 /// let c = m128d::from_array([1.0, 1.0]);
344 /// let d = fused_mul_neg_add_m128d_s(a, b, c).to_array();
345 /// assert_eq!(d, [-7.0, 3.0]);
346 /// ```
347 /// * **Intrinsic:** [`_mm_fnmadd_sd`]
348 /// * **Assembly:** one of
349 /// * `vfnmadd132sd xmm, xmm, xmm`
350 /// * `vfnmadd213sd xmm, xmm, xmm`
351 /// * `vfnmadd231sd xmm, xmm, xmm`
352 #[must_use]
353 #[inline(always)]
354 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
355 pub fn fused_mul_neg_add_m128d_s(a: m128d, b: m128d, c: m128d) -> m128d {
356 m128d(unsafe { _mm_fnmadd_sd(a.0, b.0, c.0) })
357 }
358
359 /// Lanewise fused `-(a * b) + c`
360 /// ```
361 /// # use safe_arch::*;
362 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
363 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
364 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
365 /// let d = fused_mul_neg_add_m256(a, b, c).to_array();
366 /// assert_eq!(d, [-4.0, -11.0, -20.0, -31.0, -4.0, -11.0, -20.0, -31.0]);
367 /// ```
368 /// * **Intrinsic:** [`_mm256_fnmadd_ps`]
369 /// * **Assembly:** one of
370 /// * `vfnmadd132ps ymm, ymm, ymm`
371 /// * `vfnmadd213ps ymm, ymm, ymm`
372 /// * `vfnmadd231ps ymm, ymm, ymm`
373 #[must_use]
374 #[inline(always)]
375 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
376 pub fn fused_mul_neg_add_m256(a: m256, b: m256, c: m256) -> m256 {
377 m256(unsafe { _mm256_fnmadd_ps(a.0, b.0, c.0) })
378 }
379
380 /// Lanewise fused `-(a * b) + c`
381 /// ```
382 /// # use safe_arch::*;
383 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
384 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
385 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
386 /// let d = fused_mul_neg_add_m256d(a, b, c).to_array();
387 /// assert_eq!(d, [-4.0, -11.0, -20.0, -31.0]);
388 /// ```
389 /// * **Intrinsic:** [`_mm256_fnmadd_pd`]
390 /// * **Assembly:** one of
391 /// * `vfnmadd132pd ymm, ymm, ymm`
392 /// * `vfnmadd213pd ymm, ymm, ymm`
393 /// * `vfnmadd231pd ymm, ymm, ymm`
394 #[must_use]
395 #[inline(always)]
396 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
397 pub fn fused_mul_neg_add_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
398 m256d(unsafe { _mm256_fnmadd_pd(a.0, b.0, c.0) })
399 }
400
401 //
402 // MUL NEG SUB
403 //
404
405 /// Lanewise fused `-(a * b) - c`
406 /// ```
407 /// # use safe_arch::*;
408 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
409 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
410 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
411 /// let d = fused_mul_neg_sub_m128(a, b, c).to_array();
412 /// assert_eq!(d, [-9.0, -16.0, -25.0, -36.0]);
413 /// ```
414 /// * **Intrinsic:** [`_mm_fnmsub_ps`]
415 /// * **Assembly:** one of
416 /// * `vfnmsub132ps xmm, xmm, xmm`
417 /// * `vfnmsub213ps xmm, xmm, xmm`
418 /// * `vfnmsub231ps xmm, xmm, xmm`
419 #[must_use]
420 #[inline(always)]
421 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
422 pub fn fused_mul_neg_sub_m128(a: m128, b: m128, c: m128) -> m128 {
423 m128(unsafe { _mm_fnmsub_ps(a.0, b.0, c.0) })
424 }
425
426 /// Low lane fused `-(a * b) - c`, other lanes unchanged.
427 /// ```
428 /// # use safe_arch::*;
429 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
430 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
431 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
432 /// let d = fused_mul_neg_sub_m128_s(a, b, c).to_array();
433 /// assert_eq!(d, [-9.0, 3.0, 4.0, 5.0]);
434 /// ```
435 /// * **Intrinsic:** [`_mm_fnmsub_ss`]
436 /// * **Assembly:** one of
437 /// * `vfnmsub132ss xmm, xmm, xmm`
438 /// * `vfnmsub213ss xmm, xmm, xmm`
439 /// * `vfnmsub231ss xmm, xmm, xmm`
440 #[must_use]
441 #[inline(always)]
442 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
443 pub fn fused_mul_neg_sub_m128_s(a: m128, b: m128, c: m128) -> m128 {
444 m128(unsafe { _mm_fnmsub_ss(a.0, b.0, c.0) })
445 }
446
447 /// Lanewise fused `-(a * b) - c`
448 /// ```
449 /// # use safe_arch::*;
450 /// let a = m128d::from_array([2.0, 3.0]);
451 /// let b = m128d::from_array([4.0, 5.0]);
452 /// let c = m128d::from_array([1.0, 1.0]);
453 /// let d = fused_mul_neg_sub_m128d(a, b, c).to_array();
454 /// assert_eq!(d, [-9.0, -16.0]);
455 /// ```
456 /// * **Intrinsic:** [`_mm_fnmsub_pd`]
457 /// * **Assembly:** one of
458 /// * `vfnmsub132pd xmm, xmm, xmm`
459 /// * `vfnmsub213pd xmm, xmm, xmm`
460 /// * `vfnmsub231pd xmm, xmm, xmm`
461 #[must_use]
462 #[inline(always)]
463 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
464 pub fn fused_mul_neg_sub_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
465 m128d(unsafe { _mm_fnmsub_pd(a.0, b.0, c.0) })
466 }
467
468 /// Low lane fused `-(a * b) - c`, other lanes unchanged.
469 /// ```
470 /// # use safe_arch::*;
471 /// let a = m128d::from_array([2.0, 3.0]);
472 /// let b = m128d::from_array([4.0, 5.0]);
473 /// let c = m128d::from_array([1.0, 1.0]);
474 /// let d = fused_mul_neg_sub_m128d_s(a, b, c).to_array();
475 /// assert_eq!(d, [-9.0, 3.0]);
476 /// ```
477 /// * **Intrinsic:** [`_mm_fnmsub_sd`]
478 /// * **Assembly:** one of
479 /// * `vfnmsub132sd xmm, xmm, xmm`
480 /// * `vfnmsub213sd xmm, xmm, xmm`
481 /// * `vfnmsub231sd xmm, xmm, xmm`
482 #[must_use]
483 #[inline(always)]
484 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
485 pub fn fused_mul_neg_sub_m128d_s(a: m128d, b: m128d, c: m128d) -> m128d {
486 m128d(unsafe { _mm_fnmsub_sd(a.0, b.0, c.0) })
487 }
488
489 /// Lanewise fused `-(a * b) - c`
490 /// ```
491 /// # use safe_arch::*;
492 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
493 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
494 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
495 /// let d = fused_mul_neg_sub_m256(a, b, c).to_array();
496 /// assert_eq!(d, [-6.0, -13.0, -22.0, -33.0, -6.0, -13.0, -22.0, -33.0]);
497 /// ```
498 /// * **Intrinsic:** [`_mm256_fnmsub_ps`]
499 /// * **Assembly:** one of
500 /// * `vfnmsub132ps ymm, ymm, ymm`
501 /// * `vfnmsub213ps ymm, ymm, ymm`
502 /// * `vfnmsub231ps ymm, ymm, ymm`
503 #[must_use]
504 #[inline(always)]
505 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
506 pub fn fused_mul_neg_sub_m256(a: m256, b: m256, c: m256) -> m256 {
507 m256(unsafe { _mm256_fnmsub_ps(a.0, b.0, c.0) })
508 }
509
510 /// Lanewise fused `-(a * b) - c`
511 /// ```
512 /// # use safe_arch::*;
513 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
514 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
515 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
516 /// let d = fused_mul_neg_sub_m256d(a, b, c).to_array();
517 /// assert_eq!(d, [-6.0, -13.0, -22.0, -33.0]);
518 /// ```
519 /// * **Intrinsic:** [`_mm256_fnmsub_pd`]
520 /// * **Assembly:** one of
521 /// * `vfnmsub132pd ymm, ymm, ymm`
522 /// * `vfnmsub213pd ymm, ymm, ymm`
523 /// * `vfnmsub231pd ymm, ymm, ymm`
524 #[must_use]
525 #[inline(always)]
526 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
527 pub fn fused_mul_neg_sub_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
528 m256d(unsafe { _mm256_fnmsub_pd(a.0, b.0, c.0) })
529 }
530
531 //
532 // MUL ADDSUB
533 //
534
535 /// Lanewise fused `(a * b) addsub c` (adds odd lanes and subtracts even lanes)
536 /// ```
537 /// # use safe_arch::*;
538 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
539 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
540 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
541 /// let d = fused_mul_addsub_m128(a, b, c).to_array();
542 /// assert_eq!(d, [7.0, 16.0, 23.0, 36.0]);
543 /// ```
544 /// * **Intrinsic:** [`_mm_fmaddsub_ps`]
545 /// * **Assembly:** one of
546 /// * `vfmaddsub132ps xmm, xmm, xmm`
547 /// * `vfmaddsub213ps xmm, xmm, xmm`
548 /// * `vfmaddsub231ps xmm, xmm, xmm`
549 #[must_use]
550 #[inline(always)]
551 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
552 pub fn fused_mul_addsub_m128(a: m128, b: m128, c: m128) -> m128 {
553 m128(unsafe { _mm_fmaddsub_ps(a.0, b.0, c.0) })
554 }
555
556 /// Lanewise fused `(a * b) addsub c` (adds odd lanes and subtracts even lanes)
557 /// ```
558 /// # use safe_arch::*;
559 /// let a = m128d::from_array([2.0, 3.0]);
560 /// let b = m128d::from_array([4.0, 5.0]);
561 /// let c = m128d::from_array([1.0, 1.0]);
562 /// let d = fused_mul_addsub_m128d(a, b, c).to_array();
563 /// assert_eq!(d, [7.0, 16.0]);
564 /// ```
565 /// * **Intrinsic:** [`_mm_fmaddsub_pd`]
566 /// * **Assembly:** one of
567 /// * `vfmaddsub132pd xmm, xmm, xmm`
568 /// * `vfmaddsub213pd xmm, xmm, xmm`
569 /// * `vfmaddsub231pd xmm, xmm, xmm`
570 #[must_use]
571 #[inline(always)]
572 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
573 pub fn fused_mul_addsub_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
574 m128d(unsafe { _mm_fmaddsub_pd(a.0, b.0, c.0) })
575 }
576
577 /// Lanewise fused `(a * b) addsub c` (adds odd lanes and subtracts even lanes)
578 /// ```
579 /// # use safe_arch::*;
580 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
581 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
582 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
583 /// let d = fused_mul_addsub_m256(a, b, c).to_array();
584 /// assert_eq!(d, [4.0, 13.0, 20.0, 33.0, 4.0, 13.0, 20.0, 33.0]);
585 /// ```
586 /// * **Intrinsic:** [`_mm256_fmaddsub_ps`]
587 /// * **Assembly:** one of
588 /// * `vfmaddsub132ps ymm, ymm, ymm`
589 /// * `vfmaddsub213ps ymm, ymm, ymm`
590 /// * `vfmaddsub231ps ymm, ymm, ymm`
591 #[must_use]
592 #[inline(always)]
593 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
594 pub fn fused_mul_addsub_m256(a: m256, b: m256, c: m256) -> m256 {
595 m256(unsafe { _mm256_fmaddsub_ps(a.0, b.0, c.0) })
596 }
597
598 /// Lanewise fused `(a * b) addsub c` (adds odd lanes and subtracts even lanes)
599 /// ```
600 /// # use safe_arch::*;
601 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
602 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
603 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
604 /// let d = fused_mul_addsub_m256d(a, b, c).to_array();
605 /// assert_eq!(d, [4.0, 13.0, 20.0, 33.0]);
606 /// ```
607 /// * **Intrinsic:** [`_mm256_fmaddsub_pd`]
608 /// * **Assembly:** one of
609 /// * `vfmaddsub132pd ymm, ymm, ymm`
610 /// * `vfmaddsub213pd ymm, ymm, ymm`
611 /// * `vfmaddsub231pd ymm, ymm, ymm`
612 #[must_use]
613 #[inline(always)]
614 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
615 pub fn fused_mul_addsub_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
616 m256d(unsafe { _mm256_fmaddsub_pd(a.0, b.0, c.0) })
617 }
618
619 //
620 // MUL SUBADD
621 //
622
623 /// Lanewise fused `(a * b) subadd c` (subtracts odd lanes and adds even lanes)
624 /// ```
625 /// # use safe_arch::*;
626 /// let a = m128::from_array([2.0, 3.0, 4.0, 5.0]);
627 /// let b = m128::from_array([4.0, 5.0, 6.0, 7.0]);
628 /// let c = m128::from_array([1.0, 1.0, 1.0, 1.0]);
629 /// let d = fused_mul_subadd_m128(a, b, c).to_array();
630 /// assert_eq!(d, [9.0, 14.0, 25.0, 34.0]);
631 /// ```
632 /// * **Intrinsic:** [`_mm_fmsubadd_ps`]
633 /// * **Assembly:**
634 /// * `vfmsubadd132ps xmm, xmm, xmm`
635 /// * `vfmsubadd213ps xmm, xmm, xmm`
636 /// * `vfmsubadd231ps xmm, xmm, xmm`
637 #[must_use]
638 #[inline(always)]
639 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
640 pub fn fused_mul_subadd_m128(a: m128, b: m128, c: m128) -> m128 {
641 m128(unsafe { _mm_fmsubadd_ps(a.0, b.0, c.0) })
642 }
643
644 /// Lanewise fused `(a * b) subadd c` (subtracts odd lanes and adds even lanes)
645 /// ```
646 /// # use safe_arch::*;
647 /// let a = m128d::from_array([2.0, 3.0]);
648 /// let b = m128d::from_array([4.0, 5.0]);
649 /// let c = m128d::from_array([1.0, 1.0]);
650 /// let d = fused_mul_subadd_m128d(a, b, c).to_array();
651 /// assert_eq!(d, [9.0, 14.0]);
652 /// ```
653 /// * **Intrinsic:** [`_mm_fmsubadd_pd`]
654 /// * **Assembly:** one of
655 /// * `vfmsubadd132pd xmm, xmm, xmm`
656 /// * `vfmsubadd213pd xmm, xmm, xmm`
657 /// * `vfmsubadd231pd xmm, xmm, xmm`
658 #[must_use]
659 #[inline(always)]
660 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
661 pub fn fused_mul_subadd_m128d(a: m128d, b: m128d, c: m128d) -> m128d {
662 m128d(unsafe { _mm_fmsubadd_pd(a.0, b.0, c.0) })
663 }
664
665 /// Lanewise fused `(a * b) subadd c` (subtracts odd lanes and adds even lanes)
666 /// ```
667 /// # use safe_arch::*;
668 /// let a = m256::from_array([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]);
669 /// let b = m256::from_array([5.0, 6.0, 7.0, 8.0, 5.0, 6.0, 7.0, 8.0]);
670 /// let c = m256::from_array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
671 /// let d = fused_mul_subadd_m256(a, b, c).to_array();
672 /// assert_eq!(d, [6.0, 11.0, 22.0, 31.0, 6.0, 11.0, 22.0, 31.0]);
673 /// ```
674 /// * **Intrinsic:** [`_mm256_fmsubadd_ps`]
675 /// * **Assembly:** one of
676 /// * `vfmsubadd132ps ymm, ymm, ymm`
677 /// * `vfmsubadd213ps ymm, ymm, ymm`
678 /// * `vfmsubadd231ps ymm, ymm, ymm`
679 #[must_use]
680 #[inline(always)]
681 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
682 pub fn fused_mul_subadd_m256(a: m256, b: m256, c: m256) -> m256 {
683 m256(unsafe { _mm256_fmsubadd_ps(a.0, b.0, c.0) })
684 }
685
686 /// Lanewise fused `(a * b) subadd c` (subtracts odd lanes and adds even lanes)
687 /// ```
688 /// # use safe_arch::*;
689 /// let a = m256d::from_array([1.0, 2.0, 3.0, 4.0]);
690 /// let b = m256d::from_array([5.0, 6.0, 7.0, 8.0]);
691 /// let c = m256d::from_array([1.0, 1.0, 1.0, 1.0]);
692 /// let d = fused_mul_subadd_m256d(a, b, c).to_array();
693 /// assert_eq!(d, [6.0, 11.0, 22.0, 31.0]);
694 /// ```
695 /// * **Intrinsic:** [`_mm256_fmsubadd_pd`]
696 /// * **Assembly:** one of
697 /// * `vfmsubadd132pd ymm, ymm, ymm`
698 /// * `vfmsubadd213pd ymm, ymm, ymm`
699 /// * `vfmsubadd231pd ymm, ymm, ymm`
700 #[must_use]
701 #[inline(always)]
702 #[cfg_attr(docsrs, doc(cfg(target_feature = "fma")))]
703 pub fn fused_mul_subadd_m256d(a: m256d, b: m256d, c: m256d) -> m256d {
704 m256d(unsafe { _mm256_fmsubadd_pd(a.0, b.0, c.0) })
705 }
706