Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Vector128.cs
Go to the documentation of this file.
9using System.Text;
11
13
14public static class Vector128
15{
16 [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 [Intrinsic]
18 public static Vector128<U> As<T, U>(this Vector128<T> vector) where T : struct where U : struct
19 {
20 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
21 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<U>();
22 return Unsafe.As<Vector128<T>, Vector128<U>>(ref vector);
23 }
24
25 [Intrinsic]
26 public static Vector128<byte> AsByte<T>(this Vector128<T> vector) where T : struct
27 {
28 return vector.As<T, byte>();
29 }
30
31 [Intrinsic]
32 public static Vector128<double> AsDouble<T>(this Vector128<T> vector) where T : struct
33 {
34 return vector.As<T, double>();
35 }
36
37 [Intrinsic]
38 public static Vector128<short> AsInt16<T>(this Vector128<T> vector) where T : struct
39 {
40 return vector.As<T, short>();
41 }
42
43 [Intrinsic]
44 public static Vector128<int> AsInt32<T>(this Vector128<T> vector) where T : struct
45 {
46 return vector.As<T, int>();
47 }
48
49 [Intrinsic]
50 public static Vector128<long> AsInt64<T>(this Vector128<T> vector) where T : struct
51 {
52 return vector.As<T, long>();
53 }
54
55 [Intrinsic]
56 [CLSCompliant(false)]
57 public static Vector128<sbyte> AsSByte<T>(this Vector128<T> vector) where T : struct
58 {
59 return vector.As<T, sbyte>();
60 }
61
62 [Intrinsic]
63 public static Vector128<float> AsSingle<T>(this Vector128<T> vector) where T : struct
64 {
65 return vector.As<T, float>();
66 }
67
68 [Intrinsic]
69 [CLSCompliant(false)]
70 public static Vector128<ushort> AsUInt16<T>(this Vector128<T> vector) where T : struct
71 {
72 return vector.As<T, ushort>();
73 }
74
75 [Intrinsic]
76 [CLSCompliant(false)]
77 public static Vector128<uint> AsUInt32<T>(this Vector128<T> vector) where T : struct
78 {
79 return vector.As<T, uint>();
80 }
81
82 [Intrinsic]
83 [CLSCompliant(false)]
84 public static Vector128<ulong> AsUInt64<T>(this Vector128<T> vector) where T : struct
85 {
86 return vector.As<T, ulong>();
87 }
88
90 {
91 return new Vector4(value, 0f, 0f).AsVector128();
92 }
93
95 {
96 return new Vector4(value, 0f).AsVector128();
97 }
98
99 [Intrinsic]
101 {
102 return Unsafe.As<Vector4, Vector128<float>>(ref value);
103 }
104
105 [Intrinsic]
106 public static Vector128<T> AsVector128<T>(this Vector<T> value) where T : struct
107 {
108 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
109 return Unsafe.As<Vector<T>, Vector128<T>>(ref value);
110 }
111
113 {
114 return Unsafe.As<Vector128<float>, Vector2>(ref value);
115 }
116
118 {
119 return Unsafe.As<Vector128<float>, Vector3>(ref value);
120 }
121
122 [Intrinsic]
124 {
125 return Unsafe.As<Vector128<float>, Vector4>(ref value);
126 }
127
128 [Intrinsic]
129 public static Vector<T> AsVector<T>(this Vector128<T> value) where T : struct
130 {
131 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
132 Vector<T> source = default(Vector<T>);
133 Unsafe.WriteUnaligned(ref Unsafe.As<Vector<T>, byte>(ref source), value);
134 return source;
135 }
136
137 [Intrinsic]
138 public static Vector128<byte> Create(byte value)
139 {
141 {
142 return Create(value);
143 }
144 return SoftwareFallback(value);
145 unsafe static Vector128<byte> SoftwareFallback(byte value)
146 {
147 byte* source = stackalloc byte[16]
148 {
151 };
152 return Unsafe.AsRef<Vector128<byte>>(source);
153 }
154 }
155
156 [Intrinsic]
157 public static Vector128<double> Create(double value)
158 {
160 {
161 return Create(value);
162 }
163 return SoftwareFallback(value);
164 unsafe static Vector128<double> SoftwareFallback(double value)
165 {
166 double* source = stackalloc double[2] { value, value };
167 return Unsafe.AsRef<Vector128<double>>(source);
168 }
169 }
170
171 [Intrinsic]
172 public static Vector128<short> Create(short value)
173 {
175 {
176 return Create(value);
177 }
178 return SoftwareFallback(value);
179 unsafe static Vector128<short> SoftwareFallback(short value)
180 {
181 short* source = stackalloc short[8] { value, value, value, value, value, value, value, value };
182 return Unsafe.AsRef<Vector128<short>>(source);
183 }
184 }
185
186 [Intrinsic]
187 public static Vector128<int> Create(int value)
188 {
190 {
191 return Create(value);
192 }
193 return SoftwareFallback(value);
194 unsafe static Vector128<int> SoftwareFallback(int value)
195 {
196 int* source = stackalloc int[4] { value, value, value, value };
197 return Unsafe.AsRef<Vector128<int>>(source);
198 }
199 }
200
201 [Intrinsic]
202 public static Vector128<long> Create(long value)
203 {
205 {
206 return Create(value);
207 }
208 return SoftwareFallback(value);
209 unsafe static Vector128<long> SoftwareFallback(long value)
210 {
211 long* source = stackalloc long[2] { value, value };
212 return Unsafe.AsRef<Vector128<long>>(source);
213 }
214 }
215
216 [Intrinsic]
217 [CLSCompliant(false)]
218 public static Vector128<sbyte> Create(sbyte value)
219 {
221 {
222 return Create(value);
223 }
224 return SoftwareFallback(value);
225 unsafe static Vector128<sbyte> SoftwareFallback(sbyte value)
226 {
227 sbyte* source = stackalloc sbyte[16]
228 {
231 };
232 return Unsafe.AsRef<Vector128<sbyte>>(source);
233 }
234 }
235
236 [Intrinsic]
237 public static Vector128<float> Create(float value)
238 {
240 {
241 return Create(value);
242 }
243 return SoftwareFallback(value);
244 unsafe static Vector128<float> SoftwareFallback(float value)
245 {
246 float* source = stackalloc float[4] { value, value, value, value };
247 return Unsafe.AsRef<Vector128<float>>(source);
248 }
249 }
250
251 [Intrinsic]
252 [CLSCompliant(false)]
253 public static Vector128<ushort> Create(ushort value)
254 {
256 {
257 return Create(value);
258 }
259 return SoftwareFallback(value);
260 unsafe static Vector128<ushort> SoftwareFallback(ushort value)
261 {
262 ushort* source = stackalloc ushort[8] { value, value, value, value, value, value, value, value };
263 return Unsafe.AsRef<Vector128<ushort>>(source);
264 }
265 }
266
267 [Intrinsic]
268 [CLSCompliant(false)]
269 public static Vector128<uint> Create(uint value)
270 {
272 {
273 return Create(value);
274 }
275 return SoftwareFallback(value);
276 unsafe static Vector128<uint> SoftwareFallback(uint value)
277 {
278 uint* source = stackalloc uint[4] { value, value, value, value };
279 return Unsafe.AsRef<Vector128<uint>>(source);
280 }
281 }
282
283 [Intrinsic]
284 [CLSCompliant(false)]
285 public static Vector128<ulong> Create(ulong value)
286 {
288 {
289 return Create(value);
290 }
291 return SoftwareFallback(value);
292 unsafe static Vector128<ulong> SoftwareFallback(ulong value)
293 {
294 ulong* source = stackalloc ulong[2] { value, value };
295 return Unsafe.AsRef<Vector128<ulong>>(source);
296 }
297 }
298
299 [Intrinsic]
300 public static Vector128<byte> Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15)
301 {
303 {
304 return Create(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
305 }
306 return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
307 unsafe static Vector128<byte> SoftwareFallback(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15)
308 {
309 byte* source = stackalloc byte[16]
310 {
311 e0, e1, e2, e3, e4, e5, e6, e7, e8, e9,
312 e10, e11, e12, e13, e14, e15
313 };
314 return Unsafe.AsRef<Vector128<byte>>(source);
315 }
316 }
317
318 [Intrinsic]
319 public static Vector128<double> Create(double e0, double e1)
320 {
322 {
323 return Create(e0, e1);
324 }
325 return SoftwareFallback(e0, e1);
326 unsafe static Vector128<double> SoftwareFallback(double e0, double e1)
327 {
328 double* source = stackalloc double[2] { e0, e1 };
329 return Unsafe.AsRef<Vector128<double>>(source);
330 }
331 }
332
333 [Intrinsic]
334 public static Vector128<short> Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7)
335 {
337 {
338 return Create(e0, e1, e2, e3, e4, e5, e6, e7);
339 }
340 return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
341 unsafe static Vector128<short> SoftwareFallback(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7)
342 {
343 short* source = stackalloc short[8] { e0, e1, e2, e3, e4, e5, e6, e7 };
344 return Unsafe.AsRef<Vector128<short>>(source);
345 }
346 }
347
348 [Intrinsic]
349 public static Vector128<int> Create(int e0, int e1, int e2, int e3)
350 {
352 {
353 return Create(e0, e1, e2, e3);
354 }
355 return SoftwareFallback(e0, e1, e2, e3);
356 unsafe static Vector128<int> SoftwareFallback(int e0, int e1, int e2, int e3)
357 {
358 int* source = stackalloc int[4] { e0, e1, e2, e3 };
359 return Unsafe.AsRef<Vector128<int>>(source);
360 }
361 }
362
363 [Intrinsic]
364 public static Vector128<long> Create(long e0, long e1)
365 {
367 {
368 return Create(e0, e1);
369 }
370 return SoftwareFallback(e0, e1);
371 unsafe static Vector128<long> SoftwareFallback(long e0, long e1)
372 {
373 long* source = stackalloc long[2] { e0, e1 };
374 return Unsafe.AsRef<Vector128<long>>(source);
375 }
376 }
377
378 [Intrinsic]
379 [CLSCompliant(false)]
380 public static Vector128<sbyte> Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15)
381 {
383 {
384 return Create(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
385 }
386 return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
387 unsafe static Vector128<sbyte> SoftwareFallback(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15)
388 {
389 sbyte* source = stackalloc sbyte[16]
390 {
391 e0, e1, e2, e3, e4, e5, e6, e7, e8, e9,
392 e10, e11, e12, e13, e14, e15
393 };
394 return Unsafe.AsRef<Vector128<sbyte>>(source);
395 }
396 }
397
398 [Intrinsic]
399 public static Vector128<float> Create(float e0, float e1, float e2, float e3)
400 {
402 {
403 return Create(e0, e1, e2, e3);
404 }
405 return SoftwareFallback(e0, e1, e2, e3);
406 unsafe static Vector128<float> SoftwareFallback(float e0, float e1, float e2, float e3)
407 {
408 float* source = stackalloc float[4] { e0, e1, e2, e3 };
409 return Unsafe.AsRef<Vector128<float>>(source);
410 }
411 }
412
413 [Intrinsic]
414 [CLSCompliant(false)]
415 public static Vector128<ushort> Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7)
416 {
418 {
419 return Create(e0, e1, e2, e3, e4, e5, e6, e7);
420 }
421 return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
422 unsafe static Vector128<ushort> SoftwareFallback(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7)
423 {
424 ushort* source = stackalloc ushort[8] { e0, e1, e2, e3, e4, e5, e6, e7 };
425 return Unsafe.AsRef<Vector128<ushort>>(source);
426 }
427 }
428
429 [Intrinsic]
430 [CLSCompliant(false)]
431 public static Vector128<uint> Create(uint e0, uint e1, uint e2, uint e3)
432 {
434 {
435 return Create(e0, e1, e2, e3);
436 }
437 return SoftwareFallback(e0, e1, e2, e3);
438 unsafe static Vector128<uint> SoftwareFallback(uint e0, uint e1, uint e2, uint e3)
439 {
440 uint* source = stackalloc uint[4] { e0, e1, e2, e3 };
441 return Unsafe.AsRef<Vector128<uint>>(source);
442 }
443 }
444
445 [Intrinsic]
446 [CLSCompliant(false)]
447 public static Vector128<ulong> Create(ulong e0, ulong e1)
448 {
450 {
451 return Create(e0, e1);
452 }
453 return SoftwareFallback(e0, e1);
454 unsafe static Vector128<ulong> SoftwareFallback(ulong e0, ulong e1)
455 {
456 ulong* source = stackalloc ulong[2] { e0, e1 };
457 return Unsafe.AsRef<Vector128<ulong>>(source);
458 }
459 }
460
461 [MethodImpl(MethodImplOptions.AggressiveInlining)]
463 {
465 {
466 }
467 return SoftwareFallback(lower, upper);
468 static Vector128<byte> SoftwareFallback(Vector64<byte> lower, Vector64<byte> upper)
469 {
471 ref Vector64<byte> reference = ref Unsafe.As<Vector128<byte>, Vector64<byte>>(ref source);
472 reference = lower;
473 Unsafe.Add(ref reference, 1) = upper;
474 return source;
475 }
476 }
477
478 [MethodImpl(MethodImplOptions.AggressiveInlining)]
480 {
482 {
483 }
484 return SoftwareFallback(lower, upper);
485 static Vector128<double> SoftwareFallback(Vector64<double> lower, Vector64<double> upper)
486 {
489 reference = lower;
490 Unsafe.Add(ref reference, 1) = upper;
491 return source;
492 }
493 }
494
495 [MethodImpl(MethodImplOptions.AggressiveInlining)]
497 {
499 {
500 }
501 return SoftwareFallback(lower, upper);
502 static Vector128<short> SoftwareFallback(Vector64<short> lower, Vector64<short> upper)
503 {
505 ref Vector64<short> reference = ref Unsafe.As<Vector128<short>, Vector64<short>>(ref source);
506 reference = lower;
507 Unsafe.Add(ref reference, 1) = upper;
508 return source;
509 }
510 }
511
512 [MethodImpl(MethodImplOptions.AggressiveInlining)]
514 {
516 {
517 }
518 return SoftwareFallback(lower, upper);
519 static Vector128<int> SoftwareFallback(Vector64<int> lower, Vector64<int> upper)
520 {
522 ref Vector64<int> reference = ref Unsafe.As<Vector128<int>, Vector64<int>>(ref source);
523 reference = lower;
524 Unsafe.Add(ref reference, 1) = upper;
525 return source;
526 }
527 }
528
529 [MethodImpl(MethodImplOptions.AggressiveInlining)]
531 {
533 {
534 }
535 return SoftwareFallback(lower, upper);
536 static Vector128<long> SoftwareFallback(Vector64<long> lower, Vector64<long> upper)
537 {
539 ref Vector64<long> reference = ref Unsafe.As<Vector128<long>, Vector64<long>>(ref source);
540 reference = lower;
541 Unsafe.Add(ref reference, 1) = upper;
542 return source;
543 }
544 }
545
546 [MethodImpl(MethodImplOptions.AggressiveInlining)]
547 [CLSCompliant(false)]
549 {
551 {
552 }
553 return SoftwareFallback(lower, upper);
554 static Vector128<sbyte> SoftwareFallback(Vector64<sbyte> lower, Vector64<sbyte> upper)
555 {
557 ref Vector64<sbyte> reference = ref Unsafe.As<Vector128<sbyte>, Vector64<sbyte>>(ref source);
558 reference = lower;
559 Unsafe.Add(ref reference, 1) = upper;
560 return source;
561 }
562 }
563
564 [MethodImpl(MethodImplOptions.AggressiveInlining)]
566 {
568 {
569 }
570 return SoftwareFallback(lower, upper);
571 static Vector128<float> SoftwareFallback(Vector64<float> lower, Vector64<float> upper)
572 {
574 ref Vector64<float> reference = ref Unsafe.As<Vector128<float>, Vector64<float>>(ref source);
575 reference = lower;
576 Unsafe.Add(ref reference, 1) = upper;
577 return source;
578 }
579 }
580
581 [MethodImpl(MethodImplOptions.AggressiveInlining)]
582 [CLSCompliant(false)]
584 {
586 {
587 }
588 return SoftwareFallback(lower, upper);
589 static Vector128<ushort> SoftwareFallback(Vector64<ushort> lower, Vector64<ushort> upper)
590 {
593 reference = lower;
594 Unsafe.Add(ref reference, 1) = upper;
595 return source;
596 }
597 }
598
599 [MethodImpl(MethodImplOptions.AggressiveInlining)]
600 [CLSCompliant(false)]
602 {
604 {
605 }
606 return SoftwareFallback(lower, upper);
607 static Vector128<uint> SoftwareFallback(Vector64<uint> lower, Vector64<uint> upper)
608 {
610 ref Vector64<uint> reference = ref Unsafe.As<Vector128<uint>, Vector64<uint>>(ref source);
611 reference = lower;
612 Unsafe.Add(ref reference, 1) = upper;
613 return source;
614 }
615 }
616
617 [MethodImpl(MethodImplOptions.AggressiveInlining)]
618 [CLSCompliant(false)]
620 {
622 {
623 }
624 return SoftwareFallback(lower, upper);
625 static Vector128<ulong> SoftwareFallback(Vector64<ulong> lower, Vector64<ulong> upper)
626 {
628 ref Vector64<ulong> reference = ref Unsafe.As<Vector128<ulong>, Vector64<ulong>>(ref source);
629 reference = lower;
630 Unsafe.Add(ref reference, 1) = upper;
631 return source;
632 }
633 }
634
635 [MethodImpl(MethodImplOptions.AggressiveInlining)]
637 {
639 {
640 }
641 if (Sse2.IsSupported)
642 {
644 }
645 return SoftwareFallback(value);
646 static Vector128<byte> SoftwareFallback(byte value)
647 {
649 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<byte>, byte>(ref source), value);
650 return source;
651 }
652 }
653
654 [MethodImpl(MethodImplOptions.AggressiveInlining)]
656 {
658 {
659 }
660 if (Sse2.IsSupported)
661 {
663 }
664 return SoftwareFallback(value);
665 static Vector128<double> SoftwareFallback(double value)
666 {
668 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<double>, byte>(ref source), value);
669 return source;
670 }
671 }
672
673 [MethodImpl(MethodImplOptions.AggressiveInlining)]
675 {
677 {
678 }
679 if (Sse2.IsSupported)
680 {
681 return Sse2.ConvertScalarToVector128UInt32((ushort)value).AsInt16();
682 }
683 return SoftwareFallback(value);
684 static Vector128<short> SoftwareFallback(short value)
685 {
687 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<short>, byte>(ref source), value);
688 return source;
689 }
690 }
691
692 [MethodImpl(MethodImplOptions.AggressiveInlining)]
694 {
696 {
697 }
698 if (Sse2.IsSupported)
699 {
701 }
702 return SoftwareFallback(value);
703 static Vector128<int> SoftwareFallback(int value)
704 {
706 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<int>, byte>(ref source), value);
707 return source;
708 }
709 }
710
712 {
714 {
715 }
716 if (Sse2.X64.IsSupported)
717 {
719 }
720 return SoftwareFallback(value);
721 static Vector128<long> SoftwareFallback(long value)
722 {
724 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<long>, byte>(ref source), value);
725 return source;
726 }
727 }
728
729 [MethodImpl(MethodImplOptions.AggressiveInlining)]
730 [CLSCompliant(false)]
732 {
734 {
735 }
736 if (Sse2.IsSupported)
737 {
738 return Sse2.ConvertScalarToVector128UInt32((byte)value).AsSByte();
739 }
740 return SoftwareFallback(value);
741 static Vector128<sbyte> SoftwareFallback(sbyte value)
742 {
744 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<sbyte>, byte>(ref source), value);
745 return source;
746 }
747 }
748
749 [MethodImpl(MethodImplOptions.AggressiveInlining)]
751 {
753 {
754 }
755 if (Sse.IsSupported)
756 {
758 }
759 return SoftwareFallback(value);
760 static Vector128<float> SoftwareFallback(float value)
761 {
763 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<float>, byte>(ref source), value);
764 return source;
765 }
766 }
767
768 [MethodImpl(MethodImplOptions.AggressiveInlining)]
769 [CLSCompliant(false)]
771 {
773 {
774 }
775 if (Sse2.IsSupported)
776 {
777 return Sse2.ConvertScalarToVector128UInt32(value).AsUInt16();
778 }
779 return SoftwareFallback(value);
780 static Vector128<ushort> SoftwareFallback(ushort value)
781 {
783 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<ushort>, byte>(ref source), value);
784 return source;
785 }
786 }
787
788 [MethodImpl(MethodImplOptions.AggressiveInlining)]
789 [CLSCompliant(false)]
791 {
793 {
794 }
795 if (Sse2.IsSupported)
796 {
798 }
799 return SoftwareFallback(value);
800 static Vector128<uint> SoftwareFallback(uint value)
801 {
803 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<uint>, byte>(ref source), value);
804 return source;
805 }
806 }
807
808 [MethodImpl(MethodImplOptions.AggressiveInlining)]
809 [CLSCompliant(false)]
811 {
813 {
814 }
815 if (Sse2.X64.IsSupported)
816 {
818 }
819 return SoftwareFallback(value);
820 static Vector128<ulong> SoftwareFallback(ulong value)
821 {
823 Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<ulong>, byte>(ref source), value);
824 return source;
825 }
826 }
827
828 [Intrinsic]
829 public unsafe static Vector128<byte> CreateScalarUnsafe(byte value)
830 {
831 byte* ptr = stackalloc byte[16];
832 *ptr = value;
833 return Unsafe.AsRef<Vector128<byte>>(ptr);
834 }
835
836 [Intrinsic]
837 public unsafe static Vector128<double> CreateScalarUnsafe(double value)
838 {
839 double* ptr = stackalloc double[2];
840 *ptr = value;
841 return Unsafe.AsRef<Vector128<double>>(ptr);
842 }
843
844 [Intrinsic]
845 public unsafe static Vector128<short> CreateScalarUnsafe(short value)
846 {
847 short* ptr = stackalloc short[8];
848 *ptr = value;
849 return Unsafe.AsRef<Vector128<short>>(ptr);
850 }
851
852 [Intrinsic]
853 public unsafe static Vector128<int> CreateScalarUnsafe(int value)
854 {
855 int* ptr = stackalloc int[4];
856 *ptr = value;
857 return Unsafe.AsRef<Vector128<int>>(ptr);
858 }
859
860 [Intrinsic]
861 public unsafe static Vector128<long> CreateScalarUnsafe(long value)
862 {
863 long* ptr = stackalloc long[2];
864 *ptr = value;
865 return Unsafe.AsRef<Vector128<long>>(ptr);
866 }
867
868 [Intrinsic]
869 [CLSCompliant(false)]
870 public unsafe static Vector128<sbyte> CreateScalarUnsafe(sbyte value)
871 {
872 sbyte* ptr = stackalloc sbyte[16];
873 *ptr = value;
874 return Unsafe.AsRef<Vector128<sbyte>>(ptr);
875 }
876
877 [Intrinsic]
878 public unsafe static Vector128<float> CreateScalarUnsafe(float value)
879 {
880 float* ptr = stackalloc float[4];
881 *ptr = value;
882 return Unsafe.AsRef<Vector128<float>>(ptr);
883 }
884
885 [Intrinsic]
886 [CLSCompliant(false)]
887 public unsafe static Vector128<ushort> CreateScalarUnsafe(ushort value)
888 {
889 ushort* ptr = stackalloc ushort[8];
890 *ptr = value;
891 return Unsafe.AsRef<Vector128<ushort>>(ptr);
892 }
893
894 [Intrinsic]
895 [CLSCompliant(false)]
896 public unsafe static Vector128<uint> CreateScalarUnsafe(uint value)
897 {
898 uint* ptr = stackalloc uint[4];
899 *ptr = value;
900 return Unsafe.AsRef<Vector128<uint>>(ptr);
901 }
902
903 [Intrinsic]
904 [CLSCompliant(false)]
905 public unsafe static Vector128<ulong> CreateScalarUnsafe(ulong value)
906 {
907 ulong* ptr = stackalloc ulong[2];
908 *ptr = value;
909 return Unsafe.AsRef<Vector128<ulong>>(ptr);
910 }
911
912 [Intrinsic]
913 public static T GetElement<T>(this Vector128<T> vector, int index) where T : struct
914 {
915 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
916 if ((uint)index >= (uint)Vector128<T>.Count)
917 {
919 }
920 return Unsafe.Add(ref Unsafe.As<Vector128<T>, T>(ref vector), index);
921 }
922
923 [Intrinsic]
924 public static Vector128<T> WithElement<T>(this Vector128<T> vector, int index, T value) where T : struct
925 {
926 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
927 if ((uint)index >= (uint)Vector128<T>.Count)
928 {
930 }
931 Vector128<T> source = vector;
932 Unsafe.Add(ref Unsafe.As<Vector128<T>, T>(ref source), index) = value;
933 return source;
934 }
935
936 [Intrinsic]
937 public static Vector64<T> GetLower<T>(this Vector128<T> vector) where T : struct
938 {
939 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
940 return Unsafe.As<Vector128<T>, Vector64<T>>(ref vector);
941 }
942
943 [MethodImpl(MethodImplOptions.AggressiveInlining)]
944 public static Vector128<T> WithLower<T>(this Vector128<T> vector, Vector64<T> value) where T : struct
945 {
947 {
948 }
949 return SoftwareFallback(vector, value);
950 static Vector128<T> SoftwareFallback(Vector128<T> vector, Vector64<T> value)
951 {
952 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
953 Vector128<T> source = vector;
955 return source;
956 }
957 }
958
959 [Intrinsic]
960 public static Vector64<T> GetUpper<T>(this Vector128<T> vector) where T : struct
961 {
962 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
963 return Unsafe.Add(ref Unsafe.As<Vector128<T>, Vector64<T>>(ref vector), 1);
964 }
965
966 [MethodImpl(MethodImplOptions.AggressiveInlining)]
967 public static Vector128<T> WithUpper<T>(this Vector128<T> vector, Vector64<T> value) where T : struct
968 {
970 {
971 }
972 return SoftwareFallback(vector, value);
973 static Vector128<T> SoftwareFallback(Vector128<T> vector, Vector64<T> value)
974 {
975 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
976 Vector128<T> source = vector;
977 Unsafe.Add(ref Unsafe.As<Vector128<T>, Vector64<T>>(ref source), 1) = value;
978 return source;
979 }
980 }
981
982 [Intrinsic]
983 public static T ToScalar<T>(this Vector128<T> vector) where T : struct
984 {
985 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
986 return Unsafe.As<Vector128<T>, T>(ref vector);
987 }
988
989 [Intrinsic]
990 public static Vector256<T> ToVector256<T>(this Vector128<T> vector) where T : struct
991 {
992 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
994 Unsafe.As<Vector256<T>, Vector128<T>>(ref source) = vector;
995 return source;
996 }
997
998 [Intrinsic]
999 public unsafe static Vector256<T> ToVector256Unsafe<T>(this Vector128<T> vector) where T : struct
1000 {
1001 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1002 byte* source = stackalloc byte[32];
1003 Unsafe.AsRef<Vector128<T>>(source) = vector;
1004 return Unsafe.AsRef<Vector256<T>>(source);
1005 }
1006}
1007[StructLayout(LayoutKind.Sequential, Size = 16)]
1008[Intrinsic]
1009[DebuggerDisplay("{DisplayString,nq}")]
1010[DebuggerTypeProxy(typeof(Vector128DebugView<>))]
1011public readonly struct Vector128<T> : IEquatable<Vector128<T>> where T : struct
1012{
1013 private readonly ulong _00;
1014
1015 private readonly ulong _01;
1016
1017 public static int Count
1018 {
1019 [Intrinsic]
1020 get
1021 {
1022 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1023 return 16 / Unsafe.SizeOf<T>();
1024 }
1025 }
1026
1027 public static Vector128<T> Zero
1028 {
1029 [Intrinsic]
1030 get
1031 {
1032 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1033 return default(Vector128<T>);
1034 }
1035 }
1036
1038 {
1039 [Intrinsic]
1040 get
1041 {
1042 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1043 return Vector128.Create(uint.MaxValue).As<uint, T>();
1044 }
1045 }
1046
1047 internal string DisplayString
1048 {
1049 get
1050 {
1051 if (IsSupported)
1052 {
1053 return ToString();
1054 }
1055 return SR.NotSupported_Type;
1056 }
1057 }
1058
1059 internal static bool IsSupported
1060 {
1061 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1062 get
1063 {
1064 if (!(typeof(T) == typeof(byte)) && !(typeof(T) == typeof(sbyte)) && !(typeof(T) == typeof(short)) && !(typeof(T) == typeof(ushort)) && !(typeof(T) == typeof(int)) && !(typeof(T) == typeof(uint)) && !(typeof(T) == typeof(long)) && !(typeof(T) == typeof(ulong)) && !(typeof(T) == typeof(float)))
1065 {
1066 return typeof(T) == typeof(double);
1067 }
1068 return true;
1069 }
1070 }
1071
1072 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1074 {
1075 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1076 if (Sse.IsSupported && typeof(T) == typeof(float))
1077 {
1078 Vector128<float> value = Sse.CompareEqual(this.AsSingle(), other.AsSingle());
1079 return Sse.MoveMask(value) == 15;
1080 }
1081 if (Sse2.IsSupported)
1082 {
1083 if (typeof(T) == typeof(double))
1084 {
1085 Vector128<double> value2 = Sse2.CompareEqual(this.AsDouble(), other.AsDouble());
1086 return Sse2.MoveMask(value2) == 3;
1087 }
1088 Vector128<byte> value3 = Sse2.CompareEqual(this.AsByte(), other.AsByte());
1089 return Sse2.MoveMask(value3) == 65535;
1090 }
1091 return SoftwareFallback(in this, other);
1092 static bool SoftwareFallback(in Vector128<T> vector, Vector128<T> other)
1093 {
1094 for (int i = 0; i < Count; i++)
1095 {
1096 if (!((IEquatable<T>)(object)vector.GetElement(i)).Equals(other.GetElement(i)))
1097 {
1098 return false;
1099 }
1100 }
1101 return true;
1102 }
1103 }
1104
1105 public override bool Equals([NotNullWhen(true)] object? obj)
1106 {
1107 if (obj is Vector128<T>)
1108 {
1109 return Equals((Vector128<T>)obj);
1110 }
1111 return false;
1112 }
1113
1114 public override int GetHashCode()
1115 {
1116 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1117 HashCode hashCode = default(HashCode);
1118 for (int i = 0; i < Count; i++)
1119 {
1120 hashCode.Add(this.GetElement(i).GetHashCode());
1121 }
1122 return hashCode.ToHashCode();
1123 }
1124
1125 public override string ToString()
1126 {
1127 ThrowHelper.ThrowForUnsupportedIntrinsicsVectorBaseType<T>();
1128 int num = Count - 1;
1129 Span<char> initialBuffer = stackalloc char[64];
1130 ValueStringBuilder valueStringBuilder = new ValueStringBuilder(initialBuffer);
1131 CultureInfo invariantCulture = CultureInfo.InvariantCulture;
1132 valueStringBuilder.Append('<');
1133 for (int i = 0; i < num; i++)
1134 {
1135 valueStringBuilder.Append(((IFormattable)(object)this.GetElement(i)).ToString("G", invariantCulture));
1136 valueStringBuilder.Append(',');
1137 valueStringBuilder.Append(' ');
1138 }
1139 valueStringBuilder.Append(((IFormattable)(object)this.GetElement(num)).ToString("G", invariantCulture));
1140 valueStringBuilder.Append('>');
1141 return valueStringBuilder.ToString();
1142 }
1143}
static CultureInfo InvariantCulture
static Vector128< long > AsInt64< T >(this Vector128< T > vector)
Definition Vector128.cs:50
static Vector128< long > Create(long e0, long e1)
Definition Vector128.cs:364
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static Vector128< uint > AsUInt32< T >(this Vector128< T > vector)
Definition Vector128.cs:77
static unsafe Vector128< long > CreateScalarUnsafe(long value)
Definition Vector128.cs:861
static Vector128< double > CreateScalar(double value)
Definition Vector128.cs:655
static Vector128< float > AsVector128(this Vector4 value)
Definition Vector128.cs:100
static unsafe Vector128< ushort > CreateScalarUnsafe(ushort value)
Definition Vector128.cs:887
static Vector128< long > Create(long value)
Definition Vector128.cs:202
static Vector128< int > AsInt32< T >(this Vector128< T > vector)
Definition Vector128.cs:44
static Vector128< ulong > Create(ulong e0, ulong e1)
Definition Vector128.cs:447
static Vector128< T > WithElement< T >(this Vector128< T > vector, int index, T value)
Definition Vector128.cs:924
static Vector128< byte > CreateScalar(byte value)
Definition Vector128.cs:636
static Vector64< T > GetUpper< T >(this Vector128< T > vector)
Definition Vector128.cs:960
static Vector128< T > WithLower< T >(this Vector128< T > vector, Vector64< T > value)
Definition Vector128.cs:944
static Vector2 AsVector2(this Vector128< float > value)
Definition Vector128.cs:112
static Vector128< T > AllBitsSet
static Vector128< ulong > AsUInt64< T >(this Vector128< T > vector)
Definition Vector128.cs:84
static Vector< T > AsVector< T >(this Vector128< T > value)
Definition Vector128.cs:129
static Vector128< float > AsSingle< T >(this Vector128< T > vector)
Definition Vector128.cs:63
static unsafe Vector128< float > CreateScalarUnsafe(float value)
Definition Vector128.cs:878
static Vector128< double > Create(double e0, double e1)
Definition Vector128.cs:319
static Vector128< ulong > Create(ulong value)
Definition Vector128.cs:285
static unsafe Vector128< uint > CreateScalarUnsafe(uint value)
Definition Vector128.cs:896
static Vector4 AsVector4(this Vector128< float > value)
Definition Vector128.cs:123
static Vector128< float > AsVector128(this Vector3 value)
Definition Vector128.cs:94
bool Equals(Vector128< T > other)
static Vector128< byte > Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15)
Definition Vector128.cs:300
static Vector128< int > CreateScalar(int value)
Definition Vector128.cs:693
static Vector128< float > Create(float e0, float e1, float e2, float e3)
Definition Vector128.cs:399
static Vector128< short > CreateScalar(short value)
Definition Vector128.cs:674
static Vector128< byte > AsByte< T >(this Vector128< T > vector)
Definition Vector128.cs:26
static Vector128< double > Create(Vector64< double > lower, Vector64< double > upper)
Definition Vector128.cs:479
static T ToScalar< T >(this Vector128< T > vector)
Definition Vector128.cs:983
static Vector128< sbyte > AsSByte< T >(this Vector128< T > vector)
Definition Vector128.cs:57
static Vector128< T > AsVector128< T >(this Vector< T > value)
Definition Vector128.cs:106
static unsafe Vector128< sbyte > CreateScalarUnsafe(sbyte value)
Definition Vector128.cs:870
static Vector128< float > Create(Vector64< float > lower, Vector64< float > upper)
Definition Vector128.cs:565
static Vector128< float > CreateScalar(float value)
Definition Vector128.cs:750
static unsafe Vector128< byte > CreateScalarUnsafe(byte value)
Definition Vector128.cs:829
static Vector128< sbyte > Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15)
Definition Vector128.cs:380
static Vector128< short > Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7)
Definition Vector128.cs:334
static Vector256< T > ToVector256< T >(this Vector128< T > vector)
Definition Vector128.cs:990
static Vector128< short > AsInt16< T >(this Vector128< T > vector)
Definition Vector128.cs:38
static Vector128< ushort > AsUInt16< T >(this Vector128< T > vector)
Definition Vector128.cs:70
static Vector128< long > Create(Vector64< long > lower, Vector64< long > upper)
Definition Vector128.cs:530
static Vector128< T > WithUpper< T >(this Vector128< T > vector, Vector64< T > value)
Definition Vector128.cs:967
static Vector128< uint > Create(uint value)
Definition Vector128.cs:269
static Vector64< T > GetLower< T >(this Vector128< T > vector)
Definition Vector128.cs:937
static Vector128< U > As< T, U >(this Vector128< T > vector)
Definition Vector128.cs:18
static unsafe Vector128< short > CreateScalarUnsafe(short value)
Definition Vector128.cs:845
static Vector128< short > Create(short value)
Definition Vector128.cs:172
static Vector128< ushort > Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7)
Definition Vector128.cs:415
static Vector128< short > Create(Vector64< short > lower, Vector64< short > upper)
Definition Vector128.cs:496
static Vector128< double > AsDouble< T >(this Vector128< T > vector)
Definition Vector128.cs:32
static unsafe Vector128< int > CreateScalarUnsafe(int value)
Definition Vector128.cs:853
static Vector128< int > Create(Vector64< int > lower, Vector64< int > upper)
Definition Vector128.cs:513
static Vector128< sbyte > Create(Vector64< sbyte > lower, Vector64< sbyte > upper)
Definition Vector128.cs:548
static Vector128< ushort > Create(ushort value)
Definition Vector128.cs:253
static Vector128< int > Create(int value)
Definition Vector128.cs:187
static Vector128< uint > Create(Vector64< uint > lower, Vector64< uint > upper)
Definition Vector128.cs:601
static Vector128< sbyte > CreateScalar(sbyte value)
Definition Vector128.cs:731
static Vector128< float > Create(float value)
Definition Vector128.cs:237
static Vector128< uint > Create(uint e0, uint e1, uint e2, uint e3)
Definition Vector128.cs:431
override bool Equals([NotNullWhen(true)] object? obj)
static unsafe Vector128< ulong > CreateScalarUnsafe(ulong value)
Definition Vector128.cs:905
static Vector128< ushort > CreateScalar(ushort value)
Definition Vector128.cs:770
static Vector128< byte > Create(Vector64< byte > lower, Vector64< byte > upper)
Definition Vector128.cs:462
static T GetElement< T >(this Vector128< T > vector, int index)
Definition Vector128.cs:913
static Vector128< int > Create(int e0, int e1, int e2, int e3)
Definition Vector128.cs:349
static Vector3 AsVector3(this Vector128< float > value)
Definition Vector128.cs:117
static Vector128< ulong > CreateScalar(ulong value)
Definition Vector128.cs:810
static unsafe Vector128< double > CreateScalarUnsafe(double value)
Definition Vector128.cs:837
static Vector128< sbyte > Create(sbyte value)
Definition Vector128.cs:218
static Vector128< float > AsVector128(this Vector2 value)
Definition Vector128.cs:89
static Vector128< uint > CreateScalar(uint value)
Definition Vector128.cs:790
static unsafe Vector256< T > ToVector256Unsafe< T >(this Vector128< T > vector)
Definition Vector128.cs:999
static Vector128< long > CreateScalar(long value)
Definition Vector128.cs:711
static Vector128< double > Create(double value)
Definition Vector128.cs:157
static Vector128< ulong > Create(Vector64< ulong > lower, Vector64< ulong > upper)
Definition Vector128.cs:619
static Vector128< ushort > Create(Vector64< ushort > lower, Vector64< ushort > upper)
Definition Vector128.cs:583
static Vector128< ulong > ConvertScalarToVector128UInt64(ulong value)
Definition Sse2.cs:39
static Vector128< long > ConvertScalarToVector128Int64(long value)
Definition Sse2.cs:34
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static Vector128< sbyte > CompareEqual(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:232
static Vector128< double > MoveScalar(Vector128< double > upper, Vector128< double > value)
Definition Sse2.cs:767
static Vector128< int > ConvertScalarToVector128Int32(int value)
Definition Sse2.cs:527
static new bool IsSupported
Definition Sse2.cs:60
static Vector128< uint > ConvertScalarToVector128UInt32(uint value)
Definition Sse2.cs:537
static Vector128< float > CompareEqual(Vector128< float > left, Vector128< float > right)
Definition Sse.cs:52
static int MoveMask(Vector128< float > value)
Definition Sse.cs:317
static new bool IsSupported
Definition Sse.cs:30
static Vector128< float > MoveScalar(Vector128< float > upper, Vector128< float > value)
Definition Sse.cs:302
static string NotSupported_Type
Definition SR.cs:1718
Definition SR.cs:7
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
void Add(int value)
Definition HashCode.cs:239