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