Debian Codegraph @

debian/missing-sources/glam-0.19.0/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 mul_add(self, b: Self, c: Self) -> Self {
228 f32x4_add(f32x4_mul(self, b), c)
229 }
230
231 #[inline(always)]
232 fn sub(self, other: Self) -> Self {
233 f32x4_sub(self, other)
234 }
235
236 #[inline(always)]
237 fn add_scalar(self, other: f32) -> Self {
238 f32x4_add(self, f32x4_splat(other))
239 }
240
241 #[inline(always)]
242 fn sub_scalar(self, other: f32) -> Self {
243 f32x4_sub(self, f32x4_splat(other))
244 }
245
246 #[inline(always)]
247 fn mul_scalar(self, other: f32) -> Self {
248 f32x4_mul(self, f32x4_splat(other))
249 }
250
251 #[inline(always)]
252 fn div_scalar(self, other: f32) -> Self {
253 f32x4_div(self, f32x4_splat(other))
254 }
255
256 #[inline(always)]
257 fn rem(self, other: Self) -> Self {
258 let n = f32x4_floor(f32x4_div(self, other));
259 f32x4_sub(self, f32x4_mul(n, other))
260 }
261
262 #[inline(always)]
263 fn rem_scalar(self, other: f32) -> Self {
264 self.rem(f32x4_splat(other))
265 }
266
267 #[inline(always)]
268 fn min(self, other: Self) -> Self {
269 f32x4_pmin(self, other)
270 }
271
272 #[inline(always)]
273 fn max(self, other: Self) -> Self {
274 f32x4_pmax(self, other)
275 }
276 }
277
278 impl Vector3<f32> for v128 {
279 #[inline(always)]
280 fn new(x: f32, y: f32, z: f32) -> Self {
281 f32x4(x, y, z, x)
282 }
283
284 #[inline(always)]
285 fn x(self) -> f32 {
286 f32x4_extract_lane::<0>(self)
287 }
288
289 #[inline(always)]
290 fn y(self) -> f32 {
291 f32x4_extract_lane::<1>(self)
292 }
293
294 #[inline(always)]
295 fn z(self) -> f32 {
296 f32x4_extract_lane::<2>(self)
297 }
298
299 #[inline(always)]
300 fn splat_x(self) -> Self {
301 i32x4_shuffle::<0, 0, 0, 0>(self, self)
302 }
303
304 #[inline(always)]
305 fn splat_y(self) -> Self {
306 i32x4_shuffle::<1, 1, 1, 1>(self, self)
307 }
308
309 #[inline(always)]
310 fn splat_z(self) -> Self {
311 i32x4_shuffle::<2, 2, 2, 2>(self, self)
312 }
313
314 #[inline(always)]
315 fn from_slice_unaligned(slice: &[f32]) -> Self {
316 Vector3::new(slice[0], slice[1], slice[2])
317 }
318
319 #[inline(always)]
320 fn write_to_slice_unaligned(self, slice: &mut [f32]) {
321 let xyz = self.as_ref_xyz();
322 slice[0] = xyz.x;
323 slice[1] = xyz.y;
324 slice[2] = xyz.z;
325 }
326
327 #[inline(always)]
328 fn as_ref_xyz(&self) -> &XYZ<f32> {
329 unsafe { &*(self as *const Self as *const XYZ<f32>) }
330 }
331
332 #[inline(always)]
333 fn as_mut_xyz(&mut self) -> &mut XYZ<f32> {
334 unsafe { &mut *(self as *mut Self as *mut XYZ<f32>) }
335 }
336
337 #[inline(always)]
338 fn into_xy(self) -> XY<f32> {
339 XY {
340 x: f32x4_extract_lane::<0>(self),
341 y: f32x4_extract_lane::<1>(self),
342 }
343 }
344
345 #[inline]
346 fn into_xyzw(self, w: f32) -> XYZW<f32> {
347 let v = f32x4_replace_lane::<3>(self, w);
348 unsafe { *(&v as *const v128 as *const XYZW<f32>) }
349 }
350
351 #[inline(always)]
352 fn from_array(a: [f32; 3]) -> Self {
353 Vector3::new(a[0], a[1], a[2])
354 }
355
356 #[inline(always)]
357 fn into_array(self) -> [f32; 3] {
358 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
359 unsafe {
360 v128_store(out.as_mut_ptr(), self);
361 *(&out.assume_init() as *const v128 as *const [f32; 3])
362 }
363 }
364
365 #[inline(always)]
366 fn from_tuple(t: (f32, f32, f32)) -> Self {
367 Vector3::new(t.0, t.1, t.2)
368 }
369
370 #[inline(always)]
371 fn into_tuple(self) -> (f32, f32, f32) {
372 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
373 unsafe {
374 v128_store(out.as_mut_ptr(), self);
375 *(&out.assume_init() as *const v128 as *const (f32, f32, f32))
376 }
377 }
378
379 #[inline]
380 fn min_element(self) -> f32 {
381 let v = self;
382 let v = f32x4_pmin(v, i32x4_shuffle::<2, 2, 1, 1>(v, v));
383 let v = f32x4_pmin(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
384 f32x4_extract_lane::<0>(v)
385 }
386
387 #[inline]
388 fn max_element(self) -> f32 {
389 let v = self;
390 let v = f32x4_pmax(v, i32x4_shuffle::<2, 2, 0, 0>(v, v));
391 let v = f32x4_pmax(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
392 f32x4_extract_lane::<0>(v)
393 }
394
395 #[inline]
396 fn dot(self, other: Self) -> f32 {
397 f32x4_extract_lane::<0>(dot3_in_x(self, other))
398 }
399
400 #[inline]
401 fn dot_into_vec(self, other: Self) -> Self {
402 let dot_in_x = dot3_in_x(self, other);
403 i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x)
404 }
405
406 #[inline]
407 fn cross(self, other: Self) -> Self {
408 // x <- a.y*b.z - a.z*b.y
409 // y <- a.z*b.x - a.x*b.z
410 // z <- a.x*b.y - a.y*b.x
411 // We can save a shuffle by grouping it in this wacky order:
412 // (self.zxy() * other - self * other.zxy()).zxy()
413 let lhszxy = i32x4_shuffle::<2, 0, 1, 1>(self, self);
414 let rhszxy = i32x4_shuffle::<2, 0, 1, 1>(other, other);
415 let lhszxy_rhs = f32x4_mul(lhszxy, other);
416 let rhszxy_lhs = f32x4_mul(rhszxy, self);
417 let sub = f32x4_sub(lhszxy_rhs, rhszxy_lhs);
418 i32x4_shuffle::<2, 0, 1, 1>(sub, sub)
419 }
420
421 #[inline]
422 fn clamp(self, min: Self, max: Self) -> Self {
423 glam_assert!(
424 MaskVector3::all(min.cmple(max)),
425 "clamp: expected min <= max"
426 );
427 self.max(min).min(max)
428 }
429 }
430
431 impl Vector4<f32> for v128 {
432 #[inline(always)]
433 fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
434 f32x4(x, y, z, w)
435 }
436
437 #[inline(always)]
438 fn x(self) -> f32 {
439 f32x4_extract_lane::<0>(self)
440 }
441
442 #[inline(always)]
443 fn y(self) -> f32 {
444 f32x4_extract_lane::<1>(self)
445 }
446
447 #[inline(always)]
448 fn z(self) -> f32 {
449 f32x4_extract_lane::<2>(self)
450 }
451
452 #[inline(always)]
453 fn w(self) -> f32 {
454 f32x4_extract_lane::<3>(self)
455 }
456
457 #[inline(always)]
458 fn splat_x(self) -> Self {
459 i32x4_shuffle::<0, 0, 0, 0>(self, self)
460 }
461
462 #[inline(always)]
463 fn splat_y(self) -> Self {
464 i32x4_shuffle::<1, 1, 1, 1>(self, self)
465 }
466
467 #[inline(always)]
468 fn splat_z(self) -> Self {
469 i32x4_shuffle::<2, 2, 2, 2>(self, self)
470 }
471
472 #[inline(always)]
473 fn splat_w(self) -> Self {
474 i32x4_shuffle::<3, 3, 3, 3>(self, self)
475 }
476
477 #[inline(always)]
478 fn from_slice_unaligned(slice: &[f32]) -> Self {
479 f32x4(slice[0], slice[1], slice[2], slice[3])
480 }
481
482 #[inline(always)]
483 fn write_to_slice_unaligned(self, slice: &mut [f32]) {
484 let xyzw = self.as_ref_xyzw();
485 slice[0] = xyzw.x;
486 slice[1] = xyzw.y;
487 slice[2] = xyzw.z;
488 slice[3] = xyzw.w;
489 }
490
491 #[inline(always)]
492 fn as_ref_xyzw(&self) -> &XYZW<f32> {
493 unsafe { &*(self as *const Self as *const XYZW<f32>) }
494 }
495
496 #[inline(always)]
497 fn as_mut_xyzw(&mut self) -> &mut XYZW<f32> {
498 unsafe { &mut *(self as *mut Self as *mut XYZW<f32>) }
499 }
500
501 #[inline(always)]
502 fn into_xy(self) -> XY<f32> {
503 XY {
504 x: f32x4_extract_lane::<0>(self),
505 y: f32x4_extract_lane::<1>(self),
506 }
507 }
508
509 #[inline(always)]
510 fn into_xyz(self) -> XYZ<f32> {
511 XYZ {
512 x: f32x4_extract_lane::<0>(self),
513 y: f32x4_extract_lane::<1>(self),
514 z: f32x4_extract_lane::<2>(self),
515 }
516 }
517
518 #[inline(always)]
519 fn from_array(a: [f32; 4]) -> Self {
520 Vector4::new(a[0], a[1], a[2], a[3])
521 }
522
523 #[inline(always)]
524 fn into_array(self) -> [f32; 4] {
525 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
526 unsafe {
527 v128_store(out.as_mut_ptr(), self);
528 *(&out.assume_init() as *const v128 as *const [f32; 4])
529 }
530 }
531
532 #[inline(always)]
533 fn from_tuple(t: (f32, f32, f32, f32)) -> Self {
534 Vector4::new(t.0, t.1, t.2, t.3)
535 }
536
537 #[inline(always)]
538 fn into_tuple(self) -> (f32, f32, f32, f32) {
539 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
540 unsafe {
541 v128_store(out.as_mut_ptr(), self);
542 *(&out.assume_init() as *const v128 as *const (f32, f32, f32, f32))
543 }
544 }
545
546 #[inline]
547 fn min_element(self) -> f32 {
548 let v = self;
549 let v = f32x4_pmin(v, i32x4_shuffle::<2, 3, 0, 0>(v, v));
550 let v = f32x4_pmin(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
551 f32x4_extract_lane::<0>(v)
552 }
553
554 #[inline]
555 fn max_element(self) -> f32 {
556 let v = self;
557 let v = f32x4_pmax(v, i32x4_shuffle::<2, 3, 0, 0>(v, v));
558 let v = f32x4_pmax(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
559 f32x4_extract_lane::<0>(v)
560 }
561
562 #[inline]
563 fn dot(self, other: Self) -> f32 {
564 f32x4_extract_lane::<0>(dot4_in_x(self, other))
565 }
566
567 #[inline]
568 fn dot_into_vec(self, other: Self) -> Self {
569 let dot_in_x = dot4_in_x(self, other);
570 i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x)
571 }
572
573 #[inline]
574 fn clamp(self, min: Self, max: Self) -> Self {
575 glam_assert!(
576 MaskVector4::all(min.cmple(max)),
577 "clamp: expected min <= max"
578 );
579 self.max(min).min(max)
580 }
581 }
582
583 impl SignedVector<f32> for v128 {
584 #[inline(always)]
585 fn neg(self) -> Self {
586 f32x4_neg(self)
587 }
588 }
589
590 impl SignedVector3<f32> for v128 {
591 #[inline]
592 fn abs(self) -> Self {
593 f32x4_abs(self)
594 }
595
596 #[inline]
597 fn signum(self) -> Self {
598 const NEG_ONE: v128 = const_f32x4!([-1.0; 4]);
599 let mask = self.cmpge(Self::ZERO);
600 let result = Self::select(mask, Self::ONE, NEG_ONE);
601 let mask = f32x4_isnan(self);
602 Self::select(mask, self, result)
603 }
604 }
605
606 impl SignedVector4<f32> for v128 {
607 #[inline]
608 fn abs(self) -> Self {
609 f32x4_abs(self)
610 }
611
612 #[inline]
613 fn signum(self) -> Self {
614 const NEG_ONE: v128 = const_f32x4!([-1.0; 4]);
615 let mask = self.cmpge(Self::ZERO);
616 let result = Self::select(mask, Self::ONE, NEG_ONE);
617 let mask = f32x4_isnan(self);
618 Self::select(mask, self, result)
619 }
620 }
621
622 impl FloatVector3<f32> for v128 {
623 #[inline]
624 fn is_finite(self) -> bool {
625 let (x, y, z) = Vector3::into_tuple(self);
626 x.is_finite() && y.is_finite() && z.is_finite()
627 }
628
629 #[inline]
630 fn is_nan(self) -> bool {
631 MaskVector3::any(FloatVector3::is_nan_mask(self))
632 }
633
634 #[inline(always)]
635 fn is_nan_mask(self) -> Self::Mask {
636 f32x4_isnan(self)
637 }
638
639 #[inline]
640 fn floor(self) -> Self {
641 f32x4_floor(self)
642 }
643
644 #[inline]
645 fn ceil(self) -> Self {
646 f32x4_ceil(self)
647 }
648
649 #[inline]
650 fn round(self) -> Self {
651 // TODO: might differ to m128_round
652 f32x4_nearest(self)
653 }
654
655 #[inline(always)]
656 fn recip(self) -> Self {
657 f32x4_div(Self::ONE, self)
658 }
659
660 #[inline]
661 fn exp(self) -> Self {
662 let (x, y, z) = Vector3::into_tuple(self);
663 Vector3::new(x.exp(), y.exp(), z.exp())
664 }
665
666 #[inline]
667 fn powf(self, n: f32) -> Self {
668 let (x, y, z) = Vector3::into_tuple(self);
669 Vector3::new(x.powf(n), y.powf(n), z.powf(n))
670 }
671
672 #[inline]
673 fn length(self) -> f32 {
674 let dot = dot3_in_x(self, self);
675 f32x4_extract_lane::<0>(f32x4_sqrt(dot))
676 }
677
678 #[inline]
679 fn length_recip(self) -> f32 {
680 let dot = dot3_in_x(self, self);
681 f32x4_extract_lane::<0>(f32x4_div(Self::ONE, f32x4_sqrt(dot)))
682 }
683
684 #[inline]
685 fn normalize(self) -> Self {
686 let length = f32x4_sqrt(Vector3::dot_into_vec(self, self));
687 #[allow(clippy::let_and_return)]
688 let normalized = f32x4_div(self, length);
689 glam_assert!(FloatVector3::is_finite(normalized));
690 normalized
691 }
692 }
693
694 impl FloatVector4<f32> for v128 {
695 #[inline]
696 fn is_finite(self) -> bool {
697 let (x, y, z, w) = Vector4::into_tuple(self);
698 x.is_finite() && y.is_finite() && z.is_finite() && w.is_finite()
699 }
700
701 #[inline]
702 fn is_nan(self) -> bool {
703 MaskVector4::any(FloatVector4::is_nan_mask(self))
704 }
705
706 #[inline(always)]
707 fn is_nan_mask(self) -> Self::Mask {
708 f32x4_isnan(self)
709 }
710
711 #[inline]
712 fn floor(self) -> Self {
713 f32x4_floor(self)
714 }
715
716 #[inline]
717 fn ceil(self) -> Self {
718 f32x4_ceil(self)
719 }
720
721 #[inline]
722 fn round(self) -> Self {
723 f32x4_nearest(self)
724 }
725
726 #[inline(always)]
727 fn recip(self) -> Self {
728 f32x4_div(Self::ONE, self)
729 }
730
731 #[inline]
732 fn exp(self) -> Self {
733 let (x, y, z, w) = Vector4::into_tuple(self);
734 f32x4(x.exp(), y.exp(), z.exp(), w.exp())
735 }
736
737 #[inline]
738 fn powf(self, n: f32) -> Self {
739 let (x, y, z, w) = Vector4::into_tuple(self);
740 f32x4(x.powf(n), y.powf(n), z.powf(n), w.powf(n))
741 }
742
743 #[inline]
744 fn length(self) -> f32 {
745 let dot = dot4_in_x(self, self);
746 f32x4_extract_lane::<0>(f32x4_sqrt(dot))
747 }
748
749 #[inline]
750 fn length_recip(self) -> f32 {
751 let dot = dot4_in_x(self, self);
752 f32x4_extract_lane::<0>(f32x4_div(Self::ONE, f32x4_sqrt(dot)))
753 }
754
755 #[inline]
756 fn normalize(self) -> Self {
757 let dot = Vector4::dot_into_vec(self, self);
758 #[allow(clippy::let_and_return)]
759 let normalized = f32x4_div(self, f32x4_sqrt(dot));
760 glam_assert!(FloatVector4::is_finite(normalized));
761 normalized
762 }
763 }
764
765 impl From<XYZW<f32>> for v128 {
766 #[inline(always)]
767 fn from(v: XYZW<f32>) -> v128 {
768 f32x4(v.x, v.y, v.z, v.w)
769 }
770 }
771
772 impl From<XYZ<f32>> for v128 {
773 #[inline(always)]
774 fn from(v: XYZ<f32>) -> v128 {
775 f32x4(v.x, v.y, v.z, v.z)
776 }
777 }
778
779 impl From<XY<f32>> for v128 {
780 #[inline(always)]
781 fn from(v: XY<f32>) -> v128 {
782 f32x4(v.x, v.y, v.y, v.y)
783 }
784 }
785
786 impl From<v128> for XYZW<f32> {
787 #[inline(always)]
788 fn from(v: v128) -> XYZW<f32> {
789 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
790 unsafe {
791 v128_store(out.as_mut_ptr(), v);
792 *(&out.assume_init() as *const v128 as *const XYZW<f32>)
793 }
794 }
795 }
796
797 impl From<v128> for XYZ<f32> {
798 #[inline(always)]
799 fn from(v: v128) -> XYZ<f32> {
800 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
801 unsafe {
802 v128_store(out.as_mut_ptr(), v);
803 *(&out.assume_init() as *const v128 as *const XYZ<f32>)
804 }
805 }
806 }
807
808 impl From<v128> for XY<f32> {
809 #[inline(always)]
810 fn from(v: v128) -> XY<f32> {
811 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
812 unsafe {
813 v128_store(out.as_mut_ptr(), v);
814 *(&out.assume_init() as *const v128 as *const XY<f32>)
815 }
816 }
817 }