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