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