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