Debian Codegraph @

debian/missing-sources/glam-0.20.5/src/core/wasm32/vector.rs

raw
1 use crate::core::{
2 storage::{XY, XYZ, XYZW},
3 traits::{scalar::*, vector::*},
4 };
5 use core::arch::wasm32::*;
6 use core::mem::MaybeUninit;
7
8 #[inline(always)]
9 fn f32x4_isnan(v: v128) -> v128 {
10 f32x4_ne(v, v)
11 }
12
13 /// Calculates the vector 3 dot product and returns answer in x lane of __m128.
14 #[inline(always)]
15 fn dot3_in_x(lhs: v128, rhs: v128) -> v128 {
16 let x2_y2_z2_w2 = f32x4_mul(lhs, rhs);
17 let y2_0_0_0 = i32x4_shuffle::<1, 0, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2);
18 let z2_0_0_0 = i32x4_shuffle::<2, 0, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2);
19 let x2y2_0_0_0 = f32x4_add(x2_y2_z2_w2, y2_0_0_0);
20 f32x4_add(x2y2_0_0_0, z2_0_0_0)
21 }
22
23 /// Calculates the vector 4 dot product and returns answer in x lane of __m128.
24 #[inline(always)]
25 fn dot4_in_x(lhs: v128, rhs: v128) -> v128 {
26 let x2_y2_z2_w2 = f32x4_mul(lhs, rhs);
27 let z2_w2_0_0 = i32x4_shuffle::<2, 3, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2);
28 let x2z2_y2w2_0_0 = f32x4_add(x2_y2_z2_w2, z2_w2_0_0);
29 let y2w2_0_0_0 = i32x4_shuffle::<1, 0, 0, 0>(x2z2_y2w2_0_0, x2z2_y2w2_0_0);
30 f32x4_add(x2z2_y2w2_0_0, y2w2_0_0_0)
31 }
32
33 impl MaskVectorConst for v128 {
34 const FALSE: v128 = const_f32x4!([0.0; 4]);
35 }
36
37 impl MaskVector for v128 {
38 #[inline(always)]
39 fn bitand(self, other: Self) -> Self {
40 v128_and(self, other)
41 }
42
43 #[inline(always)]
44 fn bitor(self, other: Self) -> Self {
45 v128_or(self, other)
46 }
47
48 #[inline]
49 fn not(self) -> Self {
50 v128_not(self)
51 }
52 }
53
54 impl MaskVector3 for v128 {
55 #[inline(always)]
56 fn new(x: bool, y: bool, z: bool) -> Self {
57 u32x4(
58 MaskConst::MASK[x as usize],
59 MaskConst::MASK[y as usize],
60 MaskConst::MASK[z as usize],
61 0,
62 )
63 }
64
65 #[inline(always)]
66 fn bitmask(self) -> u32 {
67 (u32x4_bitmask(self) & 0x7) as u32
68 }
69
70 #[inline(always)]
71 fn any(self) -> bool {
72 (u32x4_bitmask(self) & 0x7) != 0
73 }
74
75 #[inline(always)]
76 fn all(self) -> bool {
77 (u32x4_bitmask(self) & 0x7) == 0x7
78 }
79
80 #[inline]
81 fn into_bool_array(self) -> [bool; 3] {
82 let bitmask = MaskVector3::bitmask(self);
83 [(bitmask & 1) != 0, (bitmask & 2) != 0, (bitmask & 4) != 0]
84 }
85
86 #[inline]
87 fn into_u32_array(self) -> [u32; 3] {
88 let bitmask = MaskVector3::bitmask(self);
89 [
90 MaskConst::MASK[(bitmask & 1) as usize],
91 MaskConst::MASK[((bitmask >> 1) & 1) as usize],
92 MaskConst::MASK[((bitmask >> 2) & 1) as usize],
93 ]
94 }
95 }
96
97 impl MaskVector4 for v128 {
98 #[inline(always)]
99 fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
100 u32x4(
101 MaskConst::MASK[x as usize],
102 MaskConst::MASK[y as usize],
103 MaskConst::MASK[z as usize],
104 MaskConst::MASK[w as usize],
105 )
106 }
107
108 #[inline(always)]
109 fn bitmask(self) -> u32 {
110 u32x4_bitmask(self) as u32
111 }
112
113 #[inline(always)]
114 fn any(self) -> bool {
115 u32x4_bitmask(self) != 0
116 }
117
118 #[inline(always)]
119 fn all(self) -> bool {
120 u32x4_bitmask(self) == 0xf
121 }
122
123 #[inline]
124 fn into_bool_array(self) -> [bool; 4] {
125 let bitmask = MaskVector4::bitmask(self);
126 [
127 (bitmask & 1) != 0,
128 (bitmask & 2) != 0,
129 (bitmask & 4) != 0,
130 (bitmask & 8) != 0,
131 ]
132 }
133
134 #[inline]
135 fn into_u32_array(self) -> [u32; 4] {
136 let bitmask = MaskVector4::bitmask(self);
137 [
138 MaskConst::MASK[(bitmask & 1) as usize],
139 MaskConst::MASK[((bitmask >> 1) & 1) as usize],
140 MaskConst::MASK[((bitmask >> 2) & 1) as usize],
141 MaskConst::MASK[((bitmask >> 3) & 1) as usize],
142 ]
143 }
144 }
145
146 impl VectorConst for v128 {
147 const ZERO: v128 = const_f32x4!([0.0; 4]);
148 const ONE: v128 = const_f32x4!([1.0; 4]);
149 }
150
151 impl NanConstEx for v128 {
152 const NAN: v128 = const_f32x4!([f32::NAN; 4]);
153 }
154
155 impl Vector3Const for v128 {
156 const X: v128 = const_f32x4!([1.0, 0.0, 0.0, 0.0]);
157 const Y: v128 = const_f32x4!([0.0, 1.0, 0.0, 0.0]);
158 const Z: v128 = const_f32x4!([0.0, 0.0, 1.0, 0.0]);
159 }
160
161 impl Vector4Const for v128 {
162 const X: v128 = const_f32x4!([1.0, 0.0, 0.0, 0.0]);
163 const Y: v128 = const_f32x4!([0.0, 1.0, 0.0, 0.0]);
164 const Z: v128 = const_f32x4!([0.0, 0.0, 1.0, 0.0]);
165 const W: v128 = const_f32x4!([0.0, 0.0, 0.0, 1.0]);
166 }
167
168 impl Vector<f32> for v128 {
169 type Mask = v128;
170
171 #[inline(always)]
172 fn splat(s: f32) -> Self {
173 f32x4_splat(s)
174 }
175
176 #[inline(always)]
177 fn select(mask: Self::Mask, if_true: Self, if_false: Self) -> Self {
178 v128_bitselect(if_true, if_false, mask)
179 }
180
181 #[inline(always)]
182 fn cmpeq(self, other: Self) -> Self::Mask {
183 f32x4_eq(self, other)
184 }
185
186 #[inline(always)]
187 fn cmpne(self, other: Self) -> Self::Mask {
188 f32x4_ne(self, other)
189 }
190
191 #[inline(always)]
192 fn cmpge(self, other: Self) -> Self::Mask {
193 f32x4_ge(self, other)
194 }
195
196 #[inline(always)]
197 fn cmpgt(self, other: Self) -> Self::Mask {
198 f32x4_gt(self, other)
199 }
200
201 #[inline(always)]
202 fn cmple(self, other: Self) -> Self::Mask {
203 f32x4_le(self, other)
204 }
205
206 #[inline(always)]
207 fn cmplt(self, other: Self) -> Self::Mask {
208 f32x4_lt(self, other)
209 }
210
211 #[inline(always)]
212 fn add(self, other: Self) -> Self {
213 f32x4_add(self, other)
214 }
215
216 #[inline(always)]
217 fn div(self, other: Self) -> Self {
218 f32x4_div(self, other)
219 }
220
221 #[inline(always)]
222 fn mul(self, other: Self) -> Self {
223 f32x4_mul(self, other)
224 }
225
226 #[inline(always)]
227 fn sub(self, other: Self) -> Self {
228 f32x4_sub(self, other)
229 }
230
231 #[inline(always)]
232 fn add_scalar(self, other: f32) -> Self {
233 f32x4_add(self, f32x4_splat(other))
234 }
235
236 #[inline(always)]
237 fn sub_scalar(self, other: f32) -> Self {
238 f32x4_sub(self, f32x4_splat(other))
239 }
240
241 #[inline(always)]
242 fn mul_scalar(self, other: f32) -> Self {
243 f32x4_mul(self, f32x4_splat(other))
244 }
245
246 #[inline(always)]
247 fn div_scalar(self, other: f32) -> Self {
248 f32x4_div(self, f32x4_splat(other))
249 }
250
251 #[inline(always)]
252 fn rem(self, other: Self) -> Self {
253 let n = f32x4_floor(f32x4_div(self, other));
254 f32x4_sub(self, f32x4_mul(n, other))
255 }
256
257 #[inline(always)]
258 fn rem_scalar(self, other: f32) -> Self {
259 self.rem(f32x4_splat(other))
260 }
261
262 #[inline(always)]
263 fn min(self, other: Self) -> Self {
264 f32x4_pmin(self, other)
265 }
266
267 #[inline(always)]
268 fn max(self, other: Self) -> Self {
269 f32x4_pmax(self, other)
270 }
271 }
272
273 impl Vector3<f32> for v128 {
274 #[inline(always)]
275 fn new(x: f32, y: f32, z: f32) -> Self {
276 f32x4(x, y, z, x)
277 }
278
279 #[inline(always)]
280 fn x(self) -> f32 {
281 f32x4_extract_lane::<0>(self)
282 }
283
284 #[inline(always)]
285 fn y(self) -> f32 {
286 f32x4_extract_lane::<1>(self)
287 }
288
289 #[inline(always)]
290 fn z(self) -> f32 {
291 f32x4_extract_lane::<2>(self)
292 }
293
294 #[inline(always)]
295 fn splat_x(self) -> Self {
296 i32x4_shuffle::<0, 0, 0, 0>(self, self)
297 }
298
299 #[inline(always)]
300 fn splat_y(self) -> Self {
301 i32x4_shuffle::<1, 1, 1, 1>(self, self)
302 }
303
304 #[inline(always)]
305 fn splat_z(self) -> Self {
306 i32x4_shuffle::<2, 2, 2, 2>(self, self)
307 }
308
309 #[inline(always)]
310 fn from_slice_unaligned(slice: &[f32]) -> Self {
311 Vector3::new(slice[0], slice[1], slice[2])
312 }
313
314 #[inline(always)]
315 fn write_to_slice_unaligned(self, slice: &mut [f32]) {
316 let xyz = self.as_ref_xyz();
317 slice[0] = xyz.x;
318 slice[1] = xyz.y;
319 slice[2] = xyz.z;
320 }
321
322 #[inline(always)]
323 fn as_ref_xyz(&self) -> &XYZ<f32> {
324 unsafe { &*(self as *const Self as *const XYZ<f32>) }
325 }
326
327 #[inline(always)]
328 fn as_mut_xyz(&mut self) -> &mut XYZ<f32> {
329 unsafe { &mut *(self as *mut Self as *mut XYZ<f32>) }
330 }
331
332 #[inline(always)]
333 fn into_xy(self) -> XY<f32> {
334 XY {
335 x: f32x4_extract_lane::<0>(self),
336 y: f32x4_extract_lane::<1>(self),
337 }
338 }
339
340 #[inline]
341 fn into_xyzw(self, w: f32) -> XYZW<f32> {
342 let v = f32x4_replace_lane::<3>(self, w);
343 unsafe { *(&v as *const v128 as *const XYZW<f32>) }
344 }
345
346 #[inline(always)]
347 fn from_array(a: [f32; 3]) -> Self {
348 Vector3::new(a[0], a[1], a[2])
349 }
350
351 #[inline(always)]
352 fn into_array(self) -> [f32; 3] {
353 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
354 unsafe {
355 v128_store(out.as_mut_ptr(), self);
356 *(&out.assume_init() as *const v128 as *const [f32; 3])
357 }
358 }
359
360 #[inline(always)]
361 fn from_tuple(t: (f32, f32, f32)) -> Self {
362 Vector3::new(t.0, t.1, t.2)
363 }
364
365 #[inline(always)]
366 fn into_tuple(self) -> (f32, f32, f32) {
367 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
368 unsafe {
369 v128_store(out.as_mut_ptr(), self);
370 *(&out.assume_init() as *const v128 as *const (f32, f32, f32))
371 }
372 }
373
374 #[inline]
375 fn min_element(self) -> f32 {
376 let v = self;
377 let v = f32x4_pmin(v, i32x4_shuffle::<2, 2, 1, 1>(v, v));
378 let v = f32x4_pmin(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
379 f32x4_extract_lane::<0>(v)
380 }
381
382 #[inline]
383 fn max_element(self) -> f32 {
384 let v = self;
385 let v = f32x4_pmax(v, i32x4_shuffle::<2, 2, 0, 0>(v, v));
386 let v = f32x4_pmax(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
387 f32x4_extract_lane::<0>(v)
388 }
389
390 #[inline]
391 fn dot(self, other: Self) -> f32 {
392 f32x4_extract_lane::<0>(dot3_in_x(self, other))
393 }
394
395 #[inline]
396 fn dot_into_vec(self, other: Self) -> Self {
397 let dot_in_x = dot3_in_x(self, other);
398 i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x)
399 }
400
401 #[inline]
402 fn cross(self, other: Self) -> Self {
403 // x <- a.y*b.z - a.z*b.y
404 // y <- a.z*b.x - a.x*b.z
405 // z <- a.x*b.y - a.y*b.x
406 // We can save a shuffle by grouping it in this wacky order:
407 // (self.zxy() * other - self * other.zxy()).zxy()
408 let lhszxy = i32x4_shuffle::<2, 0, 1, 1>(self, self);
409 let rhszxy = i32x4_shuffle::<2, 0, 1, 1>(other, other);
410 let lhszxy_rhs = f32x4_mul(lhszxy, other);
411 let rhszxy_lhs = f32x4_mul(rhszxy, self);
412 let sub = f32x4_sub(lhszxy_rhs, rhszxy_lhs);
413 i32x4_shuffle::<2, 0, 1, 1>(sub, sub)
414 }
415
416 #[inline]
417 fn clamp(self, min: Self, max: Self) -> Self {
418 glam_assert!(
419 MaskVector3::all(min.cmple(max)),
420 "clamp: expected min <= max"
421 );
422 self.max(min).min(max)
423 }
424 }
425
426 impl Vector4<f32> for v128 {
427 #[inline(always)]
428 fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
429 f32x4(x, y, z, w)
430 }
431
432 #[inline(always)]
433 fn x(self) -> f32 {
434 f32x4_extract_lane::<0>(self)
435 }
436
437 #[inline(always)]
438 fn y(self) -> f32 {
439 f32x4_extract_lane::<1>(self)
440 }
441
442 #[inline(always)]
443 fn z(self) -> f32 {
444 f32x4_extract_lane::<2>(self)
445 }
446
447 #[inline(always)]
448 fn w(self) -> f32 {
449 f32x4_extract_lane::<3>(self)
450 }
451
452 #[inline(always)]
453 fn splat_x(self) -> Self {
454 i32x4_shuffle::<0, 0, 0, 0>(self, self)
455 }
456
457 #[inline(always)]
458 fn splat_y(self) -> Self {
459 i32x4_shuffle::<1, 1, 1, 1>(self, self)
460 }
461
462 #[inline(always)]
463 fn splat_z(self) -> Self {
464 i32x4_shuffle::<2, 2, 2, 2>(self, self)
465 }
466
467 #[inline(always)]
468 fn splat_w(self) -> Self {
469 i32x4_shuffle::<3, 3, 3, 3>(self, self)
470 }
471
472 #[inline(always)]
473 fn from_slice_unaligned(slice: &[f32]) -> Self {
474 f32x4(slice[0], slice[1], slice[2], slice[3])
475 }
476
477 #[inline(always)]
478 fn write_to_slice_unaligned(self, slice: &mut [f32]) {
479 let xyzw = self.as_ref_xyzw();
480 slice[0] = xyzw.x;
481 slice[1] = xyzw.y;
482 slice[2] = xyzw.z;
483 slice[3] = xyzw.w;
484 }
485
486 #[inline(always)]
487 fn as_ref_xyzw(&self) -> &XYZW<f32> {
488 unsafe { &*(self as *const Self as *const XYZW<f32>) }
489 }
490
491 #[inline(always)]
492 fn as_mut_xyzw(&mut self) -> &mut XYZW<f32> {
493 unsafe { &mut *(self as *mut Self as *mut XYZW<f32>) }
494 }
495
496 #[inline(always)]
497 fn into_xy(self) -> XY<f32> {
498 XY {
499 x: f32x4_extract_lane::<0>(self),
500 y: f32x4_extract_lane::<1>(self),
501 }
502 }
503
504 #[inline(always)]
505 fn into_xyz(self) -> XYZ<f32> {
506 XYZ {
507 x: f32x4_extract_lane::<0>(self),
508 y: f32x4_extract_lane::<1>(self),
509 z: f32x4_extract_lane::<2>(self),
510 }
511 }
512
513 #[inline(always)]
514 fn from_array(a: [f32; 4]) -> Self {
515 Vector4::new(a[0], a[1], a[2], a[3])
516 }
517
518 #[inline(always)]
519 fn into_array(self) -> [f32; 4] {
520 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
521 unsafe {
522 v128_store(out.as_mut_ptr(), self);
523 *(&out.assume_init() as *const v128 as *const [f32; 4])
524 }
525 }
526
527 #[inline(always)]
528 fn from_tuple(t: (f32, f32, f32, f32)) -> Self {
529 Vector4::new(t.0, t.1, t.2, t.3)
530 }
531
532 #[inline(always)]
533 fn into_tuple(self) -> (f32, f32, f32, f32) {
534 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
535 unsafe {
536 v128_store(out.as_mut_ptr(), self);
537 *(&out.assume_init() as *const v128 as *const (f32, f32, f32, f32))
538 }
539 }
540
541 #[inline]
542 fn min_element(self) -> f32 {
543 let v = self;
544 let v = f32x4_pmin(v, i32x4_shuffle::<2, 3, 0, 0>(v, v));
545 let v = f32x4_pmin(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
546 f32x4_extract_lane::<0>(v)
547 }
548
549 #[inline]
550 fn max_element(self) -> f32 {
551 let v = self;
552 let v = f32x4_pmax(v, i32x4_shuffle::<2, 3, 0, 0>(v, v));
553 let v = f32x4_pmax(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
554 f32x4_extract_lane::<0>(v)
555 }
556
557 #[inline]
558 fn dot(self, other: Self) -> f32 {
559 f32x4_extract_lane::<0>(dot4_in_x(self, other))
560 }
561
562 #[inline]
563 fn dot_into_vec(self, other: Self) -> Self {
564 let dot_in_x = dot4_in_x(self, other);
565 i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x)
566 }
567
568 #[inline]
569 fn clamp(self, min: Self, max: Self) -> Self {
570 glam_assert!(
571 MaskVector4::all(min.cmple(max)),
572 "clamp: expected min <= max"
573 );
574 self.max(min).min(max)
575 }
576 }
577
578 impl SignedVector<f32> for v128 {
579 #[inline(always)]
580 fn neg(self) -> Self {
581 f32x4_neg(self)
582 }
583 }
584
585 impl SignedVector3<f32> for v128 {
586 #[inline]
587 fn abs(self) -> Self {
588 f32x4_abs(self)
589 }
590
591 #[inline]
592 fn signum(self) -> Self {
593 const NEG_ONE: v128 = const_f32x4!([-1.0; 4]);
594 let mask = self.cmpge(Self::ZERO);
595 let result = Self::select(mask, Self::ONE, NEG_ONE);
596 let mask = f32x4_isnan(self);
597 Self::select(mask, self, result)
598 }
599 }
600
601 impl SignedVector4<f32> for v128 {
602 #[inline]
603 fn abs(self) -> Self {
604 f32x4_abs(self)
605 }
606
607 #[inline]
608 fn signum(self) -> Self {
609 const NEG_ONE: v128 = const_f32x4!([-1.0; 4]);
610 let mask = self.cmpge(Self::ZERO);
611 let result = Self::select(mask, Self::ONE, NEG_ONE);
612 let mask = f32x4_isnan(self);
613 Self::select(mask, self, result)
614 }
615 }
616
617 impl FloatVector3<f32> for v128 {
618 #[inline]
619 fn is_finite(self) -> bool {
620 let (x, y, z) = Vector3::into_tuple(self);
621 x.is_finite() && y.is_finite() && z.is_finite()
622 }
623
624 #[inline]
625 fn is_nan(self) -> bool {
626 MaskVector3::any(FloatVector3::is_nan_mask(self))
627 }
628
629 #[inline(always)]
630 fn is_nan_mask(self) -> Self::Mask {
631 f32x4_isnan(self)
632 }
633
634 #[inline]
635 fn floor(self) -> Self {
636 f32x4_floor(self)
637 }
638
639 #[inline]
640 fn ceil(self) -> Self {
641 f32x4_ceil(self)
642 }
643
644 #[inline]
645 fn round(self) -> Self {
646 // TODO: might differ to m128_round
647 f32x4_nearest(self)
648 }
649
650 #[inline(always)]
651 fn recip(self) -> Self {
652 f32x4_div(Self::ONE, self)
653 }
654
655 #[inline]
656 fn exp(self) -> Self {
657 let (x, y, z) = Vector3::into_tuple(self);
658 Vector3::new(x.exp(), y.exp(), z.exp())
659 }
660
661 #[inline]
662 fn powf(self, n: f32) -> Self {
663 let (x, y, z) = Vector3::into_tuple(self);
664 Vector3::new(x.powf(n), y.powf(n), z.powf(n))
665 }
666
667 #[inline]
668 fn length(self) -> f32 {
669 let dot = dot3_in_x(self, self);
670 f32x4_extract_lane::<0>(f32x4_sqrt(dot))
671 }
672
673 #[inline]
674 fn length_recip(self) -> f32 {
675 let dot = dot3_in_x(self, self);
676 f32x4_extract_lane::<0>(f32x4_div(Self::ONE, f32x4_sqrt(dot)))
677 }
678
679 #[inline]
680 fn normalize(self) -> Self {
681 let length = f32x4_sqrt(Vector3::dot_into_vec(self, self));
682 #[allow(clippy::let_and_return)]
683 let normalized = f32x4_div(self, length);
684 glam_assert!(FloatVector3::is_finite(normalized));
685 normalized
686 }
687 }
688
689 impl FloatVector4<f32> for v128 {
690 #[inline]
691 fn is_finite(self) -> bool {
692 let (x, y, z, w) = Vector4::into_tuple(self);
693 x.is_finite() && y.is_finite() && z.is_finite() && w.is_finite()
694 }
695
696 #[inline]
697 fn is_nan(self) -> bool {
698 MaskVector4::any(FloatVector4::is_nan_mask(self))
699 }
700
701 #[inline(always)]
702 fn is_nan_mask(self) -> Self::Mask {
703 f32x4_isnan(self)
704 }
705
706 #[inline]
707 fn floor(self) -> Self {
708 f32x4_floor(self)
709 }
710
711 #[inline]
712 fn ceil(self) -> Self {
713 f32x4_ceil(self)
714 }
715
716 #[inline]
717 fn round(self) -> Self {
718 f32x4_nearest(self)
719 }
720
721 #[inline(always)]
722 fn recip(self) -> Self {
723 f32x4_div(Self::ONE, self)
724 }
725
726 #[inline]
727 fn exp(self) -> Self {
728 let (x, y, z, w) = Vector4::into_tuple(self);
729 f32x4(x.exp(), y.exp(), z.exp(), w.exp())
730 }
731
732 #[inline]
733 fn powf(self, n: f32) -> Self {
734 let (x, y, z, w) = Vector4::into_tuple(self);
735 f32x4(x.powf(n), y.powf(n), z.powf(n), w.powf(n))
736 }
737
738 #[inline]
739 fn length(self) -> f32 {
740 let dot = dot4_in_x(self, self);
741 f32x4_extract_lane::<0>(f32x4_sqrt(dot))
742 }
743
744 #[inline]
745 fn length_recip(self) -> f32 {
746 let dot = dot4_in_x(self, self);
747 f32x4_extract_lane::<0>(f32x4_div(Self::ONE, f32x4_sqrt(dot)))
748 }
749
750 #[inline]
751 fn normalize(self) -> Self {
752 let dot = Vector4::dot_into_vec(self, self);
753 #[allow(clippy::let_and_return)]
754 let normalized = f32x4_div(self, f32x4_sqrt(dot));
755 glam_assert!(FloatVector4::is_finite(normalized));
756 normalized
757 }
758 }
759
760 impl From<XYZW<f32>> for v128 {
761 #[inline(always)]
762 fn from(v: XYZW<f32>) -> v128 {
763 f32x4(v.x, v.y, v.z, v.w)
764 }
765 }
766
767 impl From<XYZ<f32>> for v128 {
768 #[inline(always)]
769 fn from(v: XYZ<f32>) -> v128 {
770 f32x4(v.x, v.y, v.z, v.z)
771 }
772 }
773
774 impl From<XY<f32>> for v128 {
775 #[inline(always)]
776 fn from(v: XY<f32>) -> v128 {
777 f32x4(v.x, v.y, v.y, v.y)
778 }
779 }
780
781 impl From<v128> for XYZW<f32> {
782 #[inline(always)]
783 fn from(v: v128) -> XYZW<f32> {
784 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
785 unsafe {
786 v128_store(out.as_mut_ptr(), v);
787 *(&out.assume_init() as *const v128 as *const XYZW<f32>)
788 }
789 }
790 }
791
792 impl From<v128> for XYZ<f32> {
793 #[inline(always)]
794 fn from(v: v128) -> XYZ<f32> {
795 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
796 unsafe {
797 v128_store(out.as_mut_ptr(), v);
798 *(&out.assume_init() as *const v128 as *const XYZ<f32>)
799 }
800 }
801 }
802
803 impl From<v128> for XY<f32> {
804 #[inline(always)]
805 fn from(v: v128) -> XY<f32> {
806 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
807 unsafe {
808 v128_store(out.as_mut_ptr(), v);
809 *(&out.assume_init() as *const v128 as *const XY<f32>)
810 }
811 }
812 }