Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / simdmathlibrary / spu / tests / nextafterf4.c
1 /* Test nextafterf4 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
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <math.h>
35 #include <float.h>
36 #include "simdmath.h"
37 #include "common-test.h"
38 #include "testutils.h"
39
40 //a :float, b: float: c:bit pattern
41 #define DEFINE_DATA(var,a,b,c)  \
42   float var ## _a = a;\
43 vec_float4 var ## _a_v = spu_splats(var ## _a); \
44   float var ## _b = b;\
45 vec_float4 var ## _b_v = spu_splats(var ## _b); \
46   unsigned int var ## _inc = c ;                \
47   float var ## _out = make_float(var ## _inc);\
48   vec_float4 var ## _out_v = spu_splats(var ## _out);\
49
50 //a :bit pattern, b: bit pattern: c:bit pattern
51 #define DEFINE_DATA_UNSIGNED(var,a,b,c) \
52   unsigned int  var ## _ina = a ;               \
53   float var ## _a = make_float(var ## _ina);                   \
54   vec_float4 var ## _a_v = spu_splats(var ## _a);       \
55   unsigned int  var ## _inb = b ;               \
56   float var ## _b = make_float(var ## _inb);                  \
57   vec_float4 var ## _b_v = spu_splats(var ## _b);       \
58   unsigned int var ## _inc = c ;                \
59   float var ## _out = make_float(var ## _inc);             \
60   vec_float4 var ## _out_v = spu_splats(var ## _out);
61
62 #define DO_TEST(var,id) \
63   res_v = nextafterf4(var ## _a_v, var ## _b_v);\
64   TEST_CHECK(" #id ", allequal_float4( res_v, var ## _out_v ), 0);
65
66
67 int main()
68 {
69    vec_float4 res_v;
70
71    TEST_SET_START("958726589700","NAR", "nextafterf4");
72  
73
74
75    // ==
76    // 1.0f --> 1.0f
77    DEFINE_DATA(x1, 1.0f, 1.0f, 0x3f800000)
78      DEFINE_DATA(x2, 0.0f, 0.0f, 0x0)
79      
80      // *  Icrement *
81
82      // -FLT_MAX -> 
83      DEFINE_DATA_UNSIGNED(x3,0xffffffff, 0x0, 0xfffffffe)
84      //(1, 40, 0) --> (1, 39, 7fffff)
85      DEFINE_DATA_UNSIGNED(x4,0xd3800000, 0x0, 0xd37fffff)
86      // (1,-40,0 ) --> (1,-41,0x7fffff)
87      DEFINE_DATA_UNSIGNED(x5,0xab800000, 0x0, 0xab7fffff)
88      //-FLT_MIN --> 0
89      DEFINE_DATA_UNSIGNED(x6,0x80800000, 0x0, 0x0)
90      //0.0f --> FLT_MIN
91      DEFINE_DATA(x7, 0.0f, 1.0f, 0x800000)
92      //-0.0f --> FLT_MIN
93      DEFINE_DATA_UNSIGNED(x8, 0x80000000,  0x7fffffff, 0x800000)
94      //FLT_MIN -->
95      DEFINE_DATA_UNSIGNED(x9, 0x800000,  0x7fffffff, 0x800001)
96      // (0, -41, 7fffff) --> (0, -40, 0)
97      DEFINE_DATA_UNSIGNED(x10, 0x2b7fffff, 0x7fffffff, 0x2b800000)
98      // (0, 40, 7fffff) --> (0, 41, 0)
99      DEFINE_DATA_UNSIGNED(x11, 0x53ffffff, 0x7fffffff, 0x54000000)
100      // FLT_MAX --> 
101      DEFINE_DATA_UNSIGNED(x12,0x7fffffff,0x7fffffff,0x7fffffff)
102      
103      // * Decrement *
104
105      // FLT_MAX --> FLT_MAX
106      DEFINE_DATA_UNSIGNED(x13,0x7fffffff,0x7fffffff,0x7fffffff)
107      // FLT_MAX --> 
108      DEFINE_DATA_UNSIGNED(x14,0x7fffffff,0x0,0x7ffffffe)
109      // (0, 41, 0) -->  (0, 40, 7fffff)
110      DEFINE_DATA_UNSIGNED(x15,  0x54000000, 0x0, 0x53ffffff)
111      // (0, -40, 0) -->  (0, -41, 7fffff)
112      DEFINE_DATA_UNSIGNED(x16, 0x2b800000,0x0, 0x2b7fffff)
113      // -> FLT_MIN
114      DEFINE_DATA_UNSIGNED(x17,  0x800001, 0x800000, 0x800000)
115      // FLT_MIN --> 0
116      DEFINE_DATA_UNSIGNED(x18, 0x800000, 0x0, 0x0)
117      // 0.0 -> -FLT_MIN
118      DEFINE_DATA_UNSIGNED(x19, 0x0, 0xffffffff, 0x80800000)
119      // -0.0 -> FLT_MIN
120      DEFINE_DATA_UNSIGNED(x20, 0x80000000, 0xffffffff, 0x80800000)
121      //-FLT_MIN -->
122      DEFINE_DATA_UNSIGNED(x21, 0x80800000, 0xffffffff, 0x80800001)
123      //  (1,-41,0x7fffff) --> (1,-40,0 ) 
124      DEFINE_DATA_UNSIGNED(x22, 0xab7fffff, 0xffffffff, 0xab800000)
125      //(1, 40, 0) --> (1, 39, 7fffff)
126      DEFINE_DATA_UNSIGNED(x23, 0xd37fffff, 0xffffffff, 0xd3800000)
127      // --> -FLT_MAX 
128      DEFINE_DATA_UNSIGNED(x24,0xfffffffe, 0xffffffff, 0xffffffff)
129      
130
131      //TEST
132      TEST_START("nextafterf4");
133      DO_TEST(x1,958726589701NAR)
134      DO_TEST(x2,958726589702NAR)
135      DO_TEST(x3,958726589703NAR)
136      DO_TEST(x4,958726589704NAR)
137      DO_TEST(x5,958726589705NAR)
138      DO_TEST(x6,958726589706NAR)
139      DO_TEST(x7,958726589707NAR)
140      DO_TEST(x8,958726589708NAR)
141      DO_TEST(x9,958726589709NAR)
142      DO_TEST(x10,958726589710NAR)
143      DO_TEST(x11,958726589711NAR)
144      DO_TEST(x12,958726589712NAR)
145      DO_TEST(x13,958726589713NAR)
146      DO_TEST(x14,958726589714NAR)
147      DO_TEST(x15,958726589715NAR)
148      DO_TEST(x16,958726589716NAR)
149      DO_TEST(x17,958726589717NAR)
150      DO_TEST(x18,958726589718NAR)
151      DO_TEST(x19,958726589719NAR)
152      DO_TEST(x20,958726589720NAR)
153      DO_TEST(x21,958726589721NAR)
154      DO_TEST(x22,958726589722NAR)
155      DO_TEST(x23,958726589723NAR)
156      DO_TEST(x24,958726589724NAR)
157
158        TEST_SET_DONE();
159
160    
161    TEST_EXIT();
162 }