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