~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/src/MiniCL/cl_MiniCL_Defs.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Bullet Continuous Collision Detection and Physics Library, Copyright (c) 2007 Erwin Coumans
 
3
 
 
4
This software is provided 'as-is', without any express or implied warranty.
 
5
In no event will the authors be held liable for any damages arising from the use of this software.
 
6
Permission is granted to anyone to use this software for any purpose, 
 
7
including commercial applications, and to alter it and redistribute it freely, 
 
8
subject to the following restrictions:
 
9
 
 
10
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
 
11
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 
12
3. This notice may not be removed or altered from any source distribution.
 
13
 
 
14
*/
 
15
 
 
16
#include <float.h>
 
17
#include <math.h>
 
18
#include "LinearMath/btScalar.h"
 
19
 
 
20
#include "MiniCL/cl.h"
 
21
 
 
22
 
 
23
#define __kernel
 
24
#define __global
 
25
#define __local
 
26
#define get_global_id(a)        __guid_arg
 
27
#define get_local_id(a)         ((__guid_arg) % gMiniCLNumOutstandingTasks)
 
28
#define get_local_size(a)       (gMiniCLNumOutstandingTasks)
 
29
#define get_group_id(a)         ((__guid_arg) / gMiniCLNumOutstandingTasks)
 
30
 
 
31
static unsigned int as_uint(float val) { return *((unsigned int*)&val); }
 
32
 
 
33
 
 
34
#define CLK_LOCAL_MEM_FENCE             0x01
 
35
#define CLK_GLOBAL_MEM_FENCE    0x02
 
36
 
 
37
static void barrier(unsigned int a)
 
38
{
 
39
        // TODO : implement
 
40
}
 
41
 
 
42
//ATTRIBUTE_ALIGNED16(struct) float8
 
43
struct float8
 
44
{
 
45
        float s0;
 
46
        float s1;
 
47
        float s2;
 
48
        float s3;
 
49
        float s4;
 
50
        float s5;
 
51
        float s6;
 
52
        float s7;
 
53
 
 
54
        float8(float scalar)
 
55
        {
 
56
                s0=s1=s2=s3=s4=s5=s6=s7=scalar;
 
57
        }
 
58
};
 
59
 
 
60
//ATTRIBUTE_ALIGNED16(struct) float4
 
61
struct float4
 
62
{
 
63
        float x,y,z,w;
 
64
        float4() {}
 
65
        float4(float v) 
 
66
        {
 
67
                x = y = z = w = v; 
 
68
        }
 
69
        float4 operator*(const float4& other)
 
70
        {
 
71
                float4 tmp;
 
72
                tmp.x = x*other.x;
 
73
                tmp.y = y*other.y;
 
74
                tmp.z = z*other.z;
 
75
                tmp.w = w*other.w;
 
76
                return tmp;
 
77
        }
 
78
 
 
79
        float4 operator*(const float& other)
 
80
        {
 
81
                float4 tmp;
 
82
                tmp.x = x*other;
 
83
                tmp.y = y*other;
 
84
                tmp.z = z*other;
 
85
                tmp.w = w*other;
 
86
                return tmp;
 
87
        }
 
88
 
 
89
        
 
90
 
 
91
        float4& operator+=(const float4& other)
 
92
        {
 
93
                x += other.x;
 
94
                y += other.y;
 
95
                z += other.z;
 
96
                w += other.w;
 
97
                return *this;
 
98
        }
 
99
 
 
100
        float4& operator-=(const float4& other)
 
101
        {
 
102
                x -= other.x;
 
103
                y -= other.y;
 
104
                z -= other.z;
 
105
                w -= other.w;
 
106
                return *this;
 
107
        }
 
108
 
 
109
        float4& operator *=(float scalar)
 
110
        {
 
111
                x *= scalar;
 
112
                y *= scalar;
 
113
                z *= scalar;
 
114
                w *= scalar;
 
115
                return (*this);
 
116
        }
 
117
 
 
118
        
 
119
        
 
120
        
 
121
        
 
122
};
 
123
 
 
124
static float4 fabs(const float4& a)
 
125
{
 
126
        float4 tmp;
 
127
        tmp.x = a.x < 0.f ? 0.f  : a.x;
 
128
        tmp.y = a.y < 0.f ? 0.f  : a.y;
 
129
        tmp.z = a.z < 0.f ? 0.f  : a.z;
 
130
        tmp.w = a.w < 0.f ? 0.f  : a.w;
 
131
        return tmp;
 
132
}
 
133
static float4 operator+(const float4& a,const float4& b)
 
134
{
 
135
        float4 tmp;
 
136
        tmp.x = a.x + b.x;
 
137
        tmp.y = a.y + b.y;
 
138
        tmp.z = a.z + b.z;
 
139
        tmp.w = a.w + b.w;
 
140
        return tmp;
 
141
}
 
142
 
 
143
 
 
144
static float8 operator+(const float8& a,const float8& b)
 
145
{
 
146
        float8 tmp(0);
 
147
        tmp.s0  = a.s0 + b.s0;
 
148
        tmp.s1  = a.s1 + b.s1;
 
149
        tmp.s2  = a.s2 + b.s2;
 
150
        tmp.s3  = a.s3 + b.s3;
 
151
        tmp.s4  = a.s4 + b.s4;
 
152
        tmp.s5  = a.s5 + b.s5;
 
153
        tmp.s6  = a.s6 + b.s6;
 
154
        tmp.s7  = a.s7 + b.s7;
 
155
        return tmp;
 
156
}
 
157
 
 
158
 
 
159
static float4 operator-(const float4& a,const float4& b)
 
160
{
 
161
        float4 tmp;
 
162
        tmp.x = a.x - b.x;
 
163
        tmp.y = a.y - b.y;
 
164
        tmp.z = a.z - b.z;
 
165
        tmp.w = a.w - b.w;
 
166
        return tmp;
 
167
}
 
168
 
 
169
static float8 operator-(const float8& a,const float8& b)
 
170
{
 
171
        float8 tmp(0);
 
172
        tmp.s0  = a.s0 - b.s0;
 
173
        tmp.s1  = a.s1 - b.s1;
 
174
        tmp.s2  = a.s2 - b.s2;
 
175
        tmp.s3  = a.s3 - b.s3;
 
176
        tmp.s4  = a.s4 - b.s4;
 
177
        tmp.s5  = a.s5 - b.s5;
 
178
        tmp.s6  = a.s6 - b.s6;
 
179
        tmp.s7  = a.s7 - b.s7;
 
180
        return tmp;
 
181
}
 
182
 
 
183
static float4 operator*(float a,const float4& b)
 
184
{
 
185
        float4 tmp;
 
186
        tmp.x = a * b.x;
 
187
        tmp.y = a * b.y;
 
188
        tmp.z = a * b.z;
 
189
        tmp.w = a * b.w;
 
190
        return tmp;
 
191
}
 
192
 
 
193
static float4 operator/(const float4& b,float a)
 
194
{
 
195
        float4 tmp;
 
196
        tmp.x = b.x/a;
 
197
        tmp.y = b.y/a;
 
198
        tmp.z = b.z/a;
 
199
        tmp.w = b.w/a;
 
200
        return tmp;
 
201
}
 
202
 
 
203
 
 
204
 
 
205
 
 
206
static float dot(const float4&a ,const float4& b)
 
207
{
 
208
        float4 tmp;
 
209
        tmp.x = a.x*b.x;
 
210
        tmp.y = a.y*b.y;
 
211
        tmp.z = a.z*b.z;
 
212
        tmp.w = a.w*b.w;
 
213
        return tmp.x+tmp.y+tmp.z+tmp.w;
 
214
}
 
215
 
 
216
static float length(const float4&a)
 
217
{
 
218
        float l = sqrtf(a.x*a.x+a.y*a.y+a.z*a.z);
 
219
        return l;
 
220
}
 
221
 
 
222
static float4 normalize(const float4&a)
 
223
{
 
224
        float4 tmp;
 
225
        float l = length(a);
 
226
        tmp = 1.f/l*a;
 
227
        return tmp;
 
228
}
 
229
 
 
230
 
 
231
 
 
232
static float4 cross(const float4&a ,const float4& b)
 
233
{
 
234
        float4 tmp;
 
235
        tmp.x =  a.y*b.z - a.z*b.y;
 
236
        tmp.y = -a.x*b.z + a.z*b.x;
 
237
        tmp.z =  a.x*b.y - a.y*b.x;
 
238
        tmp.w = 0.f;
 
239
        return tmp;
 
240
}
 
241
 
 
242
static float max(float a, float b) 
 
243
{
 
244
        return (a >= b) ? a : b;
 
245
}
 
246
 
 
247
 
 
248
static float min(float a, float b) 
 
249
{
 
250
        return (a <= b) ? a : b;
 
251
}
 
252
 
 
253
static float fmax(float a, float b) 
 
254
{
 
255
        return (a >= b) ? a : b;
 
256
}
 
257
 
 
258
static float fmin(float a, float b) 
 
259
{
 
260
        return (a <= b) ? a : b;
 
261
}
 
262
 
 
263
struct int2
 
264
{
 
265
        int x,y;
 
266
};
 
267
 
 
268
struct uint2
 
269
{
 
270
        unsigned int x,y;
 
271
};
 
272
 
 
273
//typedef int2 uint2;
 
274
 
 
275
typedef unsigned int uint;
 
276
 
 
277
struct int4
 
278
{
 
279
        int x,y,z,w;
 
280
};
 
281
 
 
282
struct uint4
 
283
{
 
284
        unsigned int x,y,z,w;
 
285
        uint4() {}
 
286
        uint4(uint val) { x = y = z = w = val; }
 
287
        uint4& operator+=(const uint4& other)
 
288
        {
 
289
                x += other.x;
 
290
                y += other.y;
 
291
                z += other.z;
 
292
                w += other.w;
 
293
                return *this;
 
294
        }
 
295
};
 
296
static uint4 operator+(const uint4& a,const uint4& b)
 
297
{
 
298
        uint4 tmp;
 
299
        tmp.x = a.x + b.x;
 
300
        tmp.y = a.y + b.y;
 
301
        tmp.z = a.z + b.z;
 
302
        tmp.w = a.w + b.w;
 
303
        return tmp;
 
304
}
 
305
static uint4 operator-(const uint4& a,const uint4& b)
 
306
{
 
307
        uint4 tmp;
 
308
        tmp.x = a.x - b.x;
 
309
        tmp.y = a.y - b.y;
 
310
        tmp.z = a.z - b.z;
 
311
        tmp.w = a.w - b.w;
 
312
        return tmp;
 
313
}
 
314
 
 
315
#define native_sqrt sqrtf
 
316
#define native_sin sinf
 
317
#define native_cos cosf
 
318
#define native_powr powf
 
319
 
 
320
#define GUID_ARG ,int __guid_arg
 
321
#define GUID_ARG_VAL ,__guid_arg
 
322
 
 
323
 
 
324
#define as_int(a) (*((int*)&(a)))
 
325
 
 
326
extern "C" int gMiniCLNumOutstandingTasks;
 
327
//      extern "C" void __kernel_func();
 
328
 
 
329