More Corelib cleanup (dotnet/coreclr#26872)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / Numerics / Vector_Operations.cs
blob8d41edaf123fcc125cc9b8ab3a6ee19e8a5a1bba
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
9 /// <summary>
10 /// Contains various methods useful for creating, manipulating, combining, and converting generic vectors with one another.
11 /// </summary>
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
17 /// <summary>
18 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
19 /// </summary>
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 [Intrinsic]
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);
31 /// <summary>
32 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
33 /// </summary>
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>
38 [Intrinsic]
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);
45 /// <summary>
46 /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
47 /// </summary>
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>
52 [Intrinsic]
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
62 /// <summary>
63 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
64 /// </summary>
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>
68 [Intrinsic]
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);
75 /// <summary>
76 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
77 /// </summary>
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>
81 [Intrinsic]
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);
88 /// <summary>
89 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
90 /// </summary>
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>
94 [Intrinsic]
95 [MethodImpl(MethodImplOptions.AggressiveInlining)]
96 public static Vector<int> Equals(Vector<int> left, Vector<int> right)
98 return Vector<int>.Equals(left, right);
101 /// <summary>
102 /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
103 /// </summary>
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>
107 [Intrinsic]
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);
114 /// <summary>
115 /// Returns a new vector whose elements signal whether the elements in left and right were equal.
116 /// </summary>
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>
120 [Intrinsic]
121 [MethodImpl(MethodImplOptions.AggressiveInlining)]
122 public static Vector<long> Equals(Vector<long> left, Vector<long> right)
124 return Vector<long>.Equals(left, right);
127 /// <summary>
128 /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
129 /// </summary>
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;
139 /// <summary>
140 /// Returns a boolean indicating whether any single pair of elements in the given vectors are equal.
141 /// </summary>
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
153 /// <summary>
154 /// Returns a new vector whose elements signal whether the elements in left were less than their
155 /// corresponding elements in right.
156 /// </summary>
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>
160 [Intrinsic]
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);
167 /// <summary>
168 /// Returns an integral vector whose elements signal whether the elements in left were less than their
169 /// corresponding elements in right.
170 /// </summary>
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>
174 [Intrinsic]
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);
181 /// <summary>
182 /// Returns a new vector whose elements signal whether the elements in left were less than their
183 /// corresponding elements in right.
184 /// </summary>
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>
188 [Intrinsic]
189 [MethodImpl(MethodImplOptions.AggressiveInlining)]
190 public static Vector<int> LessThan(Vector<int> left, Vector<int> right)
192 return Vector<int>.LessThan(left, right);
195 /// <summary>
196 /// Returns an integral vector whose elements signal whether the elements in left were less than their
197 /// corresponding elements in right.
198 /// </summary>
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>
202 [Intrinsic]
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);
209 /// <summary>
210 /// Returns a new vector whose elements signal whether the elements in left were less than their
211 /// corresponding elements in right.
212 /// </summary>
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>
216 [Intrinsic]
217 [MethodImpl(MethodImplOptions.AggressiveInlining)]
218 public static Vector<long> LessThan(Vector<long> left, Vector<long> right)
220 return Vector<long>.LessThan(left, right);
223 /// <summary>
224 /// Returns a boolean indicating whether all of the elements in left are less than their corresponding elements in right.
225 /// </summary>
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);
236 /// <summary>
237 /// Returns a boolean indicating whether any element in left is less than its corresponding element in right.
238 /// </summary>
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
251 /// <summary>
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.
254 /// </summary>
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>
258 [Intrinsic]
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);
265 /// <summary>
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.
268 /// </summary>
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>
272 [Intrinsic]
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);
279 /// <summary>
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.
282 /// </summary>
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>
286 [Intrinsic]
287 [MethodImpl(MethodImplOptions.AggressiveInlining)]
288 public static Vector<int> LessThanOrEqual(Vector<int> left, Vector<int> right)
290 return Vector<int>.LessThanOrEqual(left, right);
293 /// <summary>
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.
296 /// </summary>
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>
300 [Intrinsic]
301 [MethodImpl(MethodImplOptions.AggressiveInlining)]
302 public static Vector<long> LessThanOrEqual(Vector<long> left, Vector<long> right)
304 return Vector<long>.LessThanOrEqual(left, right);
307 /// <summary>
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.
310 /// </summary>
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>
314 [Intrinsic]
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);
321 /// <summary>
322 /// Returns a boolean indicating whether all elements in left are less than or equal to their corresponding elements in right.
323 /// </summary>
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);
334 /// <summary>
335 /// Returns a boolean indicating whether any element in left is less than or equal to its corresponding element in right.
336 /// </summary>
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
349 /// <summary>
350 /// Returns a new vector whose elements signal whether the elements in left were greater than their
351 /// corresponding elements in right.
352 /// </summary>
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>
356 [Intrinsic]
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);
363 /// <summary>
364 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
365 /// corresponding elements in right.
366 /// </summary>
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>
370 [Intrinsic]
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);
377 /// <summary>
378 /// Returns a new vector whose elements signal whether the elements in left were greater than their
379 /// corresponding elements in right.
380 /// </summary>
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>
384 [Intrinsic]
385 [MethodImpl(MethodImplOptions.AggressiveInlining)]
386 public static Vector<int> GreaterThan(Vector<int> left, Vector<int> right)
388 return Vector<int>.GreaterThan(left, right);
391 /// <summary>
392 /// Returns an integral vector whose elements signal whether the elements in left were greater than their
393 /// corresponding elements in right.
394 /// </summary>
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>
398 [Intrinsic]
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);
405 /// <summary>
406 /// Returns a new vector whose elements signal whether the elements in left were greater than their
407 /// corresponding elements in right.
408 /// </summary>
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>
412 [Intrinsic]
413 [MethodImpl(MethodImplOptions.AggressiveInlining)]
414 public static Vector<long> GreaterThan(Vector<long> left, Vector<long> right)
416 return Vector<long>.GreaterThan(left, right);
419 /// <summary>
420 /// Returns a boolean indicating whether all elements in left are greater than the corresponding elements in right.
421 /// elements in right.
422 /// </summary>
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);
433 /// <summary>
434 /// Returns a boolean indicating whether any element in left is greater than its corresponding element in right.
435 /// </summary>
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
448 /// <summary>
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.
451 /// </summary>
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>
455 [Intrinsic]
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);
462 /// <summary>
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.
465 /// </summary>
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>
469 [Intrinsic]
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);
476 /// <summary>
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.
479 /// </summary>
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>
483 [Intrinsic]
484 [MethodImpl(MethodImplOptions.AggressiveInlining)]
485 public static Vector<int> GreaterThanOrEqual(Vector<int> left, Vector<int> right)
487 return Vector<int>.GreaterThanOrEqual(left, right);
490 /// <summary>
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.
493 /// </summary>
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>
497 [Intrinsic]
498 [MethodImpl(MethodImplOptions.AggressiveInlining)]
499 public static Vector<long> GreaterThanOrEqual(Vector<long> left, Vector<long> right)
501 return Vector<long>.GreaterThanOrEqual(left, right);
504 /// <summary>
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.
507 /// </summary>
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>
511 [Intrinsic]
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);
518 /// <summary>
519 /// Returns a boolean indicating whether all of the elements in left are greater than or equal to
520 /// their corresponding elements in right.
521 /// </summary>
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);
532 /// <summary>
533 /// Returns a boolean indicating whether any element in left is greater than or equal to its corresponding element in right.
534 /// </summary>
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
549 // as a thin wrapper
550 // Operations implemented over a JIT intrinsic should be inlined
551 // Methods that do not have a <T> type parameter are recognized as intrinsics
552 /// <summary>
553 /// Returns whether or not vector operations are subject to hardware acceleration through JIT intrinsic support.
554 /// </summary>
555 public static bool IsHardwareAccelerated
557 [Intrinsic]
558 get => false;
561 // Vector<T>
562 // Basic Math
563 // All Math operations for Vector<T> are aggressively inlined here
565 /// <summary>
566 /// Returns a new vector whose elements are the absolute values of the given vector's elements.
567 /// </summary>
568 /// <param name="value">The source vector.</param>
569 /// <returns>The absolute value vector.</returns>
570 [Intrinsic]
571 [MethodImpl(MethodImplOptions.AggressiveInlining)]
572 public static Vector<T> Abs<T>(Vector<T> value) where T : struct
574 return Vector<T>.Abs(value);
577 /// <summary>
578 /// Returns a new vector whose elements are the minimum of each pair of elements in the two given vectors.
579 /// </summary>
580 /// <param name="left">The first source vector.</param>
581 /// <param name="right">The second source vector.</param>
582 /// <returns>The minimum vector.</returns>
583 [Intrinsic]
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);
590 /// <summary>
591 /// Returns a new vector whose elements are the maximum of each pair of elements in the two given vectors.
592 /// </summary>
593 /// <param name="left">The first source vector.</param>
594 /// <param name="right">The second source vector.</param>
595 /// <returns>The maximum vector.</returns>
596 [Intrinsic]
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
605 /// <summary>
606 /// Returns the dot product of two vectors.
607 /// </summary>
608 /// <param name="left">The first source vector.</param>
609 /// <param name="right">The second source vector.</param>
610 /// <returns>The dot product.</returns>
611 [Intrinsic]
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);
618 /// <summary>
619 /// Returns a new vector whose elements are the square roots of the given vector's elements.
620 /// </summary>
621 /// <param name="value">The source vector.</param>
622 /// <returns>The square root vector.</returns>
623 [Intrinsic]
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
632 /// <summary>
633 /// Creates a new vector whose values are the sum of each pair of elements from the two given vectors.
634 /// </summary>
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
641 return left + right;
644 /// <summary>
645 /// Creates a new vector whose values are the difference between each pairs of elements in the given vectors.
646 /// </summary>
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
653 return left - right;
656 /// <summary>
657 /// Creates a new vector whose values are the product of each pair of elements from the two given vectors.
658 /// </summary>
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
665 return left * right;
668 /// <summary>
669 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
670 /// </summary>
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
677 return left * right;
680 /// <summary>
681 /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
682 /// </summary>
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
689 return left * right;
692 /// <summary>
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.
695 /// </summary>
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
702 return left / right;
705 /// <summary>
706 /// Returns a new vector whose elements are the given vector's elements negated.
707 /// </summary>
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
713 return -value;
715 #endregion Named Arithmetic Operators
717 #region Named Bitwise Operators
718 /// <summary>
719 /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
720 /// </summary>
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
727 return left & right;
730 /// <summary>
731 /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
732 /// </summary>
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
739 return left | right;
742 /// <summary>
743 /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
744 /// </summary>
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
750 return ~value;
753 /// <summary>
754 /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
755 /// </summary>
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
762 return left ^ right;
765 /// <summary>
766 /// Returns a new vector by performing a bitwise-and-not operation on each of the elements in the given vectors.
767 /// </summary>
768 /// <param name="left">The first source vector.</param>
769 /// <param name="right">The second source vector.</param>
770 /// <returns>The resultant vector.</returns>
771 [Intrinsic]
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
780 /// <summary>
781 /// Reinterprets the bits of the given vector into those of a vector of unsigned bytes.
782 /// </summary>
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;
791 /// <summary>
792 /// Reinterprets the bits of the given vector into those of a vector of signed bytes.
793 /// </summary>
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;
803 /// <summary>
804 /// Reinterprets the bits of the given vector into those of a vector of 16-bit integers.
805 /// </summary>
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;
815 /// <summary>
816 /// Reinterprets the bits of the given vector into those of a vector of signed 16-bit integers.
817 /// </summary>
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;
826 /// <summary>
827 /// Reinterprets the bits of the given vector into those of a vector of unsigned 32-bit integers.
828 /// </summary>
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;
838 /// <summary>
839 /// Reinterprets the bits of the given vector into those of a vector of signed 32-bit integers.
840 /// </summary>
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;
849 /// <summary>
850 /// Reinterprets the bits of the given vector into those of a vector of unsigned 64-bit integers.
851 /// </summary>
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;
862 /// <summary>
863 /// Reinterprets the bits of the given vector into those of a vector of signed 64-bit integers.
864 /// </summary>
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;
873 /// <summary>
874 /// Reinterprets the bits of the given vector into those of a vector of 32-bit floating point numbers.
875 /// </summary>
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;
884 /// <summary>
885 /// Reinterprets the bits of the given vector into those of a vector of 64-bit floating point numbers.
886 /// </summary>
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