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