blob: 5be4d4389c79c9b209f5391ac390ea08e02aa540 [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
17namespace sw
18{
John Bauman19bac1e2014-05-06 15:23:49 -040019 extern TranscendentalPrecision logPrecision;
20 extern TranscendentalPrecision expPrecision;
21 extern TranscendentalPrecision rcpPrecision;
22 extern TranscendentalPrecision rsqPrecision;
23
Alexis Hetu96517182015-04-15 10:30:23 -040024 Vector4s::Vector4s()
John Bauman19bac1e2014-05-06 15:23:49 -040025 {
26 }
27
Alexis Hetu96517182015-04-15 10:30:23 -040028 Vector4s::Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
John Bauman19bac1e2014-05-06 15:23:49 -040029 {
30 this->x = Short4(x);
31 this->y = Short4(y);
32 this->z = Short4(z);
33 this->w = Short4(w);
34 }
35
Alexis Hetu96517182015-04-15 10:30:23 -040036 Vector4s::Vector4s(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040037 {
38 x = rhs.x;
39 y = rhs.y;
40 z = rhs.z;
41 w = rhs.w;
42 }
43
Alexis Hetu96517182015-04-15 10:30:23 -040044 Vector4s &Vector4s::operator=(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040045 {
46 x = rhs.x;
47 y = rhs.y;
48 z = rhs.z;
49 w = rhs.w;
50
51 return *this;
52 }
53
Alexis Hetu96517182015-04-15 10:30:23 -040054 Short4 &Vector4s::operator[](int i)
John Bauman19bac1e2014-05-06 15:23:49 -040055 {
56 switch(i)
57 {
58 case 0: return x;
59 case 1: return y;
60 case 2: return z;
61 case 3: return w;
62 }
63
64 return x;
65 }
66
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -040067 Vector4i::Vector4i()
68 {
69 }
70
71 Vector4i::Vector4i(int x, int y, int z, int w)
72 {
73 this->x = Int4(x);
74 this->y = Int4(y);
75 this->z = Int4(z);
76 this->w = Int4(w);
77 }
78
79 Vector4i::Vector4i(const Vector4i &rhs)
80 {
81 x = rhs.x;
82 y = rhs.y;
83 z = rhs.z;
84 w = rhs.w;
85 }
86
87 Vector4i &Vector4i::operator=(const Vector4i &rhs)
88 {
89 x = rhs.x;
90 y = rhs.y;
91 z = rhs.z;
92 w = rhs.w;
93
94 return *this;
95 }
96
97 Int4 &Vector4i::operator[](int i)
98 {
99 switch(i)
100 {
101 case 0: return x;
102 case 1: return y;
103 case 2: return z;
104 case 3: return w;
105 }
106
107 return x;
108 }
109
110 Vector4u::Vector4u()
111 {
112 }
113
114 Vector4u::Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
115 {
116 this->x = UInt4(x);
117 this->y = UInt4(y);
118 this->z = UInt4(z);
119 this->w = UInt4(w);
120 }
121
122 Vector4u::Vector4u(const Vector4u &rhs)
123 {
124 x = rhs.x;
125 y = rhs.y;
126 z = rhs.z;
127 w = rhs.w;
128 }
129
130 Vector4u &Vector4u::operator=(const Vector4u &rhs)
131 {
132 x = rhs.x;
133 y = rhs.y;
134 z = rhs.z;
135 w = rhs.w;
136
137 return *this;
138 }
139
140 UInt4 &Vector4u::operator[](int i)
141 {
142 switch(i)
143 {
144 case 0: return x;
145 case 1: return y;
146 case 2: return z;
147 case 3: return w;
148 }
149
150 return x;
151 }
152
John Bauman19bac1e2014-05-06 15:23:49 -0400153 Vector4f::Vector4f()
154 {
155 }
156
157 Vector4f::Vector4f(float x, float y, float z, float w)
158 {
159 this->x = Float4(x);
160 this->y = Float4(y);
161 this->z = Float4(z);
162 this->w = Float4(w);
163 }
164
165 Vector4f::Vector4f(const Vector4f &rhs)
166 {
167 x = rhs.x;
168 y = rhs.y;
169 z = rhs.z;
170 w = rhs.w;
171 }
172
173 Vector4f &Vector4f::operator=(const Vector4f &rhs)
174 {
175 x = rhs.x;
176 y = rhs.y;
177 z = rhs.z;
178 w = rhs.w;
179
180 return *this;
181 }
182
183 Float4 &Vector4f::operator[](int i)
184 {
185 switch(i)
186 {
187 case 0: return x;
188 case 1: return y;
189 case 2: return z;
190 case 3: return w;
191 }
192
193 return x;
194 }
195
196 Float4 exponential2(RValue<Float4> x, bool pp)
197 {
198 Float4 x0;
199 Float4 x1;
200 Int4 x2;
201
202 x0 = x;
203
204 x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
205 x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f
206 x1 = x0;
207 x1 -= Float4(0.5f);
208 x2 = RoundInt(x1);
209 x1 = Float4(x2);
210 x2 += Int4(0x0000007F); // 127
211 x2 = x2 << 23;
212 x0 -= x1;
213 x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f
214 x1 *= x0;
215 x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f
216 x1 *= x0;
217 x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f
218 x1 *= x0;
219 x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
220 x1 *= x0;
221 x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
222 x1 *= x0;
223 x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f
224 x1 *= As<Float4>(x2);
225
226 return x1;
227 }
228
229 Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp)
230 {
231 Float4 x0;
232 Float4 x1;
233 Float4 x2;
234 Float4 x3;
235
236 x0 = x;
237
238 x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
239 x1 = As<Float4>(As<UInt4>(x1) >> 8);
240 x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
241 x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f;
242 x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
243
244 x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f);
245 x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f);
246 x2 /= x3;
247
248 x1 += (x0 - Float4(1.0f)) * x2;
249
250 return x1;
251 }
252
253 Float4 exponential(RValue<Float4> x, bool pp)
254 {
255 // FIXME: Propagate the constant
256 return exponential2(Float4(1.44269541f) * x, pp); // 1/ln(2)
257 }
258
259 Float4 logarithm(RValue<Float4> x, bool absolute, bool pp)
260 {
261 // FIXME: Propagate the constant
262 return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2)
263 }
264
265 Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp)
266 {
267 Float4 log = logarithm2(x, true, pp);
268 log *= y;
269 return exponential2(log, pp);
270 }
271
272 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite)
273 {
274 Float4 rcp;
275
276 if(!pp && rcpPrecision >= WHQL)
277 {
278 rcp = Float4(1.0f) / x;
279 }
280 else
281 {
282 rcp = Rcp_pp(x);
283
284 if(!pp)
285 {
286 rcp = (rcp + rcp) - (x * rcp * rcp);
287 }
288 }
289
290 if(finite)
291 {
292 int big = 0x7F7FFFFF;
293 rcp = Min(rcp, Float4((float&)big));
294 }
295
296 return rcp;
297 }
298
299 Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
300 {
301 Float4 abs = x;
302
303 if(absolute)
304 {
305 abs = Abs(abs);
306 }
307
308 Float4 rsq;
309
310 if(!pp && rsqPrecision >= IEEE)
311 {
312 rsq = Float4(1.0f) / Sqrt(abs);
313 }
314 else
315 {
316 rsq = RcpSqrt_pp(abs);
317
318 if(!pp)
319 {
320 rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
321 }
322 }
323
324 int big = 0x7F7FFFFF;
325 rsq = Min(rsq, Float4((float&)big));
326
327 return rsq;
328 }
329
330 Float4 modulo(RValue<Float4> x, RValue<Float4> y)
331 {
332 return x - y * Floor(x / y);
333 }
334
335 Float4 sine_pi(RValue<Float4> x, bool pp)
336 {
337 const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2
338 const Float4 B = Float4(1.27323954e+0f); // 4/pi
339 const Float4 C = Float4(7.75160950e-1f);
340 const Float4 D = Float4(2.24839049e-1f);
341
342 // Parabola approximating sine
343 Float4 sin = x * (Abs(x) * A + B);
344
345 // Improve precision from 0.06 to 0.001
346 if(true)
347 {
348 sin = sin * (Abs(sin) * D + C);
349 }
350
351 return sin;
352 }
353
354 Float4 cosine_pi(RValue<Float4> x, bool pp)
355 {
356 // cos(x) = sin(x + pi/2)
357 Float4 y = x + Float4(1.57079632e+0f);
358
359 // Wrap around
360 y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f)));
361
362 return sine_pi(y, pp);
363 }
364
365 Float4 sine(RValue<Float4> x, bool pp)
366 {
367 // Reduce to [-0.5, 0.5] range
368 Float4 y = x * Float4(1.59154943e-1f); // 1/2pi
369 y = y - Round(y);
370
371 const Float4 A = Float4(-16.0f);
372 const Float4 B = Float4(8.0f);
373 const Float4 C = Float4(7.75160950e-1f);
374 const Float4 D = Float4(2.24839049e-1f);
375
376 // Parabola approximating sine
377 Float4 sin = y * (Abs(y) * A + B);
378
379 // Improve precision from 0.06 to 0.001
380 if(true)
381 {
382 sin = sin * (Abs(sin) * D + C);
383 }
384
385 return sin;
386 }
387
388 Float4 cosine(RValue<Float4> x, bool pp)
389 {
390 // cos(x) = sin(x + pi/2)
391 Float4 y = x + Float4(1.57079632e+0f);
392 return sine(y, pp);
393 }
394
395 Float4 tangent(RValue<Float4> x, bool pp)
396 {
397 return sine(x, pp) / cosine(x, pp);
398 }
399
400 Float4 arccos(RValue<Float4> x, bool pp)
401 {
402 // pi/2 - arcsin(x)
403 return Float4(1.57079632e+0f) - arcsin(x);
404 }
405
406 Float4 arcsin(RValue<Float4> x, bool pp)
407 {
408 // x*(pi/2-sqrt(1-x*x)*pi/5)
409 return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f));
410 }
411
412 Float4 arctan(RValue<Float4> x, bool pp)
413 {
414 Int4 O = CmpNLT(Abs(x), Float4(1.0f));
415 Float4 y = As<Float4>(O & As<Int4>(Float4(1.0f) / x) | ~O & As<Int4>(x)); // FIXME: Vector select
416
417 // Approximation of atan in [-1..1]
418 Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
419
420 // +/-pi/2 depending on sign of x
421 Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
422
423 theta = As<Float4>(O & As<Int4>(sgnPi_2 - theta) | ~O & As<Int4>(theta)); // FIXME: Vector select
424
425 return theta;
426 }
427
428 Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp)
429 {
430 // Rotate to upper semicircle when in lower semicircle
431 Int4 S = CmpLT(y, Float4(0.0f));
432 Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi
433 Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x));
434 Float4 y0 = Abs(y);
435
436 // Rotate to right quadrant when in left quadrant
437 Int4 Q = CmpLT(x0, Float4(0.0f));
438 theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2
439 Float4 x1 = As<Float4>(Q & As<Int4>(y0) | ~Q & As<Int4>(x0)); // FIXME: Vector select
440 Float4 y1 = As<Float4>(Q & As<Int4>(-x0) | ~Q & As<Int4>(y0)); // FIXME: Vector select
441
442 // Rotate to first octant when in second octant
443 Int4 O = CmpNLT(y1, x1);
444 theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4
445 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
446 Float4 y2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1) | ~O & As<Int4>(y1)); // FIXME: Vector select
447
448 // Approximation of atan in [0..1]
449 Float4 y_x = y2 / x2;
450 theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f));
451
452 return theta;
453 }
454
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400455 Float4 sineh(RValue<Float4> x, bool pp)
456 {
457 return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f);
458 }
459
460 Float4 cosineh(RValue<Float4> x, bool pp)
461 {
462 return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f);
463 }
464
465 Float4 tangenth(RValue<Float4> x, bool pp)
466 {
467 Float4 e_x = exponential(x, pp);
468 Float4 e_minus_x = exponential(-x, pp);
469 return (e_x - e_minus_x) / (e_x + e_minus_x);
470 }
471
472 Float4 arccosh(RValue<Float4> x, bool pp)
473 {
474 return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp);
475 }
476
477 Float4 arcsinh(RValue<Float4> x, bool pp)
478 {
479 return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp);
480 }
481
482 Float4 arctanh(RValue<Float4> x, bool pp)
483 {
484 return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f);
485 }
486
487 Int4 floatBitsToInt(RValue<Float4> x)
488 {
489 return As<Int4>(x);
490 }
491
492 UInt4 floatBitsToUInt(RValue<Float4> x)
493 {
494 return As<UInt4>(x);
495 }
496
497 Float4 intBitsToFloat(RValue<Int4> x)
498 {
499 return As<Float4>(x);
500 }
501
502 Float4 uintBitsToFloat(RValue<UInt4> x)
503 {
504 return As<Float4>(x);
505 }
506
Alexis Hetuecad5192015-06-05 13:42:05 -0400507 Float4 dot2(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400508 {
509 return v0.x * v1.x + v0.y * v1.y;
510 }
511
Alexis Hetuecad5192015-06-05 13:42:05 -0400512 Float4 dot3(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400513 {
514 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
515 }
516
Alexis Hetuecad5192015-06-05 13:42:05 -0400517 Float4 dot4(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400518 {
519 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w;
520 }
521
522 void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
523 {
524 Int2 tmp0 = UnpackHigh(row0, row1);
525 Int2 tmp1 = UnpackHigh(row2, row3);
526 Int2 tmp2 = UnpackLow(row0, row1);
527 Int2 tmp3 = UnpackLow(row2, row3);
528
529 row0 = As<Short4>(UnpackLow(tmp2, tmp3));
530 row1 = As<Short4>(UnpackHigh(tmp2, tmp3));
531 row2 = As<Short4>(UnpackLow(tmp0, tmp1));
532 row3 = As<Short4>(UnpackHigh(tmp0, tmp1));
533 }
534
535 void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
536 {
537 Float4 tmp0 = UnpackLow(row0, row1);
538 Float4 tmp1 = UnpackLow(row2, row3);
539 Float4 tmp2 = UnpackHigh(row0, row1);
540 Float4 tmp3 = UnpackHigh(row2, row3);
541
542 row0 = Float4(tmp0.xy, tmp1.xy);
543 row1 = Float4(tmp0.zw, tmp1.zw);
544 row2 = Float4(tmp2.xy, tmp3.xy);
545 row3 = Float4(tmp2.zw, tmp3.zw);
546 }
547
548 void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
549 {
550 Float4 tmp0 = UnpackLow(row0, row1);
551 Float4 tmp1 = UnpackLow(row2, row3);
552 Float4 tmp2 = UnpackHigh(row0, row1);
553 Float4 tmp3 = UnpackHigh(row2, row3);
554
555 row0 = Float4(tmp0.xy, tmp1.xy);
556 row1 = Float4(tmp0.zw, tmp1.zw);
557 row2 = Float4(tmp2.xy, tmp3.xy);
558 }
559
560 void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
561 {
562 Float4 tmp0 = UnpackLow(row0, row1);
563 Float4 tmp1 = UnpackLow(row2, row3);
564
565 row0 = Float4(tmp0.xy, tmp1.xy);
566 row1 = Float4(tmp0.zw, tmp1.zw);
567 }
568
569 void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
570 {
571 Float4 tmp0 = UnpackLow(row0, row1);
572 Float4 tmp1 = UnpackLow(row2, row3);
573
574 row0 = Float4(tmp0.xy, tmp1.xy);
575 }
576
577 void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
578 {
579 row0 = UnpackLow(row0, row1);
580 row1 = Float4(row0.zw, row1.zw);
581 row2 = UnpackHigh(row0, row1);
582 row3 = Float4(row2.zw, row3.zw);
583 }
584
585 void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
586 {
587 row0 = UnpackLow(row2, row3);
588 row1 = Float4(row0.zw, row1.zw);
589 row2 = UnpackHigh(row2, row3);
590 row3 = Float4(row2.zw, row3.zw);
591 }
592
593 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
594 {
595 switch(N)
596 {
597 case 1: transpose4x1(row0, row1, row2, row3); break;
598 case 2: transpose4x2(row0, row1, row2, row3); break;
599 case 3: transpose4x3(row0, row1, row2, row3); break;
600 case 4: transpose4x4(row0, row1, row2, row3); break;
601 }
602 }
603
Alexis Hetuecad5192015-06-05 13:42:05 -0400604 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool floorToInteger)
John Bauman89401822014-05-06 15:04:28 -0400605 {
606 if(floorToInteger)
607 {
608 dst.x = Floor(src.x);
609 }
610 else
611 {
612 dst = src;
613 }
614 }
615
Alexis Hetuecad5192015-06-05 13:42:05 -0400616 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400617 {
618 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
619 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
620 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
621 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
622 }
623
Alexis Hetuecad5192015-06-05 13:42:05 -0400624 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400625 {
626 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
627 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
628 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
629 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
630 }
631
Alexis Hetuecad5192015-06-05 13:42:05 -0400632 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400633 {
634 dst.x = src0.x + src1.x;
635 dst.y = src0.y + src1.y;
636 dst.z = src0.z + src1.z;
637 dst.w = src0.w + src1.w;
638 }
639
Alexis Hetuecad5192015-06-05 13:42:05 -0400640 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400641 {
642 dst.x = src0.x - src1.x;
643 dst.y = src0.y - src1.y;
644 dst.z = src0.z - src1.z;
645 dst.w = src0.w - src1.w;
646 }
647
Alexis Hetuecad5192015-06-05 13:42:05 -0400648 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400649 {
650 dst.x = src0.x * src1.x + src2.x;
651 dst.y = src0.y * src1.y + src2.y;
652 dst.z = src0.z * src1.z + src2.z;
653 dst.w = src0.w * src1.w + src2.w;
654 }
655
Alexis Hetuecad5192015-06-05 13:42:05 -0400656 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400657 {
658 dst.x = src0.x * src1.x;
659 dst.y = src0.y * src1.y;
660 dst.z = src0.z * src1.z;
661 dst.w = src0.w * src1.w;
662 }
663
Alexis Hetuecad5192015-06-05 13:42:05 -0400664 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400665 {
666 Float4 rcp = reciprocal(src.x, pp, true);
667
668 dst.x = rcp;
669 dst.y = rcp;
670 dst.z = rcp;
671 dst.w = rcp;
672 }
673
Alexis Hetuecad5192015-06-05 13:42:05 -0400674 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400675 {
676 dst.x = src0.x / src1.x;
677 dst.y = src0.y / src1.y;
678 dst.z = src0.z / src1.z;
679 dst.w = src0.w / src1.w;
680 }
681
Alexis Hetuecad5192015-06-05 13:42:05 -0400682 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400683 {
684 dst.x = modulo(src0.x, src1.x);
685 dst.y = modulo(src0.y, src1.y);
686 dst.z = modulo(src0.z, src1.z);
687 dst.w = modulo(src0.w, src1.w);
688 }
689
Alexis Hetuecad5192015-06-05 13:42:05 -0400690 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400691 {
692 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
693
John Bauman19bac1e2014-05-06 15:23:49 -0400694 dst.x = rsq;
695 dst.y = rsq;
696 dst.z = rsq;
697 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400698 }
699
Alexis Hetuecad5192015-06-05 13:42:05 -0400700 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400701 {
702 dst.x = Sqrt(src.x);
703 dst.y = Sqrt(src.y);
704 dst.z = Sqrt(src.z);
705 dst.w = Sqrt(src.w);
706 }
707
Alexis Hetuecad5192015-06-05 13:42:05 -0400708 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400709 {
710 dst.x = reciprocalSquareRoot(src.x, false, pp);
711 dst.y = reciprocalSquareRoot(src.y, false, pp);
712 dst.z = reciprocalSquareRoot(src.z, false, pp);
713 dst.w = reciprocalSquareRoot(src.w, false, pp);
714 }
715
Alexis Hetuecad5192015-06-05 13:42:05 -0400716 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400717 {
718 dst = Sqrt(dot2(src, src));
719 }
720
Alexis Hetuecad5192015-06-05 13:42:05 -0400721 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400722 {
723 dst = Sqrt(dot3(src, src));
724 }
725
Alexis Hetuecad5192015-06-05 13:42:05 -0400726 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400727 {
728 dst = Sqrt(dot4(src, src));
729 }
730
Alexis Hetuecad5192015-06-05 13:42:05 -0400731 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400732 {
733 dst = Abs(src0.x - src1.x);
734 }
735
Alexis Hetuecad5192015-06-05 13:42:05 -0400736 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400737 {
738 Float4 dx = src0.x - src1.x;
739 Float4 dy = src0.y - src1.y;
740 Float4 dot2 = dx * dx + dy * dy;
741 dst = Sqrt(dot2);
742 }
743
Alexis Hetuecad5192015-06-05 13:42:05 -0400744 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400745 {
746 Float4 dx = src0.x - src1.x;
747 Float4 dy = src0.y - src1.y;
748 Float4 dz = src0.z - src1.z;
749 Float4 dot3 = dx * dx + dy * dy + dz * dz;
750 dst = Sqrt(dot3);
751 }
752
Alexis Hetuecad5192015-06-05 13:42:05 -0400753 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400754 {
755 Float4 dx = src0.x - src1.x;
756 Float4 dy = src0.y - src1.y;
757 Float4 dz = src0.z - src1.z;
758 Float4 dw = src0.w - src1.w;
759 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
760 dst = Sqrt(dot4);
761 }
762
Alexis Hetuecad5192015-06-05 13:42:05 -0400763 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400764 {
765 Float4 t = src0.x * src1.x;
766
767 dst.x = t;
768 dst.y = t;
769 dst.z = t;
770 dst.w = t;
771 }
772
Alexis Hetuecad5192015-06-05 13:42:05 -0400773 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400774 {
775 Float4 t = dot2(src0, src1);
776
777 dst.x = t;
778 dst.y = t;
779 dst.z = t;
780 dst.w = t;
781 }
782
Alexis Hetuecad5192015-06-05 13:42:05 -0400783 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400784 {
785 Float4 t = dot2(src0, src1) + src2.x;
786
787 dst.x = t;
788 dst.y = t;
789 dst.z = t;
790 dst.w = t;
791 }
792
Alexis Hetuecad5192015-06-05 13:42:05 -0400793 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400794 {
795 Float4 dot = dot3(src0, src1);
796
797 dst.x = dot;
798 dst.y = dot;
799 dst.z = dot;
800 dst.w = dot;
801 }
802
Alexis Hetuecad5192015-06-05 13:42:05 -0400803 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400804 {
805 Float4 dot = dot4(src0, src1);
806
807 dst.x = dot;
808 dst.y = dot;
809 dst.z = dot;
810 dst.w = dot;
811 }
812
Alexis Hetuecad5192015-06-05 13:42:05 -0400813 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400814 {
815 dst.x = Min(src0.x, src1.x);
816 dst.y = Min(src0.y, src1.y);
817 dst.z = Min(src0.z, src1.z);
818 dst.w = Min(src0.w, src1.w);
819 }
820
Alexis Hetuecad5192015-06-05 13:42:05 -0400821 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400822 {
823 dst.x = Max(src0.x, src1.x);
824 dst.y = Max(src0.y, src1.y);
825 dst.z = Max(src0.z, src1.z);
826 dst.w = Max(src0.w, src1.w);
827 }
828
Alexis Hetuecad5192015-06-05 13:42:05 -0400829 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400830 {
John Bauman19bac1e2014-05-06 15:23:49 -0400831 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
832 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
833 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
834 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400835 }
836
Alexis Hetuecad5192015-06-05 13:42:05 -0400837 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -0400838 {
John Bauman19bac1e2014-05-06 15:23:49 -0400839 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
840 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
841 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
842 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400843 }
844
Alexis Hetuecad5192015-06-05 13:42:05 -0400845 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400846 {
John Bauman19bac1e2014-05-06 15:23:49 -0400847 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -0400848
849 dst.x = exp;
850 dst.y = exp;
851 dst.z = exp;
852 dst.w = exp;
853 }
854
Alexis Hetuecad5192015-06-05 13:42:05 -0400855 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400856 {
John Bauman19bac1e2014-05-06 15:23:49 -0400857 dst.x = exponential2(src.x, pp);
858 dst.y = exponential2(src.y, pp);
859 dst.z = exponential2(src.z, pp);
860 dst.w = exponential2(src.w, pp);
861 }
862
Alexis Hetuecad5192015-06-05 13:42:05 -0400863 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400864 {
865 dst.x = exponential(src.x, pp);
866 dst.y = exponential(src.y, pp);
867 dst.z = exponential(src.z, pp);
868 dst.w = exponential(src.w, pp);
869 }
870
Alexis Hetuecad5192015-06-05 13:42:05 -0400871 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400872 {
873 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -0400874
875 dst.x = log;
876 dst.y = log;
877 dst.z = log;
878 dst.w = log;
879 }
880
Alexis Hetuecad5192015-06-05 13:42:05 -0400881 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400882 {
John Bauman19bac1e2014-05-06 15:23:49 -0400883 dst.x = logarithm2(src.x, pp);
884 dst.y = logarithm2(src.y, pp);
885 dst.z = logarithm2(src.z, pp);
886 dst.w = logarithm2(src.w, pp);
887 }
888
Alexis Hetuecad5192015-06-05 13:42:05 -0400889 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400890 {
891 dst.x = logarithm(src.x, false, pp);
892 dst.y = logarithm(src.y, false, pp);
893 dst.z = logarithm(src.z, false, pp);
894 dst.w = logarithm(src.w, false, pp);
895 }
896
Alexis Hetuecad5192015-06-05 13:42:05 -0400897 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400898 {
899 dst.x = Float4(1.0f);
900 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -0400901
902 Float4 pow;
903
904 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -0400905 pow = Min(pow, Float4(127.9961f));
906 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -0400907
908 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -0400909 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
910 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -0400911
John Bauman19bac1e2014-05-06 15:23:49 -0400912 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -0400913 }
914
Alexis Hetuecad5192015-06-05 13:42:05 -0400915 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400916 {
John Bauman19bac1e2014-05-06 15:23:49 -0400917 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -0400918 dst.x = 1;
919 dst.y = src0.y * src1.y;
920 dst.z = src0.z;
921 dst.w = src1.w;
922 }
923
Alexis Hetuecad5192015-06-05 13:42:05 -0400924 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400925 {
926 dst.x = src0.x * (src1.x - src2.x) + src2.x;
927 dst.y = src0.y * (src1.y - src2.y) + src2.y;
928 dst.z = src0.z * (src1.z - src2.z) + src2.z;
929 dst.w = src0.w * (src1.w - src2.w) + src2.w;
930 }
931
Alexis Hetuecad5192015-06-05 13:42:05 -0400932 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -0400933 {
John Bauman19bac1e2014-05-06 15:23:49 -0400934 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);
935 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);
936 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);
937 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 -0400938 }
939
Alexis Hetuecad5192015-06-05 13:42:05 -0400940 void ShaderCore::floatBitsToInt(Vector4i &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400941 {
942 dst.x = sw::floatBitsToInt(src.x);
943 dst.y = sw::floatBitsToInt(src.y);
944 dst.z = sw::floatBitsToInt(src.z);
945 dst.w = sw::floatBitsToInt(src.w);
946 }
947
Alexis Hetuecad5192015-06-05 13:42:05 -0400948 void ShaderCore::floatBitsToUInt(Vector4u &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400949 {
950 dst.x = sw::floatBitsToUInt(src.x);
951 dst.y = sw::floatBitsToUInt(src.y);
952 dst.z = sw::floatBitsToUInt(src.z);
953 dst.w = sw::floatBitsToUInt(src.w);
954 }
955
Alexis Hetuecad5192015-06-05 13:42:05 -0400956 void ShaderCore::intBitsToFloat(Vector4f &dst, const Vector4i &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400957 {
958 dst.x = sw::intBitsToFloat(src.x);
959 dst.y = sw::intBitsToFloat(src.y);
960 dst.z = sw::intBitsToFloat(src.z);
961 dst.w = sw::intBitsToFloat(src.w);
962 }
963
Alexis Hetuecad5192015-06-05 13:42:05 -0400964 void ShaderCore::uintBitsToFloat(Vector4f &dst, const Vector4u &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400965 {
966 dst.x = sw::uintBitsToFloat(src.x);
967 dst.y = sw::uintBitsToFloat(src.y);
968 dst.z = sw::uintBitsToFloat(src.z);
969 dst.w = sw::uintBitsToFloat(src.w);
970 }
971
Alexis Hetuecad5192015-06-05 13:42:05 -0400972 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400973 {
974 dst.x = Frac(src.x);
975 dst.y = Frac(src.y);
976 dst.z = Frac(src.z);
977 dst.w = Frac(src.w);
978 }
979
Alexis Hetuecad5192015-06-05 13:42:05 -0400980 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400981 {
982 dst.x = Trunc(src.x);
983 dst.y = Trunc(src.y);
984 dst.z = Trunc(src.z);
985 dst.w = Trunc(src.w);
986 }
987
Alexis Hetuecad5192015-06-05 13:42:05 -0400988 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400989 {
990 dst.x = Floor(src.x);
991 dst.y = Floor(src.y);
992 dst.z = Floor(src.z);
993 dst.w = Floor(src.w);
994 }
995
Alexis Hetuecad5192015-06-05 13:42:05 -0400996 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400997 {
998 dst.x = Round(src.x);
999 dst.y = Round(src.y);
1000 dst.z = Round(src.z);
1001 dst.w = Round(src.w);
1002 }
1003
Alexis Hetuecad5192015-06-05 13:42:05 -04001004 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001005 {
1006 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1007 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1008 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1009 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1010 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1011 // Even if the round implementation rounds the other way:
1012 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1013 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1014 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1015 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1016 round(dst, src);
1017 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));
1018 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));
1019 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));
1020 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));
1021 }
1022
Alexis Hetuecad5192015-06-05 13:42:05 -04001023 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001024 {
1025 dst.x = Ceil(src.x);
1026 dst.y = Ceil(src.y);
1027 dst.z = Ceil(src.z);
1028 dst.w = Ceil(src.w);
1029 }
1030
Alexis Hetuecad5192015-06-05 13:42:05 -04001031 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001032 {
1033 Float4 pow = power(src0.x, src1.x, pp);
1034
1035 dst.x = pow;
1036 dst.y = pow;
1037 dst.z = pow;
1038 dst.w = pow;
1039 }
1040
Alexis Hetuecad5192015-06-05 13:42:05 -04001041 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001042 {
1043 dst.x = power(src0.x, src1.x, pp);
1044 dst.y = power(src0.y, src1.y, pp);
1045 dst.z = power(src0.z, src1.z, pp);
1046 dst.w = power(src0.w, src1.w, pp);
1047 }
1048
Alexis Hetuecad5192015-06-05 13:42:05 -04001049 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001050 {
1051 dst.x = src0.y * src1.z - src0.z * src1.y;
1052 dst.y = src0.z * src1.x - src0.x * src1.z;
1053 dst.z = src0.x * src1.y - src0.y * src1.x;
1054 }
1055
Alexis Hetuecad5192015-06-05 13:42:05 -04001056 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001057 {
1058 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1059
1060 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1061 }
1062
Alexis Hetuecad5192015-06-05 13:42:05 -04001063 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001064 {
1065 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1066
1067 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1068 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1069 }
1070
Alexis Hetuecad5192015-06-05 13:42:05 -04001071 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001072 {
1073 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1074
1075 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1076 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1077 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1078 }
1079
Alexis Hetuecad5192015-06-05 13:42:05 -04001080 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001081 {
1082 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1083
1084 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1085 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1086 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1087 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1088 }
1089
Alexis Hetuecad5192015-06-05 13:42:05 -04001090 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001091 {
1092 Float4 d = N.x * I.x;
1093
1094 dst.x = I.x - Float4(2.0f) * d * N.x;
1095 }
1096
Alexis Hetuecad5192015-06-05 13:42:05 -04001097 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001098 {
1099 Float4 d = dot2(N, I);
1100
1101 dst.x = I.x - Float4(2.0f) * d * N.x;
1102 dst.y = I.y - Float4(2.0f) * d * N.y;
1103 }
1104
Alexis Hetuecad5192015-06-05 13:42:05 -04001105 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001106 {
1107 Float4 d = dot3(N, I);
1108
1109 dst.x = I.x - Float4(2.0f) * d * N.x;
1110 dst.y = I.y - Float4(2.0f) * d * N.y;
1111 dst.z = I.z - Float4(2.0f) * d * N.z;
1112 }
1113
Alexis Hetuecad5192015-06-05 13:42:05 -04001114 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001115 {
1116 Float4 d = dot4(N, I);
1117
1118 dst.x = I.x - Float4(2.0f) * d * N.x;
1119 dst.y = I.y - Float4(2.0f) * d * N.y;
1120 dst.z = I.z - Float4(2.0f) * d * N.z;
1121 dst.w = I.w - Float4(2.0f) * d * N.w;
1122 }
1123
Alexis Hetuecad5192015-06-05 13:42:05 -04001124 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001125 {
1126 Float4 d = N.x * I.x;
1127 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1128 Int4 pos = CmpNLT(k, Float4(0.0f));
1129 Float4 t = (eta * d + Sqrt(k));
1130
1131 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1132 }
1133
Alexis Hetuecad5192015-06-05 13:42:05 -04001134 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001135 {
1136 Float4 d = dot2(N, I);
1137 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1138 Int4 pos = CmpNLT(k, Float4(0.0f));
1139 Float4 t = (eta * d + Sqrt(k));
1140
1141 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1142 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1143 }
1144
Alexis Hetuecad5192015-06-05 13:42:05 -04001145 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001146 {
1147 Float4 d = dot3(N, I);
1148 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1149 Int4 pos = CmpNLT(k, Float4(0.0f));
1150 Float4 t = (eta * d + Sqrt(k));
1151
1152 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1153 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1154 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1155 }
1156
Alexis Hetuecad5192015-06-05 13:42:05 -04001157 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001158 {
1159 Float4 d = dot4(N, I);
1160 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1161 Int4 pos = CmpNLT(k, Float4(0.0f));
1162 Float4 t = (eta * d + Sqrt(k));
1163
1164 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1165 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1166 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1167 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1168 }
1169
Alexis Hetuecad5192015-06-05 13:42:05 -04001170 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001171 {
1172 sgn(dst.x, src.x);
1173 sgn(dst.y, src.y);
1174 sgn(dst.z, src.z);
1175 sgn(dst.w, src.w);
1176 }
1177
Alexis Hetuecad5192015-06-05 13:42:05 -04001178 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001179 {
1180 dst.x = Abs(src.x);
1181 dst.y = Abs(src.y);
1182 dst.z = Abs(src.z);
1183 dst.w = Abs(src.w);
1184 }
John Bauman19bac1e2014-05-06 15:23:49 -04001185
Alexis Hetuecad5192015-06-05 13:42:05 -04001186 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001187 {
1188 Float4 dot = dot2(src, src);
1189 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001190
John Bauman19bac1e2014-05-06 15:23:49 -04001191 dst.x = src.x * rsq;
1192 dst.y = src.y * rsq;
1193 dst.z = src.z * rsq;
1194 dst.w = src.w * rsq;
1195 }
1196
Alexis Hetuecad5192015-06-05 13:42:05 -04001197 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001198 {
1199 Float4 dot = dot3(src, src);
1200 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1201
1202 dst.x = src.x * rsq;
1203 dst.y = src.y * rsq;
1204 dst.z = src.z * rsq;
1205 dst.w = src.w * rsq;
1206 }
John Bauman19bac1e2014-05-06 15:23:49 -04001207
Alexis Hetuecad5192015-06-05 13:42:05 -04001208 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001209 {
John Bauman19bac1e2014-05-06 15:23:49 -04001210 Float4 dot = dot4(src, src);
1211 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001212
John Bauman19bac1e2014-05-06 15:23:49 -04001213 dst.x = src.x * rsq;
1214 dst.y = src.y * rsq;
1215 dst.z = src.z * rsq;
1216 dst.w = src.w * rsq;
1217 }
1218
Alexis Hetuecad5192015-06-05 13:42:05 -04001219 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001220 {
1221 dst.x = cosine_pi(src.x, pp);
1222 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001223 }
1224
Alexis Hetuecad5192015-06-05 13:42:05 -04001225 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001226 {
1227 dst.x = cosine(src.x, pp);
1228 dst.y = cosine(src.y, pp);
1229 dst.z = cosine(src.z, pp);
1230 dst.w = cosine(src.w, pp);
1231 }
1232
Alexis Hetuecad5192015-06-05 13:42:05 -04001233 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001234 {
1235 dst.x = sine(src.x, pp);
1236 dst.y = sine(src.y, pp);
1237 dst.z = sine(src.z, pp);
1238 dst.w = sine(src.w, pp);
1239 }
1240
Alexis Hetuecad5192015-06-05 13:42:05 -04001241 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001242 {
1243 dst.x = tangent(src.x, pp);
1244 dst.y = tangent(src.y, pp);
1245 dst.z = tangent(src.z, pp);
1246 dst.w = tangent(src.w, pp);
1247 }
1248
Alexis Hetuecad5192015-06-05 13:42:05 -04001249 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001250 {
1251 dst.x = arccos(src.x, pp);
1252 dst.y = arccos(src.y, pp);
1253 dst.z = arccos(src.z, pp);
1254 dst.w = arccos(src.w, pp);
1255 }
1256
Alexis Hetuecad5192015-06-05 13:42:05 -04001257 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001258 {
1259 dst.x = arcsin(src.x, pp);
1260 dst.y = arcsin(src.y, pp);
1261 dst.z = arcsin(src.z, pp);
1262 dst.w = arcsin(src.w, pp);
1263 }
1264
Alexis Hetuecad5192015-06-05 13:42:05 -04001265 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001266 {
1267 dst.x = arctan(src.x, pp);
1268 dst.y = arctan(src.y, pp);
1269 dst.z = arctan(src.z, pp);
1270 dst.w = arctan(src.w, pp);
1271 }
1272
Alexis Hetuecad5192015-06-05 13:42:05 -04001273 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001274 {
1275 dst.x = arctan(src0.x, src1.x, pp);
1276 dst.y = arctan(src0.y, src1.y, pp);
1277 dst.z = arctan(src0.z, src1.z, pp);
1278 dst.w = arctan(src0.w, src1.w, pp);
1279 }
1280
Alexis Hetuecad5192015-06-05 13:42:05 -04001281 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001282 {
1283 dst.x = cosineh(src.x, pp);
1284 dst.y = cosineh(src.y, pp);
1285 dst.z = cosineh(src.z, pp);
1286 dst.w = cosineh(src.w, pp);
1287 }
1288
Alexis Hetuecad5192015-06-05 13:42:05 -04001289 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001290 {
1291 dst.x = sineh(src.x, pp);
1292 dst.y = sineh(src.y, pp);
1293 dst.z = sineh(src.z, pp);
1294 dst.w = sineh(src.w, pp);
1295 }
1296
Alexis Hetuecad5192015-06-05 13:42:05 -04001297 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001298 {
1299 dst.x = tangenth(src.x, pp);
1300 dst.y = tangenth(src.y, pp);
1301 dst.z = tangenth(src.z, pp);
1302 dst.w = tangenth(src.w, pp);
1303 }
1304
Alexis Hetuecad5192015-06-05 13:42:05 -04001305 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001306 {
1307 dst.x = arccosh(src.x, pp);
1308 dst.y = arccosh(src.y, pp);
1309 dst.z = arccosh(src.z, pp);
1310 dst.w = arccosh(src.w, pp);
1311 }
1312
Alexis Hetuecad5192015-06-05 13:42:05 -04001313 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001314 {
1315 dst.x = arcsinh(src.x, pp);
1316 dst.y = arcsinh(src.y, pp);
1317 dst.z = arcsinh(src.z, pp);
1318 dst.w = arcsinh(src.w, pp);
1319 }
1320
Alexis Hetuecad5192015-06-05 13:42:05 -04001321 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001322 {
1323 dst.x = arctanh(src.x, pp);
1324 dst.y = arctanh(src.y, pp);
1325 dst.z = arctanh(src.z, pp);
1326 dst.w = arctanh(src.w, pp);
1327 }
1328
Alexis Hetuecad5192015-06-05 13:42:05 -04001329 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001330 {
1331 if(version < 0x0200)
1332 {
John Bauman19bac1e2014-05-06 15:23:49 -04001333 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001334 Float4 floor = src.x - frc;
1335
John Bauman19bac1e2014-05-06 15:23:49 -04001336 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001337 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001338 dst.z = exponential2(src.x, true);
1339 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001340 }
1341 else // Version >= 2.0
1342 {
John Bauman19bac1e2014-05-06 15:23:49 -04001343 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001344 }
1345 }
1346
Alexis Hetuecad5192015-06-05 13:42:05 -04001347 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001348 {
1349 if(version < 0x0200)
1350 {
1351 Float4 tmp0;
1352 Float4 tmp1;
1353 Float4 t;
1354 Int4 r;
1355
1356 tmp0 = Abs(src.x);
1357 tmp1 = tmp0;
1358
1359 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001360 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001361 dst.x = Float4(r);
1362
1363 // Y component
1364 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1365
1366 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001367 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001368
1369 // W component
1370 dst.w = 1.0f;
1371 }
1372 else
1373 {
John Bauman19bac1e2014-05-06 15:23:49 -04001374 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001375 }
1376 }
1377
Alexis Hetuecad5192015-06-05 13:42:05 -04001378 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001379 {
John Bauman19bac1e2014-05-06 15:23:49 -04001380 cmp0(dst.x, src0.x, src1.x, src2.x);
1381 cmp0(dst.y, src0.y, src1.y, src2.y);
1382 cmp0(dst.z, src0.z, src1.z, src2.z);
1383 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001384 }
John Bauman89401822014-05-06 15:04:28 -04001385
Alexis Hetuecad5192015-06-05 13:42:05 -04001386 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001387 {
1388 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1389 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1390 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1391 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1392 }
1393
Alexis Hetuecad5192015-06-05 13:42:05 -04001394 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001395 {
1396 select(dst, CmpEQ(src1, Float4(1.0f)), src0.y, src0.x);
1397 select(dst, CmpEQ(src1, Float4(2.0f)), src0.z, dst);
1398 select(dst, CmpEQ(src1, Float4(3.0f)), src0.w, dst);
1399 }
1400
Alexis Hetuecad5192015-06-05 13:42:05 -04001401 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001402 {
1403 select(dst.x, CmpEQ(index, Float4(0.0f)), element, src.x);
1404 select(dst.y, CmpEQ(index, Float4(1.0f)), element, src.y);
1405 select(dst.z, CmpEQ(index, Float4(2.0f)), element, src.z);
1406 select(dst.w, CmpEQ(index, Float4(3.0f)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001407 }
1408
Alexis Hetuecad5192015-06-05 13:42:05 -04001409 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001410 {
John Bauman19bac1e2014-05-06 15:23:49 -04001411 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1412 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001413 dst = As<Float4>(neg | pos);
1414 }
1415
Alexis Hetuecad5192015-06-05 13:42:05 -04001416 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001417 {
John Bauman19bac1e2014-05-06 15:23:49 -04001418 Int4 pos = CmpLE(Float4(0.0f), src0);
1419 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001420 }
1421
Alexis Hetuecad5192015-06-05 13:42:05 -04001422 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001423 {
1424 // FIXME: LLVM vector select
1425 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1426 }
1427
Alexis Hetuecad5192015-06-05 13:42:05 -04001428 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001429 {
1430 switch(control)
1431 {
John Bauman19bac1e2014-05-06 15:23:49 -04001432 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001433 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1434 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1435 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1436 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1437 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001438 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001439 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1440 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1441 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1442 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1443 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001444 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001445 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1446 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1447 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1448 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1449 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001450 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001451 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1452 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1453 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1454 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1455 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001456 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001457 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1458 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1459 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1460 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1461 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001462 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001463 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1464 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1465 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1466 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1467 break;
1468 default:
1469 ASSERT(false);
1470 }
1471 }
John Bauman19bac1e2014-05-06 15:23:49 -04001472
Alexis Hetuecad5192015-06-05 13:42:05 -04001473 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001474 {
1475 switch(control)
1476 {
1477 case Shader::CONTROL_GT:
1478 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1479 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1480 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1481 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1482 break;
1483 case Shader::CONTROL_EQ:
1484 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1485 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1486 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1487 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1488 break;
1489 case Shader::CONTROL_GE:
1490 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1491 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1492 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1493 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1494 break;
1495 case Shader::CONTROL_LT:
1496 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1497 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1498 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1499 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1500 break;
1501 case Shader::CONTROL_NE:
1502 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1503 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1504 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1505 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1506 break;
1507 case Shader::CONTROL_LE:
1508 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1509 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1510 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1511 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1512 break;
1513 default:
1514 ASSERT(false);
1515 }
1516 }
1517
Alexis Hetuecad5192015-06-05 13:42:05 -04001518 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001519 {
1520 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1521 }
1522
Alexis Hetuecad5192015-06-05 13:42:05 -04001523 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001524 {
1525 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1526 }
1527
Alexis Hetuecad5192015-06-05 13:42:05 -04001528 void ShaderCore::not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001529 {
1530 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1531 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1532 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1533 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1534 }
1535
Alexis Hetuecad5192015-06-05 13:42:05 -04001536 void ShaderCore::or(Float4 &dst, const Float4 &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001537 {
1538 dst = As<Float4>(As<Int4>(src0) | As<Int4>(src1));
1539 }
1540
Alexis Hetuecad5192015-06-05 13:42:05 -04001541 void ShaderCore::xor(Float4 &dst, const Float4 &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001542 {
1543 dst = As<Float4>(As<Int4>(src0) ^ As<Int4>(src1));
1544 }
1545
Alexis Hetuecad5192015-06-05 13:42:05 -04001546 void ShaderCore::and(Float4 &dst, const Float4 &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001547 {
1548 dst = As<Float4>(As<Int4>(src0) & As<Int4>(src1));
1549 }
John Bauman89401822014-05-06 15:04:28 -04001550}