blob: 4f5af1ab3fade2e96e5e576d0bcc9c9a449c1113 [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 Hetu9cde9742016-04-06 13:03:38 -04001126 void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0)
1127 {
1128 // round(clamp(c, -1.0, 1.0) * 32767.0)
1129 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) |
1130 ((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16));
1131 }
1132
1133 void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0)
1134 {
1135 // round(clamp(c, 0.0, 1.0) * 65535.0)
1136 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) |
1137 ((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16));
1138 }
1139
1140 void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0)
1141 {
1142 // clamp(f / 32727.0, -1.0, 1.0)
1143 dst.x = Min(Max(Float4(As<Int4>((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16)) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1144 dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1145 }
1146
1147 void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0)
1148 {
1149 // f / 65535.0
1150 dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000));
1151 dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000));
1152 }
1153
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001154 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1155 {
1156 dst.x = src0.x * src1.y - src0.y * src1.x;
1157 dst.y = dst.z = dst.w = dst.x;
1158 }
1159
1160 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1161 {
1162 crs(dst, src1, src2);
1163 dp3(dst, dst, src0);
1164 }
1165
1166 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1167 {
1168 dst.x = src2.z * src3.w - src2.w * src3.z;
1169 dst.y = src1.w * src3.z - src1.z * src3.w;
1170 dst.z = src1.z * src2.w - src1.w * src2.z;
1171 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1172 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1173 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1174 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1175 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1176 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1177 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1178 src3.x * (src1.z * src2.y - src1.y * src2.z));
1179 dst.y = dst.z = dst.w = dst.x;
1180 }
1181
Alexis Hetuecad5192015-06-05 13:42:05 -04001182 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001183 {
1184 dst.x = Frac(src.x);
1185 dst.y = Frac(src.y);
1186 dst.z = Frac(src.z);
1187 dst.w = Frac(src.w);
1188 }
1189
Alexis Hetuecad5192015-06-05 13:42:05 -04001190 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001191 {
1192 dst.x = Trunc(src.x);
1193 dst.y = Trunc(src.y);
1194 dst.z = Trunc(src.z);
1195 dst.w = Trunc(src.w);
1196 }
1197
Alexis Hetuecad5192015-06-05 13:42:05 -04001198 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001199 {
1200 dst.x = Floor(src.x);
1201 dst.y = Floor(src.y);
1202 dst.z = Floor(src.z);
1203 dst.w = Floor(src.w);
1204 }
1205
Alexis Hetuecad5192015-06-05 13:42:05 -04001206 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001207 {
1208 dst.x = Round(src.x);
1209 dst.y = Round(src.y);
1210 dst.z = Round(src.z);
1211 dst.w = Round(src.w);
1212 }
1213
Alexis Hetuecad5192015-06-05 13:42:05 -04001214 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001215 {
1216 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1217 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1218 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1219 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1220 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1221 // Even if the round implementation rounds the other way:
1222 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1223 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1224 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1225 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1226 round(dst, src);
1227 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));
1228 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));
1229 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));
1230 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));
1231 }
1232
Alexis Hetuecad5192015-06-05 13:42:05 -04001233 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001234 {
1235 dst.x = Ceil(src.x);
1236 dst.y = Ceil(src.y);
1237 dst.z = Ceil(src.z);
1238 dst.w = Ceil(src.w);
1239 }
1240
Alexis Hetuecad5192015-06-05 13:42:05 -04001241 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001242 {
1243 Float4 pow = power(src0.x, src1.x, pp);
1244
1245 dst.x = pow;
1246 dst.y = pow;
1247 dst.z = pow;
1248 dst.w = pow;
1249 }
1250
Alexis Hetuecad5192015-06-05 13:42:05 -04001251 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001252 {
1253 dst.x = power(src0.x, src1.x, pp);
1254 dst.y = power(src0.y, src1.y, pp);
1255 dst.z = power(src0.z, src1.z, pp);
1256 dst.w = power(src0.w, src1.w, pp);
1257 }
1258
Alexis Hetuecad5192015-06-05 13:42:05 -04001259 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001260 {
1261 dst.x = src0.y * src1.z - src0.z * src1.y;
1262 dst.y = src0.z * src1.x - src0.x * src1.z;
1263 dst.z = src0.x * src1.y - src0.y * src1.x;
1264 }
1265
Alexis Hetuecad5192015-06-05 13:42:05 -04001266 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001267 {
1268 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1269
1270 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1271 }
1272
Alexis Hetuecad5192015-06-05 13:42:05 -04001273 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001274 {
1275 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1276
1277 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1278 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1279 }
1280
Alexis Hetuecad5192015-06-05 13:42:05 -04001281 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001282 {
1283 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1284
1285 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1286 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1287 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1288 }
1289
Alexis Hetuecad5192015-06-05 13:42:05 -04001290 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001291 {
1292 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1293
1294 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1295 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1296 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1297 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1298 }
1299
Alexis Hetuecad5192015-06-05 13:42:05 -04001300 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001301 {
1302 Float4 d = N.x * I.x;
1303
1304 dst.x = I.x - Float4(2.0f) * d * N.x;
1305 }
1306
Alexis Hetuecad5192015-06-05 13:42:05 -04001307 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001308 {
1309 Float4 d = dot2(N, I);
1310
1311 dst.x = I.x - Float4(2.0f) * d * N.x;
1312 dst.y = I.y - Float4(2.0f) * d * N.y;
1313 }
1314
Alexis Hetuecad5192015-06-05 13:42:05 -04001315 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001316 {
1317 Float4 d = dot3(N, I);
1318
1319 dst.x = I.x - Float4(2.0f) * d * N.x;
1320 dst.y = I.y - Float4(2.0f) * d * N.y;
1321 dst.z = I.z - Float4(2.0f) * d * N.z;
1322 }
1323
Alexis Hetuecad5192015-06-05 13:42:05 -04001324 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001325 {
1326 Float4 d = dot4(N, I);
1327
1328 dst.x = I.x - Float4(2.0f) * d * N.x;
1329 dst.y = I.y - Float4(2.0f) * d * N.y;
1330 dst.z = I.z - Float4(2.0f) * d * N.z;
1331 dst.w = I.w - Float4(2.0f) * d * N.w;
1332 }
1333
Alexis Hetuecad5192015-06-05 13:42:05 -04001334 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001335 {
1336 Float4 d = N.x * I.x;
1337 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1338 Int4 pos = CmpNLT(k, Float4(0.0f));
1339 Float4 t = (eta * d + Sqrt(k));
1340
1341 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1342 }
1343
Alexis Hetuecad5192015-06-05 13:42:05 -04001344 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001345 {
1346 Float4 d = dot2(N, I);
1347 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1348 Int4 pos = CmpNLT(k, Float4(0.0f));
1349 Float4 t = (eta * d + Sqrt(k));
1350
1351 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1352 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1353 }
1354
Alexis Hetuecad5192015-06-05 13:42:05 -04001355 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001356 {
1357 Float4 d = dot3(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 }
1366
Alexis Hetuecad5192015-06-05 13:42:05 -04001367 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001368 {
1369 Float4 d = dot4(N, I);
1370 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1371 Int4 pos = CmpNLT(k, Float4(0.0f));
1372 Float4 t = (eta * d + Sqrt(k));
1373
1374 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1375 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1376 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1377 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1378 }
1379
Alexis Hetuecad5192015-06-05 13:42:05 -04001380 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001381 {
1382 sgn(dst.x, src.x);
1383 sgn(dst.y, src.y);
1384 sgn(dst.z, src.z);
1385 sgn(dst.w, src.w);
1386 }
1387
Alexis Hetu0f448072016-03-18 10:56:08 -04001388 void ShaderCore::isgn(Vector4f &dst, const Vector4f &src)
1389 {
1390 isgn(dst.x, src.x);
1391 isgn(dst.y, src.y);
1392 isgn(dst.z, src.z);
1393 isgn(dst.w, src.w);
1394 }
1395
Alexis Hetuecad5192015-06-05 13:42:05 -04001396 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001397 {
1398 dst.x = Abs(src.x);
1399 dst.y = Abs(src.y);
1400 dst.z = Abs(src.z);
1401 dst.w = Abs(src.w);
1402 }
Alexis Hetu0f448072016-03-18 10:56:08 -04001403
1404 void ShaderCore::iabs(Vector4f &dst, const Vector4f &src)
1405 {
1406 dst.x = As<Float4>(Abs(As<Int4>(src.x)));
1407 dst.y = As<Float4>(Abs(As<Int4>(src.y)));
1408 dst.z = As<Float4>(Abs(As<Int4>(src.z)));
1409 dst.w = As<Float4>(Abs(As<Int4>(src.w)));
1410 }
1411
Alexis Hetuecad5192015-06-05 13:42:05 -04001412 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001413 {
1414 Float4 dot = dot2(src, src);
1415 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001416
John Bauman19bac1e2014-05-06 15:23:49 -04001417 dst.x = src.x * rsq;
1418 dst.y = src.y * rsq;
1419 dst.z = src.z * rsq;
1420 dst.w = src.w * rsq;
1421 }
1422
Alexis Hetuecad5192015-06-05 13:42:05 -04001423 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001424 {
1425 Float4 dot = dot3(src, src);
1426 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1427
1428 dst.x = src.x * rsq;
1429 dst.y = src.y * rsq;
1430 dst.z = src.z * rsq;
1431 dst.w = src.w * rsq;
1432 }
John Bauman19bac1e2014-05-06 15:23:49 -04001433
Alexis Hetuecad5192015-06-05 13:42:05 -04001434 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001435 {
John Bauman19bac1e2014-05-06 15:23:49 -04001436 Float4 dot = dot4(src, src);
1437 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001438
John Bauman19bac1e2014-05-06 15:23:49 -04001439 dst.x = src.x * rsq;
1440 dst.y = src.y * rsq;
1441 dst.z = src.z * rsq;
1442 dst.w = src.w * rsq;
1443 }
1444
Alexis Hetuecad5192015-06-05 13:42:05 -04001445 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001446 {
1447 dst.x = cosine_pi(src.x, pp);
1448 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001449 }
1450
Alexis Hetuecad5192015-06-05 13:42:05 -04001451 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001452 {
1453 dst.x = cosine(src.x, pp);
1454 dst.y = cosine(src.y, pp);
1455 dst.z = cosine(src.z, pp);
1456 dst.w = cosine(src.w, pp);
1457 }
1458
Alexis Hetuecad5192015-06-05 13:42:05 -04001459 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001460 {
1461 dst.x = sine(src.x, pp);
1462 dst.y = sine(src.y, pp);
1463 dst.z = sine(src.z, pp);
1464 dst.w = sine(src.w, pp);
1465 }
1466
Alexis Hetuecad5192015-06-05 13:42:05 -04001467 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001468 {
1469 dst.x = tangent(src.x, pp);
1470 dst.y = tangent(src.y, pp);
1471 dst.z = tangent(src.z, pp);
1472 dst.w = tangent(src.w, pp);
1473 }
1474
Alexis Hetuecad5192015-06-05 13:42:05 -04001475 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001476 {
1477 dst.x = arccos(src.x, pp);
1478 dst.y = arccos(src.y, pp);
1479 dst.z = arccos(src.z, pp);
1480 dst.w = arccos(src.w, pp);
1481 }
1482
Alexis Hetuecad5192015-06-05 13:42:05 -04001483 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001484 {
1485 dst.x = arcsin(src.x, pp);
1486 dst.y = arcsin(src.y, pp);
1487 dst.z = arcsin(src.z, pp);
1488 dst.w = arcsin(src.w, pp);
1489 }
1490
Alexis Hetuecad5192015-06-05 13:42:05 -04001491 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001492 {
1493 dst.x = arctan(src.x, pp);
1494 dst.y = arctan(src.y, pp);
1495 dst.z = arctan(src.z, pp);
1496 dst.w = arctan(src.w, pp);
1497 }
1498
Alexis Hetuecad5192015-06-05 13:42:05 -04001499 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001500 {
1501 dst.x = arctan(src0.x, src1.x, pp);
1502 dst.y = arctan(src0.y, src1.y, pp);
1503 dst.z = arctan(src0.z, src1.z, pp);
1504 dst.w = arctan(src0.w, src1.w, pp);
1505 }
1506
Alexis Hetuecad5192015-06-05 13:42:05 -04001507 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001508 {
1509 dst.x = cosineh(src.x, pp);
1510 dst.y = cosineh(src.y, pp);
1511 dst.z = cosineh(src.z, pp);
1512 dst.w = cosineh(src.w, pp);
1513 }
1514
Alexis Hetuecad5192015-06-05 13:42:05 -04001515 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001516 {
1517 dst.x = sineh(src.x, pp);
1518 dst.y = sineh(src.y, pp);
1519 dst.z = sineh(src.z, pp);
1520 dst.w = sineh(src.w, pp);
1521 }
1522
Alexis Hetuecad5192015-06-05 13:42:05 -04001523 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001524 {
1525 dst.x = tangenth(src.x, pp);
1526 dst.y = tangenth(src.y, pp);
1527 dst.z = tangenth(src.z, pp);
1528 dst.w = tangenth(src.w, pp);
1529 }
1530
Alexis Hetuecad5192015-06-05 13:42:05 -04001531 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001532 {
1533 dst.x = arccosh(src.x, pp);
1534 dst.y = arccosh(src.y, pp);
1535 dst.z = arccosh(src.z, pp);
1536 dst.w = arccosh(src.w, pp);
1537 }
1538
Alexis Hetuecad5192015-06-05 13:42:05 -04001539 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001540 {
1541 dst.x = arcsinh(src.x, pp);
1542 dst.y = arcsinh(src.y, pp);
1543 dst.z = arcsinh(src.z, pp);
1544 dst.w = arcsinh(src.w, pp);
1545 }
1546
Alexis Hetuecad5192015-06-05 13:42:05 -04001547 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001548 {
1549 dst.x = arctanh(src.x, pp);
1550 dst.y = arctanh(src.y, pp);
1551 dst.z = arctanh(src.z, pp);
1552 dst.w = arctanh(src.w, pp);
1553 }
1554
Alexis Hetuecad5192015-06-05 13:42:05 -04001555 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001556 {
1557 if(version < 0x0200)
1558 {
John Bauman19bac1e2014-05-06 15:23:49 -04001559 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001560 Float4 floor = src.x - frc;
1561
John Bauman19bac1e2014-05-06 15:23:49 -04001562 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001563 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001564 dst.z = exponential2(src.x, true);
1565 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001566 }
1567 else // Version >= 2.0
1568 {
John Bauman19bac1e2014-05-06 15:23:49 -04001569 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001570 }
1571 }
1572
Alexis Hetuecad5192015-06-05 13:42:05 -04001573 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001574 {
1575 if(version < 0x0200)
1576 {
1577 Float4 tmp0;
1578 Float4 tmp1;
1579 Float4 t;
1580 Int4 r;
1581
1582 tmp0 = Abs(src.x);
1583 tmp1 = tmp0;
1584
1585 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001586 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001587 dst.x = Float4(r);
1588
1589 // Y component
1590 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1591
1592 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001593 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001594
1595 // W component
1596 dst.w = 1.0f;
1597 }
1598 else
1599 {
John Bauman19bac1e2014-05-06 15:23:49 -04001600 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001601 }
1602 }
1603
Alexis Hetuecad5192015-06-05 13:42:05 -04001604 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001605 {
John Bauman19bac1e2014-05-06 15:23:49 -04001606 cmp0(dst.x, src0.x, src1.x, src2.x);
1607 cmp0(dst.y, src0.y, src1.y, src2.y);
1608 cmp0(dst.z, src0.z, src1.z, src2.z);
1609 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001610 }
John Bauman89401822014-05-06 15:04:28 -04001611
Alexis Hetuecad5192015-06-05 13:42:05 -04001612 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001613 {
1614 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1615 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1616 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1617 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1618 }
1619
Alexis Hetuecad5192015-06-05 13:42:05 -04001620 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001621 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001622 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1623 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1624 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001625 }
1626
Alexis Hetuecad5192015-06-05 13:42:05 -04001627 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001628 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001629 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1630 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1631 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1632 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001633 }
1634
Alexis Hetuecad5192015-06-05 13:42:05 -04001635 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001636 {
John Bauman19bac1e2014-05-06 15:23:49 -04001637 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1638 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001639 dst = As<Float4>(neg | pos);
1640 }
1641
Alexis Hetu0f448072016-03-18 10:56:08 -04001642 void ShaderCore::isgn(Float4 &dst, const Float4 &src)
1643 {
1644 Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1);
1645 Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1);
1646 dst = As<Float4>(neg | pos);
1647 }
1648
Alexis Hetuecad5192015-06-05 13:42:05 -04001649 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001650 {
John Bauman19bac1e2014-05-06 15:23:49 -04001651 Int4 pos = CmpLE(Float4(0.0f), src0);
1652 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001653 }
1654
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001655 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1656 {
1657 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1658 select(dst, pos, src1, src2);
1659 }
1660
Alexis Hetuecad5192015-06-05 13:42:05 -04001661 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001662 {
1663 // FIXME: LLVM vector select
1664 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1665 }
1666
Alexis Hetuecad5192015-06-05 13:42:05 -04001667 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001668 {
1669 switch(control)
1670 {
John Bauman19bac1e2014-05-06 15:23:49 -04001671 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001672 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1673 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1674 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1675 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1676 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001677 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001678 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1679 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1680 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1681 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1682 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001683 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001684 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1685 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1686 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1687 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1688 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001689 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001690 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1691 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1692 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1693 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1694 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001695 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001696 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1697 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1698 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1699 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1700 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001701 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001702 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1703 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1704 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1705 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1706 break;
1707 default:
1708 ASSERT(false);
1709 }
1710 }
John Bauman19bac1e2014-05-06 15:23:49 -04001711
Alexis Hetuecad5192015-06-05 13:42:05 -04001712 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001713 {
1714 switch(control)
1715 {
1716 case Shader::CONTROL_GT:
1717 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1718 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1719 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1720 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1721 break;
1722 case Shader::CONTROL_EQ:
1723 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1724 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1725 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1726 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1727 break;
1728 case Shader::CONTROL_GE:
1729 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1730 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1731 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1732 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1733 break;
1734 case Shader::CONTROL_LT:
1735 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1736 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1737 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1738 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1739 break;
1740 case Shader::CONTROL_NE:
1741 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1742 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1743 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1744 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1745 break;
1746 case Shader::CONTROL_LE:
1747 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1748 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1749 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1750 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1751 break;
1752 default:
1753 ASSERT(false);
1754 }
1755 }
1756
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001757 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1758 {
1759 switch(control)
1760 {
1761 case Shader::CONTROL_GT:
1762 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1763 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1764 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1765 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1766 break;
1767 case Shader::CONTROL_EQ:
1768 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1769 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1770 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1771 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1772 break;
1773 case Shader::CONTROL_GE:
1774 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1775 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1776 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1777 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1778 break;
1779 case Shader::CONTROL_LT:
1780 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1781 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1782 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1783 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1784 break;
1785 case Shader::CONTROL_NE:
1786 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1787 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1788 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1789 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1790 break;
1791 case Shader::CONTROL_LE:
1792 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1793 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1794 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1795 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1796 break;
1797 default:
1798 ASSERT(false);
1799 }
1800 }
1801
Alexis Hetuecad5192015-06-05 13:42:05 -04001802 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001803 {
1804 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1805 }
1806
Alexis Hetuecad5192015-06-05 13:42:05 -04001807 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001808 {
1809 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1810 }
1811
Alexis Hetuecad5192015-06-05 13:42:05 -04001812 void ShaderCore::not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001813 {
1814 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1815 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1816 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1817 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1818 }
1819
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001820 void ShaderCore::or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001821 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001822 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1823 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1824 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1825 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001826 }
1827
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001828 void ShaderCore::xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001829 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001830 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1831 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1832 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1833 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001834 }
1835
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001836 void ShaderCore::and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001837 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001838 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1839 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1840 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1841 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1842 }
1843
1844 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1845 {
1846 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1847 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1848 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1849 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1850 dst.y = dst.x;
1851 dst.z = dst.x;
1852 dst.w = dst.x;
1853 }
1854
1855 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1856 {
1857 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1858 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1859 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1860 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1861 dst.y = dst.x;
1862 dst.z = dst.x;
1863 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001864 }
John Bauman89401822014-05-06 15:04:28 -04001865}