Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / simdmathlibrary / spu / tests / truncf4.c
1 /* Test trunf4 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 #include <stdio.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include "simdmath.h"
35 #include "common-test.h"
36 #include "testutils.h"
37
38
39 int main()
40 {
41    TEST_SET_START("20040916100012EJL","EJL", "truncf");
42    
43    unsigned int i3 = 0x4affffff;  // 2^23 - 0.5, largest truncatable value.
44    unsigned int i3i = 0x4afffffe;  
45    unsigned int i4 = 0x4b000000;  // 2^23, no fractional part.
46    unsigned int i5 = 0xcf000001;  // -2^31, one more large, and negative, value.
47
48    float x0 = hide_float(0.91825f);
49    float x0i = hide_float(0.0f);
50    float x1 = hide_float(-0.12958f);
51    float x1i = hide_float(0.0f);
52    float x2 = hide_float(-79615.1875f);
53    float x2i = hide_float(-79615.0f);
54    float x3 = hide_float(make_float(i3));
55    float x3i = hide_float(make_float(i3i));
56    float x4 = hide_float(make_float(i4));
57    float x4i = hide_float(make_float(i4));
58    float x5 = hide_float(make_float(i5));
59    float x5i = hide_float(make_float(i5));
60
61    vec_float4 x0_v = spu_splats(x0);
62    vec_float4 x0i_v = spu_splats(x0i);
63    vec_float4 x1_v = spu_splats(x1);
64    vec_float4 x1i_v = spu_splats(x1i);
65    vec_float4 x2_v = spu_splats(x2);
66    vec_float4 x2i_v = spu_splats(x2i);
67    vec_float4 x3_v = spu_splats(x3);
68    vec_float4 x3i_v = spu_splats(x3i);
69    vec_float4 x4_v = spu_splats(x4);
70    vec_float4 x4i_v = spu_splats(x4i);
71    vec_float4 x5_v = spu_splats(x5);
72    vec_float4 x5i_v = spu_splats(x5i);
73    
74    float res;
75    vec_float4 res_v;
76
77    TEST_START("truncf4");
78    res_v = truncf4(x0_v);
79    TEST_CHECK("20040916100023EJL", allequal_float4( res_v, x0i_v ), 0);
80    res_v = truncf4(x1_v);
81    TEST_CHECK("20040916100034EJL", allequal_float4( res_v, x1i_v ), 0);
82    res_v = truncf4(x2_v);
83    TEST_CHECK("20040916100043EJL", allequal_float4( res_v, x2i_v ), 0);
84    res_v = truncf4(x3_v);
85    TEST_CHECK("20040916100054EJL", allequal_float4( res_v, x3i_v ), 0);
86    res_v = truncf4(x4_v);
87    TEST_CHECK("20040916100103EJL", allequal_float4( res_v, x4i_v ), 0);
88    res_v = truncf4(x5_v);
89    TEST_CHECK("20040916100111EJL", allequal_float4( res_v, x5i_v ), 0);
90    
91    TEST_START("truncf");
92    res = truncf(x0);
93    TEST_CHECK("20040916100121EJL", res == x0i, 0);
94    res = truncf(x1);
95    TEST_CHECK("20040916100129EJL", res == x1i, 0);
96    res = truncf(x2);
97    TEST_CHECK("20040916100136EJL", res == x2i, 0);
98    res = truncf(x3);
99    TEST_CHECK("20040916100144EJL", res == x3i, 0);
100    res = truncf(x4);
101    TEST_CHECK("20040916100153EJL", res == x4i, 0);
102    res = truncf(x5);
103    TEST_CHECK("20040916100200EJL", res == x5i, 0);
104    
105    TEST_SET_DONE();
106    
107    TEST_EXIT();
108 }