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