2008-10-12 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_vector4ui_sar () {
6                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
7                 
8                 Vector4ui c = Vector4ui.ShiftRightArithmetic (a, 2);
9         
10                 if (c.X != 0xFC000000)
11                         return 1;
12                 if (c.Y != 5)
13                         return 2;
14                 if (c.Z != 0)
15                         return 3;
16                 if (c.W != 10)
17                         return 4;
18                 return 0;
19         }
20
21         public static int test_0_vector4ui_unpack_high () {
22                 Vector4ui a = new Vector4ui (1,2,3,4);
23                 Vector4ui b = new Vector4ui (5,6,7,8);
24                 
25                 Vector4ui c = Vector4ui.UnpackHigh(a, b);
26         
27                 if (c.X != 3)
28                         return 1;
29                 if (c.Y != 7)
30                         return 2;
31                 if (c.Z != 4)
32                         return 3;
33                 if (c.W != 8)
34                         return 4;
35                 return 0;
36         }
37
38         public  static int test_0_vector4ui_unpack_low () {
39                 Vector4ui a = new Vector4ui (1,2,3,4);
40                 Vector4ui b = new Vector4ui (5,6,7,8);
41                 
42                 Vector4ui c = Vector4ui.UnpackLow (a, b);
43         
44                 if (c.X != 1)
45                         return 1;
46                 if (c.Y != 5)
47                         return 2;
48                 if (c.Z != 2)
49                         return 3;
50                 if (c.W != 6)
51                         return 4;
52                 return 0;
53         }
54
55         public  static int test_0_vector4ui_xor () {
56                 Vector4ui a = new Vector4ui (1,2,3,4);
57                 Vector4ui b = new Vector4ui (7,5,3,1);
58                 
59                 Vector4ui c = a ^ b;
60         
61                 if (c.X != 6)
62                         return 1;
63                 if (c.Y != 7)
64                         return 2;
65                 if (c.Z != 0)
66                         return 3;
67                 if (c.W != 5)
68                         return 4;
69                 return 0;
70         }
71
72         public  static int test_0_vector4ui_or () {
73                 Vector4ui a = new Vector4ui (1,2,3,4);
74                 Vector4ui b = new Vector4ui (7,5,3,1);
75                 
76                 Vector4ui c = a | b;
77         
78                 if (c.X != 7)
79                         return 1;
80                 if (c.Y != 7)
81                         return 2;
82                 if (c.Z != 3)
83                         return 3;
84                 if (c.W != 5)
85                         return 4;
86                 return 0;
87         }
88         public  static int test_0_vector4ui_and () {
89                 Vector4ui a = new Vector4ui (1,2,3,4);
90                 Vector4ui b = new Vector4ui (7,5,3,1);
91                 
92                 Vector4ui c = a & b;
93         
94                 if (c.X != 1)
95                         return 1;
96                 if (c.Y != 0)
97                         return 2;
98                 if (c.Z != 3)
99                         return 3;
100                 if (c.W != 0)
101                         return 4;
102                 return 0;
103         }
104
105         public  static int test_0_vector4ui_shr () {
106                 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
107                 
108                 Vector4ui c = a >> 2;
109         
110                 if (c.X != 0x3C000000)
111                         return 1;
112                 if (c.Y != 5)
113                         return 2;
114                 if (c.Z != 0)
115                         return 3;
116                 if (c.W != 10)
117                         return 4;
118                 return 0;
119         }
120
121         public  static int test_0_vector4ui_shl () {
122                 Vector4ui a = new Vector4ui (10,20,3,40);
123                 
124                 Vector4ui c = a << 2;
125         
126                 if (c.X != 40)
127                         return 1;
128                 if (c.Y != 80)
129                         return 2;
130                 if (c.Z != 12)
131                         return 3;
132                 if (c.W != 160)
133                         return 4;
134                 return 0;
135         }
136
137         public  static int test_0_vector4ui_mul () {
138                 Vector4ui a = new Vector4ui (0x8888,20,3,40);
139                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
140                 
141                 Vector4ui c = a * b;
142         
143                 if (c.X != 0xffff7800)
144                         return 1;
145                 if (c.Y != 40)
146                         return 2;
147                 if (c.Z != 9)
148                         return 3;
149                 if (c.W != 160)
150                         return 4;
151                 return 0;
152         }
153         public  static int test_0_vector4ui_sub () {
154                 Vector4ui a = new Vector4ui (1,20,3,40);
155                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
156                 
157                 Vector4ui c = a - b;
158         
159                 if (c.X != 0xff0101)
160                         return 1;
161                 if (c.Y != 18)
162                         return 2;
163                 if (c.Z != 0)
164                         return 3;
165                 if (c.W != 36)
166                         return 4;
167                 return 0;
168         }
169
170         public  static int test_0_vector4ui_add () {
171                 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
172                 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
173                 
174                 Vector4ui c = a + b;
175         
176                 if (c.X != 0xfe01fe00)
177                         return 1;
178                 if (c.Y != 4)
179                         return 2;
180                 if (c.Z != 6)
181                         return 3;
182                 if (c.W != 8)
183                         return 4;
184                 return 0;
185         }
186
187
188         static int test_0_vector4ui_accessors () {
189                 Vector4ui a = new Vector4ui (1,2,3,4);
190
191                 if (a.X != 1)
192                         return 1;
193                 if (a.Y != 2)
194                         return 2;
195                 if (a.Z != 3)
196                         return 3;
197                 if (a.W != 4)
198                         return 4;
199                 a.X = 10;
200                 a.Y = 20;
201                 a.Z = 30;
202                 a.W = 40;
203
204                 if (a.X != 10)
205                         return 5;
206                 if (a.Y != 20)
207                         return 6;
208                 if (a.Z != 30)
209                         return 7;
210                 if (a.W != 40)
211                         return 8;
212                 return 0;
213         }
214
215         static int test_0_vector8us_sub_sat () {
216                 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
217                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
218                 Vector8us c = Vector8us.SubWithSaturation (a, b);
219
220                 if (c.V0 != 0)
221                         return 1;
222                 if (c.V1 != 0)
223                         return 2;
224                 if (c.V2 != 15)
225                         return 3;
226                 if (c.V3 != 0)
227                         return 4;
228                 if (c.V4 != 0)
229                         return 5;
230                 if (c.V5 != 0)
231                         return 6;
232                 if (c.V6 != 0)
233                         return 7;
234                 if (c.V7 != 0)
235                         return 8;
236                 return 0;
237         }
238
239         static int test_0_vector8us_add_sat () {
240                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
241                 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
242                 Vector8us c = Vector8us.AddWithSaturation (a, b);
243
244                 if (c.V0 != 0xFFFF)
245                         return 1;
246                 if (c.V1 != 5)
247                         return 2;
248                 if (c.V2 != 7)
249                         return 3;
250                 if (c.V3 != 9)
251                         return 4;
252                 if (c.V4 != 11)
253                         return 5;
254                 if (c.V5 != 13)
255                         return 6;
256                 if (c.V6 != 15)
257                         return 7;
258                 if (c.V7 != 17)
259                         return 8;
260                 return 0;
261         }
262
263         static int test_0_vector8us_unpack_low () {
264                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
265                 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
266                 Vector8us c = Vector8us.UnpackLow (a, b);
267
268                 if (c.V0 != 0)
269                         return 1;
270                 if (c.V1 != 3)
271                         return 2;
272                 if (c.V2 != 1)
273                         return 3;
274                 if (c.V3 != 4)
275                         return 4;
276                 if (c.V4 != 2)
277                         return 5;
278                 if (c.V5 != 5)
279                         return 6;
280                 if (c.V6 != 3)
281                         return 7;
282                 if (c.V7 != 6)
283                         return 8;
284                 return 0;
285         }
286
287
288         static int test_0_vector8us_shift_left () {
289                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
290                 int amt = 2;
291                 Vector8us c = a << amt;
292         
293                 if (c.V0 != 0xFC00)
294                         return 1;
295                 if (c.V1 != 4)
296                         return 2;
297                 if (c.V7 != 28)
298                         return 3;
299                 return 0;
300         }
301         
302         static int test_0_vector8us_shift_right_arithmetic () {
303                 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
304                 int amt = 2;
305                 Vector8us c = Vector8us.ShiftRightArithmetic (a, amt);
306         
307                 if (c.V0 != 0xFFC0)
308                         return 1;
309                 if (c.V1 != 0)
310                         return 2;
311                 if (c.V7 != 1)
312                         return 3;
313                 return 0;
314         }
315
316         static int test_0_vector8us_shift_variable_offset () {
317                 int off = 2;
318                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
319                 Vector8us b = a;
320                 Vector8us c = b >> off;
321                 a = b + b;
322
323                 if (c.V0 != 0x3C00)
324                         return 1;
325                 if (c.V1 != 0)
326                         return 2;
327                 if (c.V7 != 1)
328                         return 3;
329                 if (a.V1 != 2)
330                         return 4;
331                 if (a.V7 != 14)
332                         return 5;
333                 return 0;
334         }
335         
336         
337         static int test_0_vector8us_shift_operand_is_live_after_op () {
338                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
339                 Vector8us b = a;
340                 Vector8us c = b >> 2;
341                 a = b + b;
342
343                 if (c.V0 != 0x3C00)
344                         return 1;
345                 if (c.V1 != 0)
346                         return 2;
347                 if (c.V7 != 1)
348                         return 3;
349                 if (a.V1 != 2)
350                         return 4;
351                 if (a.V7 != 14)
352                         return 5;
353                 return 0;
354         }
355
356         static int test_0_vector8us_shr_constant () {
357                 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
358                 Vector8us c = a >> 2;
359
360                 if (c.V0 != 0x3C00)
361                         return 1;
362                 if (c.V1 != 0)
363                         return 2;
364                 if (c.V7 != 1)
365                         return 3;
366                 return 0;
367         }
368
369         static int test_0_vector8us_mul () {
370                 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
371                 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
372
373                 Vector8us c = a * b;
374                 if (c.V0 != 63488)
375                         return 1;
376                 if (c.V1 != 4)
377                         return 2;
378                 if (c.V7 != 80)
379                         return 3;
380                 return 0;
381         }
382
383         static int test_0_vector8us_add () {
384                 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
385                 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
386
387                 Vector8us c = a + b;
388                 if (c.V0 != 34696)
389                         return 1;
390                 if (c.V1 != 5)
391                         return 2;
392                 if (c.V7 != 18)
393                         return 3;
394                 return 0;
395         }
396
397
398         static int test_0_vector8us_sub () {
399                 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
400                 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
401
402                 Vector8us c = a - b;
403
404                 if (c.V0 != 65529)
405                         return 1;
406                 if (c.V1 != 3)
407                         return 2;
408                 if (c.V7 != 2)
409                         return 3;
410                 return 0;
411         }
412
413
414         static int test_0_vector8us_accessors () {
415                 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
416
417                 if (a.V0 != 0)
418                         return 1;
419                 if (a.V1 != 1)
420                         return 2;
421                 if (a.V2 != 2)
422                         return 3;
423                 if (a.V3 != 3)
424                         return 4;
425                 if (a.V4 != 4)
426                         return 5;
427                 if (a.V5 != 5)
428                         return 6;
429                 if (a.V6 != 6)
430                         return 7;
431                 if (a.V7 != 7)
432                         return 8;
433                 a.V0 = 10;
434                 a.V1 = 20;
435                 a.V2 = 30;
436                 a.V3 = 40;
437                 a.V4 = 50;
438                 a.V5 = 60;
439                 a.V6 = 70;
440                 a.V7 = 80;
441
442                 if (a.V0 != 10)
443                         return 17;
444                 if (a.V1 != 20)
445                         return 18;
446                 if (a.V2 != 30)
447                         return 19;
448                 if (a.V3 != 40)
449                         return 20;
450                 if (a.V4 != 50)
451                         return 21;
452                 if (a.V5 != 60)
453                         return 22;
454                 if (a.V6 != 70)
455                         return 23;
456                 if (a.V7 != 80)
457                         return 24;
458
459                 return 0;
460         }
461
462
463         static int test_0_vector16b_unpack_high () {
464                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
465                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
466                 Vector16b c = Vector16b.UnpackHigh (a, b);
467
468                 if (c.V0 != 8)
469                         return 1;
470                 if (c.V1 != 1)
471                         return 2;
472                 if (c.V2 != 9)
473                         return 3;
474                 if (c.V3 != 2)
475                         return 4;
476                 if (c.V4 != 10)
477                         return 5;
478                 if (c.V5 != 3)
479                         return 6;
480                 if (c.V14 != 15)
481                         return 7;
482                 if (c.V15 != 8)
483                         return 8;
484                 return 0;
485         }
486
487         static int test_0_vector16b_unpack_low () {
488                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
489                 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
490                 Vector16b c = Vector16b.UnpackLow (a, b);
491
492                 if (c.V0 != 0)
493                         return 1;
494                 if (c.V1 != 9)
495                         return 2;
496                 if (c.V2 != 1)
497                         return 3;
498                 if (c.V3 != 10)
499                         return 4;
500                 if (c.V4 != 2)
501                         return 5;
502                 if (c.V5 != 11)
503                         return 6;
504                 if (c.V14 != 7)
505                         return 7;
506                 if (c.V15 != 0)
507                         return 8;
508                 return 0;
509         }
510
511         static int test_0_vector16b_sar () {
512                 Vector16b a = new Vector16b (0xF0,20,3,40,0,0,0,0,0,0,0,0,0,0,0,0);
513                 
514                 Vector16b c = Vector16b.ShiftRightArithmetic (a, 2);
515                 if (c.V0 != 0xFC)
516                         return 1;
517                 if (c.V1 != 5)
518                         return 1;
519                 if (c.V2 != 0)
520                         return 2;
521                 if (c.V3 != 10)
522                         return 3;
523                 return 0;
524         }
525
526         static int test_0_vector16b_sub_sat () {
527                 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
528                 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
529                 Vector16b c = Vector16b.SubWithSaturation (a, b);
530
531                 if (c.V0 != 0)
532                         return 1;
533                 if (c.V1 != 9)
534                         return 2;
535                 if (c.V15 != 0)
536                         return 3;
537                 return 0;
538         }
539         
540         static int test_0_vector16b_add_sat () {
541                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
542                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
543                 Vector16b c = Vector16b.AddWithSaturation (a, b);
544
545                 if (c.V0 != 255)
546                         return 1;
547                 if (c.V1 != 11)
548                         return 2;
549                 if (c.V15 != 23)
550                         return 3;
551                 return 0;
552         }
553
554         static int test_0_vector16b_add_ovf () {
555                 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
556                 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
557                 Vector16b c = a + b;
558
559                 if (c.V0 != 144)
560                         return 1;
561                 if (c.V1 != 11)
562                         return 2;
563                 if (c.V15 != 23)
564                         return 3;
565                 return 0;
566         }
567
568         static int test_0_vector16b_accessors () {
569                 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
570
571                 if (a.V0 != 0)
572                         return 1;
573                 if (a.V1 != 1)
574                         return 2;
575                 if (a.V2 != 2)
576                         return 3;
577                 if (a.V3 != 3)
578                         return 4;
579                 if (a.V4 != 4)
580                         return 5;
581                 if (a.V5 != 5)
582                         return 6;
583                 if (a.V6 != 6)
584                         return 7;
585                 if (a.V7 != 7)
586                         return 8;
587                 if (a.V8 != 8)
588                         return 9;
589                 if (a.V9 != 9)
590                         return 10;
591                 if (a.V10 != 10)
592                         return 11;
593                 if (a.V11 != 11)
594                         return 12;
595                 if (a.V12 != 12)
596                         return 13;
597                 if (a.V13 != 13)
598                         return 14;
599                 if (a.V14 != 14)
600                         return 15;
601                 if (a.V15 != 15)
602                         return 16;
603
604                 a.V0 = 10;
605                 a.V1 = 20;
606                 a.V2 = 30;
607                 a.V3 = 40;
608                 a.V4 = 50;
609                 a.V5 = 60;
610                 a.V6 = 70;
611                 a.V7 = 80;
612                 a.V8 = 90;
613                 a.V9 = 100;
614                 a.V10 = 110;
615                 a.V11 = 120;
616                 a.V12 = 130;
617                 a.V13 = 140;
618                 a.V14 = 150;
619                 a.V15 = 160;
620
621                 if (a.V0 != 10)
622                         return 17;
623                 if (a.V1 != 20)
624                         return 18;
625                 if (a.V2 != 30)
626                         return 19;
627                 if (a.V3 != 40)
628                         return 20;
629                 if (a.V4 != 50)
630                         return 21;
631                 if (a.V5 != 60)
632                         return 22;
633                 if (a.V6 != 70)
634                         return 23;
635                 if (a.V7 != 80)
636                         return 24;
637                 if (a.V8 != 90)
638                         return 25;
639                 if (a.V9 != 100)
640                         return 26;
641                 if (a.V10 != 110)
642                         return 27;
643                 if (a.V11 != 120)
644                         return 28;
645                 if (a.V12 != 130)
646                         return 29;
647                 if (a.V13 != 140)
648                         return 30;
649                 if (a.V14 != 150)
650                         return 31;
651                 if (a.V15 != 160)
652                         return 32;
653                 return 0;
654         }
655
656         public static int test_0_accessors () {
657                 Vector4f a = new Vector4f (1, 2, 3, 4);
658                 if (a.X != 1f)
659                         return 1;
660                 if (a.Y != 2f)
661                         return 2;
662                 if (a.Z != 3f)
663                         return 3;
664                 if (a.W != 4f)
665                         return 4;
666                 return 0;
667         }
668
669         public static int test_0_packed_add_with_stack_tmp () {
670                 Vector4f a = new Vector4f (1, 2, 3, 4);
671                 Vector4f b = new Vector4f (5, 6, 7, 8);
672                 Vector4f c = new Vector4f (-1, -3, -4, -5);
673                 Vector4f d = a + b + c;
674                 if (d.X != 5f)
675                         return 1;
676                 if (d.Y != 5f)
677                         return 2;
678                 if (d.Z != 6f)
679                         return 3;
680                 if (d.W != 7f)
681                         return 4;
682                 return 0;
683         }
684
685         public static int test_0_simple_packed_add () {
686                 Vector4f a = new Vector4f (1, 2, 3, 4);
687                 Vector4f b = new Vector4f (5, 6, 7, 8);
688                 Vector4f c;
689                 c = a + b;
690                 if (c.X != 6f)
691                         return 1;
692                 if (c.Y != 8f)
693                         return 2;
694                 if (c.Z != 10f)
695                         return 3;
696                 if (c.W != 12f)
697                         return 4;
698                 return 0;
699         }
700
701         public static int test_0_simple_packed_sub () {
702                 Vector4f a = new Vector4f (1, 2, 3, 4);
703                 Vector4f b = new Vector4f (5, 6, 7, 8);
704                 Vector4f c = b - a;
705                 if (c.X != 4f)
706                         return 1;
707                 if (c.Y != 4f)
708                         return 2;
709                 if (c.Z != 4f)
710                         return 3;
711                 if (c.W != 4f)
712                         return 4;
713                 return 0;
714         }
715
716         public static int test_0_simple_packed_mul () {
717                 Vector4f a = new Vector4f (1, 2, 3, 4);
718                 Vector4f b = new Vector4f (5, 6, 7, 8);
719                 Vector4f c = b * a;
720                 if (c.X != 5f)
721                         return 1;
722                 if (c.Y != 12f)
723                         return 2;
724                 if (c.Z != 21f)
725                         return 3;
726                 if (c.W != 32f)
727                         return 4;
728                 return 0;
729         }
730
731         public static int test_0_simple_packed_div () {
732                 Vector4f a = new Vector4f (2, 2, 3, 4);
733                 Vector4f b = new Vector4f (20, 10, 33, 12);
734                 Vector4f c = b / a;
735                 if (c.X != 10f)
736                         return 1;
737                 if (c.Y != 5f)
738                         return 2;
739                 if (c.Z != 11f)
740                         return 3;
741                 if (c.W != 3f)
742                         return 4;
743                 return 0;
744         }
745
746         public static int test_0_simple_packed_sqrt () {
747                 Vector4f a = new Vector4f (16, 4, 9, 25);
748                 a = Vector4f.Sqrt (a);
749                 if (a.X != 4f)
750                         return 1;
751                 if (a.Y != 2f)
752                         return 2;
753                 if (a.Z != 3f)
754                         return 3;
755                 if (a.W != 5f)
756                         return 4;
757                 return 0;
758         }
759
760         public static int test_0_simple_packed_invsqrt () {
761                 Vector4f a = new Vector4f (16, 4, 100, 25);
762                 //this function has VERY low precision
763                 a = Vector4f.InvSqrt (a);
764                 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
765                         return 1;
766                 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
767                         return 2;
768                 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
769                         return 3;
770                 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
771                         return 4;
772                 return 0;
773         }
774
775         public static int test_0_simple_packed_min () {
776                 Vector4f a = new Vector4f (16, -4, 9, 25);
777                 Vector4f b = new Vector4f (5, 3, 9, 0);
778                 Vector4f c = Vector4f.Min (a, b);
779                 if (c.X != 5f)
780                         return 1;
781                 if (c.Y != -4f)
782                         return 2;
783                 if (c.Z != 9f)
784                         return 3;
785                 if (c.W != 0f)
786                         return 4;
787                 return 0;
788         }
789
790         public static int test_0_simple_packed_max () {
791                 Vector4f a = new Vector4f (16, -4, 9, 25);
792                 Vector4f b = new Vector4f (5, 3, 9, 0);
793                 Vector4f c = Vector4f.Max (a, b);
794                 if (c.X != 16f)
795                         return 1;
796                 if (c.Y != 3f)
797                         return 2;
798                 if (c.Z != 9f)
799                         return 3;
800                 if (c.W != 25f)
801                         return 4;
802                 return 0;
803         }
804
805         public static int test_0_simple_packed_hadd () {
806                 Vector4f a = new Vector4f (5, 5, 6, 6);
807                 Vector4f b = new Vector4f (7, 7, 8, 8);
808                 Vector4f c = Vector4f.HorizontalAdd (a, b);
809                 if (c.X != 10f)
810                         return 1;
811                 if (c.Y != 12f)
812                         return 2;
813                 if (c.Z != 14f)
814                         return 3;
815                 if (c.W != 16f)
816                         return 4;
817                 return 0;
818         }
819
820         public static int test_0_simple_packed_hsub () {
821                 Vector4f a = new Vector4f (5, 2, 6, 1);
822                 Vector4f b = new Vector4f (7, 0, 8, 3);
823                 Vector4f c = Vector4f.HorizontalSub (a, b);
824                 if (c.X != 3f)
825                         return 1;
826                 if (c.Y != 5f)
827                         return 2;
828                 if (c.Z != 7f)
829                         return 3;
830                 if (c.W != 5f)
831                         return 4;
832                 return 0;
833         }
834
835         public static int test_0_simple_packed_addsub () {
836                 Vector4f a = new Vector4f (5, 2, 6, 1);
837                 Vector4f b = new Vector4f (7, 0, 8, 3);
838                 Vector4f c = Vector4f.AddSub (a, b);
839                 if (c.X != -2f)
840                         return 1;
841                 if (c.Y != 2f)
842                         return 2;
843                 if (c.Z != -2f)
844                         return 3;
845                 if (c.W != 4f)
846                         return 4;
847                 return 0;
848         }
849
850         public static int test_0_simple_packed_shuffle () {
851                 Vector4f a = new Vector4f (1, 2, 3, 4);
852                 a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
853                 if (a.X != 2f)
854                         return 1;
855                 if (a.Y != 4f)
856                         return 2;
857                 if (a.Z != 1f)
858                         return 3;
859                 if (a.W != 3f)
860                         return 4;
861                 return 0;
862         }
863
864         public static int test_0_packed_shuffle_with_reg_pressure () {
865                 Vector4f v = new Vector4f (1, 2, 3, 4);
866                 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
867                 if (ff) v = v + v -v    ;
868
869                 Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
870                 Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
871                 Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
872                 Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
873                 Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
874                 Vector4f a = x;
875
876                 r0 = r0 * m0 + x;
877                 r1 = r1 * m1 + x;
878                 x = x - v + v;
879                 r2 = r2 * m2 + x;
880                 r3 = r3 * m3 + x;
881                 Vector4f result = r0 + r1 + r2 + r3;
882
883                 if (a.X != 2f)
884                         return 1;
885                 if (a.Y != 4f)
886                         return 2;
887                 if (a.Z != 1f)
888                         return 3;
889                 if (a.W != 3f)
890                         return 4;
891                 if (result.Y != result.Y)
892                         return 0;
893                 return 0;
894         }
895         
896         public static int test_24_regs_pressure_a () {
897                 Vector4f a = new Vector4f (1, 2, 3, 4);
898                 Vector4f b = a + a;
899                 Vector4f c = b * a;
900                 Vector4f d = a - b;
901                 c = a + b + c + d;
902                 return (int)c.Z;
903         }
904
905         public static int test_54_regs_pressure_b () {
906                 Vector4f a = new Vector4f (1, 2, 3, 4);
907                 Vector4f b = a + a;
908                 Vector4f c = b - a;
909                 Vector4f d = c - a;
910                 Vector4f e = a + b + c;
911                 Vector4f f = d - b + a - c;
912                 Vector4f g = a - d * f - c + b;
913                 Vector4f h = a * b - c + e;
914                 Vector4f i = h - g - f - e - d - c - b - a;
915                 Vector4f j = a + b + c + d + e + f + g + h + i;
916                 return (int)j.Z;
917         }
918
919         static bool ff;
920         public static int test_3_single_block_var_is_properly_promoted () {
921                 Vector4f a = new Vector4f (4, 5, 6, 7);
922                 if (ff)
923                         a = a - a;
924                 else {
925                         Vector4f b = new Vector4f (1, 2, 3, 4);
926                         Vector4f c = b;
927                         a = a - b;
928                         if (ff) {
929                                 c = a;
930                                 a = c;
931                         }
932                 }
933                 return (int)a.X;
934         }
935
936         static float float_val = 45f;
937
938         public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
939                 Vector4f v = new Vector4f (1, 2, 3, 4);
940                 float f = float_val;
941                 int x = (int)f;
942                 if (v.X != 1f)
943                         return 1;
944                 if (x != 45f)
945                         return 2;
946                 return 0;
947         }
948
949         public static int Main () {
950                 return TestDriver.RunTests (typeof (SimdTests));
951         }
952 }
953