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