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