Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / simdmathlibrary / spu / tests / rintd2.c
1 /* Test rintd2 for SPU
2    Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
3    All rights reserved.
4
5    Redistribution and use in source and binary forms,
6    with or without modification, are permitted provided that the
7    following conditions are met:
8     * Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright
11       notice, this list of conditions and the following disclaimer in the
12       documentation and/or other materials provided with the distribution.
13     * Neither the name of the Sony Computer Entertainment Inc nor the names
14       of its contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16
17    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27    POSSIBILITY OF SUCH DAMAGE.
28  */
29 /**
30  *
31  *@@ rintd2 - Round the input to the nearest integer according to
32  *    the current rounding mode.
33  *
34  *@brief
35  * boundary test for rintd2. 
36  * 
37  *
38  *@pre
39  *
40  *@criteria
41  * Run this program and check no error will be occurred.
42  *
43  *@note
44  * add Denormalized handling
45  * changed over 0x4330000000000000(ABS) handling
46  * 
47  *
48  **/
49
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <math.h>
53 //#include <fenv.h>
54 #include <float.h>
55
56 #include "simdmath.h"
57 #include "common-test.h"
58 #include "testutils.h"
59
60 typedef struct {
61         unsigned long long int  xxx[2];
62         unsigned long long int  ans0[2];
63         unsigned long long int  ans1[2];
64         unsigned long long int  ans2[2];
65         unsigned long long int  ans3[2];
66 } TestVec64_NerI;
67
68 int main()
69 {
70         TestVec64_NerI test_a[] = {
71                 {
72                         // zero
73                         {0x0000000000000000ULL,0x8000000000000000ULL},
74                         {0x0000000000000000ULL,0x8000000000000000ULL},
75                         {0x0000000000000000ULL,0x8000000000000000ULL},
76                         {0x0000000000000000ULL,0x8000000000000000ULL},
77                         {0x0000000000000000ULL,0x8000000000000000ULL}
78                 },{
79                         // border
80                         {0xc330000000000000ULL,0x4330000000000000ULL},
81                         {0xc330000000000000ULL,0x4330000000000000ULL},
82                         {0xc330000000000000ULL,0x4330000000000000ULL},
83                         {0xc330000000000000ULL,0x4330000000000000ULL},
84                         {0xc330000000000000ULL,0x4330000000000000ULL}
85                 },{
86                         // MIN , MAX
87                         {0xFFEFFFFFFFFFFFFFULL,0x7FEFFFFFFFFFFFFFULL},
88                         {0xFFEFFFFFFFFFFFFFULL,0x7FEFFFFFFFFFFFFFULL},
89                         {0xFFEFFFFFFFFFFFFFULL,0x7FEFFFFFFFFFFFFFULL},
90                         {0xFFEFFFFFFFFFFFFFULL,0x7FEFFFFFFFFFFFFFULL},
91                         {0xFFEFFFFFFFFFFFFFULL,0x7FEFFFFFFFFFFFFFULL}
92                 },{
93                         // Inf , -Inf
94                         {0x7FF0000000000000ULL,0xFFF0000000000000ULL},
95                         {0x7FF0000000000000ULL,0xFFF0000000000000ULL},
96                         {0x7FF0000000000000ULL,0xFFF0000000000000ULL},
97                         {0x7FF0000000000000ULL,0xFFF0000000000000ULL},
98                         {0x7FF0000000000000ULL,0xFFF0000000000000ULL}
99                 },{
100                         // denotmalized 
101                         {0x8000000000000001ULL,0x0000000000000001ULL},
102                         {0x8000000000000000ULL,0x0000000000000000ULL},
103                         {0x8000000000000000ULL,0x0000000000000000ULL},
104                         {0x8000000000000000ULL,0x3ff0000000000000ULL},
105                         {0xbff0000000000000ULL,0x0000000000000000ULL}
106                 },{
107                         // denotmalized 
108                         {0x0008000000000000ULL,0x8008000000000000ULL},
109                         {0x0000000000000000ULL,0x8000000000000000ULL},
110                         {0x0000000000000000ULL,0x8000000000000000ULL},
111                         {0x3ff0000000000000ULL,0x8000000000000000ULL},
112                         {0x0000000000000000ULL,0xbff0000000000000ULL}
113                 },{
114                         // 1.0
115                         {0x3ff0000000000000ULL,0xbff0000000000000ULL},
116                         {0x3ff0000000000000ULL,0xbff0000000000000ULL},
117                         {0x3ff0000000000000ULL,0xbff0000000000000ULL},
118                         {0x3ff0000000000000ULL,0xbff0000000000000ULL},
119                         {0x3ff0000000000000ULL,0xbff0000000000000ULL}
120                 },{
121                         // 1.5
122                         {0x3ff8000000000000ULL,0xbff8000000000000ULL},
123                         {0x4000000000000000ULL,0xc000000000000000ULL},
124                         {0x3ff0000000000000ULL,0xbff0000000000000ULL},
125                         {0x4000000000000000ULL,0xbff0000000000000ULL},
126                         {0x3ff0000000000000ULL,0xc000000000000000ULL}
127                 },{
128                         // 2.5
129                         {0x4004000000000000ULL,0xc004000000000000ULL},
130                         {0x4000000000000000ULL,0xc000000000000000ULL},
131                         {0x4000000000000000ULL,0xc000000000000000ULL},
132                         {0x4008000000000000ULL,0xc000000000000000ULL},
133                         {0x4000000000000000ULL,0xc008000000000000ULL}
134                 },{
135                         {0ULL,0ULL},
136                         {0ULL,0ULL},
137                         {0ULL,0ULL},
138                         {0ULL,0ULL},
139                         {0ULL,0ULL}
140                         
141                 }
142         };
143         int ii, test_ctr = 1;
144         char msg[80];
145         vec_double2 res_v;
146
147         TEST_SET_START("20060831210000NM","NM", "rintd2");
148
149    TEST_START("rintd2");
150
151         for (ii=0; ; ii++) {
152                 if ( (test_a[ii].xxx[0] == 0) && (test_a[ii].xxx[1] == 0) ) break;
153
154                 // set Floating point round mode
155                 spu_mtfpscr(((vec_uint4){0x0000,0,0,0}));
156                 res_v = rintd2 (*((vec_double2 *)&test_a[ii].xxx[0]));
157                 sprintf(msg,"2006083121%04dNM", test_ctr++);
158                 TEST_CHECK(msg, allequal_llong2( (vec_llong2)res_v, *((vec_llong2 *)&test_a[ii].ans0[0])), 0);
159
160                 spu_mtfpscr(((vec_uint4){0x0500,0,0,0}));
161                 res_v = rintd2 (*((vec_double2 *)&test_a[ii].xxx[0]));
162                 sprintf(msg,"2006083121%04dNM", test_ctr++);
163                 TEST_CHECK(msg, allequal_llong2( (vec_llong2)res_v, *((vec_llong2 *)&test_a[ii].ans1[0])), 0);
164
165                 spu_mtfpscr(((vec_uint4){0x0a00,0,0,0}));
166                 res_v = rintd2 (*((vec_double2 *)&test_a[ii].xxx[0]));
167                 sprintf(msg,"2006083121%04dNM", test_ctr++);
168                 TEST_CHECK(msg, allequal_llong2( (vec_llong2)res_v, *((vec_llong2 *)&test_a[ii].ans2[0])), 0);
169
170                 spu_mtfpscr(((vec_uint4){0x0f00,0,0,0}));
171                 res_v = rintd2 (*((vec_double2 *)&test_a[ii].xxx[0]));
172                 sprintf(msg,"2006083121%04dNM", test_ctr++);
173                 TEST_CHECK(msg, allequal_llong2( (vec_llong2)res_v, *((vec_llong2 *)&test_a[ii].ans3[0])), 0);
174         }
175
176    TEST_SET_DONE();
177
178    TEST_EXIT();
179
180 }