blob: 6ad395329d7b6ba5b7198cb151106673eadd1a02 [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
John Bauman19bac1e2014-05-06 15:23:49 -04003// Copyright(c) 2005-2012 TransGaming Inc.
John Bauman89401822014-05-06 15:04:28 -04004//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "ShaderCore.hpp"
13
John Bauman19bac1e2014-05-06 15:23:49 -040014#include "Renderer/Renderer.hpp"
15#include "Common/Debug.hpp"
John Bauman89401822014-05-06 15:04:28 -040016
Alexis Hetud5c31da2015-08-28 14:39:13 -040017#include <limits.h>
18
John Bauman89401822014-05-06 15:04:28 -040019namespace sw
20{
John Bauman19bac1e2014-05-06 15:23:49 -040021 extern TranscendentalPrecision logPrecision;
22 extern TranscendentalPrecision expPrecision;
23 extern TranscendentalPrecision rcpPrecision;
24 extern TranscendentalPrecision rsqPrecision;
25
Alexis Hetu96517182015-04-15 10:30:23 -040026 Vector4s::Vector4s()
John Bauman19bac1e2014-05-06 15:23:49 -040027 {
28 }
29
Alexis Hetu96517182015-04-15 10:30:23 -040030 Vector4s::Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
John Bauman19bac1e2014-05-06 15:23:49 -040031 {
32 this->x = Short4(x);
33 this->y = Short4(y);
34 this->z = Short4(z);
35 this->w = Short4(w);
36 }
37
Alexis Hetu96517182015-04-15 10:30:23 -040038 Vector4s::Vector4s(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040039 {
40 x = rhs.x;
41 y = rhs.y;
42 z = rhs.z;
43 w = rhs.w;
44 }
45
Alexis Hetu96517182015-04-15 10:30:23 -040046 Vector4s &Vector4s::operator=(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040047 {
48 x = rhs.x;
49 y = rhs.y;
50 z = rhs.z;
51 w = rhs.w;
52
53 return *this;
54 }
55
Alexis Hetu96517182015-04-15 10:30:23 -040056 Short4 &Vector4s::operator[](int i)
John Bauman19bac1e2014-05-06 15:23:49 -040057 {
58 switch(i)
59 {
60 case 0: return x;
61 case 1: return y;
62 case 2: return z;
63 case 3: return w;
64 }
65
66 return x;
67 }
68
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -040069 Vector4i::Vector4i()
70 {
71 }
72
73 Vector4i::Vector4i(int x, int y, int z, int w)
74 {
75 this->x = Int4(x);
76 this->y = Int4(y);
77 this->z = Int4(z);
78 this->w = Int4(w);
79 }
80
81 Vector4i::Vector4i(const Vector4i &rhs)
82 {
83 x = rhs.x;
84 y = rhs.y;
85 z = rhs.z;
86 w = rhs.w;
87 }
88
89 Vector4i &Vector4i::operator=(const Vector4i &rhs)
90 {
91 x = rhs.x;
92 y = rhs.y;
93 z = rhs.z;
94 w = rhs.w;
95
96 return *this;
97 }
98
99 Int4 &Vector4i::operator[](int i)
100 {
101 switch(i)
102 {
103 case 0: return x;
104 case 1: return y;
105 case 2: return z;
106 case 3: return w;
107 }
108
109 return x;
110 }
111
112 Vector4u::Vector4u()
113 {
114 }
115
116 Vector4u::Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
117 {
118 this->x = UInt4(x);
119 this->y = UInt4(y);
120 this->z = UInt4(z);
121 this->w = UInt4(w);
122 }
123
124 Vector4u::Vector4u(const Vector4u &rhs)
125 {
126 x = rhs.x;
127 y = rhs.y;
128 z = rhs.z;
129 w = rhs.w;
130 }
131
132 Vector4u &Vector4u::operator=(const Vector4u &rhs)
133 {
134 x = rhs.x;
135 y = rhs.y;
136 z = rhs.z;
137 w = rhs.w;
138
139 return *this;
140 }
141
142 UInt4 &Vector4u::operator[](int i)
143 {
144 switch(i)
145 {
146 case 0: return x;
147 case 1: return y;
148 case 2: return z;
149 case 3: return w;
150 }
151
152 return x;
153 }
154
John Bauman19bac1e2014-05-06 15:23:49 -0400155 Vector4f::Vector4f()
156 {
157 }
158
159 Vector4f::Vector4f(float x, float y, float z, float w)
160 {
161 this->x = Float4(x);
162 this->y = Float4(y);
163 this->z = Float4(z);
164 this->w = Float4(w);
165 }
166
167 Vector4f::Vector4f(const Vector4f &rhs)
168 {
169 x = rhs.x;
170 y = rhs.y;
171 z = rhs.z;
172 w = rhs.w;
173 }
174
175 Vector4f &Vector4f::operator=(const Vector4f &rhs)
176 {
177 x = rhs.x;
178 y = rhs.y;
179 z = rhs.z;
180 w = rhs.w;
181
182 return *this;
183 }
184
185 Float4 &Vector4f::operator[](int i)
186 {
187 switch(i)
188 {
189 case 0: return x;
190 case 1: return y;
191 case 2: return z;
192 case 3: return w;
193 }
194
195 return x;
196 }
197
198 Float4 exponential2(RValue<Float4> x, bool pp)
199 {
200 Float4 x0;
201 Float4 x1;
202 Int4 x2;
203
204 x0 = x;
205
206 x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
207 x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f
208 x1 = x0;
209 x1 -= Float4(0.5f);
210 x2 = RoundInt(x1);
211 x1 = Float4(x2);
212 x2 += Int4(0x0000007F); // 127
213 x2 = x2 << 23;
214 x0 -= x1;
215 x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f
216 x1 *= x0;
217 x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f
218 x1 *= x0;
219 x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f
220 x1 *= x0;
221 x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
222 x1 *= x0;
223 x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
224 x1 *= x0;
225 x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f
226 x1 *= As<Float4>(x2);
227
228 return x1;
229 }
230
231 Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp)
232 {
233 Float4 x0;
234 Float4 x1;
235 Float4 x2;
236 Float4 x3;
237
238 x0 = x;
239
240 x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
241 x1 = As<Float4>(As<UInt4>(x1) >> 8);
242 x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
243 x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f;
244 x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
245
246 x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f);
247 x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f);
248 x2 /= x3;
249
250 x1 += (x0 - Float4(1.0f)) * x2;
251
252 return x1;
253 }
254
255 Float4 exponential(RValue<Float4> x, bool pp)
256 {
257 // FIXME: Propagate the constant
258 return exponential2(Float4(1.44269541f) * x, pp); // 1/ln(2)
259 }
260
261 Float4 logarithm(RValue<Float4> x, bool absolute, bool pp)
262 {
263 // FIXME: Propagate the constant
264 return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2)
265 }
266
267 Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp)
268 {
269 Float4 log = logarithm2(x, true, pp);
270 log *= y;
271 return exponential2(log, pp);
272 }
273
274 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite)
275 {
276 Float4 rcp;
277
278 if(!pp && rcpPrecision >= WHQL)
279 {
280 rcp = Float4(1.0f) / x;
281 }
282 else
283 {
284 rcp = Rcp_pp(x);
285
286 if(!pp)
287 {
288 rcp = (rcp + rcp) - (x * rcp * rcp);
289 }
290 }
291
292 if(finite)
293 {
294 int big = 0x7F7FFFFF;
295 rcp = Min(rcp, Float4((float&)big));
296 }
297
298 return rcp;
299 }
300
301 Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
302 {
303 Float4 abs = x;
304
305 if(absolute)
306 {
307 abs = Abs(abs);
308 }
309
310 Float4 rsq;
311
312 if(!pp && rsqPrecision >= IEEE)
313 {
314 rsq = Float4(1.0f) / Sqrt(abs);
315 }
316 else
317 {
318 rsq = RcpSqrt_pp(abs);
319
320 if(!pp)
321 {
322 rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
323 }
324 }
325
326 int big = 0x7F7FFFFF;
327 rsq = Min(rsq, Float4((float&)big));
328
329 return rsq;
330 }
331
332 Float4 modulo(RValue<Float4> x, RValue<Float4> y)
333 {
334 return x - y * Floor(x / y);
335 }
336
337 Float4 sine_pi(RValue<Float4> x, bool pp)
338 {
339 const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2
340 const Float4 B = Float4(1.27323954e+0f); // 4/pi
341 const Float4 C = Float4(7.75160950e-1f);
342 const Float4 D = Float4(2.24839049e-1f);
343
344 // Parabola approximating sine
345 Float4 sin = x * (Abs(x) * A + B);
346
347 // Improve precision from 0.06 to 0.001
348 if(true)
349 {
350 sin = sin * (Abs(sin) * D + C);
351 }
352
353 return sin;
354 }
355
356 Float4 cosine_pi(RValue<Float4> x, bool pp)
357 {
358 // cos(x) = sin(x + pi/2)
359 Float4 y = x + Float4(1.57079632e+0f);
360
361 // Wrap around
362 y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f)));
363
364 return sine_pi(y, pp);
365 }
366
367 Float4 sine(RValue<Float4> x, bool pp)
368 {
369 // Reduce to [-0.5, 0.5] range
370 Float4 y = x * Float4(1.59154943e-1f); // 1/2pi
371 y = y - Round(y);
372
373 const Float4 A = Float4(-16.0f);
374 const Float4 B = Float4(8.0f);
375 const Float4 C = Float4(7.75160950e-1f);
376 const Float4 D = Float4(2.24839049e-1f);
377
378 // Parabola approximating sine
379 Float4 sin = y * (Abs(y) * A + B);
380
381 // Improve precision from 0.06 to 0.001
382 if(true)
383 {
384 sin = sin * (Abs(sin) * D + C);
385 }
386
387 return sin;
388 }
389
390 Float4 cosine(RValue<Float4> x, bool pp)
391 {
392 // cos(x) = sin(x + pi/2)
393 Float4 y = x + Float4(1.57079632e+0f);
394 return sine(y, pp);
395 }
396
397 Float4 tangent(RValue<Float4> x, bool pp)
398 {
399 return sine(x, pp) / cosine(x, pp);
400 }
401
402 Float4 arccos(RValue<Float4> x, bool pp)
403 {
404 // pi/2 - arcsin(x)
405 return Float4(1.57079632e+0f) - arcsin(x);
406 }
407
408 Float4 arcsin(RValue<Float4> x, bool pp)
409 {
410 // x*(pi/2-sqrt(1-x*x)*pi/5)
411 return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f));
412 }
413
414 Float4 arctan(RValue<Float4> x, bool pp)
415 {
416 Int4 O = CmpNLT(Abs(x), Float4(1.0f));
417 Float4 y = As<Float4>(O & As<Int4>(Float4(1.0f) / x) | ~O & As<Int4>(x)); // FIXME: Vector select
418
419 // Approximation of atan in [-1..1]
420 Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
421
422 // +/-pi/2 depending on sign of x
423 Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
424
425 theta = As<Float4>(O & As<Int4>(sgnPi_2 - theta) | ~O & As<Int4>(theta)); // FIXME: Vector select
426
427 return theta;
428 }
429
430 Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp)
431 {
432 // Rotate to upper semicircle when in lower semicircle
433 Int4 S = CmpLT(y, Float4(0.0f));
434 Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi
435 Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x));
436 Float4 y0 = Abs(y);
437
438 // Rotate to right quadrant when in left quadrant
439 Int4 Q = CmpLT(x0, Float4(0.0f));
440 theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2
441 Float4 x1 = As<Float4>(Q & As<Int4>(y0) | ~Q & As<Int4>(x0)); // FIXME: Vector select
442 Float4 y1 = As<Float4>(Q & As<Int4>(-x0) | ~Q & As<Int4>(y0)); // FIXME: Vector select
443
444 // Rotate to first octant when in second octant
445 Int4 O = CmpNLT(y1, x1);
446 theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4
447 Float4 x2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * x1 + Float4(7.07106781e-1f) * y1) | ~O & As<Int4>(x1)); // sqrt(2)/2 // FIXME: Vector select
448 Float4 y2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1) | ~O & As<Int4>(y1)); // FIXME: Vector select
449
450 // Approximation of atan in [0..1]
451 Float4 y_x = y2 / x2;
452 theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f));
453
454 return theta;
455 }
456
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400457 Float4 sineh(RValue<Float4> x, bool pp)
458 {
459 return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f);
460 }
461
462 Float4 cosineh(RValue<Float4> x, bool pp)
463 {
464 return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f);
465 }
466
467 Float4 tangenth(RValue<Float4> x, bool pp)
468 {
469 Float4 e_x = exponential(x, pp);
470 Float4 e_minus_x = exponential(-x, pp);
471 return (e_x - e_minus_x) / (e_x + e_minus_x);
472 }
473
474 Float4 arccosh(RValue<Float4> x, bool pp)
475 {
476 return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp);
477 }
478
479 Float4 arcsinh(RValue<Float4> x, bool pp)
480 {
481 return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp);
482 }
483
484 Float4 arctanh(RValue<Float4> x, bool pp)
485 {
486 return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f);
487 }
488
Alexis Hetuecad5192015-06-05 13:42:05 -0400489 Float4 dot2(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400490 {
491 return v0.x * v1.x + v0.y * v1.y;
492 }
493
Alexis Hetuecad5192015-06-05 13:42:05 -0400494 Float4 dot3(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400495 {
496 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
497 }
498
Alexis Hetuecad5192015-06-05 13:42:05 -0400499 Float4 dot4(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400500 {
501 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w;
502 }
503
504 void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
505 {
506 Int2 tmp0 = UnpackHigh(row0, row1);
507 Int2 tmp1 = UnpackHigh(row2, row3);
508 Int2 tmp2 = UnpackLow(row0, row1);
509 Int2 tmp3 = UnpackLow(row2, row3);
510
511 row0 = As<Short4>(UnpackLow(tmp2, tmp3));
512 row1 = As<Short4>(UnpackHigh(tmp2, tmp3));
513 row2 = As<Short4>(UnpackLow(tmp0, tmp1));
514 row3 = As<Short4>(UnpackHigh(tmp0, tmp1));
515 }
516
517 void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
518 {
519 Float4 tmp0 = UnpackLow(row0, row1);
520 Float4 tmp1 = UnpackLow(row2, row3);
521 Float4 tmp2 = UnpackHigh(row0, row1);
522 Float4 tmp3 = UnpackHigh(row2, row3);
523
524 row0 = Float4(tmp0.xy, tmp1.xy);
525 row1 = Float4(tmp0.zw, tmp1.zw);
526 row2 = Float4(tmp2.xy, tmp3.xy);
527 row3 = Float4(tmp2.zw, tmp3.zw);
528 }
529
530 void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
531 {
532 Float4 tmp0 = UnpackLow(row0, row1);
533 Float4 tmp1 = UnpackLow(row2, row3);
534 Float4 tmp2 = UnpackHigh(row0, row1);
535 Float4 tmp3 = UnpackHigh(row2, row3);
536
537 row0 = Float4(tmp0.xy, tmp1.xy);
538 row1 = Float4(tmp0.zw, tmp1.zw);
539 row2 = Float4(tmp2.xy, tmp3.xy);
540 }
541
542 void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
543 {
544 Float4 tmp0 = UnpackLow(row0, row1);
545 Float4 tmp1 = UnpackLow(row2, row3);
546
547 row0 = Float4(tmp0.xy, tmp1.xy);
548 row1 = Float4(tmp0.zw, tmp1.zw);
549 }
550
551 void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
552 {
553 Float4 tmp0 = UnpackLow(row0, row1);
554 Float4 tmp1 = UnpackLow(row2, row3);
555
556 row0 = Float4(tmp0.xy, tmp1.xy);
557 }
558
559 void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
560 {
561 row0 = UnpackLow(row0, row1);
562 row1 = Float4(row0.zw, row1.zw);
563 row2 = UnpackHigh(row0, row1);
564 row3 = Float4(row2.zw, row3.zw);
565 }
566
567 void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
568 {
569 row0 = UnpackLow(row2, row3);
570 row1 = Float4(row0.zw, row1.zw);
571 row2 = UnpackHigh(row2, row3);
572 row3 = Float4(row2.zw, row3.zw);
573 }
574
575 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
576 {
577 switch(N)
578 {
579 case 1: transpose4x1(row0, row1, row2, row3); break;
580 case 2: transpose4x2(row0, row1, row2, row3); break;
581 case 3: transpose4x3(row0, row1, row2, row3); break;
582 case 4: transpose4x4(row0, row1, row2, row3); break;
583 }
584 }
585
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400586 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400587 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400588 if(integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400589 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400590 dst.x = As<Float4>(RoundInt(src.x));
591 dst.y = As<Float4>(RoundInt(src.y));
592 dst.z = As<Float4>(RoundInt(src.z));
593 dst.w = As<Float4>(RoundInt(src.w));
John Bauman89401822014-05-06 15:04:28 -0400594 }
595 else
596 {
597 dst = src;
598 }
599 }
600
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400601 void ShaderCore::neg(Vector4f &dst, const Vector4f &src)
602 {
603 dst.x = -src.x;
604 dst.y = -src.y;
605 dst.z = -src.z;
606 dst.w = -src.w;
607 }
608
609 void ShaderCore::ineg(Vector4f &dst, const Vector4f &src)
610 {
611 dst.x = As<Float4>(-As<Int4>(src.x));
612 dst.y = As<Float4>(-As<Int4>(src.y));
613 dst.z = As<Float4>(-As<Int4>(src.z));
614 dst.w = As<Float4>(-As<Int4>(src.w));
615 }
616
Alexis Hetuecad5192015-06-05 13:42:05 -0400617 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400618 {
619 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
620 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
621 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
622 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
623 }
624
Alexis Hetuecad5192015-06-05 13:42:05 -0400625 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400626 {
627 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
628 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
629 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
630 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
631 }
632
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400633 void ShaderCore::f2i(Vector4f &dst, const Vector4f &src)
634 {
635 dst.x = As<Float4>(Int4(src.x));
636 dst.y = As<Float4>(Int4(src.y));
637 dst.z = As<Float4>(Int4(src.z));
638 dst.w = As<Float4>(Int4(src.w));
639 }
640
641 void ShaderCore::i2f(Vector4f &dst, const Vector4f &src)
642 {
643 dst.x = Float4(As<Int4>(src.x));
644 dst.y = Float4(As<Int4>(src.y));
645 dst.z = Float4(As<Int4>(src.z));
646 dst.w = Float4(As<Int4>(src.w));
647 }
648
649 void ShaderCore::f2u(Vector4f &dst, const Vector4f &src)
650 {
651 dst.x = As<Float4>(UInt4(src.x));
652 dst.y = As<Float4>(UInt4(src.y));
653 dst.z = As<Float4>(UInt4(src.z));
654 dst.w = As<Float4>(UInt4(src.w));
655 }
656
657 void ShaderCore::u2f(Vector4f &dst, const Vector4f &src)
658 {
659 dst.x = Float4(As<UInt4>(src.x));
660 dst.y = Float4(As<UInt4>(src.y));
661 dst.z = Float4(As<UInt4>(src.z));
662 dst.w = Float4(As<UInt4>(src.w));
663 }
664
665 void ShaderCore::i2b(Vector4f &dst, const Vector4f &src)
666 {
667 dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0)));
668 dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0)));
669 dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0)));
670 dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0)));
671 }
672
673 void ShaderCore::b2i(Vector4f &dst, const Vector4f &src)
674 {
675 dst.x = As<Float4>(As<Int4>(src.x) & Int4(1));
676 dst.y = As<Float4>(As<Int4>(src.y) & Int4(1));
677 dst.z = As<Float4>(As<Int4>(src.z) & Int4(1));
678 dst.w = As<Float4>(As<Int4>(src.w) & Int4(1));
679 }
680
681 void ShaderCore::u2b(Vector4f &dst, const Vector4f &src)
682 {
683 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src.x), UInt4(0)));
684 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src.y), UInt4(0)));
685 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src.z), UInt4(0)));
686 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src.w), UInt4(0)));
687 }
688
689 void ShaderCore::b2u(Vector4f &dst, const Vector4f &src)
690 {
691 dst.x = As<Float4>(As<UInt4>(src.x) & UInt4(1));
692 dst.y = As<Float4>(As<UInt4>(src.y) & UInt4(1));
693 dst.z = As<Float4>(As<UInt4>(src.z) & UInt4(1));
694 dst.w = As<Float4>(As<UInt4>(src.w) & UInt4(1));
695 }
696
Alexis Hetuecad5192015-06-05 13:42:05 -0400697 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400698 {
699 dst.x = src0.x + src1.x;
700 dst.y = src0.y + src1.y;
701 dst.z = src0.z + src1.z;
702 dst.w = src0.w + src1.w;
703 }
704
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400705 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
706 {
707 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
708 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
709 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
710 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
711 }
712
Alexis Hetuecad5192015-06-05 13:42:05 -0400713 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400714 {
715 dst.x = src0.x - src1.x;
716 dst.y = src0.y - src1.y;
717 dst.z = src0.z - src1.z;
718 dst.w = src0.w - src1.w;
719 }
720
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400721 void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
722 {
723 dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x));
724 dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y));
725 dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z));
726 dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w));
727 }
728
Alexis Hetuecad5192015-06-05 13:42:05 -0400729 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400730 {
731 dst.x = src0.x * src1.x + src2.x;
732 dst.y = src0.y * src1.y + src2.y;
733 dst.z = src0.z * src1.z + src2.z;
734 dst.w = src0.w * src1.w + src2.w;
735 }
736
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400737 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
738 {
739 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
740 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
741 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
742 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
743 }
744
Alexis Hetuecad5192015-06-05 13:42:05 -0400745 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400746 {
747 dst.x = src0.x * src1.x;
748 dst.y = src0.y * src1.y;
749 dst.z = src0.z * src1.z;
750 dst.w = src0.w * src1.w;
751 }
752
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400753 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
754 {
755 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
756 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
757 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
758 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
759 }
760
Alexis Hetuecad5192015-06-05 13:42:05 -0400761 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400762 {
763 Float4 rcp = reciprocal(src.x, pp, true);
764
765 dst.x = rcp;
766 dst.y = rcp;
767 dst.z = rcp;
768 dst.w = rcp;
769 }
770
Alexis Hetuecad5192015-06-05 13:42:05 -0400771 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400772 {
773 dst.x = src0.x / src1.x;
774 dst.y = src0.y / src1.y;
775 dst.z = src0.z / src1.z;
776 dst.w = src0.w / src1.w;
777 }
778
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400779 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
780 {
781 Float4 intMax(As<Float4>(Int4(INT_MAX)));
782 cmp0i(dst.x, src1.x, intMax, src1.x);
783 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
784 cmp0i(dst.y, src1.y, intMax, src1.y);
785 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
786 cmp0i(dst.z, src1.z, intMax, src1.z);
787 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
788 cmp0i(dst.w, src1.w, intMax, src1.w);
789 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
790 }
791
792 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
793 {
794 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
795 cmp0i(dst.x, src1.x, uintMax, src1.x);
796 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
797 cmp0i(dst.y, src1.y, uintMax, src1.y);
798 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
799 cmp0i(dst.z, src1.z, uintMax, src1.z);
800 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
801 cmp0i(dst.w, src1.w, uintMax, src1.w);
802 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
803 }
804
Alexis Hetuecad5192015-06-05 13:42:05 -0400805 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400806 {
807 dst.x = modulo(src0.x, src1.x);
808 dst.y = modulo(src0.y, src1.y);
809 dst.z = modulo(src0.z, src1.z);
810 dst.w = modulo(src0.w, src1.w);
811 }
812
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400813 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
814 {
815 cmp0i(dst.x, src1.x, src0.x, src1.x);
816 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
817 cmp0i(dst.y, src1.y, src0.y, src1.y);
818 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
819 cmp0i(dst.z, src1.z, src0.z, src1.z);
820 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
821 cmp0i(dst.w, src1.w, src0.w, src1.w);
822 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
823 }
824 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
825 {
826 cmp0i(dst.x, src1.x, src0.x, src1.x);
827 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
828 cmp0i(dst.y, src1.y, src0.y, src1.y);
829 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
830 cmp0i(dst.z, src1.z, src0.z, src1.z);
831 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
832 cmp0i(dst.w, src1.w, src0.w, src1.w);
833 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
834 }
835
836 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
837 {
838 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
839 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
840 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
841 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
842 }
843
844 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
845 {
846 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
847 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
848 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
849 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
850 }
851
852 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
853 {
854 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
855 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
856 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
857 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
858 }
859
Alexis Hetuecad5192015-06-05 13:42:05 -0400860 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400861 {
862 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
863
John Bauman19bac1e2014-05-06 15:23:49 -0400864 dst.x = rsq;
865 dst.y = rsq;
866 dst.z = rsq;
867 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400868 }
869
Alexis Hetuecad5192015-06-05 13:42:05 -0400870 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400871 {
872 dst.x = Sqrt(src.x);
873 dst.y = Sqrt(src.y);
874 dst.z = Sqrt(src.z);
875 dst.w = Sqrt(src.w);
876 }
877
Alexis Hetuecad5192015-06-05 13:42:05 -0400878 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400879 {
880 dst.x = reciprocalSquareRoot(src.x, false, pp);
881 dst.y = reciprocalSquareRoot(src.y, false, pp);
882 dst.z = reciprocalSquareRoot(src.z, false, pp);
883 dst.w = reciprocalSquareRoot(src.w, false, pp);
884 }
885
Alexis Hetuecad5192015-06-05 13:42:05 -0400886 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400887 {
888 dst = Sqrt(dot2(src, src));
889 }
890
Alexis Hetuecad5192015-06-05 13:42:05 -0400891 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400892 {
893 dst = Sqrt(dot3(src, src));
894 }
895
Alexis Hetuecad5192015-06-05 13:42:05 -0400896 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400897 {
898 dst = Sqrt(dot4(src, src));
899 }
900
Alexis Hetuecad5192015-06-05 13:42:05 -0400901 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400902 {
903 dst = Abs(src0.x - src1.x);
904 }
905
Alexis Hetuecad5192015-06-05 13:42:05 -0400906 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400907 {
908 Float4 dx = src0.x - src1.x;
909 Float4 dy = src0.y - src1.y;
910 Float4 dot2 = dx * dx + dy * dy;
911 dst = Sqrt(dot2);
912 }
913
Alexis Hetuecad5192015-06-05 13:42:05 -0400914 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400915 {
916 Float4 dx = src0.x - src1.x;
917 Float4 dy = src0.y - src1.y;
918 Float4 dz = src0.z - src1.z;
919 Float4 dot3 = dx * dx + dy * dy + dz * dz;
920 dst = Sqrt(dot3);
921 }
922
Alexis Hetuecad5192015-06-05 13:42:05 -0400923 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400924 {
925 Float4 dx = src0.x - src1.x;
926 Float4 dy = src0.y - src1.y;
927 Float4 dz = src0.z - src1.z;
928 Float4 dw = src0.w - src1.w;
929 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
930 dst = Sqrt(dot4);
931 }
932
Alexis Hetuecad5192015-06-05 13:42:05 -0400933 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400934 {
935 Float4 t = src0.x * src1.x;
936
937 dst.x = t;
938 dst.y = t;
939 dst.z = t;
940 dst.w = t;
941 }
942
Alexis Hetuecad5192015-06-05 13:42:05 -0400943 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400944 {
945 Float4 t = dot2(src0, src1);
946
947 dst.x = t;
948 dst.y = t;
949 dst.z = t;
950 dst.w = t;
951 }
952
Alexis Hetuecad5192015-06-05 13:42:05 -0400953 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400954 {
955 Float4 t = dot2(src0, src1) + src2.x;
956
957 dst.x = t;
958 dst.y = t;
959 dst.z = t;
960 dst.w = t;
961 }
962
Alexis Hetuecad5192015-06-05 13:42:05 -0400963 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400964 {
965 Float4 dot = dot3(src0, src1);
966
967 dst.x = dot;
968 dst.y = dot;
969 dst.z = dot;
970 dst.w = dot;
971 }
972
Alexis Hetuecad5192015-06-05 13:42:05 -0400973 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400974 {
975 Float4 dot = dot4(src0, src1);
976
977 dst.x = dot;
978 dst.y = dot;
979 dst.z = dot;
980 dst.w = dot;
981 }
982
Alexis Hetuecad5192015-06-05 13:42:05 -0400983 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400984 {
985 dst.x = Min(src0.x, src1.x);
986 dst.y = Min(src0.y, src1.y);
987 dst.z = Min(src0.z, src1.z);
988 dst.w = Min(src0.w, src1.w);
989 }
990
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400991 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
992 {
993 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
994 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
995 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
996 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
997 }
998
999 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1000 {
1001 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1002 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1003 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1004 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1005 }
1006
Alexis Hetuecad5192015-06-05 13:42:05 -04001007 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001008 {
1009 dst.x = Max(src0.x, src1.x);
1010 dst.y = Max(src0.y, src1.y);
1011 dst.z = Max(src0.z, src1.z);
1012 dst.w = Max(src0.w, src1.w);
1013 }
1014
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001015 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1016 {
1017 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1018 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1019 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1020 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1021 }
1022
1023 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1024 {
1025 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1026 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1027 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1028 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1029 }
1030
Alexis Hetuecad5192015-06-05 13:42:05 -04001031 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001032 {
John Bauman19bac1e2014-05-06 15:23:49 -04001033 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
1034 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
1035 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
1036 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001037 }
1038
Alexis Hetuecad5192015-06-05 13:42:05 -04001039 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001040 {
John Bauman19bac1e2014-05-06 15:23:49 -04001041 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
1042 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
1043 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
1044 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001045 }
1046
Alexis Hetuecad5192015-06-05 13:42:05 -04001047 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001048 {
John Bauman19bac1e2014-05-06 15:23:49 -04001049 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001050
1051 dst.x = exp;
1052 dst.y = exp;
1053 dst.z = exp;
1054 dst.w = exp;
1055 }
1056
Alexis Hetuecad5192015-06-05 13:42:05 -04001057 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001058 {
John Bauman19bac1e2014-05-06 15:23:49 -04001059 dst.x = exponential2(src.x, pp);
1060 dst.y = exponential2(src.y, pp);
1061 dst.z = exponential2(src.z, pp);
1062 dst.w = exponential2(src.w, pp);
1063 }
1064
Alexis Hetuecad5192015-06-05 13:42:05 -04001065 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001066 {
1067 dst.x = exponential(src.x, pp);
1068 dst.y = exponential(src.y, pp);
1069 dst.z = exponential(src.z, pp);
1070 dst.w = exponential(src.w, pp);
1071 }
1072
Alexis Hetuecad5192015-06-05 13:42:05 -04001073 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001074 {
1075 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -04001076
1077 dst.x = log;
1078 dst.y = log;
1079 dst.z = log;
1080 dst.w = log;
1081 }
1082
Alexis Hetuecad5192015-06-05 13:42:05 -04001083 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001084 {
John Bauman19bac1e2014-05-06 15:23:49 -04001085 dst.x = logarithm2(src.x, pp);
1086 dst.y = logarithm2(src.y, pp);
1087 dst.z = logarithm2(src.z, pp);
1088 dst.w = logarithm2(src.w, pp);
1089 }
1090
Alexis Hetuecad5192015-06-05 13:42:05 -04001091 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001092 {
1093 dst.x = logarithm(src.x, false, pp);
1094 dst.y = logarithm(src.y, false, pp);
1095 dst.z = logarithm(src.z, false, pp);
1096 dst.w = logarithm(src.w, false, pp);
1097 }
1098
Alexis Hetuecad5192015-06-05 13:42:05 -04001099 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001100 {
1101 dst.x = Float4(1.0f);
1102 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001103
1104 Float4 pow;
1105
1106 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001107 pow = Min(pow, Float4(127.9961f));
1108 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001109
1110 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001111 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1112 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001113
John Bauman19bac1e2014-05-06 15:23:49 -04001114 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001115 }
1116
Alexis Hetuecad5192015-06-05 13:42:05 -04001117 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001118 {
John Bauman19bac1e2014-05-06 15:23:49 -04001119 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001120 dst.x = 1;
1121 dst.y = src0.y * src1.y;
1122 dst.z = src0.z;
1123 dst.w = src1.w;
1124 }
1125
Alexis Hetuecad5192015-06-05 13:42:05 -04001126 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001127 {
1128 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1129 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1130 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1131 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1132 }
1133
Alexis Hetuecad5192015-06-05 13:42:05 -04001134 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001135 {
John Bauman19bac1e2014-05-06 15:23:49 -04001136 Float4 tx = Min(Max((x.x - edge0.x) / (edge1.x - edge0.x), Float4(0.0f)), Float4(1.0f)); dst.x = tx * tx * (Float4(3.0f) - Float4(2.0f) * tx);
1137 Float4 ty = Min(Max((x.y - edge0.y) / (edge1.y - edge0.y), Float4(0.0f)), Float4(1.0f)); dst.y = ty * ty * (Float4(3.0f) - Float4(2.0f) * ty);
1138 Float4 tz = Min(Max((x.z - edge0.z) / (edge1.z - edge0.z), Float4(0.0f)), Float4(1.0f)); dst.z = tz * tz * (Float4(3.0f) - Float4(2.0f) * tz);
1139 Float4 tw = Min(Max((x.w - edge0.w) / (edge1.w - edge0.w), Float4(0.0f)), Float4(1.0f)); dst.w = tw * tw * (Float4(3.0f) - Float4(2.0f) * tw);
John Bauman89401822014-05-06 15:04:28 -04001140 }
1141
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001142 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1143 {
1144 dst.x = src0.x * src1.y - src0.y * src1.x;
1145 dst.y = dst.z = dst.w = dst.x;
1146 }
1147
1148 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1149 {
1150 crs(dst, src1, src2);
1151 dp3(dst, dst, src0);
1152 }
1153
1154 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1155 {
1156 dst.x = src2.z * src3.w - src2.w * src3.z;
1157 dst.y = src1.w * src3.z - src1.z * src3.w;
1158 dst.z = src1.z * src2.w - src1.w * src2.z;
1159 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1160 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1161 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1162 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1163 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1164 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1165 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1166 src3.x * (src1.z * src2.y - src1.y * src2.z));
1167 dst.y = dst.z = dst.w = dst.x;
1168 }
1169
Alexis Hetuecad5192015-06-05 13:42:05 -04001170 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001171 {
1172 dst.x = Frac(src.x);
1173 dst.y = Frac(src.y);
1174 dst.z = Frac(src.z);
1175 dst.w = Frac(src.w);
1176 }
1177
Alexis Hetuecad5192015-06-05 13:42:05 -04001178 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001179 {
1180 dst.x = Trunc(src.x);
1181 dst.y = Trunc(src.y);
1182 dst.z = Trunc(src.z);
1183 dst.w = Trunc(src.w);
1184 }
1185
Alexis Hetuecad5192015-06-05 13:42:05 -04001186 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001187 {
1188 dst.x = Floor(src.x);
1189 dst.y = Floor(src.y);
1190 dst.z = Floor(src.z);
1191 dst.w = Floor(src.w);
1192 }
1193
Alexis Hetuecad5192015-06-05 13:42:05 -04001194 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001195 {
1196 dst.x = Round(src.x);
1197 dst.y = Round(src.y);
1198 dst.z = Round(src.z);
1199 dst.w = Round(src.w);
1200 }
1201
Alexis Hetuecad5192015-06-05 13:42:05 -04001202 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001203 {
1204 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1205 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1206 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1207 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1208 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1209 // Even if the round implementation rounds the other way:
1210 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1211 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1212 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1213 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1214 round(dst, src);
1215 dst.x += ((Float4(CmpLT(dst.x, src.x) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.x), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.x) & Int4(1));
1216 dst.y += ((Float4(CmpLT(dst.y, src.y) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.y), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.y) & Int4(1));
1217 dst.z += ((Float4(CmpLT(dst.z, src.z) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.z), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.z) & Int4(1));
1218 dst.w += ((Float4(CmpLT(dst.w, src.w) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.w), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.w) & Int4(1));
1219 }
1220
Alexis Hetuecad5192015-06-05 13:42:05 -04001221 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001222 {
1223 dst.x = Ceil(src.x);
1224 dst.y = Ceil(src.y);
1225 dst.z = Ceil(src.z);
1226 dst.w = Ceil(src.w);
1227 }
1228
Alexis Hetuecad5192015-06-05 13:42:05 -04001229 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001230 {
1231 Float4 pow = power(src0.x, src1.x, pp);
1232
1233 dst.x = pow;
1234 dst.y = pow;
1235 dst.z = pow;
1236 dst.w = pow;
1237 }
1238
Alexis Hetuecad5192015-06-05 13:42:05 -04001239 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001240 {
1241 dst.x = power(src0.x, src1.x, pp);
1242 dst.y = power(src0.y, src1.y, pp);
1243 dst.z = power(src0.z, src1.z, pp);
1244 dst.w = power(src0.w, src1.w, pp);
1245 }
1246
Alexis Hetuecad5192015-06-05 13:42:05 -04001247 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001248 {
1249 dst.x = src0.y * src1.z - src0.z * src1.y;
1250 dst.y = src0.z * src1.x - src0.x * src1.z;
1251 dst.z = src0.x * src1.y - src0.y * src1.x;
1252 }
1253
Alexis Hetuecad5192015-06-05 13:42:05 -04001254 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001255 {
1256 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1257
1258 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1259 }
1260
Alexis Hetuecad5192015-06-05 13:42:05 -04001261 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001262 {
1263 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1264
1265 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1266 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1267 }
1268
Alexis Hetuecad5192015-06-05 13:42:05 -04001269 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001270 {
1271 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1272
1273 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1274 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1275 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1276 }
1277
Alexis Hetuecad5192015-06-05 13:42:05 -04001278 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001279 {
1280 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1281
1282 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1283 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1284 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1285 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1286 }
1287
Alexis Hetuecad5192015-06-05 13:42:05 -04001288 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001289 {
1290 Float4 d = N.x * I.x;
1291
1292 dst.x = I.x - Float4(2.0f) * d * N.x;
1293 }
1294
Alexis Hetuecad5192015-06-05 13:42:05 -04001295 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001296 {
1297 Float4 d = dot2(N, I);
1298
1299 dst.x = I.x - Float4(2.0f) * d * N.x;
1300 dst.y = I.y - Float4(2.0f) * d * N.y;
1301 }
1302
Alexis Hetuecad5192015-06-05 13:42:05 -04001303 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001304 {
1305 Float4 d = dot3(N, I);
1306
1307 dst.x = I.x - Float4(2.0f) * d * N.x;
1308 dst.y = I.y - Float4(2.0f) * d * N.y;
1309 dst.z = I.z - Float4(2.0f) * d * N.z;
1310 }
1311
Alexis Hetuecad5192015-06-05 13:42:05 -04001312 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001313 {
1314 Float4 d = dot4(N, I);
1315
1316 dst.x = I.x - Float4(2.0f) * d * N.x;
1317 dst.y = I.y - Float4(2.0f) * d * N.y;
1318 dst.z = I.z - Float4(2.0f) * d * N.z;
1319 dst.w = I.w - Float4(2.0f) * d * N.w;
1320 }
1321
Alexis Hetuecad5192015-06-05 13:42:05 -04001322 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001323 {
1324 Float4 d = N.x * I.x;
1325 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1326 Int4 pos = CmpNLT(k, Float4(0.0f));
1327 Float4 t = (eta * d + Sqrt(k));
1328
1329 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1330 }
1331
Alexis Hetuecad5192015-06-05 13:42:05 -04001332 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001333 {
1334 Float4 d = dot2(N, I);
1335 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1336 Int4 pos = CmpNLT(k, Float4(0.0f));
1337 Float4 t = (eta * d + Sqrt(k));
1338
1339 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1340 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1341 }
1342
Alexis Hetuecad5192015-06-05 13:42:05 -04001343 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001344 {
1345 Float4 d = dot3(N, I);
1346 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1347 Int4 pos = CmpNLT(k, Float4(0.0f));
1348 Float4 t = (eta * d + Sqrt(k));
1349
1350 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1351 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1352 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1353 }
1354
Alexis Hetuecad5192015-06-05 13:42:05 -04001355 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001356 {
1357 Float4 d = dot4(N, I);
1358 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1359 Int4 pos = CmpNLT(k, Float4(0.0f));
1360 Float4 t = (eta * d + Sqrt(k));
1361
1362 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1363 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1364 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1365 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1366 }
1367
Alexis Hetuecad5192015-06-05 13:42:05 -04001368 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001369 {
1370 sgn(dst.x, src.x);
1371 sgn(dst.y, src.y);
1372 sgn(dst.z, src.z);
1373 sgn(dst.w, src.w);
1374 }
1375
Alexis Hetuecad5192015-06-05 13:42:05 -04001376 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001377 {
1378 dst.x = Abs(src.x);
1379 dst.y = Abs(src.y);
1380 dst.z = Abs(src.z);
1381 dst.w = Abs(src.w);
1382 }
John Bauman19bac1e2014-05-06 15:23:49 -04001383
Alexis Hetuecad5192015-06-05 13:42:05 -04001384 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001385 {
1386 Float4 dot = dot2(src, src);
1387 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001388
John Bauman19bac1e2014-05-06 15:23:49 -04001389 dst.x = src.x * rsq;
1390 dst.y = src.y * rsq;
1391 dst.z = src.z * rsq;
1392 dst.w = src.w * rsq;
1393 }
1394
Alexis Hetuecad5192015-06-05 13:42:05 -04001395 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001396 {
1397 Float4 dot = dot3(src, src);
1398 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1399
1400 dst.x = src.x * rsq;
1401 dst.y = src.y * rsq;
1402 dst.z = src.z * rsq;
1403 dst.w = src.w * rsq;
1404 }
John Bauman19bac1e2014-05-06 15:23:49 -04001405
Alexis Hetuecad5192015-06-05 13:42:05 -04001406 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001407 {
John Bauman19bac1e2014-05-06 15:23:49 -04001408 Float4 dot = dot4(src, src);
1409 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001410
John Bauman19bac1e2014-05-06 15:23:49 -04001411 dst.x = src.x * rsq;
1412 dst.y = src.y * rsq;
1413 dst.z = src.z * rsq;
1414 dst.w = src.w * rsq;
1415 }
1416
Alexis Hetuecad5192015-06-05 13:42:05 -04001417 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001418 {
1419 dst.x = cosine_pi(src.x, pp);
1420 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001421 }
1422
Alexis Hetuecad5192015-06-05 13:42:05 -04001423 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001424 {
1425 dst.x = cosine(src.x, pp);
1426 dst.y = cosine(src.y, pp);
1427 dst.z = cosine(src.z, pp);
1428 dst.w = cosine(src.w, pp);
1429 }
1430
Alexis Hetuecad5192015-06-05 13:42:05 -04001431 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001432 {
1433 dst.x = sine(src.x, pp);
1434 dst.y = sine(src.y, pp);
1435 dst.z = sine(src.z, pp);
1436 dst.w = sine(src.w, pp);
1437 }
1438
Alexis Hetuecad5192015-06-05 13:42:05 -04001439 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001440 {
1441 dst.x = tangent(src.x, pp);
1442 dst.y = tangent(src.y, pp);
1443 dst.z = tangent(src.z, pp);
1444 dst.w = tangent(src.w, pp);
1445 }
1446
Alexis Hetuecad5192015-06-05 13:42:05 -04001447 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001448 {
1449 dst.x = arccos(src.x, pp);
1450 dst.y = arccos(src.y, pp);
1451 dst.z = arccos(src.z, pp);
1452 dst.w = arccos(src.w, pp);
1453 }
1454
Alexis Hetuecad5192015-06-05 13:42:05 -04001455 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001456 {
1457 dst.x = arcsin(src.x, pp);
1458 dst.y = arcsin(src.y, pp);
1459 dst.z = arcsin(src.z, pp);
1460 dst.w = arcsin(src.w, pp);
1461 }
1462
Alexis Hetuecad5192015-06-05 13:42:05 -04001463 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001464 {
1465 dst.x = arctan(src.x, pp);
1466 dst.y = arctan(src.y, pp);
1467 dst.z = arctan(src.z, pp);
1468 dst.w = arctan(src.w, pp);
1469 }
1470
Alexis Hetuecad5192015-06-05 13:42:05 -04001471 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001472 {
1473 dst.x = arctan(src0.x, src1.x, pp);
1474 dst.y = arctan(src0.y, src1.y, pp);
1475 dst.z = arctan(src0.z, src1.z, pp);
1476 dst.w = arctan(src0.w, src1.w, pp);
1477 }
1478
Alexis Hetuecad5192015-06-05 13:42:05 -04001479 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001480 {
1481 dst.x = cosineh(src.x, pp);
1482 dst.y = cosineh(src.y, pp);
1483 dst.z = cosineh(src.z, pp);
1484 dst.w = cosineh(src.w, pp);
1485 }
1486
Alexis Hetuecad5192015-06-05 13:42:05 -04001487 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001488 {
1489 dst.x = sineh(src.x, pp);
1490 dst.y = sineh(src.y, pp);
1491 dst.z = sineh(src.z, pp);
1492 dst.w = sineh(src.w, pp);
1493 }
1494
Alexis Hetuecad5192015-06-05 13:42:05 -04001495 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001496 {
1497 dst.x = tangenth(src.x, pp);
1498 dst.y = tangenth(src.y, pp);
1499 dst.z = tangenth(src.z, pp);
1500 dst.w = tangenth(src.w, pp);
1501 }
1502
Alexis Hetuecad5192015-06-05 13:42:05 -04001503 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001504 {
1505 dst.x = arccosh(src.x, pp);
1506 dst.y = arccosh(src.y, pp);
1507 dst.z = arccosh(src.z, pp);
1508 dst.w = arccosh(src.w, pp);
1509 }
1510
Alexis Hetuecad5192015-06-05 13:42:05 -04001511 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001512 {
1513 dst.x = arcsinh(src.x, pp);
1514 dst.y = arcsinh(src.y, pp);
1515 dst.z = arcsinh(src.z, pp);
1516 dst.w = arcsinh(src.w, pp);
1517 }
1518
Alexis Hetuecad5192015-06-05 13:42:05 -04001519 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001520 {
1521 dst.x = arctanh(src.x, pp);
1522 dst.y = arctanh(src.y, pp);
1523 dst.z = arctanh(src.z, pp);
1524 dst.w = arctanh(src.w, pp);
1525 }
1526
Alexis Hetuecad5192015-06-05 13:42:05 -04001527 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001528 {
1529 if(version < 0x0200)
1530 {
John Bauman19bac1e2014-05-06 15:23:49 -04001531 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001532 Float4 floor = src.x - frc;
1533
John Bauman19bac1e2014-05-06 15:23:49 -04001534 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001535 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001536 dst.z = exponential2(src.x, true);
1537 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001538 }
1539 else // Version >= 2.0
1540 {
John Bauman19bac1e2014-05-06 15:23:49 -04001541 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001542 }
1543 }
1544
Alexis Hetuecad5192015-06-05 13:42:05 -04001545 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001546 {
1547 if(version < 0x0200)
1548 {
1549 Float4 tmp0;
1550 Float4 tmp1;
1551 Float4 t;
1552 Int4 r;
1553
1554 tmp0 = Abs(src.x);
1555 tmp1 = tmp0;
1556
1557 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001558 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001559 dst.x = Float4(r);
1560
1561 // Y component
1562 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1563
1564 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001565 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001566
1567 // W component
1568 dst.w = 1.0f;
1569 }
1570 else
1571 {
John Bauman19bac1e2014-05-06 15:23:49 -04001572 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001573 }
1574 }
1575
Alexis Hetuecad5192015-06-05 13:42:05 -04001576 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001577 {
John Bauman19bac1e2014-05-06 15:23:49 -04001578 cmp0(dst.x, src0.x, src1.x, src2.x);
1579 cmp0(dst.y, src0.y, src1.y, src2.y);
1580 cmp0(dst.z, src0.z, src1.z, src2.z);
1581 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001582 }
John Bauman89401822014-05-06 15:04:28 -04001583
Alexis Hetuecad5192015-06-05 13:42:05 -04001584 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001585 {
1586 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1587 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1588 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1589 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1590 }
1591
Alexis Hetuecad5192015-06-05 13:42:05 -04001592 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001593 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001594 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1595 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1596 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001597 }
1598
Alexis Hetuecad5192015-06-05 13:42:05 -04001599 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001600 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001601 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1602 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1603 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1604 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001605 }
1606
Alexis Hetuecad5192015-06-05 13:42:05 -04001607 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001608 {
John Bauman19bac1e2014-05-06 15:23:49 -04001609 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1610 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001611 dst = As<Float4>(neg | pos);
1612 }
1613
Alexis Hetuecad5192015-06-05 13:42:05 -04001614 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001615 {
John Bauman19bac1e2014-05-06 15:23:49 -04001616 Int4 pos = CmpLE(Float4(0.0f), src0);
1617 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001618 }
1619
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001620 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1621 {
1622 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1623 select(dst, pos, src1, src2);
1624 }
1625
Alexis Hetuecad5192015-06-05 13:42:05 -04001626 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001627 {
1628 // FIXME: LLVM vector select
1629 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1630 }
1631
Alexis Hetuecad5192015-06-05 13:42:05 -04001632 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001633 {
1634 switch(control)
1635 {
John Bauman19bac1e2014-05-06 15:23:49 -04001636 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001637 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1638 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1639 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1640 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1641 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001642 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001643 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1644 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1645 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1646 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1647 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001648 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001649 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1650 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1651 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1652 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1653 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001654 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001655 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1656 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1657 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1658 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1659 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001660 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001661 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1662 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1663 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1664 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1665 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001666 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001667 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1668 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1669 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1670 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1671 break;
1672 default:
1673 ASSERT(false);
1674 }
1675 }
John Bauman19bac1e2014-05-06 15:23:49 -04001676
Alexis Hetuecad5192015-06-05 13:42:05 -04001677 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001678 {
1679 switch(control)
1680 {
1681 case Shader::CONTROL_GT:
1682 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1683 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1684 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1685 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1686 break;
1687 case Shader::CONTROL_EQ:
1688 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1689 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1690 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1691 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1692 break;
1693 case Shader::CONTROL_GE:
1694 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1695 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1696 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1697 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1698 break;
1699 case Shader::CONTROL_LT:
1700 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1701 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1702 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1703 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1704 break;
1705 case Shader::CONTROL_NE:
1706 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1707 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1708 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1709 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1710 break;
1711 case Shader::CONTROL_LE:
1712 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1713 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1714 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1715 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1716 break;
1717 default:
1718 ASSERT(false);
1719 }
1720 }
1721
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001722 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1723 {
1724 switch(control)
1725 {
1726 case Shader::CONTROL_GT:
1727 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1728 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1729 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1730 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1731 break;
1732 case Shader::CONTROL_EQ:
1733 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1734 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1735 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1736 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1737 break;
1738 case Shader::CONTROL_GE:
1739 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1740 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1741 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1742 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1743 break;
1744 case Shader::CONTROL_LT:
1745 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1746 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1747 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1748 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1749 break;
1750 case Shader::CONTROL_NE:
1751 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1752 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1753 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1754 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1755 break;
1756 case Shader::CONTROL_LE:
1757 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1758 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1759 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1760 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1761 break;
1762 default:
1763 ASSERT(false);
1764 }
1765 }
1766
Alexis Hetuecad5192015-06-05 13:42:05 -04001767 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001768 {
1769 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1770 }
1771
Alexis Hetuecad5192015-06-05 13:42:05 -04001772 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001773 {
1774 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1775 }
1776
Alexis Hetuecad5192015-06-05 13:42:05 -04001777 void ShaderCore::not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001778 {
1779 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1780 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1781 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1782 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1783 }
1784
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001785 void ShaderCore::or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001786 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001787 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1788 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1789 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1790 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001791 }
1792
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001793 void ShaderCore::xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001794 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001795 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1796 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1797 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1798 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001799 }
1800
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001801 void ShaderCore::and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001802 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001803 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1804 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1805 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1806 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1807 }
1808
1809 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1810 {
1811 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1812 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1813 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1814 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1815 dst.y = dst.x;
1816 dst.z = dst.x;
1817 dst.w = dst.x;
1818 }
1819
1820 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1821 {
1822 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1823 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1824 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1825 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1826 dst.y = dst.x;
1827 dst.z = dst.x;
1828 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001829 }
John Bauman89401822014-05-06 15:04:28 -04001830}