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