blob: d06dc9b9b0327720b28a7d5b3c17ad2ce4876e5b [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
Nicolas Capens05b3d662016-02-25 23:58:33 -0500274 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite, bool exactAtPow2)
John Bauman19bac1e2014-05-06 15:23:49 -0400275 {
276 Float4 rcp;
277
278 if(!pp && rcpPrecision >= WHQL)
279 {
280 rcp = Float4(1.0f) / x;
281 }
282 else
283 {
Nicolas Capens05b3d662016-02-25 23:58:33 -0500284 rcp = Rcp_pp(x, exactAtPow2);
John Bauman19bac1e2014-05-06 15:23:49 -0400285
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
Alexis Hetuecad5192015-06-05 13:42:05 -0400681 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400682 {
683 dst.x = src0.x + src1.x;
684 dst.y = src0.y + src1.y;
685 dst.z = src0.z + src1.z;
686 dst.w = src0.w + src1.w;
687 }
688
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400689 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
690 {
691 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
692 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
693 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
694 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
695 }
696
Alexis Hetuecad5192015-06-05 13:42:05 -0400697 void ShaderCore::sub(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::isub(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::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400714 {
715 dst.x = src0.x * src1.x + src2.x;
716 dst.y = src0.y * src1.y + src2.y;
717 dst.z = src0.z * src1.z + src2.z;
718 dst.w = src0.w * src1.w + src2.w;
719 }
720
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400721 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
722 {
723 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
724 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
725 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
726 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
727 }
728
Alexis Hetuecad5192015-06-05 13:42:05 -0400729 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400730 {
731 dst.x = src0.x * src1.x;
732 dst.y = src0.y * src1.y;
733 dst.z = src0.z * src1.z;
734 dst.w = src0.w * src1.w;
735 }
736
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400737 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
738 {
739 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
740 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
741 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
742 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
743 }
744
Alexis Hetuecad5192015-06-05 13:42:05 -0400745 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400746 {
747 Float4 rcp = reciprocal(src.x, pp, true);
748
749 dst.x = rcp;
750 dst.y = rcp;
751 dst.z = rcp;
752 dst.w = rcp;
753 }
754
Alexis Hetuecad5192015-06-05 13:42:05 -0400755 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400756 {
757 dst.x = src0.x / src1.x;
758 dst.y = src0.y / src1.y;
759 dst.z = src0.z / src1.z;
760 dst.w = src0.w / src1.w;
761 }
762
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400763 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
764 {
765 Float4 intMax(As<Float4>(Int4(INT_MAX)));
766 cmp0i(dst.x, src1.x, intMax, src1.x);
767 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
768 cmp0i(dst.y, src1.y, intMax, src1.y);
769 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
770 cmp0i(dst.z, src1.z, intMax, src1.z);
771 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
772 cmp0i(dst.w, src1.w, intMax, src1.w);
773 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
774 }
775
776 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
777 {
778 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
779 cmp0i(dst.x, src1.x, uintMax, src1.x);
780 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
781 cmp0i(dst.y, src1.y, uintMax, src1.y);
782 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
783 cmp0i(dst.z, src1.z, uintMax, src1.z);
784 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
785 cmp0i(dst.w, src1.w, uintMax, src1.w);
786 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
787 }
788
Alexis Hetuecad5192015-06-05 13:42:05 -0400789 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400790 {
791 dst.x = modulo(src0.x, src1.x);
792 dst.y = modulo(src0.y, src1.y);
793 dst.z = modulo(src0.z, src1.z);
794 dst.w = modulo(src0.w, src1.w);
795 }
796
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400797 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
798 {
799 cmp0i(dst.x, src1.x, src0.x, src1.x);
800 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
801 cmp0i(dst.y, src1.y, src0.y, src1.y);
802 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
803 cmp0i(dst.z, src1.z, src0.z, src1.z);
804 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
805 cmp0i(dst.w, src1.w, src0.w, src1.w);
806 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
807 }
808 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
809 {
810 cmp0i(dst.x, src1.x, src0.x, src1.x);
811 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
812 cmp0i(dst.y, src1.y, src0.y, src1.y);
813 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
814 cmp0i(dst.z, src1.z, src0.z, src1.z);
815 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
816 cmp0i(dst.w, src1.w, src0.w, src1.w);
817 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
818 }
819
820 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
821 {
822 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
823 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
824 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
825 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
826 }
827
828 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
829 {
830 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
831 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
832 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
833 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
834 }
835
836 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
837 {
838 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
839 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
840 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
841 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
842 }
843
Alexis Hetuecad5192015-06-05 13:42:05 -0400844 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400845 {
846 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
847
John Bauman19bac1e2014-05-06 15:23:49 -0400848 dst.x = rsq;
849 dst.y = rsq;
850 dst.z = rsq;
851 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400852 }
853
Alexis Hetuecad5192015-06-05 13:42:05 -0400854 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400855 {
856 dst.x = Sqrt(src.x);
857 dst.y = Sqrt(src.y);
858 dst.z = Sqrt(src.z);
859 dst.w = Sqrt(src.w);
860 }
861
Alexis Hetuecad5192015-06-05 13:42:05 -0400862 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400863 {
864 dst.x = reciprocalSquareRoot(src.x, false, pp);
865 dst.y = reciprocalSquareRoot(src.y, false, pp);
866 dst.z = reciprocalSquareRoot(src.z, false, pp);
867 dst.w = reciprocalSquareRoot(src.w, false, pp);
868 }
869
Alexis Hetuecad5192015-06-05 13:42:05 -0400870 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400871 {
872 dst = Sqrt(dot2(src, src));
873 }
874
Alexis Hetuecad5192015-06-05 13:42:05 -0400875 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400876 {
877 dst = Sqrt(dot3(src, src));
878 }
879
Alexis Hetuecad5192015-06-05 13:42:05 -0400880 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400881 {
882 dst = Sqrt(dot4(src, src));
883 }
884
Alexis Hetuecad5192015-06-05 13:42:05 -0400885 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400886 {
887 dst = Abs(src0.x - src1.x);
888 }
889
Alexis Hetuecad5192015-06-05 13:42:05 -0400890 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400891 {
892 Float4 dx = src0.x - src1.x;
893 Float4 dy = src0.y - src1.y;
894 Float4 dot2 = dx * dx + dy * dy;
895 dst = Sqrt(dot2);
896 }
897
Alexis Hetuecad5192015-06-05 13:42:05 -0400898 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400899 {
900 Float4 dx = src0.x - src1.x;
901 Float4 dy = src0.y - src1.y;
902 Float4 dz = src0.z - src1.z;
903 Float4 dot3 = dx * dx + dy * dy + dz * dz;
904 dst = Sqrt(dot3);
905 }
906
Alexis Hetuecad5192015-06-05 13:42:05 -0400907 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400908 {
909 Float4 dx = src0.x - src1.x;
910 Float4 dy = src0.y - src1.y;
911 Float4 dz = src0.z - src1.z;
912 Float4 dw = src0.w - src1.w;
913 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
914 dst = Sqrt(dot4);
915 }
916
Alexis Hetuecad5192015-06-05 13:42:05 -0400917 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400918 {
919 Float4 t = src0.x * src1.x;
920
921 dst.x = t;
922 dst.y = t;
923 dst.z = t;
924 dst.w = t;
925 }
926
Alexis Hetuecad5192015-06-05 13:42:05 -0400927 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400928 {
929 Float4 t = dot2(src0, src1);
930
931 dst.x = t;
932 dst.y = t;
933 dst.z = t;
934 dst.w = t;
935 }
936
Alexis Hetuecad5192015-06-05 13:42:05 -0400937 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400938 {
939 Float4 t = dot2(src0, src1) + src2.x;
940
941 dst.x = t;
942 dst.y = t;
943 dst.z = t;
944 dst.w = t;
945 }
946
Alexis Hetuecad5192015-06-05 13:42:05 -0400947 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400948 {
949 Float4 dot = dot3(src0, src1);
950
951 dst.x = dot;
952 dst.y = dot;
953 dst.z = dot;
954 dst.w = dot;
955 }
956
Alexis Hetuecad5192015-06-05 13:42:05 -0400957 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400958 {
959 Float4 dot = dot4(src0, src1);
960
961 dst.x = dot;
962 dst.y = dot;
963 dst.z = dot;
964 dst.w = dot;
965 }
966
Alexis Hetuecad5192015-06-05 13:42:05 -0400967 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400968 {
969 dst.x = Min(src0.x, src1.x);
970 dst.y = Min(src0.y, src1.y);
971 dst.z = Min(src0.z, src1.z);
972 dst.w = Min(src0.w, src1.w);
973 }
974
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400975 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
976 {
977 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
978 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
979 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
980 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
981 }
982
983 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
984 {
985 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
986 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
987 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
988 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
989 }
990
Alexis Hetuecad5192015-06-05 13:42:05 -0400991 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400992 {
993 dst.x = Max(src0.x, src1.x);
994 dst.y = Max(src0.y, src1.y);
995 dst.z = Max(src0.z, src1.z);
996 dst.w = Max(src0.w, src1.w);
997 }
998
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400999 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1000 {
1001 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1002 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1003 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1004 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1005 }
1006
1007 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1008 {
1009 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1010 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1011 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1012 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1013 }
1014
Alexis Hetuecad5192015-06-05 13:42:05 -04001015 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001016 {
John Bauman19bac1e2014-05-06 15:23:49 -04001017 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
1018 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
1019 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
1020 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001021 }
1022
Alexis Hetuecad5192015-06-05 13:42:05 -04001023 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001024 {
John Bauman19bac1e2014-05-06 15:23:49 -04001025 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
1026 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
1027 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
1028 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001029 }
1030
Alexis Hetuecad5192015-06-05 13:42:05 -04001031 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001032 {
John Bauman19bac1e2014-05-06 15:23:49 -04001033 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001034
1035 dst.x = exp;
1036 dst.y = exp;
1037 dst.z = exp;
1038 dst.w = exp;
1039 }
1040
Alexis Hetuecad5192015-06-05 13:42:05 -04001041 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001042 {
John Bauman19bac1e2014-05-06 15:23:49 -04001043 dst.x = exponential2(src.x, pp);
1044 dst.y = exponential2(src.y, pp);
1045 dst.z = exponential2(src.z, pp);
1046 dst.w = exponential2(src.w, pp);
1047 }
1048
Alexis Hetuecad5192015-06-05 13:42:05 -04001049 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001050 {
1051 dst.x = exponential(src.x, pp);
1052 dst.y = exponential(src.y, pp);
1053 dst.z = exponential(src.z, pp);
1054 dst.w = exponential(src.w, pp);
1055 }
1056
Alexis Hetuecad5192015-06-05 13:42:05 -04001057 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001058 {
1059 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -04001060
1061 dst.x = log;
1062 dst.y = log;
1063 dst.z = log;
1064 dst.w = log;
1065 }
1066
Alexis Hetuecad5192015-06-05 13:42:05 -04001067 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001068 {
John Bauman19bac1e2014-05-06 15:23:49 -04001069 dst.x = logarithm2(src.x, pp);
1070 dst.y = logarithm2(src.y, pp);
1071 dst.z = logarithm2(src.z, pp);
1072 dst.w = logarithm2(src.w, pp);
1073 }
1074
Alexis Hetuecad5192015-06-05 13:42:05 -04001075 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001076 {
1077 dst.x = logarithm(src.x, false, pp);
1078 dst.y = logarithm(src.y, false, pp);
1079 dst.z = logarithm(src.z, false, pp);
1080 dst.w = logarithm(src.w, false, pp);
1081 }
1082
Alexis Hetuecad5192015-06-05 13:42:05 -04001083 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001084 {
1085 dst.x = Float4(1.0f);
1086 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001087
1088 Float4 pow;
1089
1090 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001091 pow = Min(pow, Float4(127.9961f));
1092 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001093
1094 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001095 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1096 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001097
John Bauman19bac1e2014-05-06 15:23:49 -04001098 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001099 }
1100
Alexis Hetuecad5192015-06-05 13:42:05 -04001101 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001102 {
John Bauman19bac1e2014-05-06 15:23:49 -04001103 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001104 dst.x = 1;
1105 dst.y = src0.y * src1.y;
1106 dst.z = src0.z;
1107 dst.w = src1.w;
1108 }
1109
Alexis Hetuecad5192015-06-05 13:42:05 -04001110 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001111 {
1112 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1113 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1114 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1115 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1116 }
1117
Alexis Hetuecad5192015-06-05 13:42:05 -04001118 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001119 {
John Bauman19bac1e2014-05-06 15:23:49 -04001120 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);
1121 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);
1122 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);
1123 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 -04001124 }
1125
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001126 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1127 {
1128 dst.x = src0.x * src1.y - src0.y * src1.x;
1129 dst.y = dst.z = dst.w = dst.x;
1130 }
1131
1132 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1133 {
1134 crs(dst, src1, src2);
1135 dp3(dst, dst, src0);
1136 }
1137
1138 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1139 {
1140 dst.x = src2.z * src3.w - src2.w * src3.z;
1141 dst.y = src1.w * src3.z - src1.z * src3.w;
1142 dst.z = src1.z * src2.w - src1.w * src2.z;
1143 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1144 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1145 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1146 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1147 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1148 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1149 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1150 src3.x * (src1.z * src2.y - src1.y * src2.z));
1151 dst.y = dst.z = dst.w = dst.x;
1152 }
1153
Alexis Hetuecad5192015-06-05 13:42:05 -04001154 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001155 {
1156 dst.x = Frac(src.x);
1157 dst.y = Frac(src.y);
1158 dst.z = Frac(src.z);
1159 dst.w = Frac(src.w);
1160 }
1161
Alexis Hetuecad5192015-06-05 13:42:05 -04001162 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001163 {
1164 dst.x = Trunc(src.x);
1165 dst.y = Trunc(src.y);
1166 dst.z = Trunc(src.z);
1167 dst.w = Trunc(src.w);
1168 }
1169
Alexis Hetuecad5192015-06-05 13:42:05 -04001170 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001171 {
1172 dst.x = Floor(src.x);
1173 dst.y = Floor(src.y);
1174 dst.z = Floor(src.z);
1175 dst.w = Floor(src.w);
1176 }
1177
Alexis Hetuecad5192015-06-05 13:42:05 -04001178 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001179 {
1180 dst.x = Round(src.x);
1181 dst.y = Round(src.y);
1182 dst.z = Round(src.z);
1183 dst.w = Round(src.w);
1184 }
1185
Alexis Hetuecad5192015-06-05 13:42:05 -04001186 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001187 {
1188 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1189 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1190 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1191 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1192 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1193 // Even if the round implementation rounds the other way:
1194 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1195 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1196 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1197 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1198 round(dst, src);
1199 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));
1200 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));
1201 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));
1202 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));
1203 }
1204
Alexis Hetuecad5192015-06-05 13:42:05 -04001205 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001206 {
1207 dst.x = Ceil(src.x);
1208 dst.y = Ceil(src.y);
1209 dst.z = Ceil(src.z);
1210 dst.w = Ceil(src.w);
1211 }
1212
Alexis Hetuecad5192015-06-05 13:42:05 -04001213 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001214 {
1215 Float4 pow = power(src0.x, src1.x, pp);
1216
1217 dst.x = pow;
1218 dst.y = pow;
1219 dst.z = pow;
1220 dst.w = pow;
1221 }
1222
Alexis Hetuecad5192015-06-05 13:42:05 -04001223 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001224 {
1225 dst.x = power(src0.x, src1.x, pp);
1226 dst.y = power(src0.y, src1.y, pp);
1227 dst.z = power(src0.z, src1.z, pp);
1228 dst.w = power(src0.w, src1.w, pp);
1229 }
1230
Alexis Hetuecad5192015-06-05 13:42:05 -04001231 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001232 {
1233 dst.x = src0.y * src1.z - src0.z * src1.y;
1234 dst.y = src0.z * src1.x - src0.x * src1.z;
1235 dst.z = src0.x * src1.y - src0.y * src1.x;
1236 }
1237
Alexis Hetuecad5192015-06-05 13:42:05 -04001238 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001239 {
1240 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1241
1242 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1243 }
1244
Alexis Hetuecad5192015-06-05 13:42:05 -04001245 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001246 {
1247 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1248
1249 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1250 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1251 }
1252
Alexis Hetuecad5192015-06-05 13:42:05 -04001253 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001254 {
1255 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1256
1257 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1258 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1259 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1260 }
1261
Alexis Hetuecad5192015-06-05 13:42:05 -04001262 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001263 {
1264 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1265
1266 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1267 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1268 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1269 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1270 }
1271
Alexis Hetuecad5192015-06-05 13:42:05 -04001272 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001273 {
1274 Float4 d = N.x * I.x;
1275
1276 dst.x = I.x - Float4(2.0f) * d * N.x;
1277 }
1278
Alexis Hetuecad5192015-06-05 13:42:05 -04001279 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001280 {
1281 Float4 d = dot2(N, I);
1282
1283 dst.x = I.x - Float4(2.0f) * d * N.x;
1284 dst.y = I.y - Float4(2.0f) * d * N.y;
1285 }
1286
Alexis Hetuecad5192015-06-05 13:42:05 -04001287 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001288 {
1289 Float4 d = dot3(N, I);
1290
1291 dst.x = I.x - Float4(2.0f) * d * N.x;
1292 dst.y = I.y - Float4(2.0f) * d * N.y;
1293 dst.z = I.z - Float4(2.0f) * d * N.z;
1294 }
1295
Alexis Hetuecad5192015-06-05 13:42:05 -04001296 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001297 {
1298 Float4 d = dot4(N, I);
1299
1300 dst.x = I.x - Float4(2.0f) * d * N.x;
1301 dst.y = I.y - Float4(2.0f) * d * N.y;
1302 dst.z = I.z - Float4(2.0f) * d * N.z;
1303 dst.w = I.w - Float4(2.0f) * d * N.w;
1304 }
1305
Alexis Hetuecad5192015-06-05 13:42:05 -04001306 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001307 {
1308 Float4 d = N.x * I.x;
1309 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1310 Int4 pos = CmpNLT(k, Float4(0.0f));
1311 Float4 t = (eta * d + Sqrt(k));
1312
1313 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1314 }
1315
Alexis Hetuecad5192015-06-05 13:42:05 -04001316 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001317 {
1318 Float4 d = dot2(N, I);
1319 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1320 Int4 pos = CmpNLT(k, Float4(0.0f));
1321 Float4 t = (eta * d + Sqrt(k));
1322
1323 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1324 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1325 }
1326
Alexis Hetuecad5192015-06-05 13:42:05 -04001327 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001328 {
1329 Float4 d = dot3(N, I);
1330 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1331 Int4 pos = CmpNLT(k, Float4(0.0f));
1332 Float4 t = (eta * d + Sqrt(k));
1333
1334 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1335 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1336 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1337 }
1338
Alexis Hetuecad5192015-06-05 13:42:05 -04001339 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001340 {
1341 Float4 d = dot4(N, I);
1342 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1343 Int4 pos = CmpNLT(k, Float4(0.0f));
1344 Float4 t = (eta * d + Sqrt(k));
1345
1346 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1347 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1348 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1349 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1350 }
1351
Alexis Hetuecad5192015-06-05 13:42:05 -04001352 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001353 {
1354 sgn(dst.x, src.x);
1355 sgn(dst.y, src.y);
1356 sgn(dst.z, src.z);
1357 sgn(dst.w, src.w);
1358 }
1359
Alexis Hetu0f448072016-03-18 10:56:08 -04001360 void ShaderCore::isgn(Vector4f &dst, const Vector4f &src)
1361 {
1362 isgn(dst.x, src.x);
1363 isgn(dst.y, src.y);
1364 isgn(dst.z, src.z);
1365 isgn(dst.w, src.w);
1366 }
1367
Alexis Hetuecad5192015-06-05 13:42:05 -04001368 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001369 {
1370 dst.x = Abs(src.x);
1371 dst.y = Abs(src.y);
1372 dst.z = Abs(src.z);
1373 dst.w = Abs(src.w);
1374 }
Alexis Hetu0f448072016-03-18 10:56:08 -04001375
1376 void ShaderCore::iabs(Vector4f &dst, const Vector4f &src)
1377 {
1378 dst.x = As<Float4>(Abs(As<Int4>(src.x)));
1379 dst.y = As<Float4>(Abs(As<Int4>(src.y)));
1380 dst.z = As<Float4>(Abs(As<Int4>(src.z)));
1381 dst.w = As<Float4>(Abs(As<Int4>(src.w)));
1382 }
1383
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 Hetu0f448072016-03-18 10:56:08 -04001614 void ShaderCore::isgn(Float4 &dst, const Float4 &src)
1615 {
1616 Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1);
1617 Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1);
1618 dst = As<Float4>(neg | pos);
1619 }
1620
Alexis Hetuecad5192015-06-05 13:42:05 -04001621 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001622 {
John Bauman19bac1e2014-05-06 15:23:49 -04001623 Int4 pos = CmpLE(Float4(0.0f), src0);
1624 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001625 }
1626
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001627 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1628 {
1629 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1630 select(dst, pos, src1, src2);
1631 }
1632
Alexis Hetuecad5192015-06-05 13:42:05 -04001633 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001634 {
1635 // FIXME: LLVM vector select
1636 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1637 }
1638
Alexis Hetuecad5192015-06-05 13:42:05 -04001639 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001640 {
1641 switch(control)
1642 {
John Bauman19bac1e2014-05-06 15:23:49 -04001643 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001644 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1645 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1646 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1647 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1648 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001649 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001650 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1651 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1652 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1653 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1654 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001655 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001656 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1657 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1658 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1659 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1660 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001661 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001662 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1663 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1664 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1665 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1666 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001667 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001668 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1669 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1670 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1671 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1672 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001673 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001674 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1675 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1676 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1677 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1678 break;
1679 default:
1680 ASSERT(false);
1681 }
1682 }
John Bauman19bac1e2014-05-06 15:23:49 -04001683
Alexis Hetuecad5192015-06-05 13:42:05 -04001684 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001685 {
1686 switch(control)
1687 {
1688 case Shader::CONTROL_GT:
1689 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1690 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1691 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1692 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1693 break;
1694 case Shader::CONTROL_EQ:
1695 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1696 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1697 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1698 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1699 break;
1700 case Shader::CONTROL_GE:
1701 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1702 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1703 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1704 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1705 break;
1706 case Shader::CONTROL_LT:
1707 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1708 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1709 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1710 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1711 break;
1712 case Shader::CONTROL_NE:
1713 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1714 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1715 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1716 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1717 break;
1718 case Shader::CONTROL_LE:
1719 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1720 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1721 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1722 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1723 break;
1724 default:
1725 ASSERT(false);
1726 }
1727 }
1728
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001729 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1730 {
1731 switch(control)
1732 {
1733 case Shader::CONTROL_GT:
1734 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1735 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1736 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1737 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1738 break;
1739 case Shader::CONTROL_EQ:
1740 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1741 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1742 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1743 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1744 break;
1745 case Shader::CONTROL_GE:
1746 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1747 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1748 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1749 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1750 break;
1751 case Shader::CONTROL_LT:
1752 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1753 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1754 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1755 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1756 break;
1757 case Shader::CONTROL_NE:
1758 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1759 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1760 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1761 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1762 break;
1763 case Shader::CONTROL_LE:
1764 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1765 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1766 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1767 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1768 break;
1769 default:
1770 ASSERT(false);
1771 }
1772 }
1773
Alexis Hetuecad5192015-06-05 13:42:05 -04001774 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001775 {
1776 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1777 }
1778
Alexis Hetuecad5192015-06-05 13:42:05 -04001779 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001780 {
1781 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1782 }
1783
Alexis Hetuecad5192015-06-05 13:42:05 -04001784 void ShaderCore::not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001785 {
1786 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1787 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1788 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1789 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1790 }
1791
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001792 void ShaderCore::or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001793 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001794 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1795 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1796 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1797 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001798 }
1799
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001800 void ShaderCore::xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001801 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001802 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1803 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1804 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1805 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001806 }
1807
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001808 void ShaderCore::and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001809 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001810 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1811 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1812 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1813 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1814 }
1815
1816 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1817 {
1818 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1819 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1820 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1821 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1822 dst.y = dst.x;
1823 dst.z = dst.x;
1824 dst.w = dst.x;
1825 }
1826
1827 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1828 {
1829 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1830 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1831 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1832 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1833 dst.y = dst.x;
1834 dst.z = dst.x;
1835 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001836 }
John Bauman89401822014-05-06 15:04:28 -04001837}