1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System
.Runtime
.CompilerServices
;
7 namespace System
.Numerics
10 /// Contains various methods useful for creating, manipulating, combining, and converting generic vectors with one another.
12 public static partial class Vector
14 // JIT is not looking at the Vector class methods
15 // all methods here should be inlined and they must be implemented in terms of Vector<T> intrinsics
16 #region Select Methods
18 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
20 /// <param name="condition">The integral mask vector used to drive selection.</param>
21 /// <param name="left">The first source vector.</param>
22 /// <param name="right">The second source vector.</param>
23 /// <returns>The new vector with elements selected based on the mask.</returns>
25 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
26 public static Vector
<float> ConditionalSelect(Vector
<int> condition
, Vector
<float> left
, Vector
<float> right
)
28 return (Vector
<float>)Vector
<float>.ConditionalSelect((Vector
<float>)condition
, left
, right
);
32 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
34 /// <param name="condition">The integral mask vector used to drive selection.</param>
35 /// <param name="left">The first source vector.</param>
36 /// <param name="right">The second source vector.</param>
37 /// <returns>The new vector with elements selected based on the mask.</returns>
39 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
40 public static Vector
<double> ConditionalSelect(Vector
<long> condition
, Vector
<double> left
, Vector
<double> right
)
42 return (Vector
<double>)Vector
<double>.ConditionalSelect((Vector
<double>)condition
, left
, right
);
46 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
48 /// <param name="condition">The mask vector used to drive selection.</param>
49 /// <param name="left">The first source vector.</param>
50 /// <param name="right">The second source vector.</param>
51 /// <returns>The new vector with elements selected based on the mask.</returns>
53 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
54 public static Vector
<T
> ConditionalSelect
<T
>(Vector
<T
> condition
, Vector
<T
> left
, Vector
<T
> right
) where T
: struct
56 return Vector
<T
>.ConditionalSelect(condition
, left
, right
);
58 #endregion Select Methods
60 #region Comparison methods
61 #region Equals methods
63 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
65 /// <param name="left">The first vector to compare.</param>
66 /// <param name="right">The second vector to compare.</param>
67 /// <returns>The resultant vector.</returns>
69 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
70 public static Vector
<T
> Equals
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
72 return Vector
<T
>.Equals(left
, right
);
76 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
78 /// <param name="left">The first vector to compare.</param>
79 /// <param name="right">The second vector to compare.</param>
80 /// <returns>The resultant vector.</returns>
82 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
83 public static Vector
<int> Equals(Vector
<float> left
, Vector
<float> right
)
85 return (Vector
<int>)Vector
<float>.Equals(left
, right
);
89 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
91 /// <param name="left">The first vector to compare.</param>
92 /// <param name="right">The second vector to compare.</param>
93 /// <returns>The resultant vector.</returns>
95 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
96 public static Vector
<int> Equals(Vector
<int> left
, Vector
<int> right
)
98 return Vector
<int>.Equals(left
, right
);
102 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
104 /// <param name="left">The first vector to compare.</param>
105 /// <param name="right">The second vector to compare.</param>
106 /// <returns>The resultant vector.</returns>
108 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
109 public static Vector
<long> Equals(Vector
<double> left
, Vector
<double> right
)
111 return (Vector
<long>)Vector
<double>.Equals(left
, right
);
115 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
117 /// <param name="left">The first vector to compare.</param>
118 /// <param name="right">The second vector to compare.</param>
119 /// <returns>The resultant vector.</returns>
121 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
122 public static Vector
<long> Equals(Vector
<long> left
, Vector
<long> right
)
124 return Vector
<long>.Equals(left
, right
);
128 /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
130 /// <param name="left">The first vector to compare.</param>
131 /// <param name="right">The first vector to compare.</param>
132 /// <returns>True if all elements are equal; False otherwise.</returns>
133 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
134 public static bool EqualsAll
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
136 return left
== right
;
140 /// Returns a boolean indicating whether any single pair of elements in the given vectors are equal.
142 /// <param name="left">The first vector to compare.</param>
143 /// <param name="right">The second vector to compare.</param>
144 /// <returns>True if any element pairs are equal; False if no element pairs are equal.</returns>
145 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
146 public static bool EqualsAny
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
148 return !Vector
<T
>.Equals(left
, right
).Equals(Vector
<T
>.Zero
);
150 #endregion Equals methods
152 #region Lessthan Methods
154 /// Returns a new vector whose elements signal whether the elements in left were less than their
155 /// corresponding elements in right.
157 /// <param name="left">The first vector to compare.</param>
158 /// <param name="right">The second vector to compare.</param>
159 /// <returns>The resultant vector.</returns>
161 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
162 public static Vector
<T
> LessThan
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
164 return Vector
<T
>.LessThan(left
, right
);
168 /// Returns an integral vector whose elements signal whether the elements in left were less than their
169 /// corresponding elements in right.
171 /// <param name="left">The first vector to compare.</param>
172 /// <param name="right">The second vector to compare.</param>
173 /// <returns>The resultant integral vector.</returns>
175 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
176 public static Vector
<int> LessThan(Vector
<float> left
, Vector
<float> right
)
178 return (Vector
<int>)Vector
<float>.LessThan(left
, right
);
182 /// Returns a new vector whose elements signal whether the elements in left were less than their
183 /// corresponding elements in right.
185 /// <param name="left">The first vector to compare.</param>
186 /// <param name="right">The second vector to compare.</param>
187 /// <returns>The resultant vector.</returns>
189 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
190 public static Vector
<int> LessThan(Vector
<int> left
, Vector
<int> right
)
192 return Vector
<int>.LessThan(left
, right
);
196 /// Returns an integral vector whose elements signal whether the elements in left were less than their
197 /// corresponding elements in right.
199 /// <param name="left">The first vector to compare.</param>
200 /// <param name="right">The second vector to compare.</param>
201 /// <returns>The resultant integral vector.</returns>
203 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
204 public static Vector
<long> LessThan(Vector
<double> left
, Vector
<double> right
)
206 return (Vector
<long>)Vector
<double>.LessThan(left
, right
);
210 /// Returns a new vector whose elements signal whether the elements in left were less than their
211 /// corresponding elements in right.
213 /// <param name="left">The first vector to compare.</param>
214 /// <param name="right">The second vector to compare.</param>
215 /// <returns>The resultant vector.</returns>
217 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
218 public static Vector
<long> LessThan(Vector
<long> left
, Vector
<long> right
)
220 return Vector
<long>.LessThan(left
, right
);
224 /// Returns a boolean indicating whether all of the elements in left are less than their corresponding elements in right.
226 /// <param name="left">The first vector to compare.</param>
227 /// <param name="right">The second vector to compare.</param>
228 /// <returns>True if all elements in left are less than their corresponding elements in right; False otherwise.</returns>
229 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
230 public static bool LessThanAll
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
232 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.LessThan(left
, right
);
233 return cond
.Equals(Vector
<int>.AllOnes
);
237 /// Returns a boolean indicating whether any element in left is less than its corresponding element in right.
239 /// <param name="left">The first vector to compare.</param>
240 /// <param name="right">The second vector to compare.</param>
241 /// <returns>True if any elements in left are less than their corresponding elements in right; False otherwise.</returns>
242 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
243 public static bool LessThanAny
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
245 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.LessThan(left
, right
);
246 return !cond
.Equals(Vector
<int>.Zero
);
248 #endregion LessthanMethods
250 #region Lessthanorequal methods
252 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
253 /// corresponding elements in right.
255 /// <param name="left">The first vector to compare.</param>
256 /// <param name="right">The second vector to compare.</param>
257 /// <returns>The resultant vector.</returns>
259 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
260 public static Vector
<T
> LessThanOrEqual
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
262 return Vector
<T
>.LessThanOrEqual(left
, right
);
266 /// Returns an integral vector whose elements signal whether the elements in left were less than or equal to their
267 /// corresponding elements in right.
269 /// <param name="left">The first vector to compare.</param>
270 /// <param name="right">The second vector to compare.</param>
271 /// <returns>The resultant integral vector.</returns>
273 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
274 public static Vector
<int> LessThanOrEqual(Vector
<float> left
, Vector
<float> right
)
276 return (Vector
<int>)Vector
<float>.LessThanOrEqual(left
, right
);
280 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
281 /// corresponding elements in right.
283 /// <param name="left">The first vector to compare.</param>
284 /// <param name="right">The second vector to compare.</param>
285 /// <returns>The resultant vector.</returns>
287 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
288 public static Vector
<int> LessThanOrEqual(Vector
<int> left
, Vector
<int> right
)
290 return Vector
<int>.LessThanOrEqual(left
, right
);
294 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
295 /// corresponding elements in right.
297 /// <param name="left">The first vector to compare.</param>
298 /// <param name="right">The second vector to compare.</param>
299 /// <returns>The resultant vector.</returns>
301 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
302 public static Vector
<long> LessThanOrEqual(Vector
<long> left
, Vector
<long> right
)
304 return Vector
<long>.LessThanOrEqual(left
, right
);
308 /// Returns an integral vector whose elements signal whether the elements in left were less than or equal to their
309 /// corresponding elements in right.
311 /// <param name="left">The first vector to compare.</param>
312 /// <param name="right">The second vector to compare.</param>
313 /// <returns>The resultant integral vector.</returns>
315 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
316 public static Vector
<long> LessThanOrEqual(Vector
<double> left
, Vector
<double> right
)
318 return (Vector
<long>)Vector
<double>.LessThanOrEqual(left
, right
);
322 /// Returns a boolean indicating whether all elements in left are less than or equal to their corresponding elements in right.
324 /// <param name="left">The first vector to compare.</param>
325 /// <param name="right">The second vector to compare.</param>
326 /// <returns>True if all elements in left are less than or equal to their corresponding elements in right; False otherwise.</returns>
327 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
328 public static bool LessThanOrEqualAll
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
330 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.LessThanOrEqual(left
, right
);
331 return cond
.Equals(Vector
<int>.AllOnes
);
335 /// Returns a boolean indicating whether any element in left is less than or equal to its corresponding element in right.
337 /// <param name="left">The first vector to compare.</param>
338 /// <param name="right">The second vector to compare.</param>
339 /// <returns>True if any elements in left are less than their corresponding elements in right; False otherwise.</returns>
340 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
341 public static bool LessThanOrEqualAny
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
343 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.LessThanOrEqual(left
, right
);
344 return !cond
.Equals(Vector
<int>.Zero
);
346 #endregion Lessthanorequal methods
348 #region Greaterthan methods
350 /// Returns a new vector whose elements signal whether the elements in left were greater than their
351 /// corresponding elements in right.
353 /// <param name="left">The first vector to compare.</param>
354 /// <param name="right">The second vector to compare.</param>
355 /// <returns>The resultant vector.</returns>
357 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
358 public static Vector
<T
> GreaterThan
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
360 return Vector
<T
>.GreaterThan(left
, right
);
364 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
365 /// corresponding elements in right.
367 /// <param name="left">The first vector to compare.</param>
368 /// <param name="right">The second vector to compare.</param>
369 /// <returns>The resultant integral vector.</returns>
371 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
372 public static Vector
<int> GreaterThan(Vector
<float> left
, Vector
<float> right
)
374 return (Vector
<int>)Vector
<float>.GreaterThan(left
, right
);
378 /// Returns a new vector whose elements signal whether the elements in left were greater than their
379 /// corresponding elements in right.
381 /// <param name="left">The first vector to compare.</param>
382 /// <param name="right">The second vector to compare.</param>
383 /// <returns>The resultant vector.</returns>
385 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
386 public static Vector
<int> GreaterThan(Vector
<int> left
, Vector
<int> right
)
388 return Vector
<int>.GreaterThan(left
, right
);
392 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
393 /// corresponding elements in right.
395 /// <param name="left">The first vector to compare.</param>
396 /// <param name="right">The second vector to compare.</param>
397 /// <returns>The resultant integral vector.</returns>
399 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
400 public static Vector
<long> GreaterThan(Vector
<double> left
, Vector
<double> right
)
402 return (Vector
<long>)Vector
<double>.GreaterThan(left
, right
);
406 /// Returns a new vector whose elements signal whether the elements in left were greater than their
407 /// corresponding elements in right.
409 /// <param name="left">The first vector to compare.</param>
410 /// <param name="right">The second vector to compare.</param>
411 /// <returns>The resultant vector.</returns>
413 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
414 public static Vector
<long> GreaterThan(Vector
<long> left
, Vector
<long> right
)
416 return Vector
<long>.GreaterThan(left
, right
);
420 /// Returns a boolean indicating whether all elements in left are greater than the corresponding elements in right.
421 /// elements in right.
423 /// <param name="left">The first vector to compare.</param>
424 /// <param name="right">The second vector to compare.</param>
425 /// <returns>True if all elements in left are greater than their corresponding elements in right; False otherwise.</returns>
426 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
427 public static bool GreaterThanAll
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
429 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.GreaterThan(left
, right
);
430 return cond
.Equals(Vector
<int>.AllOnes
);
434 /// Returns a boolean indicating whether any element in left is greater than its corresponding element in right.
436 /// <param name="left">The first vector to compare.</param>
437 /// <param name="right">The second vector to compare.</param>
438 /// <returns>True if any elements in left are greater than their corresponding elements in right; False otherwise.</returns>
439 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
440 public static bool GreaterThanAny
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
442 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.GreaterThan(left
, right
);
443 return !cond
.Equals(Vector
<int>.Zero
);
445 #endregion Greaterthan methods
447 #region Greaterthanorequal methods
449 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
450 /// corresponding elements in right.
452 /// <param name="left">The first vector to compare.</param>
453 /// <param name="right">The second vector to compare.</param>
454 /// <returns>The resultant vector.</returns>
456 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
457 public static Vector
<T
> GreaterThanOrEqual
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
459 return Vector
<T
>.GreaterThanOrEqual(left
, right
);
463 /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to their
464 /// corresponding elements in right.
466 /// <param name="left">The first vector to compare.</param>
467 /// <param name="right">The second vector to compare.</param>
468 /// <returns>The resultant integral vector.</returns>
470 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
471 public static Vector
<int> GreaterThanOrEqual(Vector
<float> left
, Vector
<float> right
)
473 return (Vector
<int>)Vector
<float>.GreaterThanOrEqual(left
, right
);
477 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
478 /// corresponding elements in right.
480 /// <param name="left">The first vector to compare.</param>
481 /// <param name="right">The second vector to compare.</param>
482 /// <returns>The resultant vector.</returns>
484 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
485 public static Vector
<int> GreaterThanOrEqual(Vector
<int> left
, Vector
<int> right
)
487 return Vector
<int>.GreaterThanOrEqual(left
, right
);
491 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
492 /// corresponding elements in right.
494 /// <param name="left">The first vector to compare.</param>
495 /// <param name="right">The second vector to compare.</param>
496 /// <returns>The resultant vector.</returns>
498 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
499 public static Vector
<long> GreaterThanOrEqual(Vector
<long> left
, Vector
<long> right
)
501 return Vector
<long>.GreaterThanOrEqual(left
, right
);
505 /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to
506 /// their corresponding elements in right.
508 /// <param name="left">The first vector to compare.</param>
509 /// <param name="right">The second vector to compare.</param>
510 /// <returns>The resultant integral vector.</returns>
512 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
513 public static Vector
<long> GreaterThanOrEqual(Vector
<double> left
, Vector
<double> right
)
515 return (Vector
<long>)Vector
<double>.GreaterThanOrEqual(left
, right
);
519 /// Returns a boolean indicating whether all of the elements in left are greater than or equal to
520 /// their corresponding elements in right.
522 /// <param name="left">The first vector to compare.</param>
523 /// <param name="right">The second vector to compare.</param>
524 /// <returns>True if all elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
525 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
526 public static bool GreaterThanOrEqualAll
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
528 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.GreaterThanOrEqual(left
, right
);
529 return cond
.Equals(Vector
<int>.AllOnes
);
533 /// Returns a boolean indicating whether any element in left is greater than or equal to its corresponding element in right.
535 /// <param name="left">The first vector to compare.</param>
536 /// <param name="right">The second vector to compare.</param>
537 /// <returns>True if any elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
538 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
539 public static bool GreaterThanOrEqualAny
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
541 Vector
<int> cond
= (Vector
<int>)Vector
<T
>.GreaterThanOrEqual(left
, right
);
542 return !cond
.Equals(Vector
<int>.Zero
);
544 #endregion Greaterthanorequal methods
545 #endregion Comparison methods
547 #region Vector Math Methods
548 // Every operation must either be a JIT intrinsic or implemented over a JIT intrinsic
550 // Operations implemented over a JIT intrinsic should be inlined
551 // Methods that do not have a <T> type parameter are recognized as intrinsics
553 /// Returns whether or not vector operations are subject to hardware acceleration through JIT intrinsic support.
555 public static bool IsHardwareAccelerated
563 // All Math operations for Vector<T> are aggressively inlined here
566 /// Returns a new vector whose elements are the absolute values of the given vector's elements.
568 /// <param name="value">The source vector.</param>
569 /// <returns>The absolute value vector.</returns>
571 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
572 public static Vector
<T
> Abs
<T
>(Vector
<T
> value) where T
: struct
574 return Vector
<T
>.Abs(value);
578 /// Returns a new vector whose elements are the minimum of each pair of elements in the two given vectors.
580 /// <param name="left">The first source vector.</param>
581 /// <param name="right">The second source vector.</param>
582 /// <returns>The minimum vector.</returns>
584 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
585 public static Vector
<T
> Min
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
587 return Vector
<T
>.Min(left
, right
);
591 /// Returns a new vector whose elements are the maximum of each pair of elements in the two given vectors.
593 /// <param name="left">The first source vector.</param>
594 /// <param name="right">The second source vector.</param>
595 /// <returns>The maximum vector.</returns>
597 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
598 public static Vector
<T
> Max
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
600 return Vector
<T
>.Max(left
, right
);
603 // Specialized vector operations
606 /// Returns the dot product of two vectors.
608 /// <param name="left">The first source vector.</param>
609 /// <param name="right">The second source vector.</param>
610 /// <returns>The dot product.</returns>
612 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
613 public static T Dot
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
615 return Vector
<T
>.Dot(left
, right
);
619 /// Returns a new vector whose elements are the square roots of the given vector's elements.
621 /// <param name="value">The source vector.</param>
622 /// <returns>The square root vector.</returns>
624 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
625 public static Vector
<T
> SquareRoot
<T
>(Vector
<T
> value) where T
: struct
627 return Vector
<T
>.SquareRoot(value);
629 #endregion Vector Math Methods
631 #region Named Arithmetic Operators
633 /// Creates a new vector whose values are the sum of each pair of elements from the two given vectors.
635 /// <param name="left">The first source vector.</param>
636 /// <param name="right">The second source vector.</param>
637 /// <returns>The summed vector.</returns>
638 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
639 public static Vector
<T
> Add
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
645 /// Creates a new vector whose values are the difference between each pairs of elements in the given vectors.
647 /// <param name="left">The first source vector.</param>
648 /// <param name="right">The second source vector.</param>
649 /// <returns>The difference vector.</returns>
650 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
651 public static Vector
<T
> Subtract
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
657 /// Creates a new vector whose values are the product of each pair of elements from the two given vectors.
659 /// <param name="left">The first source vector.</param>
660 /// <param name="right">The second source vector.</param>
661 /// <returns>The summed vector.</returns>
662 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
663 public static Vector
<T
> Multiply
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
669 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
671 /// <param name="left">The source vector.</param>
672 /// <param name="right">The scalar factor.</param>
673 /// <returns>The scaled vector.</returns>
674 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
675 public static Vector
<T
> Multiply
<T
>(Vector
<T
> left
, T right
) where T
: struct
681 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
683 /// <param name="left">The scalar factor.</param>
684 /// <param name="right">The source vector.</param>
685 /// <returns>The scaled vector.</returns>
686 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
687 public static Vector
<T
> Multiply
<T
>(T left
, Vector
<T
> right
) where T
: struct
693 /// Returns a new vector whose values are the result of dividing the first vector's elements
694 /// by the corresponding elements in the second vector.
696 /// <param name="left">The first source vector.</param>
697 /// <param name="right">The second source vector.</param>
698 /// <returns>The divided vector.</returns>
699 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
700 public static Vector
<T
> Divide
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
706 /// Returns a new vector whose elements are the given vector's elements negated.
708 /// <param name="value">The source vector.</param>
709 /// <returns>The negated vector.</returns>
710 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
711 public static Vector
<T
> Negate
<T
>(Vector
<T
> value) where T
: struct
715 #endregion Named Arithmetic Operators
717 #region Named Bitwise Operators
719 /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
721 /// <param name="left">The first source vector.</param>
722 /// <param name="right">The second source vector.</param>
723 /// <returns>The resultant vector.</returns>
724 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
725 public static Vector
<T
> BitwiseAnd
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
731 /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
733 /// <param name="left">The first source vector.</param>
734 /// <param name="right">The second source vector.</param>
735 /// <returns>The resultant vector.</returns>
736 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
737 public static Vector
<T
> BitwiseOr
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
743 /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
745 /// <param name="value">The source vector.</param>
746 /// <returns>The one's complement vector.</returns>
747 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
748 public static Vector
<T
> OnesComplement
<T
>(Vector
<T
> value) where T
: struct
754 /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
756 /// <param name="left">The first source vector.</param>
757 /// <param name="right">The second source vector.</param>
758 /// <returns>The resultant vector.</returns>
759 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
760 public static Vector
<T
> Xor
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
766 /// Returns a new vector by performing a bitwise-and-not operation on each of the elements in the given vectors.
768 /// <param name="left">The first source vector.</param>
769 /// <param name="right">The second source vector.</param>
770 /// <returns>The resultant vector.</returns>
772 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
773 public static Vector
<T
> AndNot
<T
>(Vector
<T
> left
, Vector
<T
> right
) where T
: struct
775 return left
& ~right
;
777 #endregion Named Bitwise Operators
779 #region Conversion Methods
781 /// Reinterprets the bits of the given vector into those of a vector of unsigned bytes.
783 /// <param name="value">The source vector</param>
784 /// <returns>The reinterpreted vector.</returns>
785 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
786 public static Vector
<byte> AsVectorByte
<T
>(Vector
<T
> value) where T
: struct
788 return (Vector
<byte>)value;
792 /// Reinterprets the bits of the given vector into those of a vector of signed bytes.
794 /// <param name="value">The source vector</param>
795 /// <returns>The reinterpreted vector.</returns>
796 [CLSCompliant(false)]
797 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
798 public static Vector
<sbyte> AsVectorSByte
<T
>(Vector
<T
> value) where T
: struct
800 return (Vector
<sbyte>)value;
804 /// Reinterprets the bits of the given vector into those of a vector of 16-bit integers.
806 /// <param name="value">The source vector</param>
807 /// <returns>The reinterpreted vector.</returns>
808 [CLSCompliant(false)]
809 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
810 public static Vector
<ushort> AsVectorUInt16
<T
>(Vector
<T
> value) where T
: struct
812 return (Vector
<ushort>)value;
816 /// Reinterprets the bits of the given vector into those of a vector of signed 16-bit integers.
818 /// <param name="value">The source vector</param>
819 /// <returns>The reinterpreted vector.</returns>
820 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
821 public static Vector
<short> AsVectorInt16
<T
>(Vector
<T
> value) where T
: struct
823 return (Vector
<short>)value;
827 /// Reinterprets the bits of the given vector into those of a vector of unsigned 32-bit integers.
829 /// <param name="value">The source vector</param>
830 /// <returns>The reinterpreted vector.</returns>
831 [CLSCompliant(false)]
832 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
833 public static Vector
<uint> AsVectorUInt32
<T
>(Vector
<T
> value) where T
: struct
835 return (Vector
<uint>)value;
839 /// Reinterprets the bits of the given vector into those of a vector of signed 32-bit integers.
841 /// <param name="value">The source vector</param>
842 /// <returns>The reinterpreted vector.</returns>
843 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
844 public static Vector
<int> AsVectorInt32
<T
>(Vector
<T
> value) where T
: struct
846 return (Vector
<int>)value;
850 /// Reinterprets the bits of the given vector into those of a vector of unsigned 64-bit integers.
852 /// <param name="value">The source vector</param>
853 /// <returns>The reinterpreted vector.</returns>
854 [CLSCompliant(false)]
855 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
856 public static Vector
<ulong> AsVectorUInt64
<T
>(Vector
<T
> value) where T
: struct
858 return (Vector
<ulong>)value;
863 /// Reinterprets the bits of the given vector into those of a vector of signed 64-bit integers.
865 /// <param name="value">The source vector</param>
866 /// <returns>The reinterpreted vector.</returns>
867 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
868 public static Vector
<long> AsVectorInt64
<T
>(Vector
<T
> value) where T
: struct
870 return (Vector
<long>)value;
874 /// Reinterprets the bits of the given vector into those of a vector of 32-bit floating point numbers.
876 /// <param name="value">The source vector</param>
877 /// <returns>The reinterpreted vector.</returns>
878 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
879 public static Vector
<float> AsVectorSingle
<T
>(Vector
<T
> value) where T
: struct
881 return (Vector
<float>)value;
885 /// Reinterprets the bits of the given vector into those of a vector of 64-bit floating point numbers.
887 /// <param name="value">The source vector</param>
888 /// <returns>The reinterpreted vector.</returns>
889 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
890 public static Vector
<double> AsVectorDouble
<T
>(Vector
<T
> value) where T
: struct
892 return (Vector
<double>)value;
894 #endregion Conversion Methods