2008-10-17 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
6
7         public static int vector16b_cmpeq () {
8                 Vector16b a = new Vector16b (1,0,9,0,0,0,0,0,0,0,0,0,0,0,0,1);
9                 Vector16b b = new Vector16b (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
10                 Vector16b c = Vector16b.CompareEqual (a, b);
11
12                 if (c.V0 != 0)
13                         return 1;
14                 if (c.V1 != 0)
15                         return 2;
16                 if (c.V2 != 0)
17                         return 3;
18                 if (c.V3 != 0xff)
19                         return 4;
20                 if (c.V4 != 0xff)
21                         return 5;
22                 if (c.V5 != 0xff)
23                         return 6;
24                 if (c.V6 != 0xff)
25                         return 7;
26                 if (c.V7 != 0xff)
27                         return 8;
28                 if (c.V8 != 0xff)
29                         return 9;
30                 if (c.V9 != 0xff)
31                         return 10;
32                 if (c.V10 != 0xff)
33                         return 11;
34                 if (c.V11 != 0xff)
35                         return 12;
36                 if (c.V12 != 0xff)
37                         return 13;
38                 if (c.V13 != 0xff)
39                         return 14;
40                 if (c.V14 != 0xff)
41                         return 15;
42                 if (c.V15 != 0)
43                         return 16;
44                 return 0;
45         }
46
47
48         public static int vector16b_sum_abs_diff () {
49                 Vector16b a = new Vector16b (100,20,20,20,0,0,0,0,0,0,0,0,0,0, 0, 0);
50                 Vector16b b = new Vector16b (0,  10,10,10,0,0,0,0,0,0,0,0,0,0,10,10);
51                 Vector8us c = Vector16b.SumOfAbsoluteDifferences (a, b);
52
53                 if (c.V0 != 130)
54                         return 1;
55                 if (c.V1 != 0)
56                         return 2;
57                 if (c.V2 != 0)
58                         return 3;
59                 if (c.V3 != 0)
60                         return 4;
61                 if (c.V4 != 20)
62                         return 5;
63                 if (c.V5 != 0)
64                         return 6;
65                 if (c.V6 != 0)
66                         return 7;
67                 if (c.V7 != 0)
68                         return 8;
69                 return 0;
70         }
71
72
73         public static int test_0_vector16b_extract_mask () {
74                 Vector16b a = new Vector16b (0xF0,0,0xF0,0,0,0,0xF0,0xAA,0x0F,0,0xFF,0,0,0,0,0);
75                 int c = Vector16b.ExtractByteMask (a);
76
77                 if (c != 0x4C5)
78                         return 1;
79                 return 0;
80         }
81
82         public static int test_0_vector16b_min () {
83                 Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15);
84                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
85                 Vector16b c = Vector16b.Min (a, b);
86
87                 if (c.V0 != 0)
88                         return 1;
89                 if (c.V1 != 10)
90                         return 2;
91                 if (c.V2 != 11)
92                         return 3;
93                 if (c.V3 != 12)
94                         return 4;
95                 if (c.V4 != 4)
96                         return 5;
97                 if (c.V5 != 5)
98                         return 6;
99                 if (c.V6 != 6)
100                         return 7;
101                 if (c.V7 != 0)
102                         return 8;
103                 if (c.V8 != 1)
104                         return 9;
105                 if (c.V9 != 2)
106                         return 10;
107                 if (c.V10 != 3)
108                         return 11;
109                 if (c.V11 != 4)
110                         return 12;
111                 if (c.V12 != 5)
112                         return 13;
113                 if (c.V13 != 6)
114                         return 14;
115                 if (c.V14 != 7)
116                         return 15;
117                 if (c.V15 != 8)
118                         return 16;
119                 return 0;
120         }
121
122         public static int test_0_vector16b_max () {
123                 Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15);
124                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
125                 Vector16b c = Vector16b.Max (a, b);
126
127                 if (c.V0 != 9)
128                         return 1;
129                 if (c.V1 != 12)
130                         return 2;
131                 if (c.V2 != 20)
132                         return 3;
133                 if (c.V3 != 12)
134                         return 4;
135                 if (c.V4 != 13)
136                         return 5;
137                 if (c.V5 != 14)
138                         return 6;
139                 if (c.V6 != 15)
140                         return 7;
141                 if (c.V7 != 7)
142                         return 8;
143                 if (c.V8 != 8)
144                         return 9;
145                 if (c.V9 != 9)
146                         return 10;
147                 if (c.V10 != 10)
148                         return 11;
149                 if (c.V11 != 11)
150                         return 12;
151                 if (c.V12 != 12)
152                         return 13;
153                 if (c.V13 != 13)
154                         return 14;
155                 if (c.V14 != 14)
156                         return 15;
157                 if (c.V15 != 15)
158                         return 16;
159                 return 0;
160         }
161         public static int test_0_vector16b_avg () {
162                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
163                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
164                 Vector16b c = Vector16b.Average (a, b);
165
166                 if (c.V0 != 5)
167                         return 1;
168                 if (c.V1 != 6)
169                         return 2;
170                 if (c.V2 != 7)
171                         return 3;
172                 if (c.V3 != 8)
173                         return 4;
174                 if (c.V4 != 9)
175                         return 5;
176                 if (c.V5 != 10)
177                         return 6;
178                 if (c.V6 != 11)
179                         return 7;
180                 if (c.V7 != 4)
181                         return 8;
182                 if (c.V8 != 5)
183                         return 9;
184                 if (c.V9 != 6)
185                         return 10;
186                 if (c.V10 != 7)
187                         return 11;
188                 if (c.V11 != 8)
189                         return 12;
190                 if (c.V12 != 9)
191                         return 13;
192                 if (c.V13 != 10)
193                         return 14;
194                 if (c.V14 != 11)
195                         return 15;
196                 if (c.V15 != 12)
197                         return 16;
198                 return 0;
199         }
200
201
202         static unsafe Vector8us bad_method_regression_2 (Vector16b va, Vector16b vb) {
203                 Vector8us res = new Vector8us ();
204                 byte *a = (byte*)&va;
205                 byte *b = (byte*)&vb;
206
207                 int tmp = 0;
208                 for (int i = 0; i < 8; ++i)
209                         tmp += System.Math.Abs ((int)*a++ - (int)*b++);
210                 res.V0 = (ushort)tmp;
211
212                 tmp = 0;
213                 for (int i = 0; i < 8; ++i)
214                         tmp += System.Math.Abs ((int)*a++ - (int)*b++);
215                 res.V4 = (ushort)tmp;
216                 return res;
217         }
218
219         /*This bug was caused the simplifier not taking notice of LDADDR on the remaining blocks.*/
220         public static int test_2_local_simplifier_regression_other_blocks () {
221                 Vector16b a = new Vector16b (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
222                 Vector16b b = new Vector16b (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
223                 Vector8us res = bad_method_regression_2 (a,b);
224                 return (int)res.V0 + res.V4;
225         }
226
227         static unsafe Vector8us bad_method_regression (Vector16b va, Vector16b vb) {
228                 Vector8us res = new Vector8us ();
229                 byte *a = (byte*)&va;
230                 byte *b = (byte*)&vb;
231                 *((ushort*)&res) = 10;
232
233                 int tmp = 0;
234                 if (*b != 0)
235                         tmp++;
236
237                 Vector8us dd = res;
238                 dd = dd + dd - dd;
239                 return dd;
240         }
241
242         /*This bug was caused the simplifier not taking notice of LDADDR on the first block.*/
243         public static int test_10_local_simplifier_regression_first_block () {
244                 Vector16b a = new Vector16b ();
245                 Vector16b b = new Vector16b ();
246                 Vector8us res = bad_method_regression (a,b);
247                 return (int)res.V0;
248         }
249         
250
251         public static int test_0_vecto8us_extract_mask () {
252                 Vector8us a = new Vector8us (0xF0F0, 0x700F, 0xAABB, 0x0000, 0x00F0, 0xF0F0, 0, 0);
253                 int c = Vector8us.ExtractByteMask (a);
254
255                 if (c != 0xD33)
256                         return 1;
257                 return 0;
258         }
259
260         public static int test_0_vecto8us_shuffle_low () {
261                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
262                 Vector8us c = Vector8us.ShuffleLow (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
263
264                 if (c.V0 != 2)
265                         return 1;
266                 if (c.V1 != 4)
267                         return 2;
268                 if (c.V2 != 1)
269                         return 3;
270                 if (c.V3 != 3)
271                         return 4;
272                 if (c.V4 != 5)
273                         return 5;
274                 if (c.V5 != 6)
275                         return 6;
276                 if (c.V6 != 7)
277                         return 7;
278                 if (c.V7 != 8)
279                         return 8;
280                 return 0;
281         }
282
283         public static int test_0_vecto8us_shuffle_high () {
284                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
285                 Vector8us c = Vector8us.ShuffleHigh (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
286
287                 if (c.V0 != 1)
288                         return 1;
289                 if (c.V1 != 2)
290                         return 2;
291                 if (c.V2 != 3)
292                         return 3;
293                 if (c.V3 != 4)
294                         return 4;
295                 if (c.V4 != 6)
296                         return 5;
297                 if (c.V5 != 8)
298                         return 6;
299                 if (c.V6 != 5)
300                         return 7;
301                 if (c.V7 != 7)
302                         return 8;
303
304                 return 0;
305         }
306
307         public static int test_0_vecto8us_max () {
308                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
309                 Vector8us b = new Vector8us (9, 1, 1, 2, 9, 6, 5, 1000);
310                 Vector8us c = Vector8us.Max (a, b);
311
312                 if (c.V0 != 9)
313                         return 1;
314                 if (c.V1 != 2)
315                         return 2;
316                 if (c.V2 != 3)
317                         return 3;
318                 if (c.V3 != 4)
319                         return 4;
320                 if (c.V4 != 9)
321                         return 5;
322                 if (c.V5 != 6)
323                         return 6;
324                 if (c.V6 != 7)
325                         return 7;
326                 if (c.V7 != 1000)
327                         return 0;
328
329                 return 0;
330         }
331
332         public static int test_0_vecto8us_min () {
333                 Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4);
334                 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
335                 Vector8us c = Vector8us.Min (a, b);
336
337                 if (c.V0 != 1)
338                         return 1;
339                 if (c.V1 != 1)
340                         return 2;
341                 if (c.V2 != 1)
342                         return 3;
343                 if (c.V3 != 0)
344                         return 4;
345                 if (c.V4 != 3)
346                         return 5;
347                 if (c.V5 != 4)
348                         return 6;
349                 if (c.V6 != 5)
350                         return 7;
351                 if (c.V7 != 4)
352                         return 8;
353                 return 0;
354         }
355
356         public static int test_0_vecto8us_avg () {
357                 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
358                 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
359                 Vector8us c = Vector8us.Average (a, b);
360
361                 if (c.V0 != 5)
362                         return 1;
363                 if (c.V1 != 2)
364                         return 2;
365                 if (c.V2 != 2)
366                         return 3;
367                 if (c.V3 != 3)
368                         return 4;
369                 if (c.V4 != 4)
370                         return 5;
371                 if (c.V5 != 5)
372                         return 6;
373                 if (c.V6 != 6)
374                         return 7;
375                 if (c.V7 != 7)
376                         return 8;
377                 return 0;
378         }
379
380         static void store_helper (ref Vector4f x) {
381                 Vector4f k;
382                 k = new Vector4f(9,9,9,9);
383                 x = k;
384         }
385
386         public static int test_0_vector4f_byref_store ()
387         {
388                 Vector4f k;
389                 k = new Vector4f(1,2,3,4);
390                 store_helper (ref k);
391                 if (k.X != 9)
392                         return 1;
393                 return 0;
394         }
395
396         public static int test_0_vector4f_init_array_element ()
397         {
398                 Vector4f[] v = new Vector4f[1];
399                 v[0] = new Vector4f(9,9,9,9);
400                 if (v [0].X != 9)
401                         return 1;
402                 return 0;
403         }
404
405         public static int test_0_vector4f_dup_high () {
406                 Vector4f a = new Vector4f (1, 2, 3, 4);
407                 Vector4f c = Vector4f.DuplicateHigh(a);
408
409                 if (c.X != 2)
410                         return 1;
411                 if (c.Y != 2)
412                         return 2;
413                 if (c.Z != 4)
414                         return 3;
415                 if (c.W != 4)
416                         return 4;
417                 return 0;
418         }
419
420         public static int test_0_vector4f_dup_low () {
421                 Vector4f a = new Vector4f (1, 2, 3, 4);
422                 Vector4f c = Vector4f.DuplicateLow (a);
423
424                 if (c.X != 1)
425                         return 1;
426                 if (c.Y != 1)
427                         return 2;
428                 if (c.Z != 3)
429                         return 3;
430                 if (c.W != 3)
431                         return 4;
432                 return 0;
433         }
434
435
436         public static int test_0_vector4f_interleave_high () {
437                 Vector4f a = new Vector4f (1, 2, 3, 4);
438                 Vector4f b = new Vector4f (5, 6, 7, 8);
439                 Vector4f c = Vector4f.InterleaveHigh (a, b);
440
441                 if (c.X != 3)
442                         return 1;
443                 if (c.Y != 7)
444                         return 2;
445                 if (c.Z != 4)
446                         return 3;
447                 if (c.W != 8)
448                         return 4;
449                 return 0;
450         }
451
452         public static int test_0_vector4f_interleave_low () {
453                 Vector4f a = new Vector4f (1, 2, 3, 4);
454                 Vector4f b = new Vector4f (5, 6, 7, 8);
455                 Vector4f c = Vector4f.InterleaveLow (a, b);
456
457                 if (c.X != 1)
458                         return 1;
459                 if (c.Y != 5)
460                         return 2;
461                 if (c.Z != 2)
462                         return 3;
463                 if (c.W != 6)
464                         return 4;
465                 return 0;
466         }
467
468         public static int test_0_vector4f_rcp () {
469                 Vector4f a = new Vector4f (1, 2, 4, 8);
470                 Vector4f c = Vector4f.Reciprocal (a);
471
472                 //Test with ranges due to the terrible precision.
473                 if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f))
474                         return 1;
475                 if (c.Y < (0.5 - 0.01f) || c.Y > (0.5 + 0.01f))
476                         return 2;
477                 if (c.Z < (0.25 - 0.01f) || c.Z > (0.25 + 0.01f))
478                         return 3;
479                 if (c.W < (0.125 - 0.01f) || c.W > (0.125 + 0.01f))
480                         return 4;
481                 return 0;
482         }
483
484         public static int test_0_vector4f_xor () {
485                 Vector4f a = new Vector4f (1, 2, 3, 4);
486                 Vector4f b = new Vector4f (1, 3, 3, 8);
487                 Vector4f c = a ^ b;
488
489                 if (((Vector4ui)c).X != 0)
490                         return 1;
491                 if (((Vector4ui)c).Y != 0x400000)
492                         return 2;
493                 if (((Vector4ui)c).Z != 0)
494                         return 3;
495                 if (((Vector4ui)c).W != 0x1800000)
496                         return 4;
497                 return 0;
498         }
499
500         public static int test_0_vector4f_or () {
501                 Vector4f a = new Vector4f (1, 2, 3, 4);
502                 Vector4f b = new Vector4f (1, 3, 3, 8);
503                 Vector4f c = a | b;
504
505                 if (((Vector4ui)c).X != 0x3F800000)
506                         return 1;
507                 if (((Vector4ui)c).Y != 0x40400000)
508                         return 2;
509                 if (((Vector4ui)c).Z != 0x40400000)
510                         return 3;
511                 if (((Vector4ui)c).W != 0x41800000)
512                         return 4;
513                 return 0;
514         }
515         public static int test_0_vector4f_andn () {
516                 Vector4f a = new Vector4f (1, 2, 3, 4);
517                 Vector4f b = new Vector4f (1, 3, 3, 8);
518                 Vector4f c = Vector4f.AndNot (a ,b);
519
520                 if (((Vector4ui)c).X != 0)
521                         return 1;
522                 if (((Vector4ui)c).Y != 0x400000)
523                         return 2;
524                 if (((Vector4ui)c).Z != 0)
525                         return 3;
526                 if (((Vector4ui)c).W != 0x1000000)
527                         return 4;
528                 return 0;
529         }
530
531         public static int test_0_vector4f_and () {
532                 Vector4f a = new Vector4f (1, 2, 3, 4);
533                 Vector4f b = new Vector4f (1, 3, 3, 8);
534                 Vector4f c = a & b;
535
536                 if (((Vector4ui)c).X != 0x3F800000)
537                         return 1;
538                 if (((Vector4ui)c).Y != 0x40000000)
539                         return 2;
540                 if (((Vector4ui)c).Z != 0x40400000)
541                         return 3;
542                 if (((Vector4ui)c).W != 0x40000000)
543                         return 4;
544                 return 0;
545         }
546
547         public static int test_0_vector4f_cmpord () {
548                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
549                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
550                 Vector4f c = Vector4f.CompareOrdered (a, b);
551
552                 if (((Vector4ui)c).X != 0)
553                         return 1;
554                 if (((Vector4ui)c).Y != 0)
555                         return 2;
556                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
557                         return 3;
558                 if (((Vector4ui)c).W != 0xFFFFFFFF)
559                         return 4;
560                 return 0;
561         }
562
563         public static int test_0_vector4f_cmpnle () {
564                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
565                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
566                 Vector4f c = Vector4f.CompareNotLessEqual (a, b);
567
568                 if (((Vector4ui)c).X != 0xFFFFFFFF)
569                         return 1;
570                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
571                         return 2;
572                 if (((Vector4ui)c).Z != 0)
573                         return 3;
574                 if (((Vector4ui)c).W != 0)
575                         return 4;
576                 return 0;
577         }
578
579         public static int test_0_vector4f_cmpnlt () {
580                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
581                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
582                 Vector4f c = Vector4f.CompareNotLessThan (a, b);
583
584                 if (((Vector4ui)c).X != 0xFFFFFFFF)
585                         return 1;
586                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
587                         return 2;
588                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
589                         return 3;
590                 if (((Vector4ui)c).W != 0)
591                         return 4;
592                 return 0;
593         }
594
595         public static int test_0_vector4f_cmpneq () {
596                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
597                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
598                 Vector4f c = Vector4f.CompareNotEqual (a, b);
599
600                 if (((Vector4ui)c).X != 0xFFFFFFFF)
601                         return 1;
602                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
603                         return 2;
604                 if (((Vector4ui)c).Z != 0)
605                         return 3;
606                 if (((Vector4ui)c).W != 0xFFFFFFFF)
607                         return 4;
608                 return 0;
609         }
610
611         public static int test_0_vector4f_cmpunord () {
612                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
613                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
614                 Vector4f c = Vector4f.CompareUnordered (a, b);
615
616                 if (((Vector4ui)c).X != 0xFFFFFFFF)
617                         return 1;
618                 if (((Vector4ui)c).Y != 0xFFFFFFFF)
619                         return 2;
620                 if (((Vector4ui)c).Z != 0)
621                         return 3;
622                 if (((Vector4ui)c).W != 0)
623                         return 4;
624                 return 0;
625         }
626
627         public static int test_0_vector4f_cmple () {
628                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
629                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
630                 Vector4f c = Vector4f.CompareLessEqual (a, b);
631
632                 if (((Vector4ui)c).X != 0)
633                         return 1;
634                 if (((Vector4ui)c).Y != 0)
635                         return 2;
636                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
637                         return 3;
638                 if (((Vector4ui)c).W != 0xFFFFFFFF)
639                         return 4;
640                 return 0;
641         }
642
643         public static int test_0_vector4f_cmplt () {
644                 Vector4f a = new Vector4f (float.NaN, 2,         3, 4);
645                 Vector4f b = new Vector4f (1,         float.NaN, 3, 6);
646                 Vector4f c = Vector4f.CompareLessThan (a, b);
647
648                 if (((Vector4ui)c).X != 0)
649                         return 1;
650                 if (((Vector4ui)c).Y != 0)
651                         return 2;
652                 if (((Vector4ui)c).Z != 0)
653                         return 3;
654                 if (((Vector4ui)c).W != 0xFFFFFFFF)
655                         return 4;
656                 return 0;
657         }
658
659         public static int test_0_vector4f_cmpeq () {
660                 Vector4f a = new Vector4f (float.NaN, 2,         3, 6);
661                 Vector4f b = new Vector4f (1,         float.NaN, 3, 4);
662                 Vector4f c = Vector4f.CompareEquals (a, b);
663
664                 if (((Vector4ui)c).X != 0)
665                         return 1;
666                 if (((Vector4ui)c).Y != 0)
667                         return 2;
668                 if (((Vector4ui)c).Z != 0xFFFFFFFF)
669                         return 3;
670                 if (((Vector4ui)c).W != 0)
671                         return 4;
672                 return 0;
673         }
674
675         public static int test_0_vector4ui_sar () {
676                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
677                 
678                 Vector4ui c = Vector4ui.ShiftRightArithmetic (a, 2);
679         
680                 if (c.X != 0xFC000000)
681                         return 1;
682                 if (c.Y != 5)
683                         return 2;
684                 if (c.Z != 0)
685                         return 3;
686                 if (c.W != 10)
687                         return 4;
688                 return 0;
689         }
690
691         public static int test_0_vector4ui_unpack_high () {
692                 Vector4ui a = new Vector4ui (1,2,3,4);
693                 Vector4ui b = new Vector4ui (5,6,7,8);
694                 
695                 Vector4ui c = Vector4ui.UnpackHigh(a, b);
696         
697                 if (c.X != 3)
698                         return 1;
699                 if (c.Y != 7)
700                         return 2;
701                 if (c.Z != 4)
702                         return 3;
703                 if (c.W != 8)
704                         return 4;
705                 return 0;
706         }
707
708         public  static int test_0_vector4ui_unpack_low () {
709                 Vector4ui a = new Vector4ui (1,2,3,4);
710                 Vector4ui b = new Vector4ui (5,6,7,8);
711                 
712                 Vector4ui c = Vector4ui.UnpackLow (a, b);
713         
714                 if (c.X != 1)
715                         return 1;
716                 if (c.Y != 5)
717                         return 2;
718                 if (c.Z != 2)
719                         return 3;
720                 if (c.W != 6)
721                         return 4;
722                 return 0;
723         }
724
725         public  static int test_0_vector4ui_xor () {
726                 Vector4ui a = new Vector4ui (1,2,3,4);
727                 Vector4ui b = new Vector4ui (7,5,3,1);
728                 
729                 Vector4ui c = a ^ b;
730         
731                 if (c.X != 6)
732                         return 1;
733                 if (c.Y != 7)
734                         return 2;
735                 if (c.Z != 0)
736                         return 3;
737                 if (c.W != 5)
738                         return 4;
739                 return 0;
740         }
741
742         public  static int test_0_vector4ui_or () {
743                 Vector4ui a = new Vector4ui (1,2,3,4);
744                 Vector4ui b = new Vector4ui (7,5,3,1);
745                 
746                 Vector4ui c = a | b;
747         
748                 if (c.X != 7)
749                         return 1;
750                 if (c.Y != 7)
751                         return 2;
752                 if (c.Z != 3)
753                         return 3;
754                 if (c.W != 5)
755                         return 4;
756                 return 0;
757         }
758         public  static int test_0_vector4ui_and () {
759                 Vector4ui a = new Vector4ui (1,2,3,4);
760                 Vector4ui b = new Vector4ui (7,5,3,1);
761                 
762                 Vector4ui c = a & b;
763         
764                 if (c.X != 1)
765                         return 1;
766                 if (c.Y != 0)
767                         return 2;
768                 if (c.Z != 3)
769                         return 3;
770                 if (c.W != 0)
771                         return 4;
772                 return 0;
773         }
774
775         public  static int test_0_vector4ui_shr () {
776                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
777                 
778                 Vector4ui c = a >> 2;
779         
780                 if (c.X != 0x3C000000)
781                         return 1;
782                 if (c.Y != 5)
783                         return 2;
784                 if (c.Z != 0)
785                         return 3;
786                 if (c.W != 10)
787                         return 4;
788                 return 0;
789         }
790
791         public  static int test_0_vector4ui_shl () {
792                 Vector4ui a = new Vector4ui (10,20,3,40);
793                 
794                 Vector4ui c = a << 2;
795         
796                 if (c.X != 40)
797                         return 1;
798                 if (c.Y != 80)
799                         return 2;
800                 if (c.Z != 12)
801                         return 3;
802                 if (c.W != 160)
803                         return 4;
804                 return 0;
805         }
806
807         public  static int test_0_vector4ui_mul () {
808                 Vector4ui a = new Vector4ui (0x8888,20,3,40);
809                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
810                 
811                 Vector4ui c = a * b;
812         
813                 if (c.X != 0xffff7800)
814                         return 1;
815                 if (c.Y != 40)
816                         return 2;
817                 if (c.Z != 9)
818                         return 3;
819                 if (c.W != 160)
820                         return 4;
821                 return 0;
822         }
823         public  static int test_0_vector4ui_sub () {
824                 Vector4ui a = new Vector4ui (1,20,3,40);
825                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
826                 
827                 Vector4ui c = a - b;
828         
829                 if (c.X != 0xff0101)
830                         return 1;
831                 if (c.Y != 18)
832                         return 2;
833                 if (c.Z != 0)
834                         return 3;
835                 if (c.W != 36)
836                         return 4;
837                 return 0;
838         }
839
840         public  static int test_0_vector4ui_add () {
841                 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
842                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
843                 
844                 Vector4ui c = a + b;
845         
846                 if (c.X != 0xfe01fe00)
847                         return 1;
848                 if (c.Y != 4)
849                         return 2;
850                 if (c.Z != 6)
851                         return 3;
852                 if (c.W != 8)
853                         return 4;
854                 return 0;
855         }
856
857
858         static int test_0_vector4ui_accessors () {
859                 Vector4ui a = new Vector4ui (1,2,3,4);
860
861                 if (a.X != 1)
862                         return 1;
863                 if (a.Y != 2)
864                         return 2;
865                 if (a.Z != 3)
866                         return 3;
867                 if (a.W != 4)
868                         return 4;
869                 a.X = 10;
870                 a.Y = 20;
871                 a.Z = 30;
872                 a.W = 40;
873
874                 if (a.X != 10)
875                         return 5;
876                 if (a.Y != 20)
877                         return 6;
878                 if (a.Z != 30)
879                         return 7;
880                 if (a.W != 40)
881                         return 8;
882                 return 0;
883         }
884
885         static int test_0_vector8us_sub_sat () {
886                 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
887                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
888                 Vector8us c = Vector8us.SubWithSaturation (a, b);
889
890                 if (c.V0 != 0)
891                         return 1;
892                 if (c.V1 != 0)
893                         return 2;
894                 if (c.V2 != 15)
895                         return 3;
896                 if (c.V3 != 0)
897                         return 4;
898                 if (c.V4 != 0)
899                         return 5;
900                 if (c.V5 != 0)
901                         return 6;
902                 if (c.V6 != 0)
903                         return 7;
904                 if (c.V7 != 0)
905                         return 8;
906                 return 0;
907         }
908
909         static int test_0_vector8us_add_sat () {
910                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
911                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
912                 Vector8us c = Vector8us.AddWithSaturation (a, b);
913
914                 if (c.V0 != 0xFFFF)
915                         return 1;
916                 if (c.V1 != 5)
917                         return 2;
918                 if (c.V2 != 7)
919                         return 3;
920                 if (c.V3 != 9)
921                         return 4;
922                 if (c.V4 != 11)
923                         return 5;
924                 if (c.V5 != 13)
925                         return 6;
926                 if (c.V6 != 15)
927                         return 7;
928                 if (c.V7 != 17)
929                         return 8;
930                 return 0;
931         }
932
933         static int test_0_vector8us_unpack_low () {
934                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
935                 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
936                 Vector8us c = Vector8us.UnpackLow (a, b);
937
938                 if (c.V0 != 0)
939                         return 1;
940                 if (c.V1 != 3)
941                         return 2;
942                 if (c.V2 != 1)
943                         return 3;
944                 if (c.V3 != 4)
945                         return 4;
946                 if (c.V4 != 2)
947                         return 5;
948                 if (c.V5 != 5)
949                         return 6;
950                 if (c.V6 != 3)
951                         return 7;
952                 if (c.V7 != 6)
953                         return 8;
954                 return 0;
955         }
956
957
958         static int test_0_vector8us_shift_left () {
959                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
960                 int amt = 2;
961                 Vector8us c = a << amt;
962         
963                 if (c.V0 != 0xFC00)
964                         return 1;
965                 if (c.V1 != 4)
966                         return 2;
967                 if (c.V7 != 28)
968                         return 3;
969                 return 0;
970         }
971         
972         static int test_0_vector8us_shift_right_arithmetic () {
973                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
974                 int amt = 2;
975                 Vector8us c = Vector8us.ShiftRightArithmetic (a, amt);
976         
977                 if (c.V0 != 0xFFC0)
978                         return 1;
979                 if (c.V1 != 0)
980                         return 2;
981                 if (c.V7 != 1)
982                         return 3;
983                 return 0;
984         }
985
986         static int test_0_vector8us_shift_variable_offset () {
987                 int off = 2;
988                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
989                 Vector8us b = a;
990                 Vector8us c = b >> off;
991                 a = b + b;
992
993                 if (c.V0 != 0x3C00)
994                         return 1;
995                 if (c.V1 != 0)
996                         return 2;
997                 if (c.V7 != 1)
998                         return 3;
999                 if (a.V1 != 2)
1000                         return 4;
1001                 if (a.V7 != 14)
1002                         return 5;
1003                 return 0;
1004         }
1005         
1006         
1007         static int test_0_vector8us_shift_operand_is_live_after_op () {
1008                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
1009                 Vector8us b = a;
1010                 Vector8us c = b >> 2;
1011                 a = b + b;
1012
1013                 if (c.V0 != 0x3C00)
1014                         return 1;
1015                 if (c.V1 != 0)
1016                         return 2;
1017                 if (c.V7 != 1)
1018                         return 3;
1019                 if (a.V1 != 2)
1020                         return 4;
1021                 if (a.V7 != 14)
1022                         return 5;
1023                 return 0;
1024         }
1025
1026         static int test_0_vector8us_shr_constant () {
1027                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
1028                 Vector8us c = a >> 2;
1029
1030                 if (c.V0 != 0x3C00)
1031                         return 1;
1032                 if (c.V1 != 0)
1033                         return 2;
1034                 if (c.V7 != 1)
1035                         return 3;
1036                 return 0;
1037         }
1038
1039         static int test_0_vector8us_mul () {
1040                 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
1041                 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
1042
1043                 Vector8us c = a * b;
1044                 if (c.V0 != 63488)
1045                         return 1;
1046                 if (c.V1 != 4)
1047                         return 2;
1048                 if (c.V7 != 80)
1049                         return 3;
1050                 return 0;
1051         }
1052
1053         static int test_0_vector8us_add () {
1054                 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
1055                 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
1056
1057                 Vector8us c = a + b;
1058                 if (c.V0 != 34696)
1059                         return 1;
1060                 if (c.V1 != 5)
1061                         return 2;
1062                 if (c.V7 != 18)
1063                         return 3;
1064                 return 0;
1065         }
1066
1067
1068         static int test_0_vector8us_sub () {
1069                 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
1070                 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
1071
1072                 Vector8us c = a - b;
1073
1074                 if (c.V0 != 65529)
1075                         return 1;
1076                 if (c.V1 != 3)
1077                         return 2;
1078                 if (c.V7 != 2)
1079                         return 3;
1080                 return 0;
1081         }
1082
1083
1084         static int test_0_vector8us_accessors () {
1085                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
1086
1087                 if (a.V0 != 0)
1088                         return 1;
1089                 if (a.V1 != 1)
1090                         return 2;
1091                 if (a.V2 != 2)
1092                         return 3;
1093                 if (a.V3 != 3)
1094                         return 4;
1095                 if (a.V4 != 4)
1096                         return 5;
1097                 if (a.V5 != 5)
1098                         return 6;
1099                 if (a.V6 != 6)
1100                         return 7;
1101                 if (a.V7 != 7)
1102                         return 8;
1103                 a.V0 = 10;
1104                 a.V1 = 20;
1105                 a.V2 = 30;
1106                 a.V3 = 40;
1107                 a.V4 = 50;
1108                 a.V5 = 60;
1109                 a.V6 = 70;
1110                 a.V7 = 80;
1111
1112                 if (a.V0 != 10)
1113                         return 17;
1114                 if (a.V1 != 20)
1115                         return 18;
1116                 if (a.V2 != 30)
1117                         return 19;
1118                 if (a.V3 != 40)
1119                         return 20;
1120                 if (a.V4 != 50)
1121                         return 21;
1122                 if (a.V5 != 60)
1123                         return 22;
1124                 if (a.V6 != 70)
1125                         return 23;
1126                 if (a.V7 != 80)
1127                         return 24;
1128
1129                 return 0;
1130         }
1131
1132
1133         static int test_0_vector16b_unpack_high () {
1134                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1135                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1136                 Vector16b c = Vector16b.UnpackHigh (a, b);
1137
1138                 if (c.V0 != 8)
1139                         return 1;
1140                 if (c.V1 != 1)
1141                         return 2;
1142                 if (c.V2 != 9)
1143                         return 3;
1144                 if (c.V3 != 2)
1145                         return 4;
1146                 if (c.V4 != 10)
1147                         return 5;
1148                 if (c.V5 != 3)
1149                         return 6;
1150                 if (c.V14 != 15)
1151                         return 7;
1152                 if (c.V15 != 8)
1153                         return 8;
1154                 return 0;
1155         }
1156
1157         static int test_0_vector16b_unpack_low () {
1158                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1159                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1160                 Vector16b c = Vector16b.UnpackLow (a, b);
1161
1162                 if (c.V0 != 0)
1163                         return 1;
1164                 if (c.V1 != 9)
1165                         return 2;
1166                 if (c.V2 != 1)
1167                         return 3;
1168                 if (c.V3 != 10)
1169                         return 4;
1170                 if (c.V4 != 2)
1171                         return 5;
1172                 if (c.V5 != 11)
1173                         return 6;
1174                 if (c.V14 != 7)
1175                         return 7;
1176                 if (c.V15 != 0)
1177                         return 8;
1178                 return 0;
1179         }
1180
1181         static int test_0_vector16b_sar () {
1182                 Vector16b a = new Vector16b (0xF0,20,3,40,0,0,0,0,0,0,0,0,0,0,0,0);
1183                 
1184                 Vector16b c = Vector16b.ShiftRightArithmetic (a, 2);
1185                 if (c.V0 != 0xFC)
1186                         return 1;
1187                 if (c.V1 != 5)
1188                         return 1;
1189                 if (c.V2 != 0)
1190                         return 2;
1191                 if (c.V3 != 10)
1192                         return 3;
1193                 return 0;
1194         }
1195
1196         static int test_0_vector16b_sub_sat () {
1197                 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1198                 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1199                 Vector16b c = Vector16b.SubWithSaturation (a, b);
1200
1201                 if (c.V0 != 0)
1202                         return 1;
1203                 if (c.V1 != 9)
1204                         return 2;
1205                 if (c.V15 != 0)
1206                         return 3;
1207                 return 0;
1208         }
1209         
1210         static int test_0_vector16b_add_sat () {
1211                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1212                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1213                 Vector16b c = Vector16b.AddWithSaturation (a, b);
1214
1215                 if (c.V0 != 255)
1216                         return 1;
1217                 if (c.V1 != 11)
1218                         return 2;
1219                 if (c.V15 != 23)
1220                         return 3;
1221                 return 0;
1222         }
1223
1224         static int test_0_vector16b_add_ovf () {
1225                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1226                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1227                 Vector16b c = a + b;
1228
1229                 if (c.V0 != 144)
1230                         return 1;
1231                 if (c.V1 != 11)
1232                         return 2;
1233                 if (c.V15 != 23)
1234                         return 3;
1235                 return 0;
1236         }
1237
1238         static int test_0_vector16b_accessors () {
1239                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1240
1241                 if (a.V0 != 0)
1242                         return 1;
1243                 if (a.V1 != 1)
1244                         return 2;
1245                 if (a.V2 != 2)
1246                         return 3;
1247                 if (a.V3 != 3)
1248                         return 4;
1249                 if (a.V4 != 4)
1250                         return 5;
1251                 if (a.V5 != 5)
1252                         return 6;
1253                 if (a.V6 != 6)
1254                         return 7;
1255                 if (a.V7 != 7)
1256                         return 8;
1257                 if (a.V8 != 8)
1258                         return 9;
1259                 if (a.V9 != 9)
1260                         return 10;
1261                 if (a.V10 != 10)
1262                         return 11;
1263                 if (a.V11 != 11)
1264                         return 12;
1265                 if (a.V12 != 12)
1266                         return 13;
1267                 if (a.V13 != 13)
1268                         return 14;
1269                 if (a.V14 != 14)
1270                         return 15;
1271                 if (a.V15 != 15)
1272                         return 16;
1273
1274                 a.V0 = 10;
1275                 a.V1 = 20;
1276                 a.V2 = 30;
1277                 a.V3 = 40;
1278                 a.V4 = 50;
1279                 a.V5 = 60;
1280                 a.V6 = 70;
1281                 a.V7 = 80;
1282                 a.V8 = 90;
1283                 a.V9 = 100;
1284                 a.V10 = 110;
1285                 a.V11 = 120;
1286                 a.V12 = 130;
1287                 a.V13 = 140;
1288                 a.V14 = 150;
1289                 a.V15 = 160;
1290
1291                 if (a.V0 != 10)
1292                         return 17;
1293                 if (a.V1 != 20)
1294                         return 18;
1295                 if (a.V2 != 30)
1296                         return 19;
1297                 if (a.V3 != 40)
1298                         return 20;
1299                 if (a.V4 != 50)
1300                         return 21;
1301                 if (a.V5 != 60)
1302                         return 22;
1303                 if (a.V6 != 70)
1304                         return 23;
1305                 if (a.V7 != 80)
1306                         return 24;
1307                 if (a.V8 != 90)
1308                         return 25;
1309                 if (a.V9 != 100)
1310                         return 26;
1311                 if (a.V10 != 110)
1312                         return 27;
1313                 if (a.V11 != 120)
1314                         return 28;
1315                 if (a.V12 != 130)
1316                         return 29;
1317                 if (a.V13 != 140)
1318                         return 30;
1319                 if (a.V14 != 150)
1320                         return 31;
1321                 if (a.V15 != 160)
1322                         return 32;
1323                 return 0;
1324         }
1325
1326         public static int test_0_accessors () {
1327                 Vector4f a = new Vector4f (1, 2, 3, 4);
1328                 if (a.X != 1f)
1329                         return 1;
1330                 if (a.Y != 2f)
1331                         return 2;
1332                 if (a.Z != 3f)
1333                         return 3;
1334                 if (a.W != 4f)
1335                         return 4;
1336                 return 0;
1337         }
1338
1339         public static int test_0_packed_add_with_stack_tmp () {
1340                 Vector4f a = new Vector4f (1, 2, 3, 4);
1341                 Vector4f b = new Vector4f (5, 6, 7, 8);
1342                 Vector4f c = new Vector4f (-1, -3, -4, -5);
1343                 Vector4f d = a + b + c;
1344                 if (d.X != 5f)
1345                         return 1;
1346                 if (d.Y != 5f)
1347                         return 2;
1348                 if (d.Z != 6f)
1349                         return 3;
1350                 if (d.W != 7f)
1351                         return 4;
1352                 return 0;
1353         }
1354
1355         public static int test_0_simple_packed_add () {
1356                 Vector4f a = new Vector4f (1, 2, 3, 4);
1357                 Vector4f b = new Vector4f (5, 6, 7, 8);
1358                 Vector4f c;
1359                 c = a + b;
1360                 if (c.X != 6f)
1361                         return 1;
1362                 if (c.Y != 8f)
1363                         return 2;
1364                 if (c.Z != 10f)
1365                         return 3;
1366                 if (c.W != 12f)
1367                         return 4;
1368                 return 0;
1369         }
1370
1371         public static int test_0_simple_packed_sub () {
1372                 Vector4f a = new Vector4f (1, 2, 3, 4);
1373                 Vector4f b = new Vector4f (5, 6, 7, 8);
1374                 Vector4f c = b - a;
1375                 if (c.X != 4f)
1376                         return 1;
1377                 if (c.Y != 4f)
1378                         return 2;
1379                 if (c.Z != 4f)
1380                         return 3;
1381                 if (c.W != 4f)
1382                         return 4;
1383                 return 0;
1384         }
1385
1386         public static int test_0_simple_packed_mul () {
1387                 Vector4f a = new Vector4f (1, 2, 3, 4);
1388                 Vector4f b = new Vector4f (5, 6, 7, 8);
1389                 Vector4f c = b * a;
1390                 if (c.X != 5f)
1391                         return 1;
1392                 if (c.Y != 12f)
1393                         return 2;
1394                 if (c.Z != 21f)
1395                         return 3;
1396                 if (c.W != 32f)
1397                         return 4;
1398                 return 0;
1399         }
1400
1401         public static int test_0_simple_packed_div () {
1402                 Vector4f a = new Vector4f (2, 2, 3, 4);
1403                 Vector4f b = new Vector4f (20, 10, 33, 12);
1404                 Vector4f c = b / a;
1405                 if (c.X != 10f)
1406                         return 1;
1407                 if (c.Y != 5f)
1408                         return 2;
1409                 if (c.Z != 11f)
1410                         return 3;
1411                 if (c.W != 3f)
1412                         return 4;
1413                 return 0;
1414         }
1415
1416         public static int test_0_simple_packed_sqrt () {
1417                 Vector4f a = new Vector4f (16, 4, 9, 25);
1418                 a = Vector4f.Sqrt (a);
1419                 if (a.X != 4f)
1420                         return 1;
1421                 if (a.Y != 2f)
1422                         return 2;
1423                 if (a.Z != 3f)
1424                         return 3;
1425                 if (a.W != 5f)
1426                         return 4;
1427                 return 0;
1428         }
1429
1430         public static int test_0_simple_packed_invsqrt () {
1431                 Vector4f a = new Vector4f (16, 4, 100, 25);
1432                 //this function has VERY low precision
1433                 a = Vector4f.InvSqrt (a);
1434                 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
1435                         return 1;
1436                 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
1437                         return 2;
1438                 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
1439                         return 3;
1440                 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
1441                         return 4;
1442                 return 0;
1443         }
1444
1445         public static int test_0_simple_packed_min () {
1446                 Vector4f a = new Vector4f (16, -4, 9, 25);
1447                 Vector4f b = new Vector4f (5, 3, 9, 0);
1448                 Vector4f c = Vector4f.Min (a, b);
1449                 if (c.X != 5f)
1450                         return 1;
1451                 if (c.Y != -4f)
1452                         return 2;
1453                 if (c.Z != 9f)
1454                         return 3;
1455                 if (c.W != 0f)
1456                         return 4;
1457                 return 0;
1458         }
1459
1460         public static int test_0_simple_packed_max () {
1461                 Vector4f a = new Vector4f (16, -4, 9, 25);
1462                 Vector4f b = new Vector4f (5, 3, 9, 0);
1463                 Vector4f c = Vector4f.Max (a, b);
1464                 if (c.X != 16f)
1465                         return 1;
1466                 if (c.Y != 3f)
1467                         return 2;
1468                 if (c.Z != 9f)
1469                         return 3;
1470                 if (c.W != 25f)
1471                         return 4;
1472                 return 0;
1473         }
1474
1475         public static int test_0_simple_packed_hadd () {
1476                 Vector4f a = new Vector4f (5, 5, 6, 6);
1477                 Vector4f b = new Vector4f (7, 7, 8, 8);
1478                 Vector4f c = Vector4f.HorizontalAdd (a, b);
1479                 if (c.X != 10f)
1480                         return 1;
1481                 if (c.Y != 12f)
1482                         return 2;
1483                 if (c.Z != 14f)
1484                         return 3;
1485                 if (c.W != 16f)
1486                         return 4;
1487                 return 0;
1488         }
1489
1490         public static int test_0_simple_packed_hsub () {
1491                 Vector4f a = new Vector4f (5, 2, 6, 1);
1492                 Vector4f b = new Vector4f (7, 0, 8, 3);
1493                 Vector4f c = Vector4f.HorizontalSub (a, b);
1494                 if (c.X != 3f)
1495                         return 1;
1496                 if (c.Y != 5f)
1497                         return 2;
1498                 if (c.Z != 7f)
1499                         return 3;
1500                 if (c.W != 5f)
1501                         return 4;
1502                 return 0;
1503         }
1504
1505         public static int test_0_simple_packed_addsub () {
1506                 Vector4f a = new Vector4f (5, 2, 6, 1);
1507                 Vector4f b = new Vector4f (7, 0, 8, 3);
1508                 Vector4f c = Vector4f.AddSub (a, b);
1509                 if (c.X != -2f)
1510                         return 1;
1511                 if (c.Y != 2f)
1512                         return 2;
1513                 if (c.Z != -2f)
1514                         return 3;
1515                 if (c.W != 4f)
1516                         return 4;
1517                 return 0;
1518         }
1519
1520         public static int test_0_simple_packed_shuffle () {
1521                 Vector4f a = new Vector4f (1, 2, 3, 4);
1522                 a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1523                 if (a.X != 2f)
1524                         return 1;
1525                 if (a.Y != 4f)
1526                         return 2;
1527                 if (a.Z != 1f)
1528                         return 3;
1529                 if (a.W != 3f)
1530                         return 4;
1531                 return 0;
1532         }
1533
1534         public static int test_0_packed_shuffle_with_reg_pressure () {
1535                 Vector4f v = new Vector4f (1, 2, 3, 4);
1536                 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
1537                 if (ff) v = v + v -v    ;
1538
1539                 Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1540                 Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1541                 Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1542                 Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1543                 Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1544                 Vector4f a = x;
1545
1546                 r0 = r0 * m0 + x;
1547                 r1 = r1 * m1 + x;
1548                 x = x - v + v;
1549                 r2 = r2 * m2 + x;
1550                 r3 = r3 * m3 + x;
1551                 Vector4f result = r0 + r1 + r2 + r3;
1552
1553                 if (a.X != 2f)
1554                         return 1;
1555                 if (a.Y != 4f)
1556                         return 2;
1557                 if (a.Z != 1f)
1558                         return 3;
1559                 if (a.W != 3f)
1560                         return 4;
1561                 if (result.Y != result.Y)
1562                         return 0;
1563                 return 0;
1564         }
1565         
1566         public static int test_24_regs_pressure_a () {
1567                 Vector4f a = new Vector4f (1, 2, 3, 4);
1568                 Vector4f b = a + a;
1569                 Vector4f c = b * a;
1570                 Vector4f d = a - b;
1571                 c = a + b + c + d;
1572                 return (int)c.Z;
1573         }
1574
1575         public static int test_54_regs_pressure_b () {
1576                 Vector4f a = new Vector4f (1, 2, 3, 4);
1577                 Vector4f b = a + a;
1578                 Vector4f c = b - a;
1579                 Vector4f d = c - a;
1580                 Vector4f e = a + b + c;
1581                 Vector4f f = d - b + a - c;
1582                 Vector4f g = a - d * f - c + b;
1583                 Vector4f h = a * b - c + e;
1584                 Vector4f i = h - g - f - e - d - c - b - a;
1585                 Vector4f j = a + b + c + d + e + f + g + h + i;
1586                 return (int)j.Z;
1587         }
1588
1589         static bool ff;
1590         public static int test_3_single_block_var_is_properly_promoted () {
1591                 Vector4f a = new Vector4f (4, 5, 6, 7);
1592                 if (ff)
1593                         a = a - a;
1594                 else {
1595                         Vector4f b = new Vector4f (1, 2, 3, 4);
1596                         Vector4f c = b;
1597                         a = a - b;
1598                         if (ff) {
1599                                 c = a;
1600                                 a = c;
1601                         }
1602                 }
1603                 return (int)a.X;
1604         }
1605
1606         static float float_val = 45f;
1607
1608         public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
1609                 Vector4f v = new Vector4f (1, 2, 3, 4);
1610                 float f = float_val;
1611                 int x = (int)f;
1612                 if (v.X != 1f)
1613                         return 1;
1614                 if (x != 45f)
1615                         return 2;
1616                 return 0;
1617         }
1618
1619         public static int Main () {
1620                 return TestDriver.RunTests (typeof (SimdTests));
1621         }
1622 }
1623