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