2009-01-04 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / mini / basic-simd.cs
1 using System;
2 using Mono.Simd;
3
4 public class SimdTests {
5         public static int test_0_bug_462457 ()
6         {
7                 Vector4f sum = new Vector4f(0,0,0,0);
8                 Vector4f add = new Vector4f(1.0F,1.0F,1.0F,1.0F);
9
10                 for (int i = 0; i < 10; ++i)
11                                 sum = sum + add;
12
13                 if (sum.X != 10f)
14                         return 1;
15                 return 0;
16         }
17
18         public static int test_0_vector16b_operator_neq () {
19                 Vector16b a = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8);
20                 Vector16b b = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8);
21                 if (a != b)
22                         return 1;
23                 b.V0 = 99;
24                 if (!(a != b))
25                         return 2;
26                 return 0;
27         }
28
29         public static int test_0_vector16b_operator_eq () {
30                 Vector16b a = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8);
31                 Vector16b b = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8);
32                 if (!(a == b))
33                         return 1;
34                 b.V0 = 99;
35                 if (a == b)
36                         return 2;
37                 return 0;
38         }
39
40         public static int test_0_vector8us_operator_neq () {
41                 Vector8us a = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8);
42                 Vector8us b = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8);
43                 if (a != b)
44                         return 1;
45                 b.V0 = 99;
46                 if (!(a != b))
47                         return 2;
48                 return 0;
49         }
50
51         public static int test_0_vector8us_operator_eq () {
52                 Vector8us a = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8);
53                 Vector8us b = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8);
54                 if (!(a == b))
55                         return 1;
56                 b.V0 = 99;
57                 if (a == b)
58                         return 2;
59                 return 0;
60         }
61
62         public static int test_0_set_vector4f_operator_neq () {
63                 Vector4f a = new Vector4f(1, 2, 3, 4);
64                 Vector4f b = new Vector4f(1, 2, 3, 4);
65                 if (a != b)
66                         return 1;
67
68                 a = new Vector4f(1, 2, float.NaN, 4);
69                 b = new Vector4f(1, 2, float.NaN, 4);
70                 if (!(a != b)) //NaN is always !=
71                         return 2;
72
73                 a = new Vector4f(1, 2, float.NaN, 4);
74                 b = new Vector4f(1, 2, 10, 4);
75                 if (!(a != b))
76                         return 3;
77
78                 a = new Vector4f(1, 2, float.PositiveInfinity, 4);
79                 b = new Vector4f(1, 2, float.PositiveInfinity, 4);
80                 if (a != b)
81                         return 4;
82
83                 a = new Vector4f(1, 2, 20, 4);
84                 b = new Vector4f(1, 2, 30, 4);
85                 if (!(a != b))
86                         return 5;
87
88                 return 0;
89         }
90         
91         public static int test_0_set_vector4f_operator_eq () {
92                 Vector4f a = new Vector4f(1, 2, 3, 4);
93                 Vector4f b = new Vector4f(1, 2, 3, 4);
94                 if (!(a == b))
95                         return 1;
96
97                 a = new Vector4f(1, 2, float.NaN, 4);
98                 b = new Vector4f(1, 2, float.NaN, 4);
99                 if (a == b)
100                         return 2;
101
102                 a = new Vector4f(1, 2, 10, 4);
103                 b = new Vector4f(1, 2, float.NaN, 4);
104                 if (a == b)
105                         return 3;
106
107                 a = new Vector4f(1, 2, float.PositiveInfinity, 4);
108                 b = new Vector4f(1, 2, float.PositiveInfinity, 4);
109                 if (!(a == b))
110                         return 4;
111                 return 0;
112         }
113
114         public static int test_1_set_vector4ui_operator_neq () {
115                 Vector4ui a = new Vector4ui(1, 2, 3, 4);
116                 Vector4ui b = new Vector4ui(1, 2, 3, 4);
117                 if (a != b)
118                         return 0;
119                 return 1;
120         }
121
122         public static int test_0_set_vector4ui_operator_neq () {
123                 Vector4ui a = new Vector4ui(1, 2, 3, 4);
124                 Vector4ui b = new Vector4ui(111, 2, 3, 4);
125                 if (a != b)
126                         return 0;
127                 return 1;
128         }
129
130         public static int test_0_set_vector4ui_operator_eq () {
131                 Vector4ui a = new Vector4ui(1, 2, 3, 4);
132                 Vector4ui b = new Vector4ui(1, 2, 3, 4);
133                 if (a == b)
134                         return 0;
135                 return 1;
136         }
137
138         public static int test_1_set_vector4ui_operator_eq () {
139                 Vector4ui a = new Vector4ui(1, 2, 3, 4);
140                 Vector4ui b = new Vector4ui(111, 2, 3, 4);
141                 if (a == b)
142                         return 0;
143                 return 1;
144         }
145
146         public static int test_0_set_vector_small_array () {
147                 uint[] array = new uint[3];
148
149                 try {
150                         array.SetVector (new Vector4ui (), 0);
151                         return 1;
152                 } catch (IndexOutOfRangeException) {
153                 }
154                 return 0;
155         }
156         
157         public static int test_0_set_vector_negative_index () {
158                 uint[] array = new uint[4];
159
160                 try {
161                         array.SetVector (new Vector4ui (), -1);
162                         return 1;
163                 } catch (IndexOutOfRangeException) {
164                 }
165                 return 0;
166         }
167
168         public static int test_0_set_vector_bounds_error () {
169                 uint[] array = new uint[4];
170
171                 try {
172                         array.SetVector (new Vector4ui (), 1);
173                         return 1;
174                 } catch (IndexOutOfRangeException) {
175                 }
176                 return 0;
177         }
178
179         public static int test_0_set_vector () {
180                 uint[] array = new uint[10];
181                 Vector4ui a = new Vector4ui (11, 22, 33, 44);
182
183                 array.SetVector (a, 1);
184
185                 if (array [1] != 11)
186                         return 1;
187                 if (array [2] != 22)
188                         return 2;
189                 if (array [3] != 33)
190                         return 3;
191                 if (array [4] != 44)
192                         return 4;
193                 return 0;
194         }
195
196         public static int test_0_get_vector_small_array () {
197                 uint[] array = new uint[3];
198
199                 try {
200                         Vector4ui res = array.GetVector (0);
201                         return 1;
202                 } catch (IndexOutOfRangeException) {
203                 }
204                 return 0;
205         }
206         
207         public static int test_0_get_vector_negative_index () {
208                 uint[] array = new uint[4];
209
210                 try {
211                         Vector4ui res = array.GetVector (-1);
212                         return 1;
213                 } catch (IndexOutOfRangeException) {
214                 }
215                 return 0;
216         }
217
218         public static int test_0_get_vector_bounds_error () {
219                 uint[] array = new uint[4];
220
221                 try {
222                         Vector4ui res = array.GetVector (1);
223                         return 1;
224                 } catch (IndexOutOfRangeException) {
225                 }
226                 return 0;
227         }
228         
229         public static int test_0_get_vector () {
230                 uint[] array = new uint[] { 11, 22, 33, 44, 55, 66, 77, 88, 99, 111 };
231
232                 Vector4ui res = array.GetVector (1);
233
234                 if (res.X != 22)
235                         return 1;
236                 if (res.Y != 33)
237                         return 2;
238                 if (res.Z != 44)
239                         return 3;
240                 if (res.W != 55)
241                         return 4;
242
243                 return 0;
244         }
245         
246         public static int test_0_accessor_vecto2l () {
247                 Vector2l a = new Vector2l (3, 2);
248
249                 if (a.X != 3)
250                         return 1;
251                 if (a.Y != 2)
252                         return 2;
253
254                 a.X = 500000000000055l;
255                 a.Y = -12345678900l;
256
257                 if (a.X != 500000000000055l)
258                         return 3;
259                 if (a.Y != -12345678900l)
260                         return 4;
261                 return 0;
262         }
263
264         public static int test_0_accessor_vecto2d () {
265                 Vector2d a = new Vector2d (3, 2);
266
267                 if (a.X != 3)
268                         return 1;
269                 if (a.Y != 2)
270                         return 2;
271
272                 a.X = 5000000000000;
273                 a.Y = -0.5;
274
275                 if (a.X != 5000000000000)
276                         return 3;
277                 if (a.Y != -0.5)
278                         return 4;
279                 return 0;
280         }
281
282         public static int test_0_accessor_vecto4f () {
283                 Vector4f a = new Vector4f (1,2,3,4);
284
285                 if (a.X != 1)
286                         return 1;
287                 if (a.Y != 2)
288                         return 2;
289                 if (a.Z != 3)
290                         return 3;
291                 if (a.W != 4)
292                         return 4;
293
294                 a.X = 128f;
295                 a.Y = 256f;
296                 a.Z = -0.5f;
297                 a.W = 0.125f;
298
299                 if (a.X != 128)
300                         return 5;
301                 if (a.Y != 256)
302                         return 6;
303                 if (a.Z != -0.5)
304                         return 7;
305                 if (a.W != 0.125)
306                         return 8;
307                 return 0;
308         }
309
310         public static int test_0_accessor_vecto4i () {
311                 Vector4i a = new Vector4i (0x70000000, -1, 3, 4);
312
313                 if (a.X != 0x70000000)
314                         return 1;
315                 if (a.Y != -1)
316                         return 2;
317                 if (a.Z != 3)
318                         return 3;
319                 if (a.W != 4)
320                         return 4;
321
322                 a.X = 11;
323                 a.Y = 22;
324                 a.Z = 33333344;
325                 a.W = -44444444;
326                 
327                 if (a.X != 11)
328                         return 5;
329                 if (a.Y != 22)
330                         return 6;
331                 if (a.Z != 33333344)
332                         return 7;
333                 if (a.W != -44444444)
334                         return 8;
335                 return 0;
336         }
337
338         public static int test_0_accessor_vecto4ui () {
339                 Vector4ui a = new Vector4ui (0xF0000000, 0xF0000, 3, 4);
340
341                 if (a.X != 0xF0000000)
342                         return 1;
343                 if (a.Y != 0xF0000)
344                         return 2;
345                 if (a.Z != 3)
346                         return 3;
347                 if (a.W != 4)
348                         return 4;
349
350                 a.X = 11;
351                 a.Y = 22;
352                 a.Z = 33333344;
353                 a.W = 44444444;
354
355                 if (a.X != 11)
356                         return 5;
357                 if (a.Y != 22)
358                         return 6;
359                 if (a.Z != 33333344)
360                         return 7;
361                 if (a.W != 44444444)
362                         return 8;
363                 return 0;
364         }
365         
366         static float use_getter_with_byref (ref Vector4f a) {
367                 return a.W;
368         }
369  
370         public static int test_0_accessor_and_byref_var () {
371                 Vector4f a = new Vector4f (1, 2, 3, 4);
372                 if (use_getter_with_byref (ref a) != 4)
373                         return 1;
374                 return 0;
375         }
376         
377         public static unsafe int test_0_vector2ul_slr () {
378                 Vector2ul a = new Vector2ul (1, 6);
379
380                 Vector2ul c = a >> 1;
381                 if (c.X != 0)
382                         return 1;
383                 if (c.Y != 3)
384                         return 2;       
385                 return 0;
386         }
387
388         public static unsafe int test_0_vector2l_cmp_gt () {
389                 Vector2l a = new Vector2l (10, 5);
390                 Vector2l b = new Vector2l (-1, 5);
391
392                 Vector2l c = a.CompareGreaterThan (b);
393         
394                 if (c.X != -1)
395                         return 1;
396                 if (c.Y != 0)
397                         return 2;
398                 return 0;
399         }
400
401         public static unsafe int test_0_vector2l_cmp_eq () {
402                 Vector2l a = new Vector2l (0xFF,          5);
403                 Vector2l b = new Vector2l (0xFF000000FFL, 5);
404
405                 Vector2l c = a.CompareEqual (b);
406         
407                 if (c.X != 0)
408                         return 1;
409                 if (c.Y != -1)
410                         return 2;
411                 return 0;
412         }
413
414         public static unsafe int test_0_vector2l_srl () {
415                 Vector2l a = new Vector2l (1, 6);
416
417                 Vector2l c = a.LogicalRightShift (1);
418         
419                 if (c.X != 0)
420                         return 1;
421                 if (c.Y != 3)
422                         return 2;
423                 return 0;
424         }
425
426         public static unsafe int test_0_vector2l_unpack_high () {
427                 Vector2l a = new Vector2l (1, 6);
428                 Vector2l b = new Vector2l (3, 4);
429
430                 Vector2l c = a.UnpackHigh (b);
431         
432                 if (c.X != 6)
433                         return 1;
434                 if (c.Y != 4)
435                         return 2;
436                 return 0;
437         }
438
439         public static unsafe int test_0_vector2l_unpack_low () {
440                 Vector2l a = new Vector2l (1, 6);
441                 Vector2l b = new Vector2l (3, 4);
442
443                 Vector2l c = a.UnpackLow (b);
444         
445                 if (c.X != 1)
446                         return 1;
447                 if (c.Y != 3)
448                         return 2;
449                 return 0;
450         }
451
452         public static unsafe int test_0_vector2l_xor () {
453                 Vector2l a = new Vector2l (1, 6);
454                 Vector2l b = new Vector2l (3, 4);
455
456                 Vector2l c = a ^ b;
457         
458                 if (c.X != 2)
459                         return 1;
460                 if (c.Y != 2)
461                         return 2;
462                 return 0;
463         }
464
465         public static unsafe int test_0_vector2l_or () {
466                 Vector2l a = new Vector2l (1, 6);
467                 Vector2l b = new Vector2l (3, 4);
468
469                 Vector2l c = a | b;
470         
471                 if (c.X != 3)
472                         return 1;
473                 if (c.Y != 6)
474                         return 2;
475                 return 0;
476         }
477
478         public static unsafe int test_0_vector2l_and () {
479                 Vector2l a = new Vector2l (1, 6);
480                 Vector2l b = new Vector2l (3, 4);
481
482                 Vector2l c = a & b;
483         
484                 if (c.X != 1)
485                         return 1;
486                 if (c.Y != 4)
487                         return 2;
488                 return 0;
489         }
490
491         public static unsafe int test_0_vector2l_shl() {
492                 Vector2l a = new Vector2l (1, 6);
493
494                 Vector2l c = a << 3;
495         
496                 if (c.X != 8)
497                         return 1;
498                 if (c.Y != 48)
499                         return 2;
500                 return 0;
501         }
502         public static unsafe int test_0_vector2l_sub() {
503                 Vector2l a = new Vector2l (1, 6);
504                 Vector2l b = new Vector2l (3, 4);
505
506                 Vector2l c = a - b;
507         
508                 if (c.X != -2)
509                         return 1;
510                 if (c.Y != 2)
511                         return 2;
512                 return 0;
513         }
514
515         public static unsafe int test_0_vector2l_add () {
516                 Vector2l a = new Vector2l (1, 2);
517                 Vector2l b = new Vector2l (3, 4);
518
519                 Vector2l c = a + b;
520         
521                 if (c.X != 4)
522                         return 1;
523                 if (c.Y != 6)
524                         return 2;
525                 return 0;
526         }
527
528         public static unsafe int test_0_vector2d_dup () {
529                 Vector2d a = new Vector2d (3, 2);
530
531                 Vector2d c = a.Duplicate ();
532         
533                 if (c.X != 3)
534                         return 1;
535                 if (c.Y != 3)
536                         return 2;
537                 return 0;
538         }
539
540         public static unsafe int test_0_vector2d_cmp_eq () {
541                 Vector2d a = new Vector2d (3, 2);
542                 Vector2d b = new Vector2d (3, 4);
543
544                 Vector4ui c = (Vector4ui)a.CompareEqual (b);
545         
546                 if (c.X != 0xFFFFFFFF)
547                         return 1;
548                 if (c.Y != 0xFFFFFFFF)
549                         return 2;
550                 if (c.Z != 0)
551                         return 3;
552                 if (c.W != 0)
553                         return 4;
554                 return 0;
555         }
556
557         public static unsafe int test_0_vector2d_unpack_low () {
558                 Vector2d a = new Vector2d (1, 2);
559                 Vector2d b = new Vector2d (4, 5);
560
561                 Vector2d c = a.InterleaveLow (b);
562         
563                 if (c.X != 1)
564                         return 1;
565                 if (c.Y != 4)
566                         return 2;
567                 return 0;
568         }
569
570         public static unsafe int test_0_vector2d_unpack_high () {
571                 Vector2d a = new Vector2d (1, 2);
572                 Vector2d b = new Vector2d (4, 5);
573
574                 Vector2d c = a.InterleaveHigh (b);
575         
576                 if (c.X != 2)
577                         return 1;
578                 if (c.Y != 5)
579                         return 2;
580                 return 0;
581         }
582         public static unsafe int test_0_vector2d_addsub () {
583                 Vector2d a = new Vector2d (1, 2);
584                 Vector2d b = new Vector2d (4, 1);
585
586                 Vector2d c = a.AddSub (b);
587         
588                 if (c.X != -3)
589                         return 1;
590                 if (c.Y != 3)
591                         return 2;
592                 return 0;
593         }
594         public static unsafe int test_0_vector2d_hsub () {
595                 Vector2d a = new Vector2d (1, 2);
596                 Vector2d b = new Vector2d (4, 1);
597
598                 Vector2d c = a.HorizontalSub (b);
599         
600                 if (c.X != -1)
601                         return 1;
602                 if (c.Y != 3)
603                         return 2;
604                 return 0;
605         }
606
607         public static unsafe int test_0_vector2d_hadd () {
608                 Vector2d a = new Vector2d (1, 2);
609                 Vector2d b = new Vector2d (4, 0);
610
611                 Vector2d c = a.HorizontalAdd (b);
612         
613                 if (c.X != 3)
614                         return 1;
615                 if (c.Y != 4)
616                         return 2;
617                 return 0;
618         }
619
620         public static unsafe int test_0_vector2d_min () {
621                 Vector2d a = new Vector2d (1, 2);
622                 Vector2d b = new Vector2d (4, 0);
623
624                 Vector2d c = a.Min (b);
625         
626                 if (c.X != 1)
627                         return 1;
628                 if (c.Y != 0)
629                         return 2;
630                 return 0;
631         }
632
633         public static unsafe int test_0_vector2d_max () {
634                 Vector2d a = new Vector2d (1, 2);
635                 Vector2d b = new Vector2d (4, 0);
636
637                 Vector2d c = a.Max (b);
638         
639                 if (c.X != 4)
640                         return 1;
641                 if (c.Y != 2)
642                         return 2;
643                 return 0;
644         }
645
646
647         public static unsafe int test_0_vector2d_andnot () {
648                 Vector2d a = new Vector2d (1, 2);
649                 Vector2d b = new Vector2d (3, 4);
650
651                 Vector4ui c = (Vector4ui)a.AndNot (b);
652                 Vector4ui ta = (Vector4ui)a;
653                 Vector4ui tb = (Vector4ui)b;
654         
655                 if (c.X != (~ta.X & tb.X))
656                         return 1;
657                 if (c.Y != (~ta.Y & tb.Y))
658                         return 2;
659                 if (c.Z != (~ta.Z & tb.Z))
660                         return 3;
661                 if (c.W != (~ta.W & tb.W))
662                         return 4;
663                 return 0;
664         }
665
666         public static unsafe int test_0_vector2d_div () {
667                 Vector2d a = new Vector2d (1, 2);
668                 Vector2d b = new Vector2d (4, 5);
669
670                 Vector2d c = a / b;
671         
672                 if (c.X != 0.25)
673                         return 1;
674                 if (c.Y != 0.4)
675                         return 2;
676                 return 0;
677         }
678
679         public static unsafe int test_0_vector2d_mul () {
680                 Vector2d a = new Vector2d (1, 2);
681                 Vector2d b = new Vector2d (3, 5);
682
683                 Vector2d c = a * b;
684         
685                 if (c.X != 3)
686                         return 1;
687                 if (c.Y != 10)
688                         return 2;
689                 return 0;
690         }
691         public static unsafe int test_0_vector2d_sub () {
692                 Vector2d a = new Vector2d (1, 2);
693                 Vector2d b = new Vector2d (3, 5);
694
695                 Vector2d c = a - b;
696         
697                 if (c.X != -2)
698                         return 1;
699                 if (c.Y != -3)
700                         return 2;
701                 return 0;
702         }
703         public static unsafe int test_0_vector2d_add () {
704                 Vector2d a = new Vector2d (1, 2);
705                 Vector2d b = new Vector2d (3, 4);
706
707                 Vector2d c = a + b;
708         
709                 if (c.X != 4)
710                         return 1;
711                 if (c.Y != 6)
712                         return 2;
713                 return 0;
714         }
715         public static unsafe int test_0_vector2d_xor () {
716                 Vector2d a = new Vector2d (1, 2);
717                 Vector2d b = new Vector2d (3, 4);
718
719                 Vector4ui c = (Vector4ui)(a ^ b);
720                 Vector4ui ta = (Vector4ui)a;
721                 Vector4ui tb = (Vector4ui)b;
722
723                 if (c.X != (ta.X ^ tb.X))
724                         return 1;
725                 if (c.Y != (ta.Y ^ tb.Y))
726                         return 2;
727                 if (c.Z != (ta.Z ^ tb.Z))
728                         return 3;
729                 if (c.W != (ta.W ^ tb.W))
730                         return 4;
731                 return 0;
732         }
733
734         public static unsafe int test_0_vector2d_or () {
735                 Vector2d a = new Vector2d (1, 2);
736                 Vector2d b = new Vector2d (3, 4);
737
738                 Vector4ui c = (Vector4ui)(a | b);
739                 Vector4ui ta = (Vector4ui)a;
740                 Vector4ui tb = (Vector4ui)b;
741         
742                 if (c.X != (ta.X | tb.X))
743                         return 1;
744                 if (c.Y != (ta.Y | tb.Y))
745                         return 2;
746                 if (c.Z != (ta.Z | tb.Z))
747                         return 3;
748                 if (c.W != (ta.W | tb.W))
749                         return 4;
750                 return 0;
751         }
752
753         public static unsafe int test_0_vector2d_and () {
754                 Vector2d a = new Vector2d (1, 2);
755                 Vector2d b = new Vector2d (3, 4);
756
757                 Vector4ui c = (Vector4ui)(a & b);
758                 Vector4ui ta = (Vector4ui)a;
759                 Vector4ui tb = (Vector4ui)b;
760
761                 if (c.X != (ta.X & tb.X))
762                         return 1;
763                 if (c.Y != (ta.Y & tb.Y))
764                         return 2;
765                 if (c.Z != (ta.Z & tb.Z))
766                         return 3;
767                 if (c.W != (ta.W & tb.W))
768                         return 4;
769                 return 0;
770         }
771
772         public static unsafe int test_vector8s_pack_signed_sat () {
773                 Vector8s a = new Vector8s (-200, 200, 3, 0, 5, 6, 5, 4);
774                 Vector8s b = new Vector8s (9, 2, 1, 2, 3, 6, 5, 6);
775
776                 Vector16sb c = a.PackWithSignedSaturation (b);
777
778                 if (c.V0 != -128)
779                         return 1;
780                 if (c.V1 != 127)
781                         return 2;
782
783                 return 0;
784         }
785
786         public static unsafe int test_vector16sb_sub_sat () {
787                 Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
788                 Vector16sb b = new Vector16sb (-100, 100,11,12,4,5,6,7,8,9,10,11,12,13,14,15);
789
790                 Vector16sb c = a.SubtractWithSaturation (b);
791
792                 if (c.V0 != 127)
793                         return 1;
794                 if (c.V1 != -128)
795                         return 2;
796                 if (c.V2 != 0)
797                         return 3;
798                 if (c.V3 != 0)
799                         return 4;
800                 if (c.V4 != 9)
801                         return 5;
802                 if (c.V5 != 9)
803                         return 6;
804                 if (c.V6 != 9)
805                         return 7;
806                 if (c.V7 != -7)
807                         return 8;
808                 return 0;
809         }
810
811         public static unsafe int test_vector16sb_add_sat () {
812                 Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
813                 Vector16sb b = new Vector16sb (100, -100,11,12,4,5,6,7,8,9,10,11,12,13,14,15);
814
815                 Vector16sb c = a.AddWithSaturation (b);
816
817                 if (c.V0 != 127)
818                         return 1;
819                 if (c.V1 != -128)
820                         return 2;
821                 if (c.V2 != 22)
822                         return 3;
823                 if (c.V3 != 24)
824                         return 4;
825                 if (c.V4 != 17)
826                         return 5;
827                 if (c.V5 != 19)
828                         return 6;
829                 if (c.V6 != 21)
830                         return 7;
831                 if (c.V7 != 7)
832                         return 8;
833                 return 0;
834         }
835
836         public static unsafe int test_vector16sb_cmp_gt () {
837                 Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
838                 Vector16sb b = new Vector16sb (-100, 100,11,12,4,5,6,7,8,9,10,11,12,13,14,15);
839
840                 Vector16sb c = a.CompareGreaterThan (b);
841
842                 if (c.V0 != -1)
843                         return 1;
844                 if (c.V1 != 0)
845                         return 2;
846                 if (c.V2 != 0)
847                         return 3;
848                 if (c.V3 != 0)
849                         return 4;
850                 if (c.V4 != -1)
851                         return 5;
852                 if (c.V5 != -1)
853                         return 6;
854                 if (c.V6 != -1)
855                         return 7;
856                 return 0;
857         }
858
859
860         public static int test_0_vector4ui_pack_with_sat () {
861                 Vector4ui a = new Vector4ui (0xF0000000,0xF0000,3,4);
862                 Vector4ui b = new Vector4ui (5,6,7,8);
863
864                 Vector8us c = a.SignedPackWithUnsignedSaturation (b);
865
866                 if (c.V0 != 0)
867                         return 1;
868                 if (c.V1 != 0xFFFF)
869                         return 2;
870                 if (c.V2 != 3)
871                         return 3;
872                 if (c.V3 != 4)
873                         return 4;
874                 if (c.V4 != 5)
875                         return 5;
876                 if (c.V5 != 6)
877                         return 6;
878                 if (c.V6 != 7)
879                         return 7;
880                 if (c.V7 != 8)
881                         return 8;
882                 return 0;
883         }
884
885         public static int test_0_vector8us_pack_with_sat () {
886                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
887                 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
888                 Vector16b c = a.SignedPackWithUnsignedSaturation (b);
889
890                 if (c.V0 != 0)
891                         return 1;
892                 if (c.V1 != 1)
893                         return 2;
894                 if (c.V2 != 2)
895                         return 3;
896                 if (c.V8 != 3)
897                         return 4;
898                 if (c.V15 != 10)
899                         return 5;
900                 return 0;
901         }
902
903         public static int test_0_vector8us_mul_high () {
904                 Vector8us a = new Vector8us (0xFF00, 2, 3, 0, 5, 6, 5, 4);
905                 Vector8us b = new Vector8us (0xFF00, 2, 1, 2, 3, 6, 5, 6);
906                 Vector8us c = a.MultiplyStoreHigh (b);
907
908                 if (c.V0 != 0xFE01)
909                         return 1;
910                 if (c.V1 != 0)
911                         return 2;
912                 if (c.V2 != 0)
913                         return 3;
914                 if (c.V3 != 0)
915                         return 4;
916                 if (c.V4 != 0)
917                         return 5;
918                 if (c.V5 != 0)
919                         return 6;
920                 if (c.V6 != 0)
921                         return 7;
922                 if (c.V7 != 0)
923                         return 8;
924                 return 0;
925         }
926
927         public static int test_0_vector8us_cmpeq () {
928                 Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4);
929                 Vector8us b = new Vector8us (9, 2, 1, 2, 3, 6, 5, 6);
930                 Vector8us c = a.CompareEqual (b);
931
932                 if (c.V0 != 0)
933                         return 1;
934                 if (c.V1 != 0xFFFF)
935                         return 2;
936                 if (c.V2 != 0)
937                         return 3;
938                 if (c.V3 != 0)
939                         return 4;
940                 if (c.V4 != 0)
941                         return 5;
942                 if (c.V5 != 0xFFFF)
943                         return 6;
944                 if (c.V6 != 0xFFFF)
945                         return 7;
946                 if (c.V7 != 0)
947                         return 8;
948                 return 0;
949         }
950
951
952         public static int test_0_vector4ui_cmpeq () {
953                 Vector4ui a = new Vector4ui (6,1,6,3);
954                 Vector4ui b = new Vector4ui (3,4,6,7);
955                 Vector4ui c = a.CompareEqual (b);
956
957                 if (c.X != 0)
958                         return 1;
959                 if (c.Y != 0)
960                         return 2;
961                 if (c.Z != 0xFFFFFFFF)
962                         return 3;
963                 if (c.W != 0)
964                         return 4;
965                 return 0;
966         }
967
968         public static int test_0_vector4ui_shuffle () {
969                 Vector4ui a = new Vector4ui (1,2,3,4);
970                 Vector4ui c = a.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
971
972                 if (c.X != 2)
973                         return 1;
974                 if (c.Y != 4)
975                         return 2;
976                 if (c.Z != 1)
977                         return 3;
978                 if (c.W != 3)
979                         return 4;
980                 return 0;
981         }
982
983         public static int test_0_vector4ui_min () {
984                 Vector4ui a = new Vector4ui (6,1,6,3);
985                 Vector4ui b = new Vector4ui (3,4,6,7);
986                 Vector4ui c = a.Min (b);
987
988                 if (c.X != 3)
989                         return 1;
990                 if (c.Y != 1)
991                         return 2;
992                 if (c.Z != 6)
993                         return 3;
994                 if (c.W != 3)
995                         return 4;
996                 return 0;
997         }
998
999         public static int test_0_vector4ui_max () {
1000                 Vector4ui a = new Vector4ui (6,1,6,3);
1001                 Vector4ui b = new Vector4ui (3,4,6,7);
1002                 Vector4ui c = a.Max (b);
1003
1004                 if (c.X != 6)
1005                         return 1;
1006                 if (c.Y != 4)
1007                         return 2;
1008                 if (c.Z != 6)
1009                         return 3;
1010                 if (c.W != 7)
1011                         return 4;
1012                 return 0;
1013         }
1014
1015         public static int vector16b_cmpeq () {
1016                 Vector16b a = new Vector16b (1,0,9,0,0,0,0,0,0,0,0,0,0,0,0,1);
1017                 Vector16b b = new Vector16b (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
1018                 Vector16b c = a.CompareEqual (b);
1019
1020                 if (c.V0 != 0)
1021                         return 1;
1022                 if (c.V1 != 0)
1023                         return 2;
1024                 if (c.V2 != 0)
1025                         return 3;
1026                 if (c.V3 != 0xff)
1027                         return 4;
1028                 if (c.V4 != 0xff)
1029                         return 5;
1030                 if (c.V5 != 0xff)
1031                         return 6;
1032                 if (c.V6 != 0xff)
1033                         return 7;
1034                 if (c.V7 != 0xff)
1035                         return 8;
1036                 if (c.V8 != 0xff)
1037                         return 9;
1038                 if (c.V9 != 0xff)
1039                         return 10;
1040                 if (c.V10 != 0xff)
1041                         return 11;
1042                 if (c.V11 != 0xff)
1043                         return 12;
1044                 if (c.V12 != 0xff)
1045                         return 13;
1046                 if (c.V13 != 0xff)
1047                         return 14;
1048                 if (c.V14 != 0xff)
1049                         return 15;
1050                 if (c.V15 != 0)
1051                         return 16;
1052                 return 0;
1053         }
1054
1055
1056         public static int vector16b_sum_abs_diff () {
1057                 Vector16b a = new Vector16b (100,20,20,20,0,0,0,0,0,0,0,0,0,0, 0, 0);
1058                 Vector16sb b = new Vector16sb (0,  10,10,10,0,0,0,0,0,0,0,0,0,0,10,10);
1059                 Vector8us c = a.SumOfAbsoluteDifferences (b);
1060
1061                 if (c.V0 != 130)
1062                         return 1;
1063                 if (c.V1 != 0)
1064                         return 2;
1065                 if (c.V2 != 0)
1066                         return 3;
1067                 if (c.V3 != 0)
1068                         return 4;
1069                 if (c.V4 != 20)
1070                         return 5;
1071                 if (c.V5 != 0)
1072                         return 6;
1073                 if (c.V6 != 0)
1074                         return 7;
1075                 if (c.V7 != 0)
1076                         return 8;
1077                 return 0;
1078         }
1079
1080
1081         public static int test_0_vector16b_extract_mask () {
1082                 Vector16b a = new Vector16b (0xF0,0,0xF0,0,0,0,0xF0,0xAA,0x0F,0,0xFF,0,0,0,0,0);
1083                 int c = a.ExtractByteMask ();
1084
1085                 if (c != 0x4C5)
1086                         return 1;
1087                 return 0;
1088         }
1089
1090         public static int test_0_vector16b_min () {
1091                 Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15);
1092                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1093                 Vector16b c = a.Min (b);
1094
1095                 if (c.V0 != 0)
1096                         return 1;
1097                 if (c.V1 != 10)
1098                         return 2;
1099                 if (c.V2 != 11)
1100                         return 3;
1101                 if (c.V3 != 12)
1102                         return 4;
1103                 if (c.V4 != 4)
1104                         return 5;
1105                 if (c.V5 != 5)
1106                         return 6;
1107                 if (c.V6 != 6)
1108                         return 7;
1109                 if (c.V7 != 0)
1110                         return 8;
1111                 if (c.V8 != 1)
1112                         return 9;
1113                 if (c.V9 != 2)
1114                         return 10;
1115                 if (c.V10 != 3)
1116                         return 11;
1117                 if (c.V11 != 4)
1118                         return 12;
1119                 if (c.V12 != 5)
1120                         return 13;
1121                 if (c.V13 != 6)
1122                         return 14;
1123                 if (c.V14 != 7)
1124                         return 15;
1125                 if (c.V15 != 8)
1126                         return 16;
1127                 return 0;
1128         }
1129
1130         public static int test_0_vector16b_max () {
1131                 Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15);
1132                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1133                 Vector16b c = a.Max (b);
1134
1135                 if (c.V0 != 9)
1136                         return 1;
1137                 if (c.V1 != 12)
1138                         return 2;
1139                 if (c.V2 != 20)
1140                         return 3;
1141                 if (c.V3 != 12)
1142                         return 4;
1143                 if (c.V4 != 13)
1144                         return 5;
1145                 if (c.V5 != 14)
1146                         return 6;
1147                 if (c.V6 != 15)
1148                         return 7;
1149                 if (c.V7 != 7)
1150                         return 8;
1151                 if (c.V8 != 8)
1152                         return 9;
1153                 if (c.V9 != 9)
1154                         return 10;
1155                 if (c.V10 != 10)
1156                         return 11;
1157                 if (c.V11 != 11)
1158                         return 12;
1159                 if (c.V12 != 12)
1160                         return 13;
1161                 if (c.V13 != 13)
1162                         return 14;
1163                 if (c.V14 != 14)
1164                         return 15;
1165                 if (c.V15 != 15)
1166                         return 16;
1167                 return 0;
1168         }
1169         public static int test_0_vector16b_avg () {
1170                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1171                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1172                 Vector16b c = a.Average (b);
1173
1174                 if (c.V0 != 5)
1175                         return 1;
1176                 if (c.V1 != 6)
1177                         return 2;
1178                 if (c.V2 != 7)
1179                         return 3;
1180                 if (c.V3 != 8)
1181                         return 4;
1182                 if (c.V4 != 9)
1183                         return 5;
1184                 if (c.V5 != 10)
1185                         return 6;
1186                 if (c.V6 != 11)
1187                         return 7;
1188                 if (c.V7 != 4)
1189                         return 8;
1190                 if (c.V8 != 5)
1191                         return 9;
1192                 if (c.V9 != 6)
1193                         return 10;
1194                 if (c.V10 != 7)
1195                         return 11;
1196                 if (c.V11 != 8)
1197                         return 12;
1198                 if (c.V12 != 9)
1199                         return 13;
1200                 if (c.V13 != 10)
1201                         return 14;
1202                 if (c.V14 != 11)
1203                         return 15;
1204                 if (c.V15 != 12)
1205                         return 16;
1206                 return 0;
1207         }
1208
1209
1210         static unsafe Vector8us bad_method_regression_2 (Vector16b va, Vector16b vb) {
1211                 Vector8us res = new Vector8us ();
1212                 byte *a = (byte*)&va;
1213                 byte *b = (byte*)&vb;
1214
1215                 int tmp = 0;
1216                 for (int i = 0; i < 8; ++i)
1217                         tmp += System.Math.Abs ((int)*a++ - (int)*b++);
1218                 res.V0 = (ushort)tmp;
1219
1220                 tmp = 0;
1221                 for (int i = 0; i < 8; ++i)
1222                         tmp += System.Math.Abs ((int)*a++ - (int)*b++);
1223                 res.V4 = (ushort)tmp;
1224                 return res;
1225         }
1226
1227         /*This bug was caused the simplifier not taking notice of LDADDR on the remaining blocks.*/
1228         public static int test_2_local_simplifier_regression_other_blocks () {
1229                 Vector16b a = new Vector16b (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
1230                 Vector16b b = new Vector16b (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
1231                 Vector8us res = bad_method_regression_2 (a,b);
1232                 return (int)res.V0 + res.V4;
1233         }
1234
1235         static unsafe Vector8us bad_method_regression (Vector16b va, Vector16b vb) {
1236                 Vector8us res = new Vector8us ();
1237                 byte *a = (byte*)&va;
1238                 byte *b = (byte*)&vb;
1239                 *((ushort*)&res) = 10;
1240
1241                 int tmp = 0;
1242                 if (*b != 0)
1243                         tmp++;
1244
1245                 Vector8us dd = res;
1246                 dd = dd + dd - dd;
1247                 return dd;
1248         }
1249
1250         /*This bug was caused the simplifier not taking notice of LDADDR on the first block.*/
1251         public static int test_10_local_simplifier_regression_first_block () {
1252                 Vector16b a = new Vector16b ();
1253                 Vector16b b = new Vector16b ();
1254                 Vector8us res = bad_method_regression (a,b);
1255                 return (int)res.V0;
1256         }
1257         
1258         public static int test_0_vecto8us_shuffle_low () {
1259                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
1260                 Vector8us c = a.ShuffleLow (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1261
1262                 if (c.V0 != 2)
1263                         return 1;
1264                 if (c.V1 != 4)
1265                         return 2;
1266                 if (c.V2 != 1)
1267                         return 3;
1268                 if (c.V3 != 3)
1269                         return 4;
1270                 if (c.V4 != 5)
1271                         return 5;
1272                 if (c.V5 != 6)
1273                         return 6;
1274                 if (c.V6 != 7)
1275                         return 7;
1276                 if (c.V7 != 8)
1277                         return 8;
1278                 return 0;
1279         }
1280
1281         public static int test_0_vecto8us_shuffle_high () {
1282                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
1283                 Vector8us c = a.ShuffleHigh (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1284
1285                 if (c.V0 != 1)
1286                         return 1;
1287                 if (c.V1 != 2)
1288                         return 2;
1289                 if (c.V2 != 3)
1290                         return 3;
1291                 if (c.V3 != 4)
1292                         return 4;
1293                 if (c.V4 != 6)
1294                         return 5;
1295                 if (c.V5 != 8)
1296                         return 6;
1297                 if (c.V6 != 5)
1298                         return 7;
1299                 if (c.V7 != 7)
1300                         return 8;
1301
1302                 return 0;
1303         }
1304
1305         public static int test_0_vecto8us_max () {
1306                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
1307                 Vector8us b = new Vector8us (9, 1, 1, 2, 9, 6, 5, 1000);
1308                 Vector8us c = a.Max (b);
1309
1310                 if (c.V0 != 9)
1311                         return 1;
1312                 if (c.V1 != 2)
1313                         return 2;
1314                 if (c.V2 != 3)
1315                         return 3;
1316                 if (c.V3 != 4)
1317                         return 4;
1318                 if (c.V4 != 9)
1319                         return 5;
1320                 if (c.V5 != 6)
1321                         return 6;
1322                 if (c.V6 != 7)
1323                         return 7;
1324                 if (c.V7 != 1000)
1325                         return 0;
1326
1327                 return 0;
1328         }
1329
1330         public static int test_0_vecto8us_min () {
1331                 Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4);
1332                 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
1333                 Vector8us c = a.Min (b);
1334
1335                 if (c.V0 != 1)
1336                         return 1;
1337                 if (c.V1 != 1)
1338                         return 2;
1339                 if (c.V2 != 1)
1340                         return 3;
1341                 if (c.V3 != 0)
1342                         return 4;
1343                 if (c.V4 != 3)
1344                         return 5;
1345                 if (c.V5 != 4)
1346                         return 6;
1347                 if (c.V6 != 5)
1348                         return 7;
1349                 if (c.V7 != 4)
1350                         return 8;
1351                 return 0;
1352         }
1353
1354         public static int test_0_vecto8us_avg () {
1355                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
1356                 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
1357                 Vector8us c = a.Average (b);
1358
1359                 if (c.V0 != 5)
1360                         return 1;
1361                 if (c.V1 != 2)
1362                         return 2;
1363                 if (c.V2 != 2)
1364                         return 3;
1365                 if (c.V3 != 3)
1366                         return 4;
1367                 if (c.V4 != 4)
1368                         return 5;
1369                 if (c.V5 != 5)
1370                         return 6;
1371                 if (c.V6 != 6)
1372                         return 7;
1373                 if (c.V7 != 7)
1374                         return 8;
1375                 return 0;
1376         }
1377
1378         static void store_helper (ref Vector4f x) {
1379                 Vector4f k;
1380                 k = new Vector4f(9,9,9,9);
1381                 x = k;
1382         }
1383
1384         public static int test_0_vector4f_byref_store ()
1385         {
1386                 Vector4f k;
1387                 k = new Vector4f(1,2,3,4);
1388                 store_helper (ref k);
1389                 if (k.X != 9)
1390                         return 1;
1391                 return 0;
1392         }
1393
1394         public static int test_0_vector4f_init_array_element ()
1395         {
1396                 Vector4f[] v = new Vector4f[1];
1397                 v[0] = new Vector4f(9,9,9,9);
1398                 if (v [0].X != 9)
1399                         return 1;
1400                 return 0;
1401         }
1402
1403         public static int test_0_vector4f_dup_high () {
1404                 Vector4f a = new Vector4f (1, 2, 3, 4);
1405                 Vector4f c = a.DuplicateHigh();
1406
1407                 if (c.X != 2)
1408                         return 1;
1409                 if (c.Y != 2)
1410                         return 2;
1411                 if (c.Z != 4)
1412                         return 3;
1413                 if (c.W != 4)
1414                         return 4;
1415                 return 0;
1416         }
1417
1418         public static int test_0_vector4f_dup_low () {
1419                 Vector4f a = new Vector4f (1, 2, 3, 4);
1420                 Vector4f c = a.DuplicateLow ();
1421
1422                 if (c.X != 1)
1423                         return 1;
1424                 if (c.Y != 1)
1425                         return 2;
1426                 if (c.Z != 3)
1427                         return 3;
1428                 if (c.W != 3)
1429                         return 4;
1430                 return 0;
1431         }
1432
1433
1434         public static int test_0_vector4f_interleave_high () {
1435                 Vector4f a = new Vector4f (1, 2, 3, 4);
1436                 Vector4f b = new Vector4f (5, 6, 7, 8);
1437                 Vector4f c = a.InterleaveHigh (b);
1438
1439                 if (c.X != 3)
1440                         return 1;
1441                 if (c.Y != 7)
1442                         return 2;
1443                 if (c.Z != 4)
1444                         return 3;
1445                 if (c.W != 8)
1446                         return 4;
1447                 return 0;
1448         }
1449
1450         public static int test_0_vector4f_interleave_low () {
1451                 Vector4f a = new Vector4f (1, 2, 3, 4);
1452                 Vector4f b = new Vector4f (5, 6, 7, 8);
1453                 Vector4f c = a.InterleaveLow (b);
1454
1455                 if (c.X != 1)
1456                         return 1;
1457                 if (c.Y != 5)
1458                         return 2;
1459                 if (c.Z != 2)
1460                         return 3;
1461                 if (c.W != 6)
1462                         return 4;
1463                 return 0;
1464         }
1465
1466         public static int test_0_vector4f_rcp () {
1467                 Vector4f a = new Vector4f (1, 2, 4, 8);
1468                 Vector4f c = a.Reciprocal ();
1469
1470                 //Test with ranges due to the terrible precision.
1471                 if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f))
1472                         return 1;
1473                 if (c.Y < (0.5 - 0.01f) || c.Y > (0.5 + 0.01f))
1474                         return 2;
1475                 if (c.Z < (0.25 - 0.01f) || c.Z > (0.25 + 0.01f))
1476                         return 3;
1477                 if (c.W < (0.125 - 0.01f) || c.W > (0.125 + 0.01f))
1478                         return 4;
1479                 return 0;
1480         }
1481
1482         public static int test_0_vector4f_xor () {
1483                 Vector4f a = new Vector4f (1, 2, 3, 4);
1484                 Vector4f b = new Vector4f (1, 3, 3, 8);
1485                 Vector4f c = a ^ b;
1486
1487                 if (((Vector4ui)c).X != 0)
1488                         return 1;
1489                 if (((Vector4ui)c).Y != 0x400000)
1490                         return 2;
1491                 if (((Vector4ui)c).Z != 0)
1492                         return 3;
1493                 if (((Vector4ui)c).W != 0x1800000)
1494                         return 4;
1495                 return 0;
1496         }
1497
1498         public static int test_0_vector4f_or () {
1499                 Vector4f a = new Vector4f (1, 2, 3, 4);
1500                 Vector4f b = new Vector4f (1, 3, 3, 8);
1501                 Vector4f c = a | b;
1502
1503                 if (((Vector4ui)c).X != 0x3F800000)
1504                         return 1;
1505                 if (((Vector4ui)c).Y != 0x40400000)
1506                         return 2;
1507                 if (((Vector4ui)c).Z != 0x40400000)
1508                         return 3;
1509                 if (((Vector4ui)c).W != 0x41800000)
1510                         return 4;
1511                 return 0;
1512         }
1513         public static int test_0_vector4f_andn () {
1514                 Vector4f a = new Vector4f (1, 2, 3, 4);
1515                 Vector4f b = new Vector4f (1, 3, 3, 8);
1516                 Vector4f c = a.AndNot (b);
1517
1518                 if (((Vector4ui)c).X != 0)
1519                         return 1;
1520                 if (((Vector4ui)c).Y != 0x400000)
1521                         return 2;
1522                 if (((Vector4ui)c).Z != 0)
1523                         return 3;
1524                 if (((Vector4ui)c).W != 0x1000000)
1525                         return 4;
1526                 return 0;
1527         }
1528
1529         public static int test_0_vector4f_and () {
1530                 Vector4f a = new Vector4f (1, 2, 3, 4);
1531                 Vector4f b = new Vector4f (1, 3, 3, 8);
1532                 Vector4f c = a & b;
1533
1534                 if (((Vector4ui)c).X != 0x3F800000)
1535                         return 1;
1536                 if (((Vector4ui)c).Y != 0x40000000)
1537                         return 2;
1538                 if (((Vector4ui)c).Z != 0x40400000)
1539                         return 3;
1540                 if (((Vector4ui)c).W != 0x40000000)
1541                         return 4;
1542                 return 0;
1543         }
1544
1545         public static int test_0_vector4f_cmpord () {
1546                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1547                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1548                 Vector4f c = a.CompareOrdered (b);
1549
1550                 if (((Vector4ui)c).X != 0)
1551                         return 1;
1552                 if (((Vector4ui)c).Y != 0)
1553                         return 2;
1554                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
1555                         return 3;
1556                 if (((Vector4ui)c).W != 0xFFFFFFFF)
1557                         return 4;
1558                 return 0;
1559         }
1560
1561         public static int test_0_vector4f_cmpnle () {
1562                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1563                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1564                 Vector4f c = a.CompareNotLessEqual (b);
1565
1566                 if (((Vector4ui)c).X != 0xFFFFFFFF)
1567                         return 1;
1568                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
1569                         return 2;
1570                 if (((Vector4ui)c).Z != 0)
1571                         return 3;
1572                 if (((Vector4ui)c).W != 0)
1573                         return 4;
1574                 return 0;
1575         }
1576
1577         public static int test_0_vector4f_cmpnlt () {
1578                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1579                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1580                 Vector4f c = a.CompareNotLessThan (b);
1581
1582                 if (((Vector4ui)c).X != 0xFFFFFFFF)
1583                         return 1;
1584                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
1585                         return 2;
1586                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
1587                         return 3;
1588                 if (((Vector4ui)c).W != 0)
1589                         return 4;
1590                 return 0;
1591         }
1592
1593         public static int test_0_vector4f_cmpneq () {
1594                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1595                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1596                 Vector4f c = a.CompareNotEqual (b);
1597
1598                 if (((Vector4ui)c).X != 0xFFFFFFFF)
1599                         return 1;
1600                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
1601                         return 2;
1602                 if (((Vector4ui)c).Z != 0)
1603                         return 3;
1604                 if (((Vector4ui)c).W != 0xFFFFFFFF)
1605                         return 4;
1606                 return 0;
1607         }
1608
1609         public static int test_0_vector4f_cmpunord () {
1610                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1611                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1612                 Vector4f c = a.CompareUnordered (b);
1613
1614                 if (((Vector4ui)c).X != 0xFFFFFFFF)
1615                         return 1;
1616                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
1617                         return 2;
1618                 if (((Vector4ui)c).Z != 0)
1619                         return 3;
1620                 if (((Vector4ui)c).W != 0)
1621                         return 4;
1622                 return 0;
1623         }
1624
1625         public static int test_0_vector4f_cmple () {
1626                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1627                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1628                 Vector4f c = a.CompareLessEqual (b);
1629
1630                 if (((Vector4ui)c).X != 0)
1631                         return 1;
1632                 if (((Vector4ui)c).Y != 0)
1633                         return 2;
1634                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
1635                         return 3;
1636                 if (((Vector4ui)c).W != 0xFFFFFFFF)
1637                         return 4;
1638                 return 0;
1639         }
1640
1641         public static int test_0_vector4f_cmplt () {
1642                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
1643                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
1644                 Vector4f c = a.CompareLessThan (b);
1645
1646                 if (((Vector4ui)c).X != 0)
1647                         return 1;
1648                 if (((Vector4ui)c).Y != 0)
1649                         return 2;
1650                 if (((Vector4ui)c).Z != 0)
1651                         return 3;
1652                 if (((Vector4ui)c).W != 0xFFFFFFFF)
1653                         return 4;
1654                 return 0;
1655         }
1656
1657         public static int test_0_vector4f_cmpeq () {
1658                 Vector4f a = new Vector4f (float.NaN, 2,         3, 6);
1659                 Vector4f b = new Vector4f (1,         float.NaN, 3, 4);
1660                 Vector4f c = a.CompareEqual (b);
1661
1662                 if (((Vector4ui)c).X != 0)
1663                         return 1;
1664                 if (((Vector4ui)c).Y != 0)
1665                         return 2;
1666                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
1667                         return 3;
1668                 if (((Vector4ui)c).W != 0)
1669                         return 4;
1670                 return 0;
1671         }
1672
1673         public static int test_0_vector4ui_sar () {
1674                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
1675                 
1676                 Vector4ui c = a.ArithmeticRightShift (2);
1677         
1678                 if (c.X != 0xFC000000)
1679                         return 1;
1680                 if (c.Y != 5)
1681                         return 2;
1682                 if (c.Z != 0)
1683                         return 3;
1684                 if (c.W != 10)
1685                         return 4;
1686                 return 0;
1687         }
1688
1689         public static int test_0_vector4ui_unpack_high () {
1690                 Vector4ui a = new Vector4ui (1,2,3,4);
1691                 Vector4ui b = new Vector4ui (5,6,7,8);
1692                 
1693                 Vector4ui c = a.UnpackHigh(b);
1694         
1695                 if (c.X != 3)
1696                         return 1;
1697                 if (c.Y != 7)
1698                         return 2;
1699                 if (c.Z != 4)
1700                         return 3;
1701                 if (c.W != 8)
1702                         return 4;
1703                 return 0;
1704         }
1705
1706         public  static int test_0_vector4ui_unpack_low () {
1707                 Vector4ui a = new Vector4ui (1,2,3,4);
1708                 Vector4ui b = new Vector4ui (5,6,7,8);
1709                 
1710                 Vector4ui c = a.UnpackLow (b);
1711         
1712                 if (c.X != 1)
1713                         return 1;
1714                 if (c.Y != 5)
1715                         return 2;
1716                 if (c.Z != 2)
1717                         return 3;
1718                 if (c.W != 6)
1719                         return 4;
1720                 return 0;
1721         }
1722
1723         public  static int test_0_vector4ui_xor () {
1724                 Vector4ui a = new Vector4ui (1,2,3,4);
1725                 Vector4ui b = new Vector4ui (7,5,3,1);
1726                 
1727                 Vector4ui c = a ^ b;
1728         
1729                 if (c.X != 6)
1730                         return 1;
1731                 if (c.Y != 7)
1732                         return 2;
1733                 if (c.Z != 0)
1734                         return 3;
1735                 if (c.W != 5)
1736                         return 4;
1737                 return 0;
1738         }
1739
1740         public  static int test_0_vector4ui_or () {
1741                 Vector4ui a = new Vector4ui (1,2,3,4);
1742                 Vector4ui b = new Vector4ui (7,5,3,1);
1743                 
1744                 Vector4ui c = a | b;
1745         
1746                 if (c.X != 7)
1747                         return 1;
1748                 if (c.Y != 7)
1749                         return 2;
1750                 if (c.Z != 3)
1751                         return 3;
1752                 if (c.W != 5)
1753                         return 4;
1754                 return 0;
1755         }
1756         public  static int test_0_vector4ui_and () {
1757                 Vector4ui a = new Vector4ui (1,2,3,4);
1758                 Vector4ui b = new Vector4ui (7,5,3,1);
1759                 
1760                 Vector4ui c = a & b;
1761         
1762                 if (c.X != 1)
1763                         return 1;
1764                 if (c.Y != 0)
1765                         return 2;
1766                 if (c.Z != 3)
1767                         return 3;
1768                 if (c.W != 0)
1769                         return 4;
1770                 return 0;
1771         }
1772
1773         public  static int test_0_vector4ui_shr () {
1774                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
1775                 
1776                 Vector4ui c = a >> 2;
1777         
1778                 if (c.X != 0x3C000000)
1779                         return 1;
1780                 if (c.Y != 5)
1781                         return 2;
1782                 if (c.Z != 0)
1783                         return 3;
1784                 if (c.W != 10)
1785                         return 4;
1786                 return 0;
1787         }
1788
1789         public  static int test_0_vector4ui_shl () {
1790                 Vector4ui a = new Vector4ui (10,20,3,40);
1791                 
1792                 Vector4ui c = a << 2;
1793         
1794                 if (c.X != 40)
1795                         return 1;
1796                 if (c.Y != 80)
1797                         return 2;
1798                 if (c.Z != 12)
1799                         return 3;
1800                 if (c.W != 160)
1801                         return 4;
1802                 return 0;
1803         }
1804
1805         public  static int test_0_vector4ui_mul () {
1806                 Vector4ui a = new Vector4ui (0x8888,20,3,40);
1807                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
1808                 
1809                 Vector4ui c = a * b;
1810         
1811                 if (c.X != 0xffff7800)
1812                         return 1;
1813                 if (c.Y != 40)
1814                         return 2;
1815                 if (c.Z != 9)
1816                         return 3;
1817                 if (c.W != 160)
1818                         return 4;
1819                 return 0;
1820         }
1821         public  static int test_0_vector4ui_sub () {
1822                 Vector4ui a = new Vector4ui (1,20,3,40);
1823                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
1824                 
1825                 Vector4ui c = a - b;
1826         
1827                 if (c.X != 0xff0101)
1828                         return 1;
1829                 if (c.Y != 18)
1830                         return 2;
1831                 if (c.Z != 0)
1832                         return 3;
1833                 if (c.W != 36)
1834                         return 4;
1835                 return 0;
1836         }
1837
1838         public  static int test_0_vector4ui_add () {
1839                 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
1840                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
1841                 
1842                 Vector4ui c = a + b;
1843         
1844                 if (c.X != 0xfe01fe00)
1845                         return 1;
1846                 if (c.Y != 4)
1847                         return 2;
1848                 if (c.Z != 6)
1849                         return 3;
1850                 if (c.W != 8)
1851                         return 4;
1852                 return 0;
1853         }
1854
1855
1856         static int test_0_vector4ui_accessors () {
1857                 Vector4ui a = new Vector4ui (1,2,3,4);
1858
1859                 if (a.X != 1)
1860                         return 1;
1861                 if (a.Y != 2)
1862                         return 2;
1863                 if (a.Z != 3)
1864                         return 3;
1865                 if (a.W != 4)
1866                         return 4;
1867                 a.X = 10;
1868                 a.Y = 20;
1869                 a.Z = 30;
1870                 a.W = 40;
1871
1872                 if (a.X != 10)
1873                         return 5;
1874                 if (a.Y != 20)
1875                         return 6;
1876                 if (a.Z != 30)
1877                         return 7;
1878                 if (a.W != 40)
1879                         return 8;
1880                 return 0;
1881         }
1882
1883         static int test_0_vector8us_sub_sat () {
1884                 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
1885                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
1886                 Vector8us c = a.SubtractWithSaturation (b);
1887
1888                 if (c.V0 != 0)
1889                         return 1;
1890                 if (c.V1 != 0)
1891                         return 2;
1892                 if (c.V2 != 15)
1893                         return 3;
1894                 if (c.V3 != 0)
1895                         return 4;
1896                 if (c.V4 != 0)
1897                         return 5;
1898                 if (c.V5 != 0)
1899                         return 6;
1900                 if (c.V6 != 0)
1901                         return 7;
1902                 if (c.V7 != 0)
1903                         return 8;
1904                 return 0;
1905         }
1906
1907         static int test_0_vector8us_add_sat () {
1908                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
1909                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
1910                 Vector8us c = a.AddWithSaturation (b);
1911
1912                 if (c.V0 != 0xFFFF)
1913                         return 1;
1914                 if (c.V1 != 5)
1915                         return 2;
1916                 if (c.V2 != 7)
1917                         return 3;
1918                 if (c.V3 != 9)
1919                         return 4;
1920                 if (c.V4 != 11)
1921                         return 5;
1922                 if (c.V5 != 13)
1923                         return 6;
1924                 if (c.V6 != 15)
1925                         return 7;
1926                 if (c.V7 != 17)
1927                         return 8;
1928                 return 0;
1929         }
1930
1931         static int test_0_vector8us_unpack_low () {
1932                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
1933                 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
1934                 Vector8us c = a.UnpackLow (b);
1935
1936                 if (c.V0 != 0)
1937                         return 1;
1938                 if (c.V1 != 3)
1939                         return 2;
1940                 if (c.V2 != 1)
1941                         return 3;
1942                 if (c.V3 != 4)
1943                         return 4;
1944                 if (c.V4 != 2)
1945                         return 5;
1946                 if (c.V5 != 5)
1947                         return 6;
1948                 if (c.V6 != 3)
1949                         return 7;
1950                 if (c.V7 != 6)
1951                         return 8;
1952                 return 0;
1953         }
1954
1955
1956         static int test_0_vector8us_shift_left () {
1957                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
1958                 int amt = 2;
1959                 Vector8us c = a << amt;
1960         
1961                 if (c.V0 != 0xFC00)
1962                         return 1;
1963                 if (c.V1 != 4)
1964                         return 2;
1965                 if (c.V7 != 28)
1966                         return 3;
1967                 return 0;
1968         }
1969         
1970         static int test_0_vector8us_shift_right_arithmetic () {
1971                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
1972                 int amt = 2;
1973                 Vector8us c = a.ArithmeticRightShift (amt);
1974         
1975                 if (c.V0 != 0xFFC0)
1976                         return 1;
1977                 if (c.V1 != 0)
1978                         return 2;
1979                 if (c.V7 != 1)
1980                         return 3;
1981                 return 0;
1982         }
1983
1984         static int test_0_vector8us_shift_variable_offset () {
1985                 int off = 2;
1986                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
1987                 Vector8us b = a;
1988                 Vector8us c = b >> off;
1989                 a = b + b;
1990
1991                 if (c.V0 != 0x3C00)
1992                         return 1;
1993                 if (c.V1 != 0)
1994                         return 2;
1995                 if (c.V7 != 1)
1996                         return 3;
1997                 if (a.V1 != 2)
1998                         return 4;
1999                 if (a.V7 != 14)
2000                         return 5;
2001                 return 0;
2002         }
2003         
2004         
2005         static int test_0_vector8us_shift_operand_is_live_after_op () {
2006                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
2007                 Vector8us b = a;
2008                 Vector8us c = b >> 2;
2009                 a = b + b;
2010
2011                 if (c.V0 != 0x3C00)
2012                         return 1;
2013                 if (c.V1 != 0)
2014                         return 2;
2015                 if (c.V7 != 1)
2016                         return 3;
2017                 if (a.V1 != 2)
2018                         return 4;
2019                 if (a.V7 != 14)
2020                         return 5;
2021                 return 0;
2022         }
2023
2024         static int test_0_vector8us_shr_constant () {
2025                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
2026                 Vector8us c = a >> 2;
2027
2028                 if (c.V0 != 0x3C00)
2029                         return 1;
2030                 if (c.V1 != 0)
2031                         return 2;
2032                 if (c.V7 != 1)
2033                         return 3;
2034                 return 0;
2035         }
2036
2037         static int test_0_vector8us_mul () {
2038                 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
2039                 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
2040
2041                 Vector8us c = a * b;
2042                 if (c.V0 != 63488)
2043                         return 1;
2044                 if (c.V1 != 4)
2045                         return 2;
2046                 if (c.V7 != 80)
2047                         return 3;
2048                 return 0;
2049         }
2050
2051         static int test_0_vector8us_add () {
2052                 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
2053                 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
2054
2055                 Vector8us c = a + b;
2056                 if (c.V0 != 34696)
2057                         return 1;
2058                 if (c.V1 != 5)
2059                         return 2;
2060                 if (c.V7 != 18)
2061                         return 3;
2062                 return 0;
2063         }
2064
2065
2066         static int test_0_vector8us_sub () {
2067                 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
2068                 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
2069
2070                 Vector8us c = a - b;
2071
2072                 if (c.V0 != 65529)
2073                         return 1;
2074                 if (c.V1 != 3)
2075                         return 2;
2076                 if (c.V7 != 2)
2077                         return 3;
2078                 return 0;
2079         }
2080
2081
2082         static int test_0_vector8us_accessors () {
2083                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
2084
2085                 if (a.V0 != 0)
2086                         return 1;
2087                 if (a.V1 != 1)
2088                         return 2;
2089                 if (a.V2 != 2)
2090                         return 3;
2091                 if (a.V3 != 3)
2092                         return 4;
2093                 if (a.V4 != 4)
2094                         return 5;
2095                 if (a.V5 != 5)
2096                         return 6;
2097                 if (a.V6 != 6)
2098                         return 7;
2099                 if (a.V7 != 7)
2100                         return 8;
2101                 a.V0 = 10;
2102                 a.V1 = 20;
2103                 a.V2 = 30;
2104                 a.V3 = 40;
2105                 a.V4 = 50;
2106                 a.V5 = 60;
2107                 a.V6 = 70;
2108                 a.V7 = 80;
2109
2110                 if (a.V0 != 10)
2111                         return 17;
2112                 if (a.V1 != 20)
2113                         return 18;
2114                 if (a.V2 != 30)
2115                         return 19;
2116                 if (a.V3 != 40)
2117                         return 20;
2118                 if (a.V4 != 50)
2119                         return 21;
2120                 if (a.V5 != 60)
2121                         return 22;
2122                 if (a.V6 != 70)
2123                         return 23;
2124                 if (a.V7 != 80)
2125                         return 24;
2126
2127                 return 0;
2128         }
2129
2130
2131         static int test_0_vector16b_unpack_high () {
2132                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2133                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
2134                 Vector16b c = a.UnpackHigh (b);
2135
2136                 if (c.V0 != 8)
2137                         return 1;
2138                 if (c.V1 != 1)
2139                         return 2;
2140                 if (c.V2 != 9)
2141                         return 3;
2142                 if (c.V3 != 2)
2143                         return 4;
2144                 if (c.V4 != 10)
2145                         return 5;
2146                 if (c.V5 != 3)
2147                         return 6;
2148                 if (c.V14 != 15)
2149                         return 7;
2150                 if (c.V15 != 8)
2151                         return 8;
2152                 return 0;
2153         }
2154
2155         static int test_0_vector16b_unpack_low () {
2156                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2157                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
2158                 Vector16b c = a.UnpackLow (b);
2159
2160                 if (c.V0 != 0)
2161                         return 1;
2162                 if (c.V1 != 9)
2163                         return 2;
2164                 if (c.V2 != 1)
2165                         return 3;
2166                 if (c.V3 != 10)
2167                         return 4;
2168                 if (c.V4 != 2)
2169                         return 5;
2170                 if (c.V5 != 11)
2171                         return 6;
2172                 if (c.V14 != 7)
2173                         return 7;
2174                 if (c.V15 != 0)
2175                         return 8;
2176                 return 0;
2177         }
2178
2179         static int test_0_vector16b_sub_sat () {
2180                 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
2181                 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2182                 Vector16b c = a.SubtractWithSaturation (b);
2183
2184                 if (c.V0 != 0)
2185                         return 1;
2186                 if (c.V1 != 9)
2187                         return 2;
2188                 if (c.V15 != 0)
2189                         return 3;
2190                 return 0;
2191         }
2192         
2193         static int test_0_vector16b_add_sat () {
2194                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2195                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
2196                 Vector16b c = a.AddWithSaturation (b);
2197
2198                 if (c.V0 != 255)
2199                         return 1;
2200                 if (c.V1 != 11)
2201                         return 2;
2202                 if (c.V15 != 23)
2203                         return 3;
2204                 return 0;
2205         }
2206
2207         static int test_0_vector16b_add_ovf () {
2208                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2209                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
2210                 Vector16b c = a + b;
2211
2212                 if (c.V0 != 144)
2213                         return 1;
2214                 if (c.V1 != 11)
2215                         return 2;
2216                 if (c.V15 != 23)
2217                         return 3;
2218                 return 0;
2219         }
2220
2221         static int test_0_vector16b_accessors () {
2222                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
2223
2224                 if (a.V0 != 0)
2225                         return 1;
2226                 if (a.V1 != 1)
2227                         return 2;
2228                 if (a.V2 != 2)
2229                         return 3;
2230                 if (a.V3 != 3)
2231                         return 4;
2232                 if (a.V4 != 4)
2233                         return 5;
2234                 if (a.V5 != 5)
2235                         return 6;
2236                 if (a.V6 != 6)
2237                         return 7;
2238                 if (a.V7 != 7)
2239                         return 8;
2240                 if (a.V8 != 8)
2241                         return 9;
2242                 if (a.V9 != 9)
2243                         return 10;
2244                 if (a.V10 != 10)
2245                         return 11;
2246                 if (a.V11 != 11)
2247                         return 12;
2248                 if (a.V12 != 12)
2249                         return 13;
2250                 if (a.V13 != 13)
2251                         return 14;
2252                 if (a.V14 != 14)
2253                         return 15;
2254                 if (a.V15 != 15)
2255                         return 16;
2256
2257                 a.V0 = 10;
2258                 a.V1 = 20;
2259                 a.V2 = 30;
2260                 a.V3 = 40;
2261                 a.V4 = 50;
2262                 a.V5 = 60;
2263                 a.V6 = 70;
2264                 a.V7 = 80;
2265                 a.V8 = 90;
2266                 a.V9 = 100;
2267                 a.V10 = 110;
2268                 a.V11 = 120;
2269                 a.V12 = 130;
2270                 a.V13 = 140;
2271                 a.V14 = 150;
2272                 a.V15 = 160;
2273
2274                 if (a.V0 != 10)
2275                         return 17;
2276                 if (a.V1 != 20)
2277                         return 18;
2278                 if (a.V2 != 30)
2279                         return 19;
2280                 if (a.V3 != 40)
2281                         return 20;
2282                 if (a.V4 != 50)
2283                         return 21;
2284                 if (a.V5 != 60)
2285                         return 22;
2286                 if (a.V6 != 70)
2287                         return 23;
2288                 if (a.V7 != 80)
2289                         return 24;
2290                 if (a.V8 != 90)
2291                         return 25;
2292                 if (a.V9 != 100)
2293                         return 26;
2294                 if (a.V10 != 110)
2295                         return 27;
2296                 if (a.V11 != 120)
2297                         return 28;
2298                 if (a.V12 != 130)
2299                         return 29;
2300                 if (a.V13 != 140)
2301                         return 30;
2302                 if (a.V14 != 150)
2303                         return 31;
2304                 if (a.V15 != 160)
2305                         return 32;
2306                 return 0;
2307         }
2308
2309         public static int test_0_accessors () {
2310                 Vector4f a = new Vector4f (1, 2, 3, 4);
2311                 if (a.X != 1f)
2312                         return 1;
2313                 if (a.Y != 2f)
2314                         return 2;
2315                 if (a.Z != 3f)
2316                         return 3;
2317                 if (a.W != 4f)
2318                         return 4;
2319                 return 0;
2320         }
2321
2322         public static int test_0_packed_add_with_stack_tmp () {
2323                 Vector4f a = new Vector4f (1, 2, 3, 4);
2324                 Vector4f b = new Vector4f (5, 6, 7, 8);
2325                 Vector4f c = new Vector4f (-1, -3, -4, -5);
2326                 Vector4f d = a + b + c;
2327                 if (d.X != 5f)
2328                         return 1;
2329                 if (d.Y != 5f)
2330                         return 2;
2331                 if (d.Z != 6f)
2332                         return 3;
2333                 if (d.W != 7f)
2334                         return 4;
2335                 return 0;
2336         }
2337
2338         public static int test_0_simple_packed_add () {
2339                 Vector4f a = new Vector4f (1, 2, 3, 4);
2340                 Vector4f b = new Vector4f (5, 6, 7, 8);
2341                 Vector4f c;
2342                 c = a + b;
2343                 if (c.X != 6f)
2344                         return 1;
2345                 if (c.Y != 8f)
2346                         return 2;
2347                 if (c.Z != 10f)
2348                         return 3;
2349                 if (c.W != 12f)
2350                         return 4;
2351                 return 0;
2352         }
2353
2354         public static int test_0_simple_packed_sub () {
2355                 Vector4f a = new Vector4f (1, 2, 3, 4);
2356                 Vector4f b = new Vector4f (5, 6, 7, 8);
2357                 Vector4f c = b - a;
2358                 if (c.X != 4f)
2359                         return 1;
2360                 if (c.Y != 4f)
2361                         return 2;
2362                 if (c.Z != 4f)
2363                         return 3;
2364                 if (c.W != 4f)
2365                         return 4;
2366                 return 0;
2367         }
2368
2369         public static int test_0_simple_packed_mul () {
2370                 Vector4f a = new Vector4f (1, 2, 3, 4);
2371                 Vector4f b = new Vector4f (5, 6, 7, 8);
2372                 Vector4f c = b * a;
2373                 if (c.X != 5f)
2374                         return 1;
2375                 if (c.Y != 12f)
2376                         return 2;
2377                 if (c.Z != 21f)
2378                         return 3;
2379                 if (c.W != 32f)
2380                         return 4;
2381                 return 0;
2382         }
2383
2384         public static int test_0_simple_packed_div () {
2385                 Vector4f a = new Vector4f (2, 2, 3, 4);
2386                 Vector4f b = new Vector4f (20, 10, 33, 12);
2387                 Vector4f c = b / a;
2388                 if (c.X != 10f)
2389                         return 1;
2390                 if (c.Y != 5f)
2391                         return 2;
2392                 if (c.Z != 11f)
2393                         return 3;
2394                 if (c.W != 3f)
2395                         return 4;
2396                 return 0;
2397         }
2398
2399         public static int test_0_simple_packed_sqrt () {
2400                 Vector4f a = new Vector4f (16, 4, 9, 25);
2401                 a = a.Sqrt ();
2402                 if (a.X != 4f)
2403                         return 1;
2404                 if (a.Y != 2f)
2405                         return 2;
2406                 if (a.Z != 3f)
2407                         return 3;
2408                 if (a.W != 5f)
2409                         return 4;
2410                 return 0;
2411         }
2412
2413         public static int test_0_simple_packed_invsqrt () {
2414                 Vector4f a = new Vector4f (16, 4, 100, 25);
2415                 //this function has VERY low precision
2416                 a = a.InvSqrt ();
2417                 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
2418                         return 1;
2419                 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
2420                         return 2;
2421                 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
2422                         return 3;
2423                 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
2424                         return 4;
2425                 return 0;
2426         }
2427
2428         public static int test_0_simple_packed_min () {
2429                 Vector4f a = new Vector4f (16, -4, 9, 25);
2430                 Vector4f b = new Vector4f (5, 3, 9, 0);
2431                 Vector4f c = a.Min (b);
2432                 if (c.X != 5f)
2433                         return 1;
2434                 if (c.Y != -4f)
2435                         return 2;
2436                 if (c.Z != 9f)
2437                         return 3;
2438                 if (c.W != 0f)
2439                         return 4;
2440                 return 0;
2441         }
2442
2443         public static int test_0_simple_packed_max () {
2444                 Vector4f a = new Vector4f (16, -4, 9, 25);
2445                 Vector4f b = new Vector4f (5, 3, 9, 0);
2446                 Vector4f c = a.Max (b);
2447                 if (c.X != 16f)
2448                         return 1;
2449                 if (c.Y != 3f)
2450                         return 2;
2451                 if (c.Z != 9f)
2452                         return 3;
2453                 if (c.W != 25f)
2454                         return 4;
2455                 return 0;
2456         }
2457
2458         public static int test_0_simple_packed_hadd () {
2459                 Vector4f a = new Vector4f (5, 5, 6, 6);
2460                 Vector4f b = new Vector4f (7, 7, 8, 8);
2461                 Vector4f c = a.HorizontalAdd (b);
2462                 if (c.X != 10f)
2463                         return 1;
2464                 if (c.Y != 12f)
2465                         return 2;
2466                 if (c.Z != 14f)
2467                         return 3;
2468                 if (c.W != 16f)
2469                         return 4;
2470                 return 0;
2471         }
2472
2473         public static int test_0_simple_packed_hsub () {
2474                 Vector4f a = new Vector4f (5, 2, 6, 1);
2475                 Vector4f b = new Vector4f (7, 0, 8, 3);
2476                 Vector4f c = a.HorizontalSub (b);
2477                 if (c.X != 3f)
2478                         return 1;
2479                 if (c.Y != 5f)
2480                         return 2;
2481                 if (c.Z != 7f)
2482                         return 3;
2483                 if (c.W != 5f)
2484                         return 4;
2485                 return 0;
2486         }
2487
2488         public static int test_0_simple_packed_addsub () {
2489                 Vector4f a = new Vector4f (5, 2, 6, 1);
2490                 Vector4f b = new Vector4f (7, 0, 8, 3);
2491                 Vector4f c = a.AddSub (b);
2492                 if (c.X != -2f)
2493                         return 1;
2494                 if (c.Y != 2f)
2495                         return 2;
2496                 if (c.Z != -2f)
2497                         return 3;
2498                 if (c.W != 4f)
2499                         return 4;
2500                 return 0;
2501         }
2502
2503         public static int test_0_simple_packed_shuffle () {
2504                 Vector4f a = new Vector4f (1, 2, 3, 4);
2505                 a = a.Shuffle(ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2506                 if (a.X != 2f)
2507                         return 1;
2508                 if (a.Y != 4f)
2509                         return 2;
2510                 if (a.Z != 1f)
2511                         return 3;
2512                 if (a.W != 3f)
2513                         return 4;
2514                 return 0;
2515         }
2516
2517         public static int test_0_packed_shuffle_with_reg_pressure () {
2518                 Vector4f v = new Vector4f (1, 2, 3, 4);
2519                 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
2520                 if (ff) v = v + v -v    ;
2521
2522                 Vector4f r0 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2523                 Vector4f r1 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2524                 Vector4f x = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2525                 Vector4f r2 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2526                 Vector4f r3 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
2527                 Vector4f a = x;
2528
2529                 r0 = r0 * m0 + x;
2530                 r1 = r1 * m1 + x;
2531                 x = x - v + v;
2532                 r2 = r2 * m2 + x;
2533                 r3 = r3 * m3 + x;
2534                 Vector4f result = r0 + r1 + r2 + r3;
2535
2536                 if (a.X != 2f)
2537                         return 1;
2538                 if (a.Y != 4f)
2539                         return 2;
2540                 if (a.Z != 1f)
2541                         return 3;
2542                 if (a.W != 3f)
2543                         return 4;
2544                 if (result.Y != result.Y)
2545                         return 0;
2546                 return 0;
2547         }
2548         
2549         public static int test_24_regs_pressure_a () {
2550                 Vector4f a = new Vector4f (1, 2, 3, 4);
2551                 Vector4f b = a + a;
2552                 Vector4f c = b * a;
2553                 Vector4f d = a - b;
2554                 c = a + b + c + d;
2555                 return (int)c.Z;
2556         }
2557
2558         public static int test_54_regs_pressure_b () {
2559                 Vector4f a = new Vector4f (1, 2, 3, 4);
2560                 Vector4f b = a + a;
2561                 Vector4f c = b - a;
2562                 Vector4f d = c - a;
2563                 Vector4f e = a + b + c;
2564                 Vector4f f = d - b + a - c;
2565                 Vector4f g = a - d * f - c + b;
2566                 Vector4f h = a * b - c + e;
2567                 Vector4f i = h - g - f - e - d - c - b - a;
2568                 Vector4f j = a + b + c + d + e + f + g + h + i;
2569                 return (int)j.Z;
2570         }
2571
2572         static bool ff;
2573         public static int test_3_single_block_var_is_properly_promoted () {
2574                 Vector4f a = new Vector4f (4, 5, 6, 7);
2575                 if (ff)
2576                         a = a - a;
2577                 else {
2578                         Vector4f b = new Vector4f (1, 2, 3, 4);
2579                         Vector4f c = b;
2580                         a = a - b;
2581                         if (ff) {
2582                                 c = a;
2583                                 a = c;
2584                         }
2585                 }
2586                 return (int)a.X;
2587         }
2588
2589         static float float_val = 45f;
2590
2591         public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
2592                 Vector4f v = new Vector4f (1, 2, 3, 4);
2593                 float f = float_val;
2594                 int x = (int)f;
2595                 if (v.X != 1f)
2596                         return 1;
2597                 if (x != 45f)
2598                         return 2;
2599                 return 0;
2600         }
2601
2602         public static int Main () {
2603                 return TestDriver.RunTests (typeof (SimdTests));
2604         }
2605 }
2606