1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
class Float4 {
public:
float x, y, z, w;
__device__ const Float4
operator+(const Float4& iv) const {
Float4 rv ;
rv.x = x + iv.x ;
rv.y = y + iv.y ;
rv.z = z + iv.z ;
rv.w = w + iv.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator*(const Float4& iv) const {
Float4 rv ;
rv.x = x * iv.x ;
rv.y = y * iv.y ;
rv.z = z * iv.z ;
rv.w = w * iv.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator/(const Float4& iv) const {
Float4 rv ;
rv.x = x / iv.x ;
rv.y = y / iv.y ;
rv.z = z / iv.z ;
rv.w = w / iv.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator-(const Float4& iv) const {
Float4 rv ;
rv.x = x - iv.x ;
rv.y = y - iv.y ;
rv.z = z - iv.z ;
rv.w = w - iv.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator+(const float iv) const {
Float4 rv ;
rv.x = x + iv ;
rv.y = y + iv ;
rv.z = z + iv ;
rv.w = w + iv ;
return Float4( rv ) ;
}
__device__ const Float4
operator*(const float iv) const {
Float4 rv ;
rv.x = x * iv ;
rv.y = y * iv ;
rv.z = z * iv ;
rv.w = w * iv ;
return Float4( rv ) ;
}
__device__ const Float4
operator/(const float iv) const {
Float4 rv ;
rv.x = x / iv ;
rv.y = y / iv ;
rv.z = z / iv ;
rv.w = w / iv ;
return Float4( rv ) ;
}
__device__ const Float4
operator-(const float iv) const {
Float4 rv ;
rv.x = x - iv ;
rv.y = y - iv ;
rv.z = z - iv ;
rv.w = w - iv ;
return Float4( rv ) ;
}
__device__ const Float4
operator-() const {
Float4 rv ;
rv.x = -x ;
rv.y = -y ;
rv.z = -z ;
rv.w = -w ;
return Float4( rv ) ;
}
__device__ void operator=(const float iv) {
x = iv ;
y = iv ;
z = iv ;
w = iv ;
}
__device__ void operator+=(const Float4 iv) {
x += iv.x ;
y += iv.y ;
z += iv.z ;
w += iv.w ;
}
__device__ void operator-=(const Float4 iv) {
x -= iv.x ;
y -= iv.y ;
z -= iv.z ;
w -= iv.w ;
}
};
__device__ const Float4
operator+( const float iv1, const Float4 iv2 ) {
Float4 rv ;
rv.x = iv1 + iv2.x ;
rv.y = iv1 + iv2.y ;
rv.z = iv1 + iv2.z ;
rv.w = iv1 + iv2.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator*( const float iv1, const Float4 iv2 ) {
Float4 rv ;
rv.x = iv1 * iv2.x ;
rv.y = iv1 * iv2.y ;
rv.z = iv1 * iv2.z ;
rv.w = iv1 * iv2.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator/( const float iv1, const Float4 iv2 ) {
Float4 rv ;
rv.x = iv1 / iv2.x ;
rv.y = iv1 / iv2.y ;
rv.z = iv1 / iv2.z ;
rv.w = iv1 / iv2.w ;
return Float4( rv ) ;
}
__device__ const Float4
operator-( const float iv1, const Float4 iv2 ) {
Float4 rv ;
rv.x = iv1 - iv2.x ;
rv.y = iv1 - iv2.y ;
rv.z = iv1 - iv2.z ;
rv.w = iv1 - iv2.w ;
return Float4( rv ) ;
}
__device__ Float4 max ( const Float4 a , const Float4 b )
{
Float4 c ;
c.x = (a.x>b.x)?a.x:b.x;
c.y = (a.y>b.y)?a.y:b.y;
c.z = (a.z>b.z)?a.z:b.z;
c.w = (a.w>b.w)?a.w:b.w;
return(c) ;
}
__device__ Float4 max ( const float a , const Float4 b )
{
Float4 c ;
c.x = (a>b.x)?a:b.x;
c.y = (a>b.y)?a:b.y;
c.z = (a>b.z)?a:b.z;
c.w = (a>b.w)?a:b.w;
return(c) ;
}
__device__ Float4 max ( const Float4 a , const float b )
{
Float4 c ;
c.x = (a.x>b)?a.x:b;
c.y = (a.y>b)?a.y:b;
c.z = (a.z>b)?a.z:b;
c.w = (a.w>b)?a.w:b;
return(c) ;
}
//__device__ float max ( const float a , const float b )
//{
// return(a>b)?a:b) ;
//}
__device__ Float4 min ( const Float4 a , const Float4 b )
{
Float4 c ;
c.x = (a.x<b.x)?a.x:b.x;
c.y = (a.y<b.y)?a.y:b.y;
c.z = (a.z<b.z)?a.z:b.z;
c.w = (a.w<b.w)?a.w:b.w;
return(c) ;
}
__device__ Float4 min ( const float a , const Float4 b )
{
Float4 c ;
c.x = (a<b.x)?a:b.x;
c.y = (a<b.y)?a:b.y;
c.z = (a<b.z)?a:b.z;
c.w = (a<b.w)?a:b.w;
return(c) ;
}
__device__ Float4 min ( const Float4 a , const float b )
{
Float4 c ;
c.x = (a.x<b)?a.x:b;
c.y = (a.y<b)?a.y:b;
c.z = (a.z<b)?a.z:b;
c.w = (a.w<b)?a.w:b;
return(c) ;
}
__device__ Float4 trunc ( const Float4 a )
{
Float4 c ;
c.x = trunc(a.x) ;
c.y = trunc(a.y) ;
c.z = trunc(a.z) ;
c.w = trunc(a.w) ;
return(c) ;
}
__device__ Float4 log ( const Float4 a )
{
Float4 c ;
c.x = log(a.x) ; c.y = log(a.y) ; c.z = log(a.z) ; c.w = log(a.w) ;
return(c) ;
}
__device__ Float4 exp ( const Float4 a )
{
Float4 c ;
c.x = exp(a.x) ; c.y = exp(a.y) ; c.z = exp(a.z) ; c.w = exp(a.w) ;
return(c) ;
}
__device__ Float4 sqrt ( const Float4 a )
{
Float4 c ;
c.x = sqrt(a.x) ; c.y = sqrt(a.y) ; c.z = sqrt(a.z) ; c.w = sqrt(a.w) ;
return(c) ;
}
#if 0
int main() {
Float4 a, b, c ;
a.x = 0. ; a.y = 1. ; a.z = 2. ; a.w = 3. ;
b.x = 0. ; b.y = 1. ; b.z = 2. ; b.w = 3. ;
c = 2. + a ;
fprintf(stderr,"%f %f %f %f\n",a.x,a.y,a.z,a.w) ;
fprintf(stderr,"%f %f %f %f\n",b.x,b.y,b.z,b.w) ;
fprintf(stderr,"%f %f %f %f\n",c.x,c.y,c.z,c.w) ;
c = 2. * b ;
fprintf(stderr,"%f %f %f %f\n",a.x,a.y,a.z,a.w) ;
fprintf(stderr,"%f %f %f %f\n",b.x,b.y,b.z,b.w) ;
fprintf(stderr,"%f %f %f %f\n",c.x,c.y,c.z,c.w) ;
c = 2. - b ;
fprintf(stderr,"%f %f %f %f\n",a.x,a.y,a.z,a.w) ;
fprintf(stderr,"%f %f %f %f\n",b.x,b.y,b.z,b.w) ;
fprintf(stderr,"%f %f %f %f\n",c.x,c.y,c.z,c.w) ;
c = 2. / b ;
fprintf(stderr,"%f %f %f %f\n",a.x,a.y,a.z,a.w) ;
fprintf(stderr,"%f %f %f %f\n",b.x,b.y,b.z,b.w) ;
fprintf(stderr,"%f %f %f %f\n",c.x,c.y,c.z,c.w) ;
}
#endif
|