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