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