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 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>
24 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
25 public static Vector<Single> ConditionalSelect(Vector<int> condition, Vector<Single> left, Vector<Single> right)
27 return (Vector<Single>)Vector<Single>.ConditionalSelect((Vector<Single>)condition, left, right);
31 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
33 /// <param name="condition">The integral mask vector used to drive selection.</param>
34 /// <param name="left">The first source vector.</param>
35 /// <param name="right">The second source vector.</param>
36 /// <returns>The new vector with elements selected based on the mask.</returns>
37 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
38 public static Vector<double> ConditionalSelect(Vector<long> condition, Vector<double> left, Vector<double> right)
40 return (Vector<double>)Vector<double>.ConditionalSelect((Vector<double>)condition, left, right);
44 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
46 /// <param name="condition">The mask vector used to drive selection.</param>
47 /// <param name="left">The first source vector.</param>
48 /// <param name="right">The second source vector.</param>
49 /// <returns>The new vector with elements selected based on the mask.</returns>
50 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
51 public static Vector<T> ConditionalSelect<T>(Vector<T> condition, Vector<T> left, Vector<T> right) where T : struct
53 return Vector<T>.ConditionalSelect(condition, left, right);
55 #endregion Select Methods
57 #region Comparison methods
58 #region Equals methods
60 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
62 /// <param name="left">The first vector to compare.</param>
63 /// <param name="right">The second vector to compare.</param>
64 /// <returns>The resultant vector.</returns>
65 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
66 public static Vector<T> Equals<T>(Vector<T> left, Vector<T> right) where T : struct
68 return Vector<T>.Equals(left, right);
72 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
74 /// <param name="left">The first vector to compare.</param>
75 /// <param name="right">The second vector to compare.</param>
76 /// <returns>The resultant vector.</returns>
77 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
78 public static Vector<int> Equals(Vector<Single> left, Vector<Single> right)
80 return (Vector<int>)Vector<Single>.Equals(left, right);
84 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
86 /// <param name="left">The first vector to compare.</param>
87 /// <param name="right">The second vector to compare.</param>
88 /// <returns>The resultant vector.</returns>
89 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
90 public static Vector<int> Equals(Vector<int> left, Vector<int> right)
92 return Vector<int>.Equals(left, right);
96 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
98 /// <param name="left">The first vector to compare.</param>
99 /// <param name="right">The second vector to compare.</param>
100 /// <returns>The resultant vector.</returns>
101 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
102 public static Vector<long> Equals(Vector<double> left, Vector<double> right)
104 return (Vector<long>)Vector<double>.Equals(left, right);
108 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
110 /// <param name="left">The first vector to compare.</param>
111 /// <param name="right">The second vector to compare.</param>
112 /// <returns>The resultant vector.</returns>
113 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
114 public static Vector<long> Equals(Vector<long> left, Vector<long> right)
116 return Vector<long>.Equals(left, right);
120 /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
122 /// <param name="left">The first vector to compare.</param>
123 /// <param name="right">The first vector to compare.</param>
124 /// <returns>True if all elements are equal; False otherwise.</returns>
125 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
126 public static bool EqualsAll<T>(Vector<T> left, Vector<T> right) where T : struct
128 return left == right;
132 /// Returns a boolean indicating whether any single pair of elements in the given vectors are equal.
134 /// <param name="left">The first vector to compare.</param>
135 /// <param name="right">The second vector to compare.</param>
136 /// <returns>True if any element pairs are equal; False if no element pairs are equal.</returns>
137 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
138 public static bool EqualsAny<T>(Vector<T> left, Vector<T> right) where T : struct
140 return !Vector<T>.Equals(left, right).Equals(Vector<T>.Zero);
142 #endregion Equals methods
144 #region Lessthan Methods
146 /// Returns a new vector whose elements signal whether the elements in left were less than their
147 /// corresponding elements in right.
149 /// <param name="left">The first vector to compare.</param>
150 /// <param name="right">The second vector to compare.</param>
151 /// <returns>The resultant vector.</returns>
152 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
153 public static Vector<T> LessThan<T>(Vector<T> left, Vector<T> right) where T : struct
155 return Vector<T>.LessThan(left, right);
159 /// Returns an integral vector whose elements signal whether the elements in left were less than their
160 /// corresponding elements in right.
162 /// <param name="left">The first vector to compare.</param>
163 /// <param name="right">The second vector to compare.</param>
164 /// <returns>The resultant integral vector.</returns>
165 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
166 public static Vector<int> LessThan(Vector<Single> left, Vector<Single> right)
168 return (Vector<int>)Vector<Single>.LessThan(left, right);
172 /// Returns a new vector whose elements signal whether the elements in left were less than their
173 /// corresponding elements in right.
175 /// <param name="left">The first vector to compare.</param>
176 /// <param name="right">The second vector to compare.</param>
177 /// <returns>The resultant vector.</returns>
178 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
179 public static Vector<int> LessThan(Vector<int> left, Vector<int> right)
181 return Vector<int>.LessThan(left, right);
185 /// Returns an integral vector whose elements signal whether the elements in left were less than their
186 /// corresponding elements in right.
188 /// <param name="left">The first vector to compare.</param>
189 /// <param name="right">The second vector to compare.</param>
190 /// <returns>The resultant integral vector.</returns>
191 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
192 public static Vector<long> LessThan(Vector<double> left, Vector<double> right)
194 return (Vector<long>)Vector<double>.LessThan(left, right);
198 /// Returns a new vector whose elements signal whether the elements in left were less than their
199 /// corresponding elements in right.
201 /// <param name="left">The first vector to compare.</param>
202 /// <param name="right">The second vector to compare.</param>
203 /// <returns>The resultant vector.</returns>
204 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
205 public static Vector<long> LessThan(Vector<long> left, Vector<long> right)
207 return Vector<long>.LessThan(left, right);
211 /// Returns a boolean indicating whether all of the elements in left are less than their 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>True if all elements in left are less than their corresponding elements in right; False otherwise.</returns>
216 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
217 public static bool LessThanAll<T>(Vector<T> left, Vector<T> right) where T : struct
219 Vector<int> cond = (Vector<int>)Vector<T>.LessThan(left, right);
220 return cond.Equals(Vector<int>.AllOnes);
224 /// Returns a boolean indicating whether any element in left is less than its corresponding element 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 any elements in left are less than their corresponding elements in right; False otherwise.</returns>
229 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
230 public static bool LessThanAny<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>.Zero);
235 #endregion LessthanMethods
237 #region Lessthanorequal methods
239 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
240 /// corresponding elements in right.
242 /// <param name="left">The first vector to compare.</param>
243 /// <param name="right">The second vector to compare.</param>
244 /// <returns>The resultant vector.</returns>
245 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
246 public static Vector<T> LessThanOrEqual<T>(Vector<T> left, Vector<T> right) where T : struct
248 return Vector<T>.LessThanOrEqual(left, right);
252 /// Returns an integral 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 integral vector.</returns>
258 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
259 public static Vector<int> LessThanOrEqual(Vector<Single> left, Vector<Single> right)
261 return (Vector<int>)Vector<Single>.LessThanOrEqual(left, right);
265 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
266 /// corresponding elements in right.
268 /// <param name="left">The first vector to compare.</param>
269 /// <param name="right">The second vector to compare.</param>
270 /// <returns>The resultant vector.</returns>
271 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
272 public static Vector<int> LessThanOrEqual(Vector<int> left, Vector<int> right)
274 return Vector<int>.LessThanOrEqual(left, right);
278 /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
279 /// corresponding elements in right.
281 /// <param name="left">The first vector to compare.</param>
282 /// <param name="right">The second vector to compare.</param>
283 /// <returns>The resultant vector.</returns>
284 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
285 public static Vector<long> LessThanOrEqual(Vector<long> left, Vector<long> right)
287 return Vector<long>.LessThanOrEqual(left, right);
291 /// Returns an integral vector whose elements signal whether the elements in left were less than or equal to their
292 /// corresponding elements in right.
294 /// <param name="left">The first vector to compare.</param>
295 /// <param name="right">The second vector to compare.</param>
296 /// <returns>The resultant integral vector.</returns>
297 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
298 public static Vector<long> LessThanOrEqual(Vector<double> left, Vector<double> right)
300 return (Vector<long>)Vector<double>.LessThanOrEqual(left, right);
304 /// Returns a boolean indicating whether all elements in left are less than or equal to their corresponding elements in right.
306 /// <param name="left">The first vector to compare.</param>
307 /// <param name="right">The second vector to compare.</param>
308 /// <returns>True if all elements in left are less than or equal to their corresponding elements in right; False otherwise.</returns>
309 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
310 public static bool LessThanOrEqualAll<T>(Vector<T> left, Vector<T> right) where T : struct
312 Vector<int> cond = (Vector<int>)Vector<T>.LessThanOrEqual(left, right);
313 return cond.Equals(Vector<int>.AllOnes);
317 /// Returns a boolean indicating whether any element in left is less than or equal to its corresponding element in right.
319 /// <param name="left">The first vector to compare.</param>
320 /// <param name="right">The second vector to compare.</param>
321 /// <returns>True if any elements in left are less than their corresponding elements in right; False otherwise.</returns>
322 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
323 public static bool LessThanOrEqualAny<T>(Vector<T> left, Vector<T> right) where T : struct
325 Vector<int> cond = (Vector<int>)Vector<T>.LessThanOrEqual(left, right);
326 return !cond.Equals(Vector<int>.Zero);
328 #endregion Lessthanorequal methods
330 #region Greaterthan methods
332 /// Returns a new vector whose elements signal whether the elements in left were greater than their
333 /// corresponding elements in right.
335 /// <param name="left">The first vector to compare.</param>
336 /// <param name="right">The second vector to compare.</param>
337 /// <returns>The resultant vector.</returns>
338 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
339 public static Vector<T> GreaterThan<T>(Vector<T> left, Vector<T> right) where T : struct
341 return Vector<T>.GreaterThan(left, right);
345 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
346 /// corresponding elements in right.
348 /// <param name="left">The first vector to compare.</param>
349 /// <param name="right">The second vector to compare.</param>
350 /// <returns>The resultant integral vector.</returns>
351 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
352 public static Vector<int> GreaterThan(Vector<Single> left, Vector<Single> right)
354 return (Vector<int>)Vector<Single>.GreaterThan(left, right);
358 /// Returns a new vector whose elements signal whether the elements in left were greater than their
359 /// corresponding elements in right.
361 /// <param name="left">The first vector to compare.</param>
362 /// <param name="right">The second vector to compare.</param>
363 /// <returns>The resultant vector.</returns>
364 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
365 public static Vector<int> GreaterThan(Vector<int> left, Vector<int> right)
367 return Vector<int>.GreaterThan(left, right);
371 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
372 /// corresponding elements in right.
374 /// <param name="left">The first vector to compare.</param>
375 /// <param name="right">The second vector to compare.</param>
376 /// <returns>The resultant integral vector.</returns>
377 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
378 public static Vector<long> GreaterThan(Vector<double> left, Vector<double> right)
380 return (Vector<long>)Vector<double>.GreaterThan(left, right);
384 /// Returns a new vector whose elements signal whether the elements in left were greater than their
385 /// corresponding elements in right.
387 /// <param name="left">The first vector to compare.</param>
388 /// <param name="right">The second vector to compare.</param>
389 /// <returns>The resultant vector.</returns>
390 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
391 public static Vector<long> GreaterThan(Vector<long> left, Vector<long> right)
393 return Vector<long>.GreaterThan(left, right);
397 /// Returns a boolean indicating whether all elements in left are greater than the corresponding elements in right.
398 /// elements in right.
400 /// <param name="left">The first vector to compare.</param>
401 /// <param name="right">The second vector to compare.</param>
402 /// <returns>True if all elements in left are greater than their corresponding elements in right; False otherwise.</returns>
403 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
404 public static bool GreaterThanAll<T>(Vector<T> left, Vector<T> right) where T : struct
406 Vector<int> cond = (Vector<int>)Vector<T>.GreaterThan(left, right);
407 return cond.Equals(Vector<int>.AllOnes);
411 /// Returns a boolean indicating whether any element in left is greater than its corresponding element in right.
413 /// <param name="left">The first vector to compare.</param>
414 /// <param name="right">The second vector to compare.</param>
415 /// <returns>True if any elements in left are greater than their corresponding elements in right; False otherwise.</returns>
416 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
417 public static bool GreaterThanAny<T>(Vector<T> left, Vector<T> right) where T : struct
419 Vector<int> cond = (Vector<int>)Vector<T>.GreaterThan(left, right);
420 return !cond.Equals(Vector<int>.Zero);
422 #endregion Greaterthan methods
424 #region Greaterthanorequal methods
426 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
427 /// corresponding elements in right.
429 /// <param name="left">The first vector to compare.</param>
430 /// <param name="right">The second vector to compare.</param>
431 /// <returns>The resultant vector.</returns>
432 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
433 public static Vector<T> GreaterThanOrEqual<T>(Vector<T> left, Vector<T> right) where T : struct
435 return Vector<T>.GreaterThanOrEqual(left, right);
439 /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to their
440 /// corresponding elements in right.
442 /// <param name="left">The first vector to compare.</param>
443 /// <param name="right">The second vector to compare.</param>
444 /// <returns>The resultant integral vector.</returns>
445 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
446 public static Vector<int> GreaterThanOrEqual(Vector<Single> left, Vector<Single> right)
448 return (Vector<int>)Vector<Single>.GreaterThanOrEqual(left, right);
452 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
453 /// corresponding elements in right.
455 /// <param name="left">The first vector to compare.</param>
456 /// <param name="right">The second vector to compare.</param>
457 /// <returns>The resultant vector.</returns>
458 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
459 public static Vector<int> GreaterThanOrEqual(Vector<int> left, Vector<int> right)
461 return Vector<int>.GreaterThanOrEqual(left, right);
465 /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
466 /// corresponding elements in right.
468 /// <param name="left">The first vector to compare.</param>
469 /// <param name="right">The second vector to compare.</param>
470 /// <returns>The resultant vector.</returns>
471 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
472 public static Vector<long> GreaterThanOrEqual(Vector<long> left, Vector<long> right)
474 return Vector<long>.GreaterThanOrEqual(left, right);
478 /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to
479 /// their corresponding elements in right.
481 /// <param name="left">The first vector to compare.</param>
482 /// <param name="right">The second vector to compare.</param>
483 /// <returns>The resultant integral vector.</returns>
484 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
485 public static Vector<long> GreaterThanOrEqual(Vector<double> left, Vector<double> right)
487 return (Vector<long>)Vector<double>.GreaterThanOrEqual(left, right);
491 /// Returns a boolean indicating whether all of the elements in left are greater than or equal to
492 /// their 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>True if all elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
497 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
498 public static bool GreaterThanOrEqualAll<T>(Vector<T> left, Vector<T> right) where T : struct
500 Vector<int> cond = (Vector<int>)Vector<T>.GreaterThanOrEqual(left, right);
501 return cond.Equals(Vector<int>.AllOnes);
505 /// Returns a boolean indicating whether any element in left is greater than or equal to its corresponding element in right.
507 /// <param name="left">The first vector to compare.</param>
508 /// <param name="right">The second vector to compare.</param>
509 /// <returns>True if any elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
510 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
511 public static bool GreaterThanOrEqualAny<T>(Vector<T> left, Vector<T> right) where T : struct
513 Vector<int> cond = (Vector<int>)Vector<T>.GreaterThanOrEqual(left, right);
514 return !cond.Equals(Vector<int>.Zero);
516 #endregion Greaterthanorequal methods
517 #endregion Comparison methods
519 #region Vector Math Methods
520 // Every operation must either be a JIT intrinsic or implemented over a JIT intrinsic
522 // Operations implemented over a JIT intrinsic should be inlined
523 // Methods that do not have a <T> type parameter are recognized as intrinsics
525 /// Returns whether or not vector operations are subject to hardware acceleration through JIT intrinsic support.
528 public static bool IsHardwareAccelerated
538 // All Math operations for Vector<T> are aggressively inlined here
541 /// Returns a new vector whose elements are the absolute values of the given vector's elements.
543 /// <param name="value">The source vector.</param>
544 /// <returns>The absolute value vector.</returns>
545 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
546 public static Vector<T> Abs<T>(Vector<T> value) where T : struct
548 return Vector<T>.Abs(value);
552 /// Returns a new vector whose elements are the minimum of each pair of elements in the two given vectors.
554 /// <param name="left">The first source vector.</param>
555 /// <param name="right">The second source vector.</param>
556 /// <returns>The minimum vector.</returns>
557 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
558 public static Vector<T> Min<T>(Vector<T> left, Vector<T> right) where T : struct
560 return Vector<T>.Min(left, right);
564 /// Returns a new vector whose elements are the maximum of each pair of elements in the two given vectors.
566 /// <param name="left">The first source vector.</param>
567 /// <param name="right">The second source vector.</param>
568 /// <returns>The maximum vector.</returns>
569 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
570 public static Vector<T> Max<T>(Vector<T> left, Vector<T> right) where T : struct
572 return Vector<T>.Max(left, right);
575 // Specialized vector operations
578 /// Returns the dot product of two vectors.
580 /// <param name="left">The first source vector.</param>
581 /// <param name="right">The second source vector.</param>
582 /// <returns>The dot product.</returns>
583 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
584 public static T Dot<T>(Vector<T> left, Vector<T> right) where T : struct
586 return Vector<T>.DotProduct(left, right);
590 /// Returns a new vector whose elements are the square roots of the given vector's elements.
592 /// <param name="value">The source vector.</param>
593 /// <returns>The square root vector.</returns>
594 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
595 public static Vector<T> SquareRoot<T>(Vector<T> value) where T : struct
597 return Vector<T>.SquareRoot(value);
599 #endregion Vector Math Methods
601 #region Named Arithmetic Operators
603 /// Creates a new vector whose values are the sum of each pair of elements from the two given vectors.
605 /// <param name="left">The first source vector.</param>
606 /// <param name="right">The second source vector.</param>
607 /// <returns>The summed vector.</returns>
608 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
609 public static Vector<T> Add<T>(Vector<T> left, Vector<T> right) where T : struct
615 /// Creates a new vector whose values are the difference between each pairs of elements in the given vectors.
617 /// <param name="left">The first source vector.</param>
618 /// <param name="right">The second source vector.</param>
619 /// <returns>The difference vector.</returns>
620 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
621 public static Vector<T> Subtract<T>(Vector<T> left, Vector<T> right) where T : struct
627 /// Creates a new vector whose values are the product of each pair of elements from the two given vectors.
629 /// <param name="left">The first source vector.</param>
630 /// <param name="right">The second source vector.</param>
631 /// <returns>The summed vector.</returns>
632 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
633 public static Vector<T> Multiply<T>(Vector<T> left, Vector<T> right) where T : struct
639 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
641 /// <param name="left">The source vector.</param>
642 /// <param name="right">The scalar factor.</param>
643 /// <returns>The scaled vector.</returns>
644 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
645 public static Vector<T> Multiply<T>(Vector<T> left, T right) where T : struct
651 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
653 /// <param name="left">The scalar factor.</param>
654 /// <param name="right">The source vector.</param>
655 /// <returns>The scaled vector.</returns>
656 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
657 public static Vector<T> Multiply<T>(T left, Vector<T> right) where T : struct
663 /// Returns a new vector whose values are the result of dividing the first vector's elements
664 /// by the corresponding elements in the second vector.
666 /// <param name="left">The first source vector.</param>
667 /// <param name="right">The second source vector.</param>
668 /// <returns>The divided vector.</returns>
669 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
670 public static Vector<T> Divide<T>(Vector<T> left, Vector<T> right) where T : struct
676 /// Returns a new vector whose elements are the given vector's elements negated.
678 /// <param name="value">The source vector.</param>
679 /// <returns>The negated vector.</returns>
680 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
681 public static Vector<T> Negate<T>(Vector<T> value) where T : struct
685 #endregion Named Arithmetic Operators
687 #region Named Bitwise Operators
689 /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
691 /// <param name="left">The first source vector.</param>
692 /// <param name="right">The second source vector.</param>
693 /// <returns>The resultant vector.</returns>
694 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
695 public static Vector<T> BitwiseAnd<T>(Vector<T> left, Vector<T> right) where T : struct
701 /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
703 /// <param name="left">The first source vector.</param>
704 /// <param name="right">The second source vector.</param>
705 /// <returns>The resultant vector.</returns>
706 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
707 public static Vector<T> BitwiseOr<T>(Vector<T> left, Vector<T> right) where T : struct
713 /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
715 /// <param name="value">The source vector.</param>
716 /// <returns>The one's complement vector.</returns>
717 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
718 public static Vector<T> OnesComplement<T>(Vector<T> value) where T : struct
724 /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
726 /// <param name="left">The first source vector.</param>
727 /// <param name="right">The second source vector.</param>
728 /// <returns>The resultant vector.</returns>
729 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
730 public static Vector<T> Xor<T>(Vector<T> left, Vector<T> right) where T : struct
736 /// Returns a new vector by performing a bitwise-and-not operation on each of the elements in the given vectors.
738 /// <param name="left">The first source vector.</param>
739 /// <param name="right">The second source vector.</param>
740 /// <returns>The resultant vector.</returns>
741 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
742 public static Vector<T> AndNot<T>(Vector<T> left, Vector<T> right) where T : struct
744 return left & ~right;
746 #endregion Named Bitwise Operators
748 #region Conversion Methods
750 /// Reinterprets the bits of the given vector into those of a vector of unsigned bytes.
752 /// <param name="value">The source vector</param>
753 /// <returns>The reinterpreted vector.</returns>
754 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
755 public static Vector<Byte> AsVectorByte<T>(Vector<T> value) where T : struct
757 return (Vector<Byte>)value;
761 /// Reinterprets the bits of the given vector into those of a vector of signed bytes.
763 /// <param name="value">The source vector</param>
764 /// <returns>The reinterpreted vector.</returns>
765 [CLSCompliant(false)]
766 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
767 public static Vector<SByte> AsVectorSByte<T>(Vector<T> value) where T : struct
769 return (Vector<SByte>)value;
773 /// Reinterprets the bits of the given vector into those of a vector of 16-bit integers.
775 /// <param name="value">The source vector</param>
776 /// <returns>The reinterpreted vector.</returns>
777 [CLSCompliant(false)]
778 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
779 public static Vector<UInt16> AsVectorUInt16<T>(Vector<T> value) where T : struct
781 return (Vector<UInt16>)value;
785 /// Reinterprets the bits of the given vector into those of a vector of signed 16-bit integers.
787 /// <param name="value">The source vector</param>
788 /// <returns>The reinterpreted vector.</returns>
789 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
790 public static Vector<Int16> AsVectorInt16<T>(Vector<T> value) where T : struct
792 return (Vector<Int16>)value;
796 /// Reinterprets the bits of the given vector into those of a vector of unsigned 32-bit integers.
798 /// <param name="value">The source vector</param>
799 /// <returns>The reinterpreted vector.</returns>
800 [CLSCompliant(false)]
801 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
802 public static Vector<UInt32> AsVectorUInt32<T>(Vector<T> value) where T : struct
804 return (Vector<UInt32>)value;
808 /// Reinterprets the bits of the given vector into those of a vector of signed 32-bit integers.
810 /// <param name="value">The source vector</param>
811 /// <returns>The reinterpreted vector.</returns>
812 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
813 public static Vector<Int32> AsVectorInt32<T>(Vector<T> value) where T : struct
815 return (Vector<Int32>)value;
819 /// Reinterprets the bits of the given vector into those of a vector of unsigned 64-bit integers.
821 /// <param name="value">The source vector</param>
822 /// <returns>The reinterpreted vector.</returns>
823 [CLSCompliant(false)]
824 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
825 public static Vector<UInt64> AsVectorUInt64<T>(Vector<T> value) where T : struct
827 return (Vector<UInt64>)value;
832 /// Reinterprets the bits of the given vector into those of a vector of signed 64-bit integers.
834 /// <param name="value">The source vector</param>
835 /// <returns>The reinterpreted vector.</returns>
836 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
837 public static Vector<Int64> AsVectorInt64<T>(Vector<T> value) where T : struct
839 return (Vector<Int64>)value;
843 /// Reinterprets the bits of the given vector into those of a vector of 32-bit floating point numbers.
845 /// <param name="value">The source vector</param>
846 /// <returns>The reinterpreted vector.</returns>
847 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
848 public static Vector<Single> AsVectorSingle<T>(Vector<T> value) where T : struct
850 return (Vector<Single>)value;
854 /// Reinterprets the bits of the given vector into those of a vector of 64-bit floating point numbers.
856 /// <param name="value">The source vector</param>
857 /// <returns>The reinterpreted vector.</returns>
858 [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
859 public static Vector<Double> AsVectorDouble<T>(Vector<T> value) where T : struct
861 return (Vector<Double>)value;
863 #endregion Conversion Methods