blob: 17659cfc4767d1dab2aef2e8b0ae1c0048e71382 [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
John Bauman19bac1e2014-05-06 15:23:49 -04003// Copyright(c) 2005-2012 TransGaming Inc.
John Bauman89401822014-05-06 15:04:28 -04004//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "ShaderCore.hpp"
13
John Bauman19bac1e2014-05-06 15:23:49 -040014#include "Renderer/Renderer.hpp"
15#include "Common/Debug.hpp"
John Bauman89401822014-05-06 15:04:28 -040016
Alexis Hetud5c31da2015-08-28 14:39:13 -040017#include <limits.h>
18
John Bauman89401822014-05-06 15:04:28 -040019namespace sw
20{
John Bauman19bac1e2014-05-06 15:23:49 -040021 extern TranscendentalPrecision logPrecision;
22 extern TranscendentalPrecision expPrecision;
23 extern TranscendentalPrecision rcpPrecision;
24 extern TranscendentalPrecision rsqPrecision;
25
Alexis Hetu96517182015-04-15 10:30:23 -040026 Vector4s::Vector4s()
John Bauman19bac1e2014-05-06 15:23:49 -040027 {
28 }
29
Alexis Hetu96517182015-04-15 10:30:23 -040030 Vector4s::Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
John Bauman19bac1e2014-05-06 15:23:49 -040031 {
32 this->x = Short4(x);
33 this->y = Short4(y);
34 this->z = Short4(z);
35 this->w = Short4(w);
36 }
37
Alexis Hetu96517182015-04-15 10:30:23 -040038 Vector4s::Vector4s(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040039 {
40 x = rhs.x;
41 y = rhs.y;
42 z = rhs.z;
43 w = rhs.w;
44 }
45
Alexis Hetu96517182015-04-15 10:30:23 -040046 Vector4s &Vector4s::operator=(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040047 {
48 x = rhs.x;
49 y = rhs.y;
50 z = rhs.z;
51 w = rhs.w;
52
53 return *this;
54 }
55
Alexis Hetu96517182015-04-15 10:30:23 -040056 Short4 &Vector4s::operator[](int i)
John Bauman19bac1e2014-05-06 15:23:49 -040057 {
58 switch(i)
59 {
60 case 0: return x;
61 case 1: return y;
62 case 2: return z;
63 case 3: return w;
64 }
65
66 return x;
67 }
68
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -040069 Vector4i::Vector4i()
70 {
71 }
72
73 Vector4i::Vector4i(int x, int y, int z, int w)
74 {
75 this->x = Int4(x);
76 this->y = Int4(y);
77 this->z = Int4(z);
78 this->w = Int4(w);
79 }
80
81 Vector4i::Vector4i(const Vector4i &rhs)
82 {
83 x = rhs.x;
84 y = rhs.y;
85 z = rhs.z;
86 w = rhs.w;
87 }
88
89 Vector4i &Vector4i::operator=(const Vector4i &rhs)
90 {
91 x = rhs.x;
92 y = rhs.y;
93 z = rhs.z;
94 w = rhs.w;
95
96 return *this;
97 }
98
99 Int4 &Vector4i::operator[](int i)
100 {
101 switch(i)
102 {
103 case 0: return x;
104 case 1: return y;
105 case 2: return z;
106 case 3: return w;
107 }
108
109 return x;
110 }
111
112 Vector4u::Vector4u()
113 {
114 }
115
116 Vector4u::Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
117 {
118 this->x = UInt4(x);
119 this->y = UInt4(y);
120 this->z = UInt4(z);
121 this->w = UInt4(w);
122 }
123
124 Vector4u::Vector4u(const Vector4u &rhs)
125 {
126 x = rhs.x;
127 y = rhs.y;
128 z = rhs.z;
129 w = rhs.w;
130 }
131
132 Vector4u &Vector4u::operator=(const Vector4u &rhs)
133 {
134 x = rhs.x;
135 y = rhs.y;
136 z = rhs.z;
137 w = rhs.w;
138
139 return *this;
140 }
141
142 UInt4 &Vector4u::operator[](int i)
143 {
144 switch(i)
145 {
146 case 0: return x;
147 case 1: return y;
148 case 2: return z;
149 case 3: return w;
150 }
151
152 return x;
153 }
154
John Bauman19bac1e2014-05-06 15:23:49 -0400155 Vector4f::Vector4f()
156 {
157 }
158
159 Vector4f::Vector4f(float x, float y, float z, float w)
160 {
161 this->x = Float4(x);
162 this->y = Float4(y);
163 this->z = Float4(z);
164 this->w = Float4(w);
165 }
166
167 Vector4f::Vector4f(const Vector4f &rhs)
168 {
169 x = rhs.x;
170 y = rhs.y;
171 z = rhs.z;
172 w = rhs.w;
173 }
174
175 Vector4f &Vector4f::operator=(const Vector4f &rhs)
176 {
177 x = rhs.x;
178 y = rhs.y;
179 z = rhs.z;
180 w = rhs.w;
181
182 return *this;
183 }
184
185 Float4 &Vector4f::operator[](int i)
186 {
187 switch(i)
188 {
189 case 0: return x;
190 case 1: return y;
191 case 2: return z;
192 case 3: return w;
193 }
194
195 return x;
196 }
197
198 Float4 exponential2(RValue<Float4> x, bool pp)
199 {
200 Float4 x0;
201 Float4 x1;
202 Int4 x2;
203
204 x0 = x;
205
206 x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
207 x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f
208 x1 = x0;
209 x1 -= Float4(0.5f);
210 x2 = RoundInt(x1);
211 x1 = Float4(x2);
212 x2 += Int4(0x0000007F); // 127
213 x2 = x2 << 23;
214 x0 -= x1;
215 x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f
216 x1 *= x0;
217 x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f
218 x1 *= x0;
219 x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f
220 x1 *= x0;
221 x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
222 x1 *= x0;
223 x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
224 x1 *= x0;
225 x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f
226 x1 *= As<Float4>(x2);
227
228 return x1;
229 }
230
231 Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp)
232 {
233 Float4 x0;
234 Float4 x1;
235 Float4 x2;
236 Float4 x3;
237
238 x0 = x;
239
240 x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
241 x1 = As<Float4>(As<UInt4>(x1) >> 8);
242 x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
243 x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f;
244 x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
245
246 x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f);
247 x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f);
248 x2 /= x3;
249
250 x1 += (x0 - Float4(1.0f)) * x2;
251
252 return x1;
253 }
254
255 Float4 exponential(RValue<Float4> x, bool pp)
256 {
257 // FIXME: Propagate the constant
258 return exponential2(Float4(1.44269541f) * x, pp); // 1/ln(2)
259 }
260
261 Float4 logarithm(RValue<Float4> x, bool absolute, bool pp)
262 {
263 // FIXME: Propagate the constant
264 return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2)
265 }
266
267 Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp)
268 {
269 Float4 log = logarithm2(x, true, pp);
270 log *= y;
271 return exponential2(log, pp);
272 }
273
274 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite)
275 {
276 Float4 rcp;
277
278 if(!pp && rcpPrecision >= WHQL)
279 {
280 rcp = Float4(1.0f) / x;
281 }
282 else
283 {
284 rcp = Rcp_pp(x);
285
286 if(!pp)
287 {
288 rcp = (rcp + rcp) - (x * rcp * rcp);
289 }
290 }
291
292 if(finite)
293 {
294 int big = 0x7F7FFFFF;
295 rcp = Min(rcp, Float4((float&)big));
296 }
297
298 return rcp;
299 }
300
301 Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
302 {
303 Float4 abs = x;
304
305 if(absolute)
306 {
307 abs = Abs(abs);
308 }
309
310 Float4 rsq;
311
312 if(!pp && rsqPrecision >= IEEE)
313 {
314 rsq = Float4(1.0f) / Sqrt(abs);
315 }
316 else
317 {
318 rsq = RcpSqrt_pp(abs);
319
320 if(!pp)
321 {
322 rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
323 }
324 }
325
326 int big = 0x7F7FFFFF;
327 rsq = Min(rsq, Float4((float&)big));
328
329 return rsq;
330 }
331
332 Float4 modulo(RValue<Float4> x, RValue<Float4> y)
333 {
334 return x - y * Floor(x / y);
335 }
336
337 Float4 sine_pi(RValue<Float4> x, bool pp)
338 {
339 const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2
340 const Float4 B = Float4(1.27323954e+0f); // 4/pi
341 const Float4 C = Float4(7.75160950e-1f);
342 const Float4 D = Float4(2.24839049e-1f);
343
344 // Parabola approximating sine
345 Float4 sin = x * (Abs(x) * A + B);
346
347 // Improve precision from 0.06 to 0.001
348 if(true)
349 {
350 sin = sin * (Abs(sin) * D + C);
351 }
352
353 return sin;
354 }
355
356 Float4 cosine_pi(RValue<Float4> x, bool pp)
357 {
358 // cos(x) = sin(x + pi/2)
359 Float4 y = x + Float4(1.57079632e+0f);
360
361 // Wrap around
362 y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f)));
363
364 return sine_pi(y, pp);
365 }
366
367 Float4 sine(RValue<Float4> x, bool pp)
368 {
369 // Reduce to [-0.5, 0.5] range
370 Float4 y = x * Float4(1.59154943e-1f); // 1/2pi
371 y = y - Round(y);
372
373 const Float4 A = Float4(-16.0f);
374 const Float4 B = Float4(8.0f);
375 const Float4 C = Float4(7.75160950e-1f);
376 const Float4 D = Float4(2.24839049e-1f);
377
378 // Parabola approximating sine
379 Float4 sin = y * (Abs(y) * A + B);
380
381 // Improve precision from 0.06 to 0.001
382 if(true)
383 {
384 sin = sin * (Abs(sin) * D + C);
385 }
386
387 return sin;
388 }
389
390 Float4 cosine(RValue<Float4> x, bool pp)
391 {
392 // cos(x) = sin(x + pi/2)
393 Float4 y = x + Float4(1.57079632e+0f);
394 return sine(y, pp);
395 }
396
397 Float4 tangent(RValue<Float4> x, bool pp)
398 {
399 return sine(x, pp) / cosine(x, pp);
400 }
401
402 Float4 arccos(RValue<Float4> x, bool pp)
403 {
404 // pi/2 - arcsin(x)
405 return Float4(1.57079632e+0f) - arcsin(x);
406 }
407
408 Float4 arcsin(RValue<Float4> x, bool pp)
409 {
410 // x*(pi/2-sqrt(1-x*x)*pi/5)
411 return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f));
412 }
413
414 Float4 arctan(RValue<Float4> x, bool pp)
415 {
416 Int4 O = CmpNLT(Abs(x), Float4(1.0f));
417 Float4 y = As<Float4>(O & As<Int4>(Float4(1.0f) / x) | ~O & As<Int4>(x)); // FIXME: Vector select
418
419 // Approximation of atan in [-1..1]
420 Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
421
422 // +/-pi/2 depending on sign of x
423 Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
424
425 theta = As<Float4>(O & As<Int4>(sgnPi_2 - theta) | ~O & As<Int4>(theta)); // FIXME: Vector select
426
427 return theta;
428 }
429
430 Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp)
431 {
432 // Rotate to upper semicircle when in lower semicircle
433 Int4 S = CmpLT(y, Float4(0.0f));
434 Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi
435 Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x));
436 Float4 y0 = Abs(y);
437
438 // Rotate to right quadrant when in left quadrant
439 Int4 Q = CmpLT(x0, Float4(0.0f));
440 theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2
441 Float4 x1 = As<Float4>(Q & As<Int4>(y0) | ~Q & As<Int4>(x0)); // FIXME: Vector select
442 Float4 y1 = As<Float4>(Q & As<Int4>(-x0) | ~Q & As<Int4>(y0)); // FIXME: Vector select
443
444 // Rotate to first octant when in second octant
445 Int4 O = CmpNLT(y1, x1);
446 theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4
447 Float4 x2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * x1 + Float4(7.07106781e-1f) * y1) | ~O & As<Int4>(x1)); // sqrt(2)/2 // FIXME: Vector select
448 Float4 y2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1) | ~O & As<Int4>(y1)); // FIXME: Vector select
449
450 // Approximation of atan in [0..1]
451 Float4 y_x = y2 / x2;
452 theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f));
453
454 return theta;
455 }
456
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400457 Float4 sineh(RValue<Float4> x, bool pp)
458 {
459 return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f);
460 }
461
462 Float4 cosineh(RValue<Float4> x, bool pp)
463 {
464 return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f);
465 }
466
467 Float4 tangenth(RValue<Float4> x, bool pp)
468 {
469 Float4 e_x = exponential(x, pp);
470 Float4 e_minus_x = exponential(-x, pp);
471 return (e_x - e_minus_x) / (e_x + e_minus_x);
472 }
473
474 Float4 arccosh(RValue<Float4> x, bool pp)
475 {
476 return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp);
477 }
478
479 Float4 arcsinh(RValue<Float4> x, bool pp)
480 {
481 return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp);
482 }
483
484 Float4 arctanh(RValue<Float4> x, bool pp)
485 {
486 return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f);
487 }
488
Alexis Hetuecad5192015-06-05 13:42:05 -0400489 Float4 dot2(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400490 {
491 return v0.x * v1.x + v0.y * v1.y;
492 }
493
Alexis Hetuecad5192015-06-05 13:42:05 -0400494 Float4 dot3(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400495 {
496 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
497 }
498
Alexis Hetuecad5192015-06-05 13:42:05 -0400499 Float4 dot4(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400500 {
501 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w;
502 }
503
504 void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
505 {
506 Int2 tmp0 = UnpackHigh(row0, row1);
507 Int2 tmp1 = UnpackHigh(row2, row3);
508 Int2 tmp2 = UnpackLow(row0, row1);
509 Int2 tmp3 = UnpackLow(row2, row3);
510
511 row0 = As<Short4>(UnpackLow(tmp2, tmp3));
512 row1 = As<Short4>(UnpackHigh(tmp2, tmp3));
513 row2 = As<Short4>(UnpackLow(tmp0, tmp1));
514 row3 = As<Short4>(UnpackHigh(tmp0, tmp1));
515 }
516
517 void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
518 {
519 Float4 tmp0 = UnpackLow(row0, row1);
520 Float4 tmp1 = UnpackLow(row2, row3);
521 Float4 tmp2 = UnpackHigh(row0, row1);
522 Float4 tmp3 = UnpackHigh(row2, row3);
523
524 row0 = Float4(tmp0.xy, tmp1.xy);
525 row1 = Float4(tmp0.zw, tmp1.zw);
526 row2 = Float4(tmp2.xy, tmp3.xy);
527 row3 = Float4(tmp2.zw, tmp3.zw);
528 }
529
530 void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
531 {
532 Float4 tmp0 = UnpackLow(row0, row1);
533 Float4 tmp1 = UnpackLow(row2, row3);
534 Float4 tmp2 = UnpackHigh(row0, row1);
535 Float4 tmp3 = UnpackHigh(row2, row3);
536
537 row0 = Float4(tmp0.xy, tmp1.xy);
538 row1 = Float4(tmp0.zw, tmp1.zw);
539 row2 = Float4(tmp2.xy, tmp3.xy);
540 }
541
542 void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
543 {
544 Float4 tmp0 = UnpackLow(row0, row1);
545 Float4 tmp1 = UnpackLow(row2, row3);
546
547 row0 = Float4(tmp0.xy, tmp1.xy);
548 row1 = Float4(tmp0.zw, tmp1.zw);
549 }
550
551 void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
552 {
553 Float4 tmp0 = UnpackLow(row0, row1);
554 Float4 tmp1 = UnpackLow(row2, row3);
555
556 row0 = Float4(tmp0.xy, tmp1.xy);
557 }
558
559 void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
560 {
561 row0 = UnpackLow(row0, row1);
562 row1 = Float4(row0.zw, row1.zw);
563 row2 = UnpackHigh(row0, row1);
564 row3 = Float4(row2.zw, row3.zw);
565 }
566
567 void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
568 {
569 row0 = UnpackLow(row2, row3);
570 row1 = Float4(row0.zw, row1.zw);
571 row2 = UnpackHigh(row2, row3);
572 row3 = Float4(row2.zw, row3.zw);
573 }
574
575 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
576 {
577 switch(N)
578 {
579 case 1: transpose4x1(row0, row1, row2, row3); break;
580 case 2: transpose4x2(row0, row1, row2, row3); break;
581 case 3: transpose4x3(row0, row1, row2, row3); break;
582 case 4: transpose4x4(row0, row1, row2, row3); break;
583 }
584 }
585
Alexis Hetuecad5192015-06-05 13:42:05 -0400586 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool floorToInteger)
John Bauman89401822014-05-06 15:04:28 -0400587 {
588 if(floorToInteger)
589 {
590 dst.x = Floor(src.x);
591 }
592 else
593 {
594 dst = src;
595 }
596 }
597
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400598 void ShaderCore::neg(Vector4f &dst, const Vector4f &src)
599 {
600 dst.x = -src.x;
601 dst.y = -src.y;
602 dst.z = -src.z;
603 dst.w = -src.w;
604 }
605
606 void ShaderCore::ineg(Vector4f &dst, const Vector4f &src)
607 {
608 dst.x = As<Float4>(-As<Int4>(src.x));
609 dst.y = As<Float4>(-As<Int4>(src.y));
610 dst.z = As<Float4>(-As<Int4>(src.z));
611 dst.w = As<Float4>(-As<Int4>(src.w));
612 }
613
Alexis Hetuecad5192015-06-05 13:42:05 -0400614 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400615 {
616 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
617 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
618 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
619 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
620 }
621
Alexis Hetuecad5192015-06-05 13:42:05 -0400622 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400623 {
624 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
625 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
626 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
627 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
628 }
629
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400630 void ShaderCore::f2i(Vector4f &dst, const Vector4f &src)
631 {
632 dst.x = As<Float4>(Int4(src.x));
633 dst.y = As<Float4>(Int4(src.y));
634 dst.z = As<Float4>(Int4(src.z));
635 dst.w = As<Float4>(Int4(src.w));
636 }
637
638 void ShaderCore::i2f(Vector4f &dst, const Vector4f &src)
639 {
640 dst.x = Float4(As<Int4>(src.x));
641 dst.y = Float4(As<Int4>(src.y));
642 dst.z = Float4(As<Int4>(src.z));
643 dst.w = Float4(As<Int4>(src.w));
644 }
645
646 void ShaderCore::f2u(Vector4f &dst, const Vector4f &src)
647 {
648 dst.x = As<Float4>(UInt4(src.x));
649 dst.y = As<Float4>(UInt4(src.y));
650 dst.z = As<Float4>(UInt4(src.z));
651 dst.w = As<Float4>(UInt4(src.w));
652 }
653
654 void ShaderCore::u2f(Vector4f &dst, const Vector4f &src)
655 {
656 dst.x = Float4(As<UInt4>(src.x));
657 dst.y = Float4(As<UInt4>(src.y));
658 dst.z = Float4(As<UInt4>(src.z));
659 dst.w = Float4(As<UInt4>(src.w));
660 }
661
662 void ShaderCore::i2b(Vector4f &dst, const Vector4f &src)
663 {
664 dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0)));
665 dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0)));
666 dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0)));
667 dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0)));
668 }
669
670 void ShaderCore::b2i(Vector4f &dst, const Vector4f &src)
671 {
672 dst.x = As<Float4>(As<Int4>(src.x) & Int4(1));
673 dst.y = As<Float4>(As<Int4>(src.y) & Int4(1));
674 dst.z = As<Float4>(As<Int4>(src.z) & Int4(1));
675 dst.w = As<Float4>(As<Int4>(src.w) & Int4(1));
676 }
677
678 void ShaderCore::u2b(Vector4f &dst, const Vector4f &src)
679 {
680 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src.x), UInt4(0)));
681 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src.y), UInt4(0)));
682 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src.z), UInt4(0)));
683 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src.w), UInt4(0)));
684 }
685
686 void ShaderCore::b2u(Vector4f &dst, const Vector4f &src)
687 {
688 dst.x = As<Float4>(As<UInt4>(src.x) & UInt4(1));
689 dst.y = As<Float4>(As<UInt4>(src.y) & UInt4(1));
690 dst.z = As<Float4>(As<UInt4>(src.z) & UInt4(1));
691 dst.w = As<Float4>(As<UInt4>(src.w) & UInt4(1));
692 }
693
Alexis Hetuecad5192015-06-05 13:42:05 -0400694 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400695 {
696 dst.x = src0.x + src1.x;
697 dst.y = src0.y + src1.y;
698 dst.z = src0.z + src1.z;
699 dst.w = src0.w + src1.w;
700 }
701
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400702 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
703 {
704 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
705 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
706 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
707 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
708 }
709
Alexis Hetuecad5192015-06-05 13:42:05 -0400710 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400711 {
712 dst.x = src0.x - src1.x;
713 dst.y = src0.y - src1.y;
714 dst.z = src0.z - src1.z;
715 dst.w = src0.w - src1.w;
716 }
717
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400718 void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
719 {
720 dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x));
721 dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y));
722 dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z));
723 dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w));
724 }
725
Alexis Hetuecad5192015-06-05 13:42:05 -0400726 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400727 {
728 dst.x = src0.x * src1.x + src2.x;
729 dst.y = src0.y * src1.y + src2.y;
730 dst.z = src0.z * src1.z + src2.z;
731 dst.w = src0.w * src1.w + src2.w;
732 }
733
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400734 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
735 {
736 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
737 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
738 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
739 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
740 }
741
Alexis Hetuecad5192015-06-05 13:42:05 -0400742 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400743 {
744 dst.x = src0.x * src1.x;
745 dst.y = src0.y * src1.y;
746 dst.z = src0.z * src1.z;
747 dst.w = src0.w * src1.w;
748 }
749
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400750 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
751 {
752 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
753 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
754 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
755 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
756 }
757
Alexis Hetuecad5192015-06-05 13:42:05 -0400758 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400759 {
760 Float4 rcp = reciprocal(src.x, pp, true);
761
762 dst.x = rcp;
763 dst.y = rcp;
764 dst.z = rcp;
765 dst.w = rcp;
766 }
767
Alexis Hetuecad5192015-06-05 13:42:05 -0400768 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400769 {
770 dst.x = src0.x / src1.x;
771 dst.y = src0.y / src1.y;
772 dst.z = src0.z / src1.z;
773 dst.w = src0.w / src1.w;
774 }
775
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400776 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
777 {
778 Float4 intMax(As<Float4>(Int4(INT_MAX)));
779 cmp0i(dst.x, src1.x, intMax, src1.x);
780 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
781 cmp0i(dst.y, src1.y, intMax, src1.y);
782 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
783 cmp0i(dst.z, src1.z, intMax, src1.z);
784 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
785 cmp0i(dst.w, src1.w, intMax, src1.w);
786 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
787 }
788
789 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
790 {
791 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
792 cmp0i(dst.x, src1.x, uintMax, src1.x);
793 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
794 cmp0i(dst.y, src1.y, uintMax, src1.y);
795 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
796 cmp0i(dst.z, src1.z, uintMax, src1.z);
797 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
798 cmp0i(dst.w, src1.w, uintMax, src1.w);
799 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
800 }
801
Alexis Hetuecad5192015-06-05 13:42:05 -0400802 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400803 {
804 dst.x = modulo(src0.x, src1.x);
805 dst.y = modulo(src0.y, src1.y);
806 dst.z = modulo(src0.z, src1.z);
807 dst.w = modulo(src0.w, src1.w);
808 }
809
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400810 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
811 {
812 cmp0i(dst.x, src1.x, src0.x, src1.x);
813 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
814 cmp0i(dst.y, src1.y, src0.y, src1.y);
815 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
816 cmp0i(dst.z, src1.z, src0.z, src1.z);
817 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
818 cmp0i(dst.w, src1.w, src0.w, src1.w);
819 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
820 }
821 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
822 {
823 cmp0i(dst.x, src1.x, src0.x, src1.x);
824 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
825 cmp0i(dst.y, src1.y, src0.y, src1.y);
826 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
827 cmp0i(dst.z, src1.z, src0.z, src1.z);
828 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
829 cmp0i(dst.w, src1.w, src0.w, src1.w);
830 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
831 }
832
833 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
834 {
835 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
836 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
837 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
838 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
839 }
840
841 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
842 {
843 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
844 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
845 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
846 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
847 }
848
849 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
850 {
851 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
852 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
853 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
854 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
855 }
856
Alexis Hetuecad5192015-06-05 13:42:05 -0400857 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400858 {
859 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
860
John Bauman19bac1e2014-05-06 15:23:49 -0400861 dst.x = rsq;
862 dst.y = rsq;
863 dst.z = rsq;
864 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400865 }
866
Alexis Hetuecad5192015-06-05 13:42:05 -0400867 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400868 {
869 dst.x = Sqrt(src.x);
870 dst.y = Sqrt(src.y);
871 dst.z = Sqrt(src.z);
872 dst.w = Sqrt(src.w);
873 }
874
Alexis Hetuecad5192015-06-05 13:42:05 -0400875 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400876 {
877 dst.x = reciprocalSquareRoot(src.x, false, pp);
878 dst.y = reciprocalSquareRoot(src.y, false, pp);
879 dst.z = reciprocalSquareRoot(src.z, false, pp);
880 dst.w = reciprocalSquareRoot(src.w, false, pp);
881 }
882
Alexis Hetuecad5192015-06-05 13:42:05 -0400883 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400884 {
885 dst = Sqrt(dot2(src, src));
886 }
887
Alexis Hetuecad5192015-06-05 13:42:05 -0400888 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400889 {
890 dst = Sqrt(dot3(src, src));
891 }
892
Alexis Hetuecad5192015-06-05 13:42:05 -0400893 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400894 {
895 dst = Sqrt(dot4(src, src));
896 }
897
Alexis Hetuecad5192015-06-05 13:42:05 -0400898 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400899 {
900 dst = Abs(src0.x - src1.x);
901 }
902
Alexis Hetuecad5192015-06-05 13:42:05 -0400903 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400904 {
905 Float4 dx = src0.x - src1.x;
906 Float4 dy = src0.y - src1.y;
907 Float4 dot2 = dx * dx + dy * dy;
908 dst = Sqrt(dot2);
909 }
910
Alexis Hetuecad5192015-06-05 13:42:05 -0400911 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400912 {
913 Float4 dx = src0.x - src1.x;
914 Float4 dy = src0.y - src1.y;
915 Float4 dz = src0.z - src1.z;
916 Float4 dot3 = dx * dx + dy * dy + dz * dz;
917 dst = Sqrt(dot3);
918 }
919
Alexis Hetuecad5192015-06-05 13:42:05 -0400920 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400921 {
922 Float4 dx = src0.x - src1.x;
923 Float4 dy = src0.y - src1.y;
924 Float4 dz = src0.z - src1.z;
925 Float4 dw = src0.w - src1.w;
926 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
927 dst = Sqrt(dot4);
928 }
929
Alexis Hetuecad5192015-06-05 13:42:05 -0400930 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400931 {
932 Float4 t = src0.x * src1.x;
933
934 dst.x = t;
935 dst.y = t;
936 dst.z = t;
937 dst.w = t;
938 }
939
Alexis Hetuecad5192015-06-05 13:42:05 -0400940 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400941 {
942 Float4 t = dot2(src0, src1);
943
944 dst.x = t;
945 dst.y = t;
946 dst.z = t;
947 dst.w = t;
948 }
949
Alexis Hetuecad5192015-06-05 13:42:05 -0400950 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400951 {
952 Float4 t = dot2(src0, src1) + src2.x;
953
954 dst.x = t;
955 dst.y = t;
956 dst.z = t;
957 dst.w = t;
958 }
959
Alexis Hetuecad5192015-06-05 13:42:05 -0400960 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400961 {
962 Float4 dot = dot3(src0, src1);
963
964 dst.x = dot;
965 dst.y = dot;
966 dst.z = dot;
967 dst.w = dot;
968 }
969
Alexis Hetuecad5192015-06-05 13:42:05 -0400970 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400971 {
972 Float4 dot = dot4(src0, src1);
973
974 dst.x = dot;
975 dst.y = dot;
976 dst.z = dot;
977 dst.w = dot;
978 }
979
Alexis Hetuecad5192015-06-05 13:42:05 -0400980 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400981 {
982 dst.x = Min(src0.x, src1.x);
983 dst.y = Min(src0.y, src1.y);
984 dst.z = Min(src0.z, src1.z);
985 dst.w = Min(src0.w, src1.w);
986 }
987
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400988 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
989 {
990 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
991 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
992 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
993 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
994 }
995
996 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
997 {
998 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
999 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1000 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1001 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1002 }
1003
Alexis Hetuecad5192015-06-05 13:42:05 -04001004 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001005 {
1006 dst.x = Max(src0.x, src1.x);
1007 dst.y = Max(src0.y, src1.y);
1008 dst.z = Max(src0.z, src1.z);
1009 dst.w = Max(src0.w, src1.w);
1010 }
1011
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001012 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1013 {
1014 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1015 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1016 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1017 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1018 }
1019
1020 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1021 {
1022 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
1023 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
1024 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
1025 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
1026 }
1027
Alexis Hetuecad5192015-06-05 13:42:05 -04001028 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001029 {
John Bauman19bac1e2014-05-06 15:23:49 -04001030 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
1031 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
1032 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
1033 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001034 }
1035
Alexis Hetuecad5192015-06-05 13:42:05 -04001036 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001037 {
John Bauman19bac1e2014-05-06 15:23:49 -04001038 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
1039 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
1040 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
1041 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -04001042 }
1043
Alexis Hetuecad5192015-06-05 13:42:05 -04001044 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001045 {
John Bauman19bac1e2014-05-06 15:23:49 -04001046 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001047
1048 dst.x = exp;
1049 dst.y = exp;
1050 dst.z = exp;
1051 dst.w = exp;
1052 }
1053
Alexis Hetuecad5192015-06-05 13:42:05 -04001054 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001055 {
John Bauman19bac1e2014-05-06 15:23:49 -04001056 dst.x = exponential2(src.x, pp);
1057 dst.y = exponential2(src.y, pp);
1058 dst.z = exponential2(src.z, pp);
1059 dst.w = exponential2(src.w, pp);
1060 }
1061
Alexis Hetuecad5192015-06-05 13:42:05 -04001062 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001063 {
1064 dst.x = exponential(src.x, pp);
1065 dst.y = exponential(src.y, pp);
1066 dst.z = exponential(src.z, pp);
1067 dst.w = exponential(src.w, pp);
1068 }
1069
Alexis Hetuecad5192015-06-05 13:42:05 -04001070 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001071 {
1072 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -04001073
1074 dst.x = log;
1075 dst.y = log;
1076 dst.z = log;
1077 dst.w = log;
1078 }
1079
Alexis Hetuecad5192015-06-05 13:42:05 -04001080 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001081 {
John Bauman19bac1e2014-05-06 15:23:49 -04001082 dst.x = logarithm2(src.x, pp);
1083 dst.y = logarithm2(src.y, pp);
1084 dst.z = logarithm2(src.z, pp);
1085 dst.w = logarithm2(src.w, pp);
1086 }
1087
Alexis Hetuecad5192015-06-05 13:42:05 -04001088 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001089 {
1090 dst.x = logarithm(src.x, false, pp);
1091 dst.y = logarithm(src.y, false, pp);
1092 dst.z = logarithm(src.z, false, pp);
1093 dst.w = logarithm(src.w, false, pp);
1094 }
1095
Alexis Hetuecad5192015-06-05 13:42:05 -04001096 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001097 {
1098 dst.x = Float4(1.0f);
1099 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001100
1101 Float4 pow;
1102
1103 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001104 pow = Min(pow, Float4(127.9961f));
1105 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001106
1107 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001108 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1109 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001110
John Bauman19bac1e2014-05-06 15:23:49 -04001111 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001112 }
1113
Alexis Hetuecad5192015-06-05 13:42:05 -04001114 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001115 {
John Bauman19bac1e2014-05-06 15:23:49 -04001116 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001117 dst.x = 1;
1118 dst.y = src0.y * src1.y;
1119 dst.z = src0.z;
1120 dst.w = src1.w;
1121 }
1122
Alexis Hetuecad5192015-06-05 13:42:05 -04001123 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001124 {
1125 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1126 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1127 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1128 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1129 }
1130
Alexis Hetuecad5192015-06-05 13:42:05 -04001131 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001132 {
John Bauman19bac1e2014-05-06 15:23:49 -04001133 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);
1134 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);
1135 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);
1136 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 -04001137 }
1138
Alexis Hetuecad5192015-06-05 13:42:05 -04001139 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001140 {
1141 dst.x = Frac(src.x);
1142 dst.y = Frac(src.y);
1143 dst.z = Frac(src.z);
1144 dst.w = Frac(src.w);
1145 }
1146
Alexis Hetuecad5192015-06-05 13:42:05 -04001147 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001148 {
1149 dst.x = Trunc(src.x);
1150 dst.y = Trunc(src.y);
1151 dst.z = Trunc(src.z);
1152 dst.w = Trunc(src.w);
1153 }
1154
Alexis Hetuecad5192015-06-05 13:42:05 -04001155 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001156 {
1157 dst.x = Floor(src.x);
1158 dst.y = Floor(src.y);
1159 dst.z = Floor(src.z);
1160 dst.w = Floor(src.w);
1161 }
1162
Alexis Hetuecad5192015-06-05 13:42:05 -04001163 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001164 {
1165 dst.x = Round(src.x);
1166 dst.y = Round(src.y);
1167 dst.z = Round(src.z);
1168 dst.w = Round(src.w);
1169 }
1170
Alexis Hetuecad5192015-06-05 13:42:05 -04001171 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001172 {
1173 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1174 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1175 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1176 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1177 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1178 // Even if the round implementation rounds the other way:
1179 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1180 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1181 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1182 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1183 round(dst, src);
1184 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));
1185 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));
1186 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));
1187 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));
1188 }
1189
Alexis Hetuecad5192015-06-05 13:42:05 -04001190 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001191 {
1192 dst.x = Ceil(src.x);
1193 dst.y = Ceil(src.y);
1194 dst.z = Ceil(src.z);
1195 dst.w = Ceil(src.w);
1196 }
1197
Alexis Hetuecad5192015-06-05 13:42:05 -04001198 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001199 {
1200 Float4 pow = power(src0.x, src1.x, pp);
1201
1202 dst.x = pow;
1203 dst.y = pow;
1204 dst.z = pow;
1205 dst.w = pow;
1206 }
1207
Alexis Hetuecad5192015-06-05 13:42:05 -04001208 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001209 {
1210 dst.x = power(src0.x, src1.x, pp);
1211 dst.y = power(src0.y, src1.y, pp);
1212 dst.z = power(src0.z, src1.z, pp);
1213 dst.w = power(src0.w, src1.w, pp);
1214 }
1215
Alexis Hetuecad5192015-06-05 13:42:05 -04001216 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001217 {
1218 dst.x = src0.y * src1.z - src0.z * src1.y;
1219 dst.y = src0.z * src1.x - src0.x * src1.z;
1220 dst.z = src0.x * src1.y - src0.y * src1.x;
1221 }
1222
Alexis Hetuecad5192015-06-05 13:42:05 -04001223 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001224 {
1225 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1226
1227 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1228 }
1229
Alexis Hetuecad5192015-06-05 13:42:05 -04001230 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001231 {
1232 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1233
1234 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1235 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1236 }
1237
Alexis Hetuecad5192015-06-05 13:42:05 -04001238 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001239 {
1240 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1241
1242 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1243 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1244 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1245 }
1246
Alexis Hetuecad5192015-06-05 13:42:05 -04001247 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001248 {
1249 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1250
1251 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1252 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1253 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1254 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1255 }
1256
Alexis Hetuecad5192015-06-05 13:42:05 -04001257 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001258 {
1259 Float4 d = N.x * I.x;
1260
1261 dst.x = I.x - Float4(2.0f) * d * N.x;
1262 }
1263
Alexis Hetuecad5192015-06-05 13:42:05 -04001264 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001265 {
1266 Float4 d = dot2(N, I);
1267
1268 dst.x = I.x - Float4(2.0f) * d * N.x;
1269 dst.y = I.y - Float4(2.0f) * d * N.y;
1270 }
1271
Alexis Hetuecad5192015-06-05 13:42:05 -04001272 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001273 {
1274 Float4 d = dot3(N, I);
1275
1276 dst.x = I.x - Float4(2.0f) * d * N.x;
1277 dst.y = I.y - Float4(2.0f) * d * N.y;
1278 dst.z = I.z - Float4(2.0f) * d * N.z;
1279 }
1280
Alexis Hetuecad5192015-06-05 13:42:05 -04001281 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001282 {
1283 Float4 d = dot4(N, I);
1284
1285 dst.x = I.x - Float4(2.0f) * d * N.x;
1286 dst.y = I.y - Float4(2.0f) * d * N.y;
1287 dst.z = I.z - Float4(2.0f) * d * N.z;
1288 dst.w = I.w - Float4(2.0f) * d * N.w;
1289 }
1290
Alexis Hetuecad5192015-06-05 13:42:05 -04001291 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001292 {
1293 Float4 d = N.x * I.x;
1294 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1295 Int4 pos = CmpNLT(k, Float4(0.0f));
1296 Float4 t = (eta * d + Sqrt(k));
1297
1298 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1299 }
1300
Alexis Hetuecad5192015-06-05 13:42:05 -04001301 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001302 {
1303 Float4 d = dot2(N, I);
1304 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1305 Int4 pos = CmpNLT(k, Float4(0.0f));
1306 Float4 t = (eta * d + Sqrt(k));
1307
1308 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1309 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1310 }
1311
Alexis Hetuecad5192015-06-05 13:42:05 -04001312 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001313 {
1314 Float4 d = dot3(N, I);
1315 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1316 Int4 pos = CmpNLT(k, Float4(0.0f));
1317 Float4 t = (eta * d + Sqrt(k));
1318
1319 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1320 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1321 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1322 }
1323
Alexis Hetuecad5192015-06-05 13:42:05 -04001324 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001325 {
1326 Float4 d = dot4(N, I);
1327 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1328 Int4 pos = CmpNLT(k, Float4(0.0f));
1329 Float4 t = (eta * d + Sqrt(k));
1330
1331 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1332 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1333 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1334 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1335 }
1336
Alexis Hetuecad5192015-06-05 13:42:05 -04001337 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001338 {
1339 sgn(dst.x, src.x);
1340 sgn(dst.y, src.y);
1341 sgn(dst.z, src.z);
1342 sgn(dst.w, src.w);
1343 }
1344
Alexis Hetuecad5192015-06-05 13:42:05 -04001345 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001346 {
1347 dst.x = Abs(src.x);
1348 dst.y = Abs(src.y);
1349 dst.z = Abs(src.z);
1350 dst.w = Abs(src.w);
1351 }
John Bauman19bac1e2014-05-06 15:23:49 -04001352
Alexis Hetuecad5192015-06-05 13:42:05 -04001353 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001354 {
1355 Float4 dot = dot2(src, src);
1356 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001357
John Bauman19bac1e2014-05-06 15:23:49 -04001358 dst.x = src.x * rsq;
1359 dst.y = src.y * rsq;
1360 dst.z = src.z * rsq;
1361 dst.w = src.w * rsq;
1362 }
1363
Alexis Hetuecad5192015-06-05 13:42:05 -04001364 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001365 {
1366 Float4 dot = dot3(src, src);
1367 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1368
1369 dst.x = src.x * rsq;
1370 dst.y = src.y * rsq;
1371 dst.z = src.z * rsq;
1372 dst.w = src.w * rsq;
1373 }
John Bauman19bac1e2014-05-06 15:23:49 -04001374
Alexis Hetuecad5192015-06-05 13:42:05 -04001375 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001376 {
John Bauman19bac1e2014-05-06 15:23:49 -04001377 Float4 dot = dot4(src, src);
1378 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001379
John Bauman19bac1e2014-05-06 15:23:49 -04001380 dst.x = src.x * rsq;
1381 dst.y = src.y * rsq;
1382 dst.z = src.z * rsq;
1383 dst.w = src.w * rsq;
1384 }
1385
Alexis Hetuecad5192015-06-05 13:42:05 -04001386 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001387 {
1388 dst.x = cosine_pi(src.x, pp);
1389 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001390 }
1391
Alexis Hetuecad5192015-06-05 13:42:05 -04001392 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001393 {
1394 dst.x = cosine(src.x, pp);
1395 dst.y = cosine(src.y, pp);
1396 dst.z = cosine(src.z, pp);
1397 dst.w = cosine(src.w, pp);
1398 }
1399
Alexis Hetuecad5192015-06-05 13:42:05 -04001400 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001401 {
1402 dst.x = sine(src.x, pp);
1403 dst.y = sine(src.y, pp);
1404 dst.z = sine(src.z, pp);
1405 dst.w = sine(src.w, pp);
1406 }
1407
Alexis Hetuecad5192015-06-05 13:42:05 -04001408 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001409 {
1410 dst.x = tangent(src.x, pp);
1411 dst.y = tangent(src.y, pp);
1412 dst.z = tangent(src.z, pp);
1413 dst.w = tangent(src.w, pp);
1414 }
1415
Alexis Hetuecad5192015-06-05 13:42:05 -04001416 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001417 {
1418 dst.x = arccos(src.x, pp);
1419 dst.y = arccos(src.y, pp);
1420 dst.z = arccos(src.z, pp);
1421 dst.w = arccos(src.w, pp);
1422 }
1423
Alexis Hetuecad5192015-06-05 13:42:05 -04001424 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001425 {
1426 dst.x = arcsin(src.x, pp);
1427 dst.y = arcsin(src.y, pp);
1428 dst.z = arcsin(src.z, pp);
1429 dst.w = arcsin(src.w, pp);
1430 }
1431
Alexis Hetuecad5192015-06-05 13:42:05 -04001432 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001433 {
1434 dst.x = arctan(src.x, pp);
1435 dst.y = arctan(src.y, pp);
1436 dst.z = arctan(src.z, pp);
1437 dst.w = arctan(src.w, pp);
1438 }
1439
Alexis Hetuecad5192015-06-05 13:42:05 -04001440 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001441 {
1442 dst.x = arctan(src0.x, src1.x, pp);
1443 dst.y = arctan(src0.y, src1.y, pp);
1444 dst.z = arctan(src0.z, src1.z, pp);
1445 dst.w = arctan(src0.w, src1.w, pp);
1446 }
1447
Alexis Hetuecad5192015-06-05 13:42:05 -04001448 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001449 {
1450 dst.x = cosineh(src.x, pp);
1451 dst.y = cosineh(src.y, pp);
1452 dst.z = cosineh(src.z, pp);
1453 dst.w = cosineh(src.w, pp);
1454 }
1455
Alexis Hetuecad5192015-06-05 13:42:05 -04001456 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001457 {
1458 dst.x = sineh(src.x, pp);
1459 dst.y = sineh(src.y, pp);
1460 dst.z = sineh(src.z, pp);
1461 dst.w = sineh(src.w, pp);
1462 }
1463
Alexis Hetuecad5192015-06-05 13:42:05 -04001464 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001465 {
1466 dst.x = tangenth(src.x, pp);
1467 dst.y = tangenth(src.y, pp);
1468 dst.z = tangenth(src.z, pp);
1469 dst.w = tangenth(src.w, pp);
1470 }
1471
Alexis Hetuecad5192015-06-05 13:42:05 -04001472 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001473 {
1474 dst.x = arccosh(src.x, pp);
1475 dst.y = arccosh(src.y, pp);
1476 dst.z = arccosh(src.z, pp);
1477 dst.w = arccosh(src.w, pp);
1478 }
1479
Alexis Hetuecad5192015-06-05 13:42:05 -04001480 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001481 {
1482 dst.x = arcsinh(src.x, pp);
1483 dst.y = arcsinh(src.y, pp);
1484 dst.z = arcsinh(src.z, pp);
1485 dst.w = arcsinh(src.w, pp);
1486 }
1487
Alexis Hetuecad5192015-06-05 13:42:05 -04001488 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001489 {
1490 dst.x = arctanh(src.x, pp);
1491 dst.y = arctanh(src.y, pp);
1492 dst.z = arctanh(src.z, pp);
1493 dst.w = arctanh(src.w, pp);
1494 }
1495
Alexis Hetuecad5192015-06-05 13:42:05 -04001496 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001497 {
1498 if(version < 0x0200)
1499 {
John Bauman19bac1e2014-05-06 15:23:49 -04001500 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001501 Float4 floor = src.x - frc;
1502
John Bauman19bac1e2014-05-06 15:23:49 -04001503 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001504 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001505 dst.z = exponential2(src.x, true);
1506 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001507 }
1508 else // Version >= 2.0
1509 {
John Bauman19bac1e2014-05-06 15:23:49 -04001510 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001511 }
1512 }
1513
Alexis Hetuecad5192015-06-05 13:42:05 -04001514 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001515 {
1516 if(version < 0x0200)
1517 {
1518 Float4 tmp0;
1519 Float4 tmp1;
1520 Float4 t;
1521 Int4 r;
1522
1523 tmp0 = Abs(src.x);
1524 tmp1 = tmp0;
1525
1526 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001527 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001528 dst.x = Float4(r);
1529
1530 // Y component
1531 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1532
1533 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001534 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001535
1536 // W component
1537 dst.w = 1.0f;
1538 }
1539 else
1540 {
John Bauman19bac1e2014-05-06 15:23:49 -04001541 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001542 }
1543 }
1544
Alexis Hetuecad5192015-06-05 13:42:05 -04001545 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001546 {
John Bauman19bac1e2014-05-06 15:23:49 -04001547 cmp0(dst.x, src0.x, src1.x, src2.x);
1548 cmp0(dst.y, src0.y, src1.y, src2.y);
1549 cmp0(dst.z, src0.z, src1.z, src2.z);
1550 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001551 }
John Bauman89401822014-05-06 15:04:28 -04001552
Alexis Hetuecad5192015-06-05 13:42:05 -04001553 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001554 {
1555 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1556 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1557 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1558 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1559 }
1560
Alexis Hetuecad5192015-06-05 13:42:05 -04001561 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001562 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001563 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1564 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1565 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001566 }
1567
Alexis Hetuecad5192015-06-05 13:42:05 -04001568 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001569 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001570 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1571 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1572 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1573 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001574 }
1575
Alexis Hetuecad5192015-06-05 13:42:05 -04001576 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001577 {
John Bauman19bac1e2014-05-06 15:23:49 -04001578 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1579 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001580 dst = As<Float4>(neg | pos);
1581 }
1582
Alexis Hetuecad5192015-06-05 13:42:05 -04001583 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001584 {
John Bauman19bac1e2014-05-06 15:23:49 -04001585 Int4 pos = CmpLE(Float4(0.0f), src0);
1586 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001587 }
1588
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001589 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1590 {
1591 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1592 select(dst, pos, src1, src2);
1593 }
1594
Alexis Hetuecad5192015-06-05 13:42:05 -04001595 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001596 {
1597 // FIXME: LLVM vector select
1598 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1599 }
1600
Alexis Hetuecad5192015-06-05 13:42:05 -04001601 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001602 {
1603 switch(control)
1604 {
John Bauman19bac1e2014-05-06 15:23:49 -04001605 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001606 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1607 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1608 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1609 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1610 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001611 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001612 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1613 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1614 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1615 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1616 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001617 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001618 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1619 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1620 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1621 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1622 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001623 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001624 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1625 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1626 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1627 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1628 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001629 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001630 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1631 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1632 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1633 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1634 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001635 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001636 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1637 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1638 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1639 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1640 break;
1641 default:
1642 ASSERT(false);
1643 }
1644 }
John Bauman19bac1e2014-05-06 15:23:49 -04001645
Alexis Hetuecad5192015-06-05 13:42:05 -04001646 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001647 {
1648 switch(control)
1649 {
1650 case Shader::CONTROL_GT:
1651 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1652 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1653 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1654 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1655 break;
1656 case Shader::CONTROL_EQ:
1657 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1658 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1659 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1660 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1661 break;
1662 case Shader::CONTROL_GE:
1663 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1664 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1665 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1666 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1667 break;
1668 case Shader::CONTROL_LT:
1669 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1670 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1671 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1672 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1673 break;
1674 case Shader::CONTROL_NE:
1675 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1676 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1677 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1678 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1679 break;
1680 case Shader::CONTROL_LE:
1681 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1682 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1683 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1684 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1685 break;
1686 default:
1687 ASSERT(false);
1688 }
1689 }
1690
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001691 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1692 {
1693 switch(control)
1694 {
1695 case Shader::CONTROL_GT:
1696 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1697 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1698 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1699 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1700 break;
1701 case Shader::CONTROL_EQ:
1702 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1703 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1704 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1705 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1706 break;
1707 case Shader::CONTROL_GE:
1708 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1709 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1710 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1711 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1712 break;
1713 case Shader::CONTROL_LT:
1714 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1715 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1716 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1717 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1718 break;
1719 case Shader::CONTROL_NE:
1720 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1721 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1722 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1723 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1724 break;
1725 case Shader::CONTROL_LE:
1726 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1727 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1728 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1729 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1730 break;
1731 default:
1732 ASSERT(false);
1733 }
1734 }
1735
Alexis Hetuecad5192015-06-05 13:42:05 -04001736 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001737 {
1738 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1739 }
1740
Alexis Hetuecad5192015-06-05 13:42:05 -04001741 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001742 {
1743 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1744 }
1745
Alexis Hetuecad5192015-06-05 13:42:05 -04001746 void ShaderCore::not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001747 {
1748 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1749 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1750 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1751 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1752 }
1753
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001754 void ShaderCore::or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001755 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001756 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1757 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1758 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1759 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001760 }
1761
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001762 void ShaderCore::xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001763 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001764 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1765 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1766 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1767 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001768 }
1769
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001770 void ShaderCore::and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001771 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001772 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1773 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1774 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1775 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1776 }
1777
1778 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1779 {
1780 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1781 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1782 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1783 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1784 dst.y = dst.x;
1785 dst.z = dst.x;
1786 dst.w = dst.x;
1787 }
1788
1789 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1790 {
1791 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1792 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1793 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1794 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1795 dst.y = dst.x;
1796 dst.z = dst.x;
1797 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001798 }
John Bauman89401822014-05-06 15:04:28 -04001799}