[2019-12] [jit] Avoid passing a vtable argument to DIM methods when making calls...
[mono-project.git] / mono / mini / basic-vectors.cs
bloba2cf101450e792a1faf5177fdeb7e6b84ad06cbf
1 using System;
2 using System.Numerics;
3 using System.Runtime.CompilerServices;
5 /*
6 * Tests for the SIMD intrinsics in the System.Numerics.Vectors assembly.
7 */
8 public class VectorTests {
10 #if !MOBILE
11 public static int Main (string[] args) {
12 return TestDriver.RunTests (typeof (VectorTests), args);
14 #endif
17 // Vector2 tests
20 public static int test_0_vector2_ctor_1 () {
21 var v = new Vector2 (1.0f);
23 if (v.X != 1.0f)
24 return 1;
25 if (v.Y != 1.0f)
26 return 2;
27 return 0;
30 public static int test_0_vector2_ctor_2 () {
31 var v = new Vector2 (1.0f, 2.0f);
33 if (v.X != 1.0f)
34 return 1;
35 if (v.Y != 2.0f)
36 return 2;
37 return 0;
40 [MethodImplAttribute (MethodImplOptions.NoInlining)]
41 public static bool vector2_equals (Vector2 v1, Vector2 v2) {
42 // cmpeqps+pmovmskb
43 return v1.Equals (v2);
46 public static int test_0_vector2_equals () {
47 var v1 = new Vector2 (1.0f, 2.0f);
48 var v2 = new Vector2 (2.0f, 2.0f);
50 if (vector2_equals (v1, v2))
51 return 1;
52 if (!vector2_equals (v1, v1))
53 return 2;
54 return 0;
57 [MethodImplAttribute (MethodImplOptions.NoInlining)]
58 public static float vector2_dot (Vector2 v1, Vector2 v2) {
59 return Vector2.Dot (v1, v2);
62 public static int test_0_vector2_dot () {
63 var v1 = new Vector2 (1.0f, 1.0f);
64 var v2 = new Vector2 (2.0f, 2.0f);
66 float f = vector2_dot (v1, v2);
67 if (f != 4.0f)
68 return 1;
69 f = vector2_dot (v1, v1);
70 if (f != 2.0f)
71 return 2;
72 return 0;
75 [MethodImplAttribute (MethodImplOptions.NoInlining)]
76 public static Vector2 vector2_min (Vector2 v1, Vector2 v2) {
77 return Vector2.Min (v1, v2);
80 public static int test_0_vector2_min () {
81 var v1 = new Vector2 (1.0f, 1.0f);
82 var v2 = new Vector2 (2.0f, 2.0f);
84 var v3 = vector2_min (v1, v2);
85 if (v3.X != 1.0f || v3.Y != 1.0f)
86 return 1;
87 v3 = vector2_min (v2, v2);
88 if (v3.X != 2.0f || v3.Y != 2.0f)
89 return 2;
90 return 0;
93 [MethodImplAttribute (MethodImplOptions.NoInlining)]
94 public static Vector2 vector2_max (Vector2 v1, Vector2 v2) {
95 return Vector2.Max (v1, v2);
98 public static int test_0_vector2_max () {
99 var v1 = new Vector2 (1.0f, 1.0f);
100 var v2 = new Vector2 (2.0f, 2.0f);
102 var v3 = vector2_max (v1, v2);
103 if (v3.X != 2.0f || v3.Y != 2.0f)
104 return 1;
105 v3 = vector2_min (v1, v1);
106 if (v3.X != 1.0f || v3.Y != 1.0f)
107 return 2;
108 return 0;
111 [MethodImplAttribute (MethodImplOptions.NoInlining)]
112 public static Vector2 vector2_abs (Vector2 v1) {
113 return Vector2.Abs (v1);
116 public static int test_0_vector2_abs () {
117 var v1 = new Vector2 (-1.0f, -2.0f);
118 var v2 = new Vector2 (1.0f, 2.0f);
120 var v3 = vector2_abs (v1);
121 if (v3.X != 1.0f || v3.Y != 2.0f)
122 return 1;
123 v3 = vector2_abs (v2);
124 if (v3.X != 1.0f || v3.Y != 2.0f)
125 return 2;
126 return 0;
129 [MethodImplAttribute (MethodImplOptions.NoInlining)]
130 public static Vector2 vector2_sqrt (Vector2 v1) {
131 return Vector2.SquareRoot (v1);
134 public static int test_0_vector2_sqrt () {
135 var v1 = new Vector2 (1.0f, 0.0f);
137 var v3 = vector2_sqrt (v1);
138 if (v3.X != 1.0f || v3.Y != 0.0f)
139 return 1;
140 return 0;
143 [MethodImplAttribute (MethodImplOptions.NoInlining)]
144 public static Vector2 vector2_add (Vector2 v1, Vector2 v2) {
145 return v1 + v2;
148 public static int test_0_vector2_add () {
149 var v1 = new Vector2 (1.0f, 2.0f);
150 var v2 = new Vector2 (3.0f, 4.0f);
152 var v3 = vector2_add (v1, v2);
153 if (v3.X != 4.0f || v3.Y != 6.0f)
154 return 1;
155 return 0;
158 [MethodImplAttribute (MethodImplOptions.NoInlining)]
159 public static Vector2 vector2_sub (Vector2 v1, Vector2 v2) {
160 return v1 - v2;
163 public static int test_0_vector2_sub () {
164 var v1 = new Vector2 (1.0f, 2.0f);
165 var v2 = new Vector2 (3.0f, 5.0f);
167 var v3 = vector2_sub (v2, v1);
168 if (v3.X != 2.0f || v3.Y != 3.0f)
169 return 1;
170 return 0;
173 [MethodImplAttribute (MethodImplOptions.NoInlining)]
174 public static Vector2 vector2_mul (Vector2 v1, Vector2 v2) {
175 return v1 * v2;
178 public static int test_0_vector2_mul () {
179 var v1 = new Vector2 (1.0f, 2.0f);
180 var v2 = new Vector2 (3.0f, 5.0f);
182 var v3 = vector2_mul (v2, v1);
183 if (v3.X != 3.0f || v3.Y != 10.0f)
184 return 1;
185 return 0;
188 [MethodImplAttribute (MethodImplOptions.NoInlining)]
189 public static Vector2 vector2_mul_left (float v1, Vector2 v2) {
190 return v1 * v2;
193 public static int test_0_vector2_mul_left () {
194 var v1 = new Vector2 (3.0f, 5.0f);
196 var v3 = vector2_mul_left (2.0f, v1);
197 if (v3.X != 6.0f || v3.Y != 10.0f)
198 return 1;
199 return 0;
202 [MethodImplAttribute (MethodImplOptions.NoInlining)]
203 public static Vector2 vector2_mul_right (Vector2 v1, float v2) {
204 return v1 * v2;
207 public static int test_0_vector2_mul_right () {
208 var v1 = new Vector2 (3.0f, 5.0f);
210 var v3 = vector2_mul_right (v1, 2.0f);
211 if (v3.X != 6.0f || v3.Y != 10.0f)
212 return 1;
213 return 0;
216 [MethodImplAttribute (MethodImplOptions.NoInlining)]
217 public static Vector2 vector2_div (Vector2 v1, Vector2 v2) {
218 return v1 / v2;
221 public static int test_0_vector2_div () {
222 var v1 = new Vector2 (9.0f, 10.0f);
223 var v2 = new Vector2 (3.0f, 5.0f);
225 var v3 = vector2_div (v1, v2);
226 if (v3.X != 3.0f || v3.Y != 2.0f)
227 return 1;
228 return 0;
231 [MethodImplAttribute (MethodImplOptions.NoInlining)]
232 public static Vector2 vector2_div_right (Vector2 v1, float v2) {
233 return v1 / v2;
236 public static int test_0_vector2_div_right () {
237 var v1 = new Vector2 (9.0f, 15.0f);
239 var v3 = vector2_div_right (v1, 3.0f);
240 if (v3.X != 3.0f || v3.Y != 5.0f)
241 return 1;
242 return 0;
246 // Vector4 tests
249 public static int test_0_vector4_ctor_1 () {
250 var v = new Vector4 (1.0f);
252 if (v.X != 1.0f)
253 return 1;
254 if (v.Y != 1.0f)
255 return 2;
256 if (v.Z != 1.0f)
257 return 3;
258 if (v.W != 1.0f)
259 return 4;
260 return 0;
263 public static int test_0_vector4_ctor_2 () {
264 var v = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
266 if (v.X != 1.0f)
267 return 1;
268 if (v.Y != 2.0f)
269 return 2;
270 if (v.Z != 3.0f)
271 return 3;
272 if (v.W != 4.0f)
273 return 4;
274 return 0;
277 [MethodImplAttribute (MethodImplOptions.NoInlining)]
278 public static bool vector4_equals (Vector4 v1, Vector4 v2) {
279 // cmpeqps+pmovmskb
280 return v1.Equals (v2);
283 public static int test_0_vector4_equals () {
284 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
285 var v2 = new Vector4 (2.0f, 2.0f, 2.0f, 2.0f);
287 if (vector4_equals (v1, v2))
288 return 1;
289 if (!vector4_equals (v1, v1))
290 return 2;
291 return 0;
294 [MethodImplAttribute (MethodImplOptions.NoInlining)]
295 public static float vector4_dot (Vector4 v1, Vector4 v2) {
296 return Vector4.Dot (v1, v2);
299 public static int test_0_vector4_dot () {
300 var v1 = new Vector4 (1.0f, 1.0f, 1.0f, 1.0f);
301 var v2 = new Vector4 (2.0f, 2.0f, 2.0f, 2.0f);
303 float f = vector4_dot (v1, v2);
304 if (f != 8.0f)
305 return 1;
306 f = vector4_dot (v1, v1);
307 if (f != 4.0f)
308 return 2;
309 return 0;
312 [MethodImplAttribute (MethodImplOptions.NoInlining)]
313 public static Vector4 vector4_min (Vector4 v1, Vector4 v2) {
314 return Vector4.Min (v1, v2);
317 public static int test_0_vector4_min () {
318 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
319 var v2 = new Vector4 (5.0f, 6.0f, 7.0f, 8.0f);
321 var v3 = vector4_min (v1, v2);
322 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f || v3.W != 4.0f)
323 return 1;
324 v3 = vector4_min (v2, v2);
325 if (v3.X != 5.0f || v3.Y != 6.0f || v3.Z != 7.0f || v3.W != 8.0f)
326 return 2;
327 return 0;
330 [MethodImplAttribute (MethodImplOptions.NoInlining)]
331 public static Vector4 vector4_max (Vector4 v1, Vector4 v2) {
332 return Vector4.Max (v1, v2);
335 public static int test_0_vector4_max () {
336 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
337 var v2 = new Vector4 (5.0f, 6.0f, 7.0f, 8.0f);
339 var v3 = vector4_max (v1, v2);
340 if (v3.X != 5.0f || v3.Y != 6.0f || v3.Z != 7.0f || v3.W != 8.0f)
341 return 1;
342 v3 = vector4_max (v1, v1);
343 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f || v3.W != 4.0f)
344 return 2;
345 return 0;
348 [MethodImplAttribute (MethodImplOptions.NoInlining)]
349 public static Vector4 vector4_abs (Vector4 v1) {
350 return Vector4.Abs (v1);
353 public static int test_0_vector4_abs () {
354 var v1 = new Vector4 (-1.0f, -2.0f, -3.0f, -4.0f);
355 var v2 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
357 var v3 = vector4_abs (v1);
358 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f || v3.W != 4.0f)
359 return 1;
360 v3 = vector4_abs (v2);
361 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f || v3.W != 4.0f)
362 return 2;
363 return 0;
366 [MethodImplAttribute (MethodImplOptions.NoInlining)]
367 public static Vector4 vector4_sqrt (Vector4 v1) {
368 return Vector4.SquareRoot (v1);
371 public static int test_0_vector4_sqrt () {
372 var v1 = new Vector4 (1.0f, 0.0f, 1.0f, 0.0f);
374 var v3 = vector4_sqrt (v1);
375 if (v3.X != 1.0f || v3.Y != 0.0f || v3.Z != 1.0f || v3.W != 0.0f)
376 return 1;
377 return 0;
380 [MethodImplAttribute (MethodImplOptions.NoInlining)]
381 public static Vector4 vector4_add (Vector4 v1, Vector4 v2) {
382 return v1 + v2;
385 public static int test_0_vector4_add () {
386 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
387 var v2 = new Vector4 (5.0f, 6.0f, 7.0f, 8.0f);
389 var v3 = vector4_add (v1, v2);
390 if (v3.X != 6.0f || v3.Y != 8.0f || v3.Z != 10.0f || v3.W != 12.0f)
391 return 1;
392 return 0;
395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
396 public static Vector4 vector4_sub (Vector4 v1, Vector4 v2) {
397 return v1 - v2;
400 public static int test_0_vector4_sub () {
401 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
402 var v2 = new Vector4 (3.0f, 5.0f, 7.0f, 9.0f);
404 var v3 = vector4_sub (v2, v1);
405 if (v3.X != 2.0f || v3.Y != 3.0f || v3.Z != 4.0f || v3.W != 5.0f)
406 return 1;
407 return 0;
410 [MethodImplAttribute (MethodImplOptions.NoInlining)]
411 public static Vector4 vector4_mul (Vector4 v1, Vector4 v2) {
412 return v1 * v2;
415 public static int test_0_vector4_mul () {
416 var v1 = new Vector4 (1.0f, 2.0f, 3.0f, 4.0f);
417 var v2 = new Vector4 (3.0f, 5.0f, 6.0f, 7.0f);
419 var v3 = vector4_mul (v2, v1);
420 if (v3.X != 3.0f || v3.Y != 10.0f || v3.Z != 18.0f || v3.W != 28.0f)
421 return 1;
422 return 0;
425 [MethodImplAttribute (MethodImplOptions.NoInlining)]
426 public static Vector4 vector4_mul_left (float v1, Vector4 v2) {
427 return v1 * v2;
430 public static int test_0_vector4_mul_left () {
431 var v1 = new Vector4 (3.0f, 5.0f, 6.0f, 7.0f);
433 var v3 = vector4_mul_left (2.0f, v1);
434 if (v3.X != 6.0f || v3.Y != 10.0f || v3.Z != 12.0f || v3.W != 14.0f)
435 return 1;
436 return 0;
439 [MethodImplAttribute (MethodImplOptions.NoInlining)]
440 public static Vector4 vector4_mul_right (Vector4 v1, float v2) {
441 return v1 * v2;
444 public static int test_0_vector4_mul_right () {
445 var v1 = new Vector4 (3.0f, 5.0f, 6.0f, 7.0f);
447 var v3 = vector4_mul_right (v1, 2.0f);
448 if (v3.X != 6.0f || v3.Y != 10.0f || v3.Z != 12.0f || v3.W != 14.0f)
449 return 1;
450 return 0;
453 [MethodImplAttribute (MethodImplOptions.NoInlining)]
454 public static Vector4 vector4_div (Vector4 v1, Vector4 v2) {
455 return v1 / v2;
458 public static int test_0_vector4_div () {
459 var v1 = new Vector4 (9.0f, 10.0f, 12.0f, 21.0f);
460 var v2 = new Vector4 (3.0f, 5.0f, 6.0f, 7.0f);
462 var v3 = vector4_div (v1, v2);
463 if (v3.X != 3.0f || v3.Y != 2.0f || v3.Z != 2.0f || v3.W != 3.0f)
464 return 1;
465 return 0;
468 [MethodImplAttribute (MethodImplOptions.NoInlining)]
469 public static Vector4 vector4_div_right (Vector4 v1, float v2) {
470 return v1 / v2;
473 public static int test_0_vector4_div_right () {
474 var v1 = new Vector4 (9.0f, 15.0f, 21.0f, 30.0f);
476 var v3 = vector4_div_right (v1, 3.0f);
477 if (v3.X != 3.0f || v3.Y != 5.0f || v3.Z != 7.0f || v3.W != 10.0f)
478 return 1;
479 return 0;
482 public static int test_0_vector4_length () {
483 var v = new Vector4 (2.0f, 2.0f, 2.0f, 2.0f);
484 return v.Length () == 4.0f ? 0 : 1;
488 // Vector3 tests
491 public static int test_0_vector3_ctor_1 () {
492 var v = new Vector3 (1.0f);
494 if (v.X != 1.0f)
495 return 1;
496 if (v.Y != 1.0f)
497 return 2;
498 if (v.Z != 1.0f)
499 return 3;
500 return 0;
503 public static int test_0_vector3_ctor_2 () {
504 var v = new Vector3 (1.0f, 2.0f, 3.0f);
506 if (v.X != 1.0f)
507 return 1;
508 if (v.Y != 2.0f)
509 return 2;
510 if (v.Z != 3.0f)
511 return 3;
512 return 0;
515 [MethodImplAttribute (MethodImplOptions.NoInlining)]
516 public static bool vector3_equals (Vector3 v1, Vector3 v2) {
517 // cmpeqps+pmovmskb
518 return v1.Equals (v2);
521 public static int test_0_vector3_equals () {
522 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
523 var v2 = new Vector3 (2.0f, 2.0f, 2.0f);
525 if (vector3_equals (v1, v2))
526 return 1;
527 if (!vector3_equals (v1, v1))
528 return 2;
529 return 0;
532 [MethodImplAttribute (MethodImplOptions.NoInlining)]
533 public static float vector3_dot (Vector3 v1, Vector3 v2) {
534 return Vector3.Dot (v1, v2);
537 public static int test_0_vector3_dot () {
538 var v1 = new Vector3 (1.0f, 1.0f, 1.0f);
539 var v2 = new Vector3 (2.0f, 2.0f, 2.0f);
541 float f = vector3_dot (v1, v2);
542 if (f != 6.0f)
543 return 1;
544 f = vector3_dot (v1, v1);
545 if (f != 3.0f)
546 return 2;
547 return 0;
550 [MethodImplAttribute (MethodImplOptions.NoInlining)]
551 public static Vector3 vector3_min (Vector3 v1, Vector3 v2) {
552 return Vector3.Min (v1, v2);
555 public static int test_0_vector3_min () {
556 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
557 var v2 = new Vector3 (5.0f, 6.0f, 7.0f);
559 var v3 = vector3_min (v1, v2);
560 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f)
561 return 1;
562 v3 = vector3_min (v2, v2);
563 if (v3.X != 5.0f || v3.Y != 6.0f || v3.Z != 7.0f)
564 return 2;
565 return 0;
568 [MethodImplAttribute (MethodImplOptions.NoInlining)]
569 public static Vector3 vector3_max (Vector3 v1, Vector3 v2) {
570 return Vector3.Max (v1, v2);
573 public static int test_0_vector3_max () {
574 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
575 var v2 = new Vector3 (5.0f, 6.0f, 7.0f);
577 var v3 = vector3_max (v1, v2);
578 if (v3.X != 5.0f || v3.Y != 6.0f || v3.Z != 7.0f)
579 return 1;
580 v3 = vector3_max (v1, v1);
581 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f)
582 return 2;
583 return 0;
586 [MethodImplAttribute (MethodImplOptions.NoInlining)]
587 public static Vector3 vector3_abs (Vector3 v1) {
588 return Vector3.Abs (v1);
591 public static int test_0_vector3_abs () {
592 var v1 = new Vector3 (-1.0f, -2.0f, -3.0f);
593 var v2 = new Vector3 (1.0f, 2.0f, 3.0f);
595 var v3 = vector3_abs (v1);
596 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f)
597 return 1;
598 v3 = vector3_abs (v2);
599 if (v3.X != 1.0f || v3.Y != 2.0f || v3.Z != 3.0f)
600 return 2;
601 return 0;
604 [MethodImplAttribute (MethodImplOptions.NoInlining)]
605 public static Vector3 vector3_sqrt (Vector3 v1) {
606 return Vector3.SquareRoot (v1);
609 public static int test_0_vector3_sqrt () {
610 var v1 = new Vector3 (1.0f, 0.0f, 1.0f);
612 var v3 = vector3_sqrt (v1);
613 if (v3.X != 1.0f || v3.Y != 0.0f || v3.Z != 1.0f)
614 return 1;
615 return 0;
618 [MethodImplAttribute (MethodImplOptions.NoInlining)]
619 public static Vector3 vector3_add (Vector3 v1, Vector3 v2) {
620 return v1 + v2;
623 public static int test_0_vector3_add () {
624 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
625 var v2 = new Vector3 (5.0f, 6.0f, 7.0f);
627 var v3 = vector3_add (v1, v2);
628 if (v3.X != 6.0f || v3.Y != 8.0f || v3.Z != 10.0f)
629 return 1;
630 return 0;
633 [MethodImplAttribute (MethodImplOptions.NoInlining)]
634 public static Vector3 vector3_sub (Vector3 v1, Vector3 v2) {
635 return v1 - v2;
638 public static int test_0_vector3_sub () {
639 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
640 var v2 = new Vector3 (3.0f, 5.0f, 7.0f);
642 var v3 = vector3_sub (v2, v1);
643 if (v3.X != 2.0f || v3.Y != 3.0f || v3.Z != 4.0f)
644 return 1;
645 return 0;
648 [MethodImplAttribute (MethodImplOptions.NoInlining)]
649 public static Vector3 vector3_mul (Vector3 v1, Vector3 v2) {
650 return v1 * v2;
653 public static int test_0_vector3_mul () {
654 var v1 = new Vector3 (1.0f, 2.0f, 3.0f);
655 var v2 = new Vector3 (3.0f, 5.0f, 6.0f);
657 var v3 = vector3_mul (v2, v1);
658 if (v3.X != 3.0f || v3.Y != 10.0f || v3.Z != 18.0f)
659 return 1;
660 return 0;
663 [MethodImplAttribute (MethodImplOptions.NoInlining)]
664 public static Vector3 vector3_mul_left (float v1, Vector3 v2) {
665 return v1 * v2;
668 public static int test_0_vector3_mul_left () {
669 var v1 = new Vector3 (3.0f, 5.0f, 6.0f);
671 var v3 = vector3_mul_left (2.0f, v1);
672 if (v3.X != 6.0f || v3.Y != 10.0f || v3.Z != 12.0f)
673 return 1;
674 return 0;
677 [MethodImplAttribute (MethodImplOptions.NoInlining)]
678 public static Vector3 vector3_mul_right (Vector3 v1, float v2) {
679 return v1 * v2;
682 public static int test_0_vector3_mul_right () {
683 var v1 = new Vector3 (3.0f, 5.0f, 6.0f);
685 var v3 = vector3_mul_right (v1, 2.0f);
686 if (v3.X != 6.0f || v3.Y != 10.0f || v3.Z != 12.0f)
687 return 1;
688 return 0;
691 [MethodImplAttribute (MethodImplOptions.NoInlining)]
692 public static Vector3 vector3_div (Vector3 v1, Vector3 v2) {
693 return v1 / v2;
696 public static int test_0_vector3_div () {
697 var v1 = new Vector3 (9.0f, 10.0f, 12.0f);
698 var v2 = new Vector3 (3.0f, 5.0f, 6.0f);
700 var v3 = vector3_div (v1, v2);
701 if (v3.X != 3.0f || v3.Y != 2.0f || v3.Z != 2.0f)
702 return 1;
703 return 0;
706 [MethodImplAttribute (MethodImplOptions.NoInlining)]
707 public static Vector3 vector3_div_right (Vector3 v1, float v2) {
708 return v1 / v2;
711 public static int test_0_vector3_div_right () {
712 var v1 = new Vector3 (9.0f, 15.0f, 21.0f);
714 var v3 = vector3_div_right (v1, 3.0f);
715 if (v3.X != 3.0f || v3.Y != 5.0f || v3.Z != 7.0f)
716 return 1;
717 return 0;
721 // Vector<T>
724 public static int test_0_vector_t_count () {
725 // This assumes a 16 byte simd register size
726 if (Vector<byte>.Count != 16)
727 return 1;
728 if (Vector<short>.Count != 8)
729 return 2;
730 if (Vector<int>.Count != 4)
731 return 3;
732 if (Vector<long>.Count != 2)
733 return 4;
734 return 0;
737 public static int test_0_vector_t_zero () {
738 var v = Vector<byte>.Zero;
739 for (int i = 0; i < Vector<byte>.Count; ++i)
740 if (v [i] != 0)
741 return 1;
742 var v2 = Vector<double>.Zero;
743 for (int i = 0; i < Vector<double>.Count; ++i)
744 if (v2 [i] != 0.0)
745 return 2;
746 return 0;
749 public static int test_0_vector_t_i1_accessor () {
750 var elems = new byte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
751 var v = new Vector<byte> (elems, 0);
752 for (int i = 0; i < Vector<byte>.Count; ++i)
753 if (v [i] != i + 1)
754 return 1;
755 if (v [0] != 1)
756 return 2;
757 if (v [1] != 2)
758 return 2;
759 if (v [15] != 16)
760 return 2;
761 try {
762 int r = v [-1];
763 return 3;
764 } catch (IndexOutOfRangeException) {
766 try {
767 int r = v [16];
768 return 4;
769 } catch (IndexOutOfRangeException) {
771 return 0;
774 public static int test_0_vector_t_i4_accessor () {
775 var elems = new int [] { 1, 2, 3, 4 };
776 var v = new Vector<int> (elems, 0);
777 for (int i = 0; i < Vector<int>.Count; ++i)
778 if (v [i] != i + 1)
779 return 1;
780 if (v [0] != 1)
781 return 2;
782 if (v [1] != 2)
783 return 2;
784 if (v [3] != 4)
785 return 2;
786 try {
787 int r = v [-1];
788 return 3;
789 } catch (IndexOutOfRangeException) {
791 try {
792 int r = v [Vector<int>.Count];
793 return 4;
794 } catch (IndexOutOfRangeException) {
796 return 0;
799 public static int test_0_vector_t_i8_accessor () {
800 var elems = new long [] { 1, 2 };
801 var v = new Vector<long> (elems, 0);
802 for (int i = 0; i < Vector<long>.Count; ++i)
803 if (v [i] != i + 1)
804 return 1;
805 if (v [0] != 1)
806 return 2;
807 if (v [1] != 2)
808 return 2;
809 try {
810 var r = v [-1];
811 return 3;
812 } catch (IndexOutOfRangeException) {
814 try {
815 var r = v [Vector<long>.Count];
816 return 4;
817 } catch (IndexOutOfRangeException) {
819 return 0;
822 public static int test_0_vector_t_r8_accessor () {
823 var elems = new double [] { 1.0, 2.0 };
824 var v = new Vector<double> (elems, 0);
825 for (int i = 0; i < Vector<double>.Count; ++i)
826 if (v [i] != (double)i + 1.0)
827 return 1;
828 if (v [0] != 1.0)
829 return 2;
830 if (v [1] != 2.0)
831 return 2;
832 try {
833 var r = v [-1];
834 return 3;
835 } catch (IndexOutOfRangeException) {
837 try {
838 var r = v [Vector<double>.Count];
839 return 4;
840 } catch (IndexOutOfRangeException) {
842 return 0;
845 public static int test_0_vector_t_i1_ctor_3 () {
846 var v = new Vector<byte> (5);
847 for (int i = 0; i < 16; ++i)
848 if (v [i] != 5)
849 return 1;
850 return 0;
853 public static int test_0_vector_t_i2_ctor_3 () {
854 var v = new Vector<short> (5);
855 for (int i = 0; i < 8; ++i)
856 if (v [i] != 5)
857 return 1;
858 return 0;
861 public static int test_0_vector_t_i4_ctor_3 () {
862 var v = new Vector<int> (0xffffeee);
863 for (int i = 0; i < 4; ++i)
864 if (v [i] != 0xffffeee)
865 return 1;
866 return 0;
869 public static int test_0_vector_t_i8_ctor_3 () {
870 var v = new Vector<long> (0xffffeeeeabcdefL);
871 for (int i = 0; i < 2; ++i)
872 if (v [i] != 0xffffeeeeabcdefL)
873 return 1;
874 return 0;
877 public static int test_0_vector_t_r4_ctor_3 () {
878 var v = new Vector<float> (0.5f);
879 for (int i = 0; i < 4; ++i) {
880 if (v [i] != 0.5f)
881 return 1;
883 return 0;
886 public static int test_0_vector_t_r8_ctor_3 () {
887 var v = new Vector<double> (0.5f);
888 for (int i = 0; i < 2; ++i) {
889 if (v [i] != 0.5f)
890 return 1;
892 return 0;
895 public static int test_0_vector_t_i1_ctor () {
896 var elems = new byte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
897 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
898 var v = new Vector<byte> (elems, 16);
899 for (int i = 0; i < 16; ++i)
900 if (v [i] != i)
901 return 1;
902 try {
903 var v2 = new Vector<byte> (elems, 16 + 4);
904 return 2;
905 } catch (IndexOutOfRangeException) {
907 return 0;
910 public static int test_0_vector_t_i1_ctor_2 () {
911 var elems = new byte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
912 var v = new Vector<byte> (elems);
913 for (int i = 0; i < 16; ++i)
914 if (v [i] != i + 1)
915 return 1;
916 try {
917 var elems2 = new byte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
918 var v2 = new Vector<byte> (elems2);
919 return 2;
920 } catch (IndexOutOfRangeException) {
922 return 0;
925 public static int test_0_vector_t_r4_equal () {
926 var elems1 = new float [4] { 1.0f, 1.0f, 1.0f, 1.0f };
927 var v1 = new Vector<float> (elems1);
928 var elems2 = new float [4] { 1.0f, 2.0f, 1.0f, 2.0f };
929 var v2 = new Vector<float> (elems2);
930 Vector<int> v = Vector.Equals (v1, v2);
931 if (v [0] != -1 || v [1] != 0 || v [2] != -1 || v [3] != 0)
932 return 1;
933 return 0;
936 public static int test_0_vector_t_r8_equal () {
937 var elems1 = new double [] { 1.0f, 1.0f };
938 var v1 = new Vector<double> (elems1);
939 var elems2 = new double [] { 1.0f, 2.0f };
940 var v2 = new Vector<double> (elems2);
941 Vector<long> v = Vector.Equals (v1, v2);
942 if (v [0] != -1 || v [1] != 0)
943 return 1;
944 return 0;
947 public static int test_0_vector_t_i8_equal () {
948 var elems1 = new long [] { 1, 1 };
949 var v1 = new Vector<long> (elems1);
950 var elems2 = new long [] { 1, 2 };
951 var v2 = new Vector<long> (elems2);
952 Vector<long> v = Vector.Equals (v1, v2);
953 if (v [0] != -1 || v [1] != 0)
954 return 1;
955 return 0;
958 public static int test_0_vector_t_i4_equal () {
959 var elems1 = new int [] { 1, 1, 1, 1 };
960 var v1 = new Vector<int> (elems1);
961 var elems2 = new int [] { 1, 2, 1, 2 };
962 var v2 = new Vector<int> (elems2);
963 Vector<int> v = Vector.Equals (v1, v2);
964 if (v [0] != -1 || v [1] != 0 || v [2] != -1 || v[3] != 0)
965 return 1;
966 return 0;
970 public static int test_0_vector_t_u4_equal () {
971 var elems1 = new uint [] { 1, 1, 1, 1 };
972 var v1 = new Vector<uint> (elems1);
973 var elems2 = new uint [] { 1, 2, 1, 2 };
974 var v2 = new Vector<uint> (elems2);
975 Vector<uint> v = Vector.Equals (v1, v2);
976 if (v [0] != 0xffffffff || v [1] != 0 || v [2] != 0xffffffff || v[3] != 0)
977 return 1;
978 return 0;
982 public static int test_0_vector_t_i2_equal () {
983 var elems1 = new short [] { 1, 1, 1, 1, 1, 1, 1, 1 };
984 var v1 = new Vector<short> (elems1);
985 var elems2 = new short [] { 1, 2, 1, 2, 1, 2, 1, 2 };
986 var v2 = new Vector<short> (elems2);
987 Vector<short> v = Vector.Equals (v1, v2);
988 for (int i = 0; i < Vector<short>.Count; ++i) {
989 if (i % 2 == 0 && v [i] != -1)
990 return 1;
991 if (i % 2 == 1 && v [i] != 0)
992 return 1;
994 return 0;
997 public static int test_0_vector_t_u2_equal () {
998 var elems1 = new ushort [] { 1, 1, 1, 1, 1, 1, 1, 1 };
999 var v1 = new Vector<ushort> (elems1);
1000 var elems2 = new ushort [] { 1, 2, 1, 2, 1, 2, 1, 2 };
1001 var v2 = new Vector<ushort> (elems2);
1002 Vector<ushort> v = Vector.Equals (v1, v2);
1003 for (int i = 0; i < Vector<ushort>.Count; ++i) {
1004 if (i % 2 == 0 && v [i] != 0xffff)
1005 return 1;
1006 if (i % 2 == 1 && v [i] != 0)
1007 return 1;
1009 return 0;
1012 public static int test_0_vector_t_i1_equal () {
1013 var elems1 = new sbyte [] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
1014 var v1 = new Vector<sbyte> (elems1);
1015 var elems2 = new sbyte [] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 };
1016 var v2 = new Vector<sbyte> (elems2);
1017 Vector<sbyte> v = Vector.Equals (v1, v2);
1018 for (int i = 0; i < Vector<sbyte>.Count; ++i) {
1019 if (i % 2 == 0 && v [i] != -1)
1020 return 1;
1021 if (i % 2 == 1 && v [i] != 0)
1022 return 1;
1024 return 0;
1027 public static int test_0_vector_t_u1_equal () {
1028 var elems1 = new byte [] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
1029 var v1 = new Vector<byte> (elems1);
1030 var elems2 = new byte [] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 };
1031 var v2 = new Vector<byte> (elems2);
1032 Vector<byte> v = Vector.Equals (v1, v2);
1033 for (int i = 0; i < Vector<byte>.Count; ++i) {
1034 if (i % 2 == 0 && v [i] != 0xff)
1035 return 1;
1036 if (i % 2 == 1 && v [i] != 0)
1037 return 1;
1039 return 0;
1042 /* op_Explicit () -> Vector<int32> */
1044 public static int test_0_vector_t_cast_vector_int32 () {
1045 var v1 = new Vector<long> (new long [] { 0x123456789abcdef0L, 0x23456789abcdef01L });
1046 var v = (Vector<int>)v1;
1047 if (BitConverter.IsLittleEndian) {
1048 if ((uint)v [0] != 0x9abcdef0 || (uint)v [1] != 0x12345678)
1049 return 1;
1050 if ((uint)v [2] != 0xabcdef01 || (uint)v [3] != 0x23456789)
1051 return 2;
1052 } else {
1053 if ((uint)v [1] != 0x9abcdef0 || (uint)v [0] != 0x12345678)
1054 return 1;
1055 if ((uint)v [3] != 0xabcdef01 || (uint)v [2] != 0x23456789)
1056 return 2;
1058 return 0;
1061 /* Vector.GreaterThanOrEqual */
1063 public static int test_0_vector_t_i1_ge () {
1064 var elems1 = new sbyte [] { 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 };
1065 var v1 = new Vector<sbyte> (elems1);
1066 var elems2 = new sbyte [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1067 var v2 = new Vector<sbyte> (elems2);
1068 Vector<sbyte> v = Vector.GreaterThanOrEqual (v1, v2);
1069 for (int i = 0; i < Vector<sbyte>.Count; ++i) {
1070 if (i % 2 == 0 && v [i] != -1)
1071 return 1;
1072 if (i % 2 == 1 && v [i] != 0)
1073 return 1;
1075 return 0;
1078 public static int test_0_vector_t_i2_ge () {
1079 var elems1 = new short [] { 1, 1, 0, 1, 1, 1, 0, 1 };
1080 var v1 = new Vector<short> (elems1);
1081 var elems2 = new short [] { 0, 2, 0, 2, 0, 2, 0, 2 };
1082 var v2 = new Vector<short> (elems2);
1083 Vector<short> v = Vector.GreaterThanOrEqual (v1, v2);
1084 for (int i = 0; i < Vector<short>.Count; ++i) {
1085 if (i % 2 == 0 && v [i] != -1)
1086 return 1;
1087 if (i % 2 == 1 && v [i] != 0)
1088 return 1;
1090 return 0;
1093 public static int test_0_vector_t_i4_ge () {
1094 var elems1 = new int [] { 1, 1, 0, 1 };
1095 var v1 = new Vector<int> (elems1);
1096 var elems2 = new int [] { 0, 2, 0, 2 };
1097 var v2 = new Vector<int> (elems2);
1098 Vector<int> v = Vector.GreaterThanOrEqual (v1, v2);
1099 if (v [0] != -1 || v [1] != 0 || v [2] != -1 || v[3] != 0)
1100 return 1;
1101 return 0;
1104 public static int test_0_vector_t_i8_ge () {
1105 var elems1 = new long [] { 1, 1 };
1106 var v1 = new Vector<long> (elems1);
1107 var elems2 = new long [] { 0, 1 };
1108 var v2 = new Vector<long> (elems2);
1109 Vector<long> v = Vector.GreaterThanOrEqual (v1, v2);
1110 if (v [0] != -1 || v [1] != -1)
1111 return 1;
1112 return 0;
1115 /* Vector.LessThan */
1117 public static int test_0_vector_t_i1_lt () {
1118 var elems1 = new sbyte [] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
1119 var v1 = new Vector<sbyte> (elems1);
1120 var elems2 = new sbyte [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1121 var v2 = new Vector<sbyte> (elems2);
1122 Vector<sbyte> v = Vector.LessThan (v2, v1);
1123 for (int i = 0; i < Vector<sbyte>.Count; ++i) {
1124 if (i % 2 == 0 && v [i] != -1)
1125 return 1;
1126 if (i % 2 == 1 && v [i] != 0)
1127 return 1;
1129 return 0;
1132 /* Vector.GreaterThan */
1134 public static int test_0_vector_t_i1_gt () {
1135 var elems1 = new sbyte [] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
1136 var v1 = new Vector<sbyte> (elems1);
1137 var elems2 = new sbyte [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1138 var v2 = new Vector<sbyte> (elems2);
1139 Vector<sbyte> v = Vector.GreaterThan (v1, v2);
1140 for (int i = 0; i < Vector<sbyte>.Count; ++i) {
1141 if (i % 2 == 0 && v [i] != -1)
1142 return 1;
1143 if (i % 2 == 1 && v [i] != 0)
1144 return 1;
1146 return 0;
1149 /* Vector.LessThanOrEqual */
1150 public static int test_0_vector_t_i1_le () {
1151 var elems1 = new sbyte [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1152 var v1 = new Vector<sbyte> (elems1);
1153 var elems2 = new sbyte [] { 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 };
1154 var v2 = new Vector<sbyte> (elems2);
1155 Vector<sbyte> v = Vector.LessThanOrEqual (v1, v2);
1156 for (int i = 0; i < Vector<sbyte>.Count; ++i) {
1157 if (i % 2 == 0 && v [i] != -1)
1158 return 1;
1159 if (i % 2 == 1 && v [i] != 0)
1160 return 1;
1162 return 0;
1165 /* Vector.Abs */
1167 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1168 public static Vector<T> vector_t_abs<T> (Vector<T> v1) where T: struct {
1169 return Vector.Abs (v1);
1172 public static int test_0_vector_t_u1_abs () {
1173 var elems1 = new byte [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1174 var v1 = new Vector<byte> (elems1);
1176 if (vector_t_abs (v1) != v1)
1177 return 1;
1178 return 0;
1181 public static int test_0_vector_t_u2_abs () {
1182 var elems1 = new ushort [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1183 var v1 = new Vector<ushort> (elems1);
1185 if (vector_t_abs (v1) != v1)
1186 return 1;
1187 return 0;
1190 public static int test_0_vector_t_u4_abs () {
1191 var elems1 = new uint [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1192 var v1 = new Vector<uint> (elems1);
1194 if (vector_t_abs (v1) != v1)
1195 return 1;
1196 return 0;
1199 public static int test_0_vector_t_u8_abs () {
1200 var elems1 = new ulong [] { 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 };
1201 var v1 = new Vector<ulong> (elems1);
1203 if (vector_t_abs (v1) != v1)
1204 return 1;
1205 return 0;
1208 public static int test_0_vector_t_i1_abs () {
1209 var elems1 = new sbyte [] { 1, -2, 1, -2, 1, -2, 1, -2, 1, -2, 1, -2, 1, -2, 1, -2 };
1210 var v1 = new Vector<sbyte> (elems1);
1211 var elems2 = new sbyte [] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 };
1212 var v2 = new Vector<sbyte> (elems2);
1214 if (vector_t_abs (v1) != v2)
1215 return 1;
1216 return 0;
1219 // Vector<T>.Add
1220 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1221 public static Vector<T> vector_add<T> (Vector<T> v1, Vector<T> v2) where T: struct {
1222 return v1 + v2;
1225 public static int test_0_vector_byte_add () {
1226 var v1 = new Vector<byte> (new byte[] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 });
1227 var v2 = new Vector<byte> (new byte[] { 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4 });
1229 var res = vector_add (v1, v1);
1230 if (res != v2)
1231 return 1;
1232 return 0;
1235 public static int test_0_vector_sbyte_add () {
1236 var v1 = new Vector<sbyte> (new sbyte[] { 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 });
1237 var v2 = new Vector<sbyte> (new sbyte[] { 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2 });
1239 var res = vector_add (v1, v1);
1240 if (res != v2)
1241 return 1;
1242 return 0;
1245 public static int test_0_vector_ushort_add () {
1246 var v1 = new Vector<ushort> (new ushort[] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 });
1247 var v2 = new Vector<ushort> (new ushort[] { 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4 });
1249 var res = vector_add (v1, v1);
1250 if (res != v2)
1251 return 1;
1252 return 0;
1255 public static int test_0_vector_short_add () {
1256 var v1 = new Vector<short> (new short[] { 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 });
1257 var v2 = new Vector<short> (new short[] { 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2 });
1259 var res = vector_add (v1, v1);
1260 if (res != v2)
1261 return 1;
1262 return 0;
1265 public static int test_0_vector_uint_add () {
1266 var v1 = new Vector<uint> (new uint[] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 });
1267 var v2 = new Vector<uint> (new uint[] { 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4 });
1269 var res = vector_add (v1, v1);
1270 if (res != v2)
1271 return 1;
1272 return 0;
1275 public static int test_0_vector_int_add () {
1276 var v1 = new Vector<int> (new int[] { 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 });
1277 var v2 = new Vector<int> (new int[] { 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, 2, 2, -2, 2, -2 });
1279 var res = vector_add (v1, v1);
1280 if (res != v2)
1281 return 1;
1282 return 0;
1285 public static int test_0_vector_double_add () {
1286 var v1 = new Vector<double> (new double[] { 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0 });
1287 var v2 = new Vector<double> (new double[] { 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0, 2.0, 2.0, -2.0, 2.0, -2.0 });
1289 var res = vector_add (v1, v1);
1290 if (res != v2)
1291 return 1;
1292 return 0;
1295 public static int test_0_vector_float_add () {
1296 var v1 = new Vector<float> (new float[] { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f });
1297 var v2 = new Vector<float> (new float[] { 2.0f, -2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f, 2.0f, 2.0f, -2.0f, 2.0f, -2.0f });
1299 var res = vector_add (v1, v1);
1300 if (res != v2)
1301 return 1;
1302 return 0;
1305 // Vector<T>.op_Subtraction
1307 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1308 public static Vector<T> vector_sub<T> (Vector<T> v1, Vector<T> v2) where T: struct {
1309 return v1 - v2;
1312 public static int test_0_vector_byte_sub () {
1313 var v1 = new Vector<byte> (new byte[] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 });
1315 var res = vector_sub (v1, v1);
1316 if (res != Vector<byte>.Zero)
1317 return 1;
1318 return 0;
1321 public static int test_0_vector_double_sub () {
1322 var v1 = new Vector<double> (new double[] { 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0 });
1324 var res = vector_sub (v1, v1);
1325 if (res != Vector<double>.Zero)
1326 return 1;
1327 return 0;
1330 public static int test_0_vector_float_sub () {
1331 var v1 = new Vector<float> (new float[] { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f });
1333 var res = vector_sub (v1, v1);
1334 if (res != Vector<float>.Zero)
1335 return 1;
1336 return 0;
1339 // Vector<T>.op_Multiply
1340 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1341 public static Vector<T> vector_mul<T> (Vector<T> v1, Vector<T> v2) where T: struct {
1342 return v1 * v2;
1345 public static int test_0_vector_int_mul () {
1346 var v1 = new Vector<int> (new int[] { 1, 2, -1, 2, 1, 2, -1, 2, 1, -2, 1, 2, 1, 2, -1, 2 });
1347 var v2 = new Vector<int> (new int[] { 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4 });
1349 var res = vector_mul (v1, v1);
1350 if (res != v2)
1351 return 1;
1352 return 0;
1355 public static int test_0_vector_double_mul () {
1356 var v1 = new Vector<double> (new double[] { 2.0, -1.0, 2.0, -1.0 });
1357 var v2 = new Vector<double> (new double[] { 4.0, 1.0, 4.0, 1.0 });
1359 var res = vector_mul (v1, v1);
1360 if (res != v2)
1361 return 1;
1362 return 0;
1365 public static int test_0_vector_float_mul () {
1366 var v1 = new Vector<float> (new float[] { 2.0f, -1.0f, 2.0f, -1.0f });
1367 var v2 = new Vector<float> (new float[] { 4.0f, 1.0f, 4.0f, 1.0f });
1369 var res = vector_mul (v1, v1);
1370 if (res != v2)
1371 return 1;
1372 return 0;
1375 // Vector<T>.op_Division
1376 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1377 public static Vector<T> vector_div<T> (Vector<T> v1, Vector<T> v2) where T: struct {
1378 return v1 / v2;
1381 public static int test_0_vector_double_div () {
1382 var v1 = new Vector<double> (new double[] { 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0 });
1383 var v2 = new Vector<double> (new double[] { 1.0, 1.0, 1.0, 1.0 });
1385 var res = vector_div (v1, v1);
1386 if (res != v2)
1387 return 1;
1388 return 0;
1391 public static int test_0_vector_float_div () {
1392 var v1 = new Vector<float> (new float[] { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f });
1393 var v2 = new Vector<float> (new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
1395 var res = vector_div (v1, v1);
1396 if (res != v2)
1397 return 1;
1398 return 0;
1401 // Vector<T>.CopyTo
1402 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1403 public static void vector_copyto<T> (Vector<T> v1, T[] array, int index) where T: struct {
1404 v1.CopyTo (array, index);
1407 public static int test_0_vector_byte_copyto () {
1408 var v1 = new Vector<byte> (new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
1410 byte[] arr = new byte [256];
1411 vector_copyto (v1, arr, 1);
1412 for (int i = 0; i < 16; ++i)
1413 if (arr [i + 1] != (i + 1))
1414 return 1;
1415 vector_copyto (v1, arr, 240);
1416 try {
1417 vector_copyto (v1, arr, 241);
1418 return 1;
1419 } catch (ArgumentException) {
1421 return 0;