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