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