blob: be1ca2e18e9b2bb15ce23a743a6fc2c4bc25aba1 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman89401822014-05-06 15:04:28 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman89401822014-05-06 15:04:28 -040014
15#include "ShaderCore.hpp"
16
John Bauman19bac1e2014-05-06 15:23:49 -040017#include "Renderer/Renderer.hpp"
18#include "Common/Debug.hpp"
John Bauman89401822014-05-06 15:04:28 -040019
Alexis Hetud5c31da2015-08-28 14:39:13 -040020#include <limits.h>
21
John Bauman89401822014-05-06 15:04:28 -040022namespace sw
23{
John Bauman19bac1e2014-05-06 15:23:49 -040024 extern TranscendentalPrecision logPrecision;
25 extern TranscendentalPrecision expPrecision;
26 extern TranscendentalPrecision rcpPrecision;
27 extern TranscendentalPrecision rsqPrecision;
28
Alexis Hetu96517182015-04-15 10:30:23 -040029 Vector4s::Vector4s()
John Bauman19bac1e2014-05-06 15:23:49 -040030 {
31 }
32
Alexis Hetu96517182015-04-15 10:30:23 -040033 Vector4s::Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
John Bauman19bac1e2014-05-06 15:23:49 -040034 {
35 this->x = Short4(x);
36 this->y = Short4(y);
37 this->z = Short4(z);
38 this->w = Short4(w);
39 }
40
Alexis Hetu96517182015-04-15 10:30:23 -040041 Vector4s::Vector4s(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040042 {
43 x = rhs.x;
44 y = rhs.y;
45 z = rhs.z;
46 w = rhs.w;
47 }
48
Alexis Hetu96517182015-04-15 10:30:23 -040049 Vector4s &Vector4s::operator=(const Vector4s &rhs)
John Bauman19bac1e2014-05-06 15:23:49 -040050 {
51 x = rhs.x;
52 y = rhs.y;
53 z = rhs.z;
54 w = rhs.w;
55
56 return *this;
57 }
58
Alexis Hetu96517182015-04-15 10:30:23 -040059 Short4 &Vector4s::operator[](int i)
John Bauman19bac1e2014-05-06 15:23:49 -040060 {
61 switch(i)
62 {
63 case 0: return x;
64 case 1: return y;
65 case 2: return z;
66 case 3: return w;
67 }
68
69 return x;
70 }
71
72 Vector4f::Vector4f()
73 {
74 }
75
76 Vector4f::Vector4f(float x, float y, float z, float w)
77 {
78 this->x = Float4(x);
79 this->y = Float4(y);
80 this->z = Float4(z);
81 this->w = Float4(w);
82 }
83
84 Vector4f::Vector4f(const Vector4f &rhs)
85 {
86 x = rhs.x;
87 y = rhs.y;
88 z = rhs.z;
89 w = rhs.w;
90 }
91
92 Vector4f &Vector4f::operator=(const Vector4f &rhs)
93 {
94 x = rhs.x;
95 y = rhs.y;
96 z = rhs.z;
97 w = rhs.w;
98
99 return *this;
100 }
101
102 Float4 &Vector4f::operator[](int i)
103 {
104 switch(i)
105 {
106 case 0: return x;
107 case 1: return y;
108 case 2: return z;
109 case 3: return w;
110 }
111
112 return x;
113 }
114
115 Float4 exponential2(RValue<Float4> x, bool pp)
116 {
117 Float4 x0;
118 Float4 x1;
119 Int4 x2;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400120
John Bauman19bac1e2014-05-06 15:23:49 -0400121 x0 = x;
122
123 x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
124 x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f
125 x1 = x0;
126 x1 -= Float4(0.5f);
127 x2 = RoundInt(x1);
128 x1 = Float4(x2);
129 x2 += Int4(0x0000007F); // 127
130 x2 = x2 << 23;
131 x0 -= x1;
132 x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f
133 x1 *= x0;
134 x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f
135 x1 *= x0;
136 x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f
137 x1 *= x0;
138 x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
139 x1 *= x0;
140 x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
141 x1 *= x0;
142 x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f
143 x1 *= As<Float4>(x2);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400144
John Bauman19bac1e2014-05-06 15:23:49 -0400145 return x1;
146 }
147
148 Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp)
149 {
150 Float4 x0;
151 Float4 x1;
152 Float4 x2;
153 Float4 x3;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400154
John Bauman19bac1e2014-05-06 15:23:49 -0400155 x0 = x;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400156
John Bauman19bac1e2014-05-06 15:23:49 -0400157 x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
158 x1 = As<Float4>(As<UInt4>(x1) >> 8);
159 x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
160 x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f;
161 x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
162
163 x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f);
164 x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f);
165 x2 /= x3;
166
167 x1 += (x0 - Float4(1.0f)) * x2;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400168
John Bauman19bac1e2014-05-06 15:23:49 -0400169 return x1;
170 }
171
172 Float4 exponential(RValue<Float4> x, bool pp)
173 {
174 // FIXME: Propagate the constant
175 return exponential2(Float4(1.44269541f) * x, pp); // 1/ln(2)
176 }
177
178 Float4 logarithm(RValue<Float4> x, bool absolute, bool pp)
179 {
180 // FIXME: Propagate the constant
181 return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2)
182 }
183
184 Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp)
185 {
186 Float4 log = logarithm2(x, true, pp);
187 log *= y;
188 return exponential2(log, pp);
189 }
190
Nicolas Capens05b3d662016-02-25 23:58:33 -0500191 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite, bool exactAtPow2)
John Bauman19bac1e2014-05-06 15:23:49 -0400192 {
193 Float4 rcp;
194
195 if(!pp && rcpPrecision >= WHQL)
196 {
197 rcp = Float4(1.0f) / x;
198 }
199 else
200 {
Nicolas Capens05b3d662016-02-25 23:58:33 -0500201 rcp = Rcp_pp(x, exactAtPow2);
John Bauman19bac1e2014-05-06 15:23:49 -0400202
203 if(!pp)
204 {
205 rcp = (rcp + rcp) - (x * rcp * rcp);
206 }
207 }
208
209 if(finite)
210 {
211 int big = 0x7F7FFFFF;
212 rcp = Min(rcp, Float4((float&)big));
213 }
214
215 return rcp;
216 }
217
218 Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
219 {
220 Float4 abs = x;
221
222 if(absolute)
223 {
224 abs = Abs(abs);
225 }
226
227 Float4 rsq;
228
229 if(!pp && rsqPrecision >= IEEE)
230 {
231 rsq = Float4(1.0f) / Sqrt(abs);
232 }
233 else
234 {
235 rsq = RcpSqrt_pp(abs);
236
237 if(!pp)
238 {
239 rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
240 }
241 }
242
243 int big = 0x7F7FFFFF;
244 rsq = Min(rsq, Float4((float&)big));
245
246 return rsq;
247 }
248
249 Float4 modulo(RValue<Float4> x, RValue<Float4> y)
250 {
251 return x - y * Floor(x / y);
252 }
253
254 Float4 sine_pi(RValue<Float4> x, bool pp)
255 {
256 const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2
257 const Float4 B = Float4(1.27323954e+0f); // 4/pi
258 const Float4 C = Float4(7.75160950e-1f);
259 const Float4 D = Float4(2.24839049e-1f);
260
261 // Parabola approximating sine
262 Float4 sin = x * (Abs(x) * A + B);
263
264 // Improve precision from 0.06 to 0.001
265 if(true)
266 {
267 sin = sin * (Abs(sin) * D + C);
268 }
269
270 return sin;
271 }
272
273 Float4 cosine_pi(RValue<Float4> x, bool pp)
274 {
275 // cos(x) = sin(x + pi/2)
276 Float4 y = x + Float4(1.57079632e+0f);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400277
John Bauman19bac1e2014-05-06 15:23:49 -0400278 // Wrap around
279 y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f)));
280
281 return sine_pi(y, pp);
282 }
283
284 Float4 sine(RValue<Float4> x, bool pp)
285 {
286 // Reduce to [-0.5, 0.5] range
287 Float4 y = x * Float4(1.59154943e-1f); // 1/2pi
288 y = y - Round(y);
289
290 const Float4 A = Float4(-16.0f);
291 const Float4 B = Float4(8.0f);
292 const Float4 C = Float4(7.75160950e-1f);
293 const Float4 D = Float4(2.24839049e-1f);
294
295 // Parabola approximating sine
296 Float4 sin = y * (Abs(y) * A + B);
297
298 // Improve precision from 0.06 to 0.001
299 if(true)
300 {
301 sin = sin * (Abs(sin) * D + C);
302 }
303
304 return sin;
305 }
306
307 Float4 cosine(RValue<Float4> x, bool pp)
308 {
309 // cos(x) = sin(x + pi/2)
310 Float4 y = x + Float4(1.57079632e+0f);
311 return sine(y, pp);
312 }
313
314 Float4 tangent(RValue<Float4> x, bool pp)
315 {
316 return sine(x, pp) / cosine(x, pp);
317 }
318
319 Float4 arccos(RValue<Float4> x, bool pp)
320 {
321 // pi/2 - arcsin(x)
322 return Float4(1.57079632e+0f) - arcsin(x);
323 }
324
325 Float4 arcsin(RValue<Float4> x, bool pp)
326 {
327 // x*(pi/2-sqrt(1-x*x)*pi/5)
328 return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f));
329 }
330
331 Float4 arctan(RValue<Float4> x, bool pp)
332 {
333 Int4 O = CmpNLT(Abs(x), Float4(1.0f));
334 Float4 y = As<Float4>(O & As<Int4>(Float4(1.0f) / x) | ~O & As<Int4>(x)); // FIXME: Vector select
335
336 // Approximation of atan in [-1..1]
337 Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
Nicolas Capens0bac2852016-05-07 06:09:58 -0400338
John Bauman19bac1e2014-05-06 15:23:49 -0400339 // +/-pi/2 depending on sign of x
340 Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
341
342 theta = As<Float4>(O & As<Int4>(sgnPi_2 - theta) | ~O & As<Int4>(theta)); // FIXME: Vector select
343
344 return theta;
345 }
346
347 Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp)
348 {
349 // Rotate to upper semicircle when in lower semicircle
350 Int4 S = CmpLT(y, Float4(0.0f));
351 Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi
352 Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x));
353 Float4 y0 = Abs(y);
354
355 // Rotate to right quadrant when in left quadrant
356 Int4 Q = CmpLT(x0, Float4(0.0f));
357 theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2
358 Float4 x1 = As<Float4>(Q & As<Int4>(y0) | ~Q & As<Int4>(x0)); // FIXME: Vector select
359 Float4 y1 = As<Float4>(Q & As<Int4>(-x0) | ~Q & As<Int4>(y0)); // FIXME: Vector select
360
361 // Rotate to first octant when in second octant
362 Int4 O = CmpNLT(y1, x1);
363 theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4
364 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
365 Float4 y2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1) | ~O & As<Int4>(y1)); // FIXME: Vector select
366
367 // Approximation of atan in [0..1]
368 Float4 y_x = y2 / x2;
369 theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f));
370
371 return theta;
372 }
373
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400374 Float4 sineh(RValue<Float4> x, bool pp)
375 {
376 return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f);
377 }
378
379 Float4 cosineh(RValue<Float4> x, bool pp)
380 {
381 return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f);
382 }
383
384 Float4 tangenth(RValue<Float4> x, bool pp)
385 {
386 Float4 e_x = exponential(x, pp);
387 Float4 e_minus_x = exponential(-x, pp);
388 return (e_x - e_minus_x) / (e_x + e_minus_x);
389 }
390
391 Float4 arccosh(RValue<Float4> x, bool pp)
392 {
393 return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp);
394 }
395
396 Float4 arcsinh(RValue<Float4> x, bool pp)
397 {
398 return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp);
399 }
400
401 Float4 arctanh(RValue<Float4> x, bool pp)
402 {
403 return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f);
404 }
405
Alexis Hetuecad5192015-06-05 13:42:05 -0400406 Float4 dot2(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400407 {
408 return v0.x * v1.x + v0.y * v1.y;
409 }
410
Alexis Hetuecad5192015-06-05 13:42:05 -0400411 Float4 dot3(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400412 {
413 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
414 }
415
Alexis Hetuecad5192015-06-05 13:42:05 -0400416 Float4 dot4(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400417 {
418 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w;
419 }
420
421 void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
422 {
423 Int2 tmp0 = UnpackHigh(row0, row1);
424 Int2 tmp1 = UnpackHigh(row2, row3);
425 Int2 tmp2 = UnpackLow(row0, row1);
426 Int2 tmp3 = UnpackLow(row2, row3);
427
Nicolas Capens45f187a2016-12-02 15:30:56 -0500428 row0 = UnpackLow(tmp2, tmp3);
429 row1 = UnpackHigh(tmp2, tmp3);
430 row2 = UnpackLow(tmp0, tmp1);
431 row3 = UnpackHigh(tmp0, tmp1);
John Bauman19bac1e2014-05-06 15:23:49 -0400432 }
433
434 void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
435 {
436 Float4 tmp0 = UnpackLow(row0, row1);
437 Float4 tmp1 = UnpackLow(row2, row3);
438 Float4 tmp2 = UnpackHigh(row0, row1);
439 Float4 tmp3 = UnpackHigh(row2, row3);
440
441 row0 = Float4(tmp0.xy, tmp1.xy);
442 row1 = Float4(tmp0.zw, tmp1.zw);
443 row2 = Float4(tmp2.xy, tmp3.xy);
444 row3 = Float4(tmp2.zw, tmp3.zw);
445 }
446
447 void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
448 {
449 Float4 tmp0 = UnpackLow(row0, row1);
450 Float4 tmp1 = UnpackLow(row2, row3);
451 Float4 tmp2 = UnpackHigh(row0, row1);
452 Float4 tmp3 = UnpackHigh(row2, row3);
453
454 row0 = Float4(tmp0.xy, tmp1.xy);
455 row1 = Float4(tmp0.zw, tmp1.zw);
456 row2 = Float4(tmp2.xy, tmp3.xy);
457 }
458
459 void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
460 {
461 Float4 tmp0 = UnpackLow(row0, row1);
462 Float4 tmp1 = UnpackLow(row2, row3);
463
464 row0 = Float4(tmp0.xy, tmp1.xy);
465 row1 = Float4(tmp0.zw, tmp1.zw);
466 }
467
468 void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
469 {
470 Float4 tmp0 = UnpackLow(row0, row1);
471 Float4 tmp1 = UnpackLow(row2, row3);
472
473 row0 = Float4(tmp0.xy, tmp1.xy);
474 }
475
476 void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
477 {
478 row0 = UnpackLow(row0, row1);
479 row1 = Float4(row0.zw, row1.zw);
480 row2 = UnpackHigh(row0, row1);
481 row3 = Float4(row2.zw, row3.zw);
482 }
483
484 void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
485 {
486 row0 = UnpackLow(row2, row3);
487 row1 = Float4(row0.zw, row1.zw);
488 row2 = UnpackHigh(row2, row3);
489 row3 = Float4(row2.zw, row3.zw);
490 }
491
492 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
493 {
494 switch(N)
495 {
496 case 1: transpose4x1(row0, row1, row2, row3); break;
497 case 2: transpose4x2(row0, row1, row2, row3); break;
498 case 3: transpose4x3(row0, row1, row2, row3); break;
499 case 4: transpose4x4(row0, row1, row2, row3); break;
500 }
501 }
502
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400503 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400504 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400505 if(integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400506 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400507 dst.x = As<Float4>(RoundInt(src.x));
508 dst.y = As<Float4>(RoundInt(src.y));
509 dst.z = As<Float4>(RoundInt(src.z));
510 dst.w = As<Float4>(RoundInt(src.w));
John Bauman89401822014-05-06 15:04:28 -0400511 }
512 else
513 {
514 dst = src;
515 }
516 }
517
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400518 void ShaderCore::neg(Vector4f &dst, const Vector4f &src)
519 {
520 dst.x = -src.x;
521 dst.y = -src.y;
522 dst.z = -src.z;
523 dst.w = -src.w;
524 }
525
526 void ShaderCore::ineg(Vector4f &dst, const Vector4f &src)
527 {
528 dst.x = As<Float4>(-As<Int4>(src.x));
529 dst.y = As<Float4>(-As<Int4>(src.y));
530 dst.z = As<Float4>(-As<Int4>(src.z));
531 dst.w = As<Float4>(-As<Int4>(src.w));
532 }
533
Alexis Hetuecad5192015-06-05 13:42:05 -0400534 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400535 {
536 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
537 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
538 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
539 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
540 }
541
Alexis Hetuecad5192015-06-05 13:42:05 -0400542 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400543 {
544 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
545 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
546 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
547 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
548 }
549
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400550 void ShaderCore::f2i(Vector4f &dst, const Vector4f &src)
551 {
552 dst.x = As<Float4>(Int4(src.x));
553 dst.y = As<Float4>(Int4(src.y));
554 dst.z = As<Float4>(Int4(src.z));
555 dst.w = As<Float4>(Int4(src.w));
556 }
557
558 void ShaderCore::i2f(Vector4f &dst, const Vector4f &src)
559 {
560 dst.x = Float4(As<Int4>(src.x));
561 dst.y = Float4(As<Int4>(src.y));
562 dst.z = Float4(As<Int4>(src.z));
563 dst.w = Float4(As<Int4>(src.w));
564 }
565
566 void ShaderCore::f2u(Vector4f &dst, const Vector4f &src)
567 {
568 dst.x = As<Float4>(UInt4(src.x));
569 dst.y = As<Float4>(UInt4(src.y));
570 dst.z = As<Float4>(UInt4(src.z));
571 dst.w = As<Float4>(UInt4(src.w));
572 }
573
574 void ShaderCore::u2f(Vector4f &dst, const Vector4f &src)
575 {
576 dst.x = Float4(As<UInt4>(src.x));
577 dst.y = Float4(As<UInt4>(src.y));
578 dst.z = Float4(As<UInt4>(src.z));
579 dst.w = Float4(As<UInt4>(src.w));
580 }
581
582 void ShaderCore::i2b(Vector4f &dst, const Vector4f &src)
583 {
584 dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0)));
585 dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0)));
586 dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0)));
587 dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0)));
588 }
589
590 void ShaderCore::b2i(Vector4f &dst, const Vector4f &src)
591 {
592 dst.x = As<Float4>(As<Int4>(src.x) & Int4(1));
593 dst.y = As<Float4>(As<Int4>(src.y) & Int4(1));
594 dst.z = As<Float4>(As<Int4>(src.z) & Int4(1));
595 dst.w = As<Float4>(As<Int4>(src.w) & Int4(1));
596 }
597
Alexis Hetuecad5192015-06-05 13:42:05 -0400598 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400599 {
600 dst.x = src0.x + src1.x;
601 dst.y = src0.y + src1.y;
602 dst.z = src0.z + src1.z;
603 dst.w = src0.w + src1.w;
604 }
605
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400606 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
607 {
608 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
609 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
610 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
611 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
612 }
613
Alexis Hetuecad5192015-06-05 13:42:05 -0400614 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400615 {
616 dst.x = src0.x - src1.x;
617 dst.y = src0.y - src1.y;
618 dst.z = src0.z - src1.z;
619 dst.w = src0.w - src1.w;
620 }
621
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400622 void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
623 {
624 dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x));
625 dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y));
626 dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z));
627 dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w));
628 }
629
Alexis Hetuecad5192015-06-05 13:42:05 -0400630 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400631 {
632 dst.x = src0.x * src1.x + src2.x;
633 dst.y = src0.y * src1.y + src2.y;
634 dst.z = src0.z * src1.z + src2.z;
635 dst.w = src0.w * src1.w + src2.w;
636 }
637
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400638 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
639 {
640 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
641 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
642 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
643 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
644 }
645
Alexis Hetuecad5192015-06-05 13:42:05 -0400646 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400647 {
648 dst.x = src0.x * src1.x;
649 dst.y = src0.y * src1.y;
650 dst.z = src0.z * src1.z;
651 dst.w = src0.w * src1.w;
652 }
653
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400654 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
655 {
656 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
657 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
658 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
659 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
660 }
661
Alexis Hetuecad5192015-06-05 13:42:05 -0400662 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400663 {
664 Float4 rcp = reciprocal(src.x, pp, true);
665
666 dst.x = rcp;
667 dst.y = rcp;
668 dst.z = rcp;
669 dst.w = rcp;
670 }
671
Alexis Hetuecad5192015-06-05 13:42:05 -0400672 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400673 {
674 dst.x = src0.x / src1.x;
675 dst.y = src0.y / src1.y;
676 dst.z = src0.z / src1.z;
677 dst.w = src0.w / src1.w;
678 }
679
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400680 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
681 {
682 Float4 intMax(As<Float4>(Int4(INT_MAX)));
683 cmp0i(dst.x, src1.x, intMax, src1.x);
684 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
685 cmp0i(dst.y, src1.y, intMax, src1.y);
686 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
687 cmp0i(dst.z, src1.z, intMax, src1.z);
688 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
689 cmp0i(dst.w, src1.w, intMax, src1.w);
690 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
691 }
692
693 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
694 {
695 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
696 cmp0i(dst.x, src1.x, uintMax, src1.x);
697 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
698 cmp0i(dst.y, src1.y, uintMax, src1.y);
699 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
700 cmp0i(dst.z, src1.z, uintMax, src1.z);
701 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
702 cmp0i(dst.w, src1.w, uintMax, src1.w);
703 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
704 }
705
Alexis Hetuecad5192015-06-05 13:42:05 -0400706 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400707 {
708 dst.x = modulo(src0.x, src1.x);
709 dst.y = modulo(src0.y, src1.y);
710 dst.z = modulo(src0.z, src1.z);
711 dst.w = modulo(src0.w, src1.w);
712 }
713
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400714 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
715 {
716 cmp0i(dst.x, src1.x, src0.x, src1.x);
717 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
718 cmp0i(dst.y, src1.y, src0.y, src1.y);
719 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
720 cmp0i(dst.z, src1.z, src0.z, src1.z);
721 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
722 cmp0i(dst.w, src1.w, src0.w, src1.w);
723 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
724 }
725 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
726 {
727 cmp0i(dst.x, src1.x, src0.x, src1.x);
728 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
729 cmp0i(dst.y, src1.y, src0.y, src1.y);
730 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
731 cmp0i(dst.z, src1.z, src0.z, src1.z);
732 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
733 cmp0i(dst.w, src1.w, src0.w, src1.w);
734 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
735 }
736
737 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
738 {
739 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
740 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
741 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
742 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
743 }
744
745 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
746 {
747 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
748 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
749 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
750 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
751 }
752
753 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
754 {
755 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
756 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
757 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
758 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
759 }
760
Alexis Hetuecad5192015-06-05 13:42:05 -0400761 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400762 {
763 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
764
John Bauman19bac1e2014-05-06 15:23:49 -0400765 dst.x = rsq;
766 dst.y = rsq;
767 dst.z = rsq;
768 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400769 }
770
Alexis Hetuecad5192015-06-05 13:42:05 -0400771 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400772 {
773 dst.x = Sqrt(src.x);
774 dst.y = Sqrt(src.y);
775 dst.z = Sqrt(src.z);
776 dst.w = Sqrt(src.w);
777 }
778
Alexis Hetuecad5192015-06-05 13:42:05 -0400779 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400780 {
781 dst.x = reciprocalSquareRoot(src.x, false, pp);
782 dst.y = reciprocalSquareRoot(src.y, false, pp);
783 dst.z = reciprocalSquareRoot(src.z, false, pp);
784 dst.w = reciprocalSquareRoot(src.w, false, pp);
785 }
786
Alexis Hetuecad5192015-06-05 13:42:05 -0400787 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400788 {
789 dst = Sqrt(dot2(src, src));
790 }
791
Alexis Hetuecad5192015-06-05 13:42:05 -0400792 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400793 {
794 dst = Sqrt(dot3(src, src));
795 }
796
Alexis Hetuecad5192015-06-05 13:42:05 -0400797 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400798 {
799 dst = Sqrt(dot4(src, src));
800 }
801
Alexis Hetuecad5192015-06-05 13:42:05 -0400802 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400803 {
804 dst = Abs(src0.x - src1.x);
805 }
806
Alexis Hetuecad5192015-06-05 13:42:05 -0400807 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400808 {
809 Float4 dx = src0.x - src1.x;
810 Float4 dy = src0.y - src1.y;
811 Float4 dot2 = dx * dx + dy * dy;
812 dst = Sqrt(dot2);
813 }
814
Alexis Hetuecad5192015-06-05 13:42:05 -0400815 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400816 {
817 Float4 dx = src0.x - src1.x;
818 Float4 dy = src0.y - src1.y;
819 Float4 dz = src0.z - src1.z;
820 Float4 dot3 = dx * dx + dy * dy + dz * dz;
821 dst = Sqrt(dot3);
822 }
823
Alexis Hetuecad5192015-06-05 13:42:05 -0400824 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400825 {
826 Float4 dx = src0.x - src1.x;
827 Float4 dy = src0.y - src1.y;
828 Float4 dz = src0.z - src1.z;
829 Float4 dw = src0.w - src1.w;
830 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
831 dst = Sqrt(dot4);
832 }
833
Alexis Hetuecad5192015-06-05 13:42:05 -0400834 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400835 {
836 Float4 t = src0.x * src1.x;
837
838 dst.x = t;
839 dst.y = t;
840 dst.z = t;
841 dst.w = t;
842 }
843
Alexis Hetuecad5192015-06-05 13:42:05 -0400844 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400845 {
846 Float4 t = dot2(src0, src1);
847
848 dst.x = t;
849 dst.y = t;
850 dst.z = t;
851 dst.w = t;
852 }
853
Alexis Hetuecad5192015-06-05 13:42:05 -0400854 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400855 {
856 Float4 t = dot2(src0, src1) + src2.x;
857
858 dst.x = t;
859 dst.y = t;
860 dst.z = t;
861 dst.w = t;
862 }
863
Alexis Hetuecad5192015-06-05 13:42:05 -0400864 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400865 {
866 Float4 dot = dot3(src0, src1);
867
868 dst.x = dot;
869 dst.y = dot;
870 dst.z = dot;
871 dst.w = dot;
872 }
873
Alexis Hetuecad5192015-06-05 13:42:05 -0400874 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400875 {
876 Float4 dot = dot4(src0, src1);
877
878 dst.x = dot;
879 dst.y = dot;
880 dst.z = dot;
881 dst.w = dot;
882 }
883
Alexis Hetuecad5192015-06-05 13:42:05 -0400884 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400885 {
886 dst.x = Min(src0.x, src1.x);
887 dst.y = Min(src0.y, src1.y);
888 dst.z = Min(src0.z, src1.z);
889 dst.w = Min(src0.w, src1.w);
890 }
891
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400892 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
893 {
894 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
895 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
896 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
897 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
898 }
899
900 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
901 {
902 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
903 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
904 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
905 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
906 }
907
Alexis Hetuecad5192015-06-05 13:42:05 -0400908 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400909 {
910 dst.x = Max(src0.x, src1.x);
911 dst.y = Max(src0.y, src1.y);
912 dst.z = Max(src0.z, src1.z);
913 dst.w = Max(src0.w, src1.w);
914 }
915
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400916 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
917 {
918 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
919 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
920 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
921 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
922 }
923
924 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
925 {
926 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
927 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
928 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
929 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
930 }
931
Alexis Hetuecad5192015-06-05 13:42:05 -0400932 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400933 {
John Bauman19bac1e2014-05-06 15:23:49 -0400934 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
935 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
936 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
937 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400938 }
939
Alexis Hetuecad5192015-06-05 13:42:05 -0400940 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -0400941 {
John Bauman19bac1e2014-05-06 15:23:49 -0400942 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
943 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
944 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
945 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400946 }
947
Alexis Hetuecad5192015-06-05 13:42:05 -0400948 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
Nicolas Capens0bac2852016-05-07 06:09:58 -0400949 {
John Bauman19bac1e2014-05-06 15:23:49 -0400950 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -0400951
952 dst.x = exp;
953 dst.y = exp;
954 dst.z = exp;
955 dst.w = exp;
956 }
957
Alexis Hetuecad5192015-06-05 13:42:05 -0400958 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400959 {
John Bauman19bac1e2014-05-06 15:23:49 -0400960 dst.x = exponential2(src.x, pp);
961 dst.y = exponential2(src.y, pp);
962 dst.z = exponential2(src.z, pp);
963 dst.w = exponential2(src.w, pp);
964 }
965
Alexis Hetuecad5192015-06-05 13:42:05 -0400966 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400967 {
968 dst.x = exponential(src.x, pp);
969 dst.y = exponential(src.y, pp);
970 dst.z = exponential(src.z, pp);
971 dst.w = exponential(src.w, pp);
972 }
973
Alexis Hetuecad5192015-06-05 13:42:05 -0400974 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400975 {
976 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -0400977
978 dst.x = log;
979 dst.y = log;
980 dst.z = log;
981 dst.w = log;
982 }
983
Alexis Hetuecad5192015-06-05 13:42:05 -0400984 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400985 {
John Bauman19bac1e2014-05-06 15:23:49 -0400986 dst.x = logarithm2(src.x, pp);
987 dst.y = logarithm2(src.y, pp);
988 dst.z = logarithm2(src.z, pp);
989 dst.w = logarithm2(src.w, pp);
990 }
991
Alexis Hetuecad5192015-06-05 13:42:05 -0400992 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400993 {
994 dst.x = logarithm(src.x, false, pp);
995 dst.y = logarithm(src.y, false, pp);
996 dst.z = logarithm(src.z, false, pp);
997 dst.w = logarithm(src.w, false, pp);
998 }
999
Alexis Hetuecad5192015-06-05 13:42:05 -04001000 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001001 {
1002 dst.x = Float4(1.0f);
1003 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001004
1005 Float4 pow;
1006
1007 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001008 pow = Min(pow, Float4(127.9961f));
1009 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001010
1011 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001012 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1013 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001014
John Bauman19bac1e2014-05-06 15:23:49 -04001015 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001016 }
1017
Alexis Hetuecad5192015-06-05 13:42:05 -04001018 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001019 {
John Bauman19bac1e2014-05-06 15:23:49 -04001020 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001021 dst.x = 1;
1022 dst.y = src0.y * src1.y;
1023 dst.z = src0.z;
1024 dst.w = src1.w;
1025 }
1026
Alexis Hetuecad5192015-06-05 13:42:05 -04001027 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001028 {
1029 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1030 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1031 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1032 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1033 }
1034
Alexis Hetuecad5192015-06-05 13:42:05 -04001035 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001036 {
John Bauman19bac1e2014-05-06 15:23:49 -04001037 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);
1038 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);
1039 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);
1040 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 -04001041 }
1042
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001043 void ShaderCore::floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits)
1044 {
1045 static const uint32_t mask_sign = 0x80000000u;
1046 static const uint32_t mask_round = ~0xfffu;
1047 static const uint32_t c_f32infty = 255 << 23;
1048 static const uint32_t c_magic = 15 << 23;
1049 static const uint32_t c_nanbit = 0x200;
1050 static const uint32_t c_infty_as_fp16 = 0x7c00;
1051 static const uint32_t c_clamp = (31 << 23) - 0x1000;
Nicolas Capens0bac2852016-05-07 06:09:58 -04001052
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001053 UInt4 justsign = UInt4(mask_sign) & As<UInt4>(floatBits);
1054 UInt4 absf = As<UInt4>(floatBits) ^ justsign;
1055 UInt4 b_isnormal = CmpNLE(UInt4(c_f32infty), absf);
1056
1057 // Note: this version doesn't round to the nearest even in case of a tie as defined by IEEE 754-2008, it rounds to +inf
1058 // instead of nearest even, since that's fine for GLSL ES 3.0's needs (see section 2.1.1 Floating-Point Computation)
1059 UInt4 joined = ((((As<UInt4>(Min(As<Float4>(absf & UInt4(mask_round)) * As<Float4>(UInt4(c_magic)),
1060 As<Float4>(UInt4(c_clamp))))) - UInt4(mask_round)) >> 13) & b_isnormal) |
1061 ((b_isnormal ^ UInt4(0xFFFFFFFF)) & ((CmpNLE(absf, UInt4(c_f32infty)) & UInt4(c_nanbit)) |
1062 UInt4(c_infty_as_fp16)));
1063
1064 dst = As<Float4>(storeInUpperBits ? As<UInt4>(dst) | ((joined << 16) | justsign) : joined | (justsign >> 16));
1065 }
1066
1067 void ShaderCore::halfToFloatBits(Float4& dst, const Float4& halfBits)
1068 {
1069 static const uint32_t mask_nosign = 0x7FFF;
1070 static const uint32_t magic = (254 - 15) << 23;
1071 static const uint32_t was_infnan = 0x7BFF;
1072 static const uint32_t exp_infnan = 255 << 23;
1073
1074 UInt4 expmant = As<UInt4>(halfBits) & UInt4(mask_nosign);
1075 dst = As<Float4>(As<UInt4>(As<Float4>(expmant << 13) * As<Float4>(UInt4(magic))) |
1076 ((As<UInt4>(halfBits) ^ UInt4(expmant)) << 16) |
1077 (CmpNLE(As<UInt4>(expmant), UInt4(was_infnan)) & UInt4(exp_infnan)));
1078 }
1079
1080 void ShaderCore::packHalf2x16(Vector4f &d, const Vector4f &s0)
1081 {
1082 // half2 | half1
1083 floatToHalfBits(d.x, s0.x, false);
1084 floatToHalfBits(d.x, s0.y, true);
1085 }
1086
1087 void ShaderCore::unpackHalf2x16(Vector4f &dst, const Vector4f &s0)
1088 {
1089 // half2 | half1
1090 halfToFloatBits(dst.x, As<Float4>(As<UInt4>(s0.x) & UInt4(0x0000FFFF)));
1091 halfToFloatBits(dst.y, As<Float4>((As<UInt4>(s0.x) & UInt4(0xFFFF0000)) >> 16));
1092 }
1093
Alexis Hetu9cde9742016-04-06 13:03:38 -04001094 void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0)
1095 {
1096 // round(clamp(c, -1.0, 1.0) * 32767.0)
1097 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) |
1098 ((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16));
1099 }
1100
1101 void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0)
1102 {
1103 // round(clamp(c, 0.0, 1.0) * 65535.0)
1104 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) |
1105 ((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16));
1106 }
1107
1108 void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0)
1109 {
1110 // clamp(f / 32727.0, -1.0, 1.0)
1111 dst.x = Min(Max(Float4(As<Int4>((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16)) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1112 dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1113 }
1114
1115 void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0)
1116 {
1117 // f / 65535.0
1118 dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000));
1119 dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000));
1120 }
1121
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001122 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1123 {
1124 dst.x = src0.x * src1.y - src0.y * src1.x;
1125 dst.y = dst.z = dst.w = dst.x;
1126 }
1127
1128 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1129 {
1130 crs(dst, src1, src2);
1131 dp3(dst, dst, src0);
1132 }
1133
1134 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1135 {
1136 dst.x = src2.z * src3.w - src2.w * src3.z;
1137 dst.y = src1.w * src3.z - src1.z * src3.w;
1138 dst.z = src1.z * src2.w - src1.w * src2.z;
1139 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1140 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1141 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1142 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1143 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1144 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1145 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1146 src3.x * (src1.z * src2.y - src1.y * src2.z));
1147 dst.y = dst.z = dst.w = dst.x;
1148 }
1149
Alexis Hetuecad5192015-06-05 13:42:05 -04001150 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001151 {
1152 dst.x = Frac(src.x);
1153 dst.y = Frac(src.y);
1154 dst.z = Frac(src.z);
1155 dst.w = Frac(src.w);
1156 }
1157
Alexis Hetuecad5192015-06-05 13:42:05 -04001158 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001159 {
1160 dst.x = Trunc(src.x);
1161 dst.y = Trunc(src.y);
1162 dst.z = Trunc(src.z);
1163 dst.w = Trunc(src.w);
1164 }
1165
Alexis Hetuecad5192015-06-05 13:42:05 -04001166 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001167 {
1168 dst.x = Floor(src.x);
1169 dst.y = Floor(src.y);
1170 dst.z = Floor(src.z);
1171 dst.w = Floor(src.w);
1172 }
1173
Alexis Hetuecad5192015-06-05 13:42:05 -04001174 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001175 {
1176 dst.x = Round(src.x);
1177 dst.y = Round(src.y);
1178 dst.z = Round(src.z);
1179 dst.w = Round(src.w);
1180 }
1181
Alexis Hetuecad5192015-06-05 13:42:05 -04001182 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001183 {
1184 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1185 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1186 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1187 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1188 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1189 // Even if the round implementation rounds the other way:
1190 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1191 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1192 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1193 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1194 round(dst, src);
1195 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));
1196 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));
1197 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));
1198 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));
1199 }
1200
Alexis Hetuecad5192015-06-05 13:42:05 -04001201 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001202 {
1203 dst.x = Ceil(src.x);
1204 dst.y = Ceil(src.y);
1205 dst.z = Ceil(src.z);
1206 dst.w = Ceil(src.w);
1207 }
1208
Alexis Hetuecad5192015-06-05 13:42:05 -04001209 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001210 {
1211 Float4 pow = power(src0.x, src1.x, pp);
1212
1213 dst.x = pow;
1214 dst.y = pow;
1215 dst.z = pow;
1216 dst.w = pow;
1217 }
1218
Alexis Hetuecad5192015-06-05 13:42:05 -04001219 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001220 {
1221 dst.x = power(src0.x, src1.x, pp);
1222 dst.y = power(src0.y, src1.y, pp);
1223 dst.z = power(src0.z, src1.z, pp);
1224 dst.w = power(src0.w, src1.w, pp);
1225 }
1226
Alexis Hetuecad5192015-06-05 13:42:05 -04001227 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001228 {
1229 dst.x = src0.y * src1.z - src0.z * src1.y;
1230 dst.y = src0.z * src1.x - src0.x * src1.z;
1231 dst.z = src0.x * src1.y - src0.y * src1.x;
1232 }
1233
Alexis Hetuecad5192015-06-05 13:42:05 -04001234 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001235 {
1236 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1237
1238 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1239 }
1240
Alexis Hetuecad5192015-06-05 13:42:05 -04001241 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001242 {
1243 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1244
1245 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1246 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1247 }
1248
Alexis Hetuecad5192015-06-05 13:42:05 -04001249 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001250 {
1251 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1252
1253 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1254 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1255 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1256 }
1257
Alexis Hetuecad5192015-06-05 13:42:05 -04001258 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001259 {
1260 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1261
1262 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1263 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1264 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1265 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1266 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001267
Alexis Hetuecad5192015-06-05 13:42:05 -04001268 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001269 {
1270 Float4 d = N.x * I.x;
1271
1272 dst.x = I.x - Float4(2.0f) * d * N.x;
1273 }
1274
Alexis Hetuecad5192015-06-05 13:42:05 -04001275 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001276 {
1277 Float4 d = dot2(N, I);
1278
1279 dst.x = I.x - Float4(2.0f) * d * N.x;
1280 dst.y = I.y - Float4(2.0f) * d * N.y;
1281 }
1282
Alexis Hetuecad5192015-06-05 13:42:05 -04001283 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001284 {
1285 Float4 d = dot3(N, I);
1286
1287 dst.x = I.x - Float4(2.0f) * d * N.x;
1288 dst.y = I.y - Float4(2.0f) * d * N.y;
1289 dst.z = I.z - Float4(2.0f) * d * N.z;
1290 }
1291
Alexis Hetuecad5192015-06-05 13:42:05 -04001292 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001293 {
1294 Float4 d = dot4(N, I);
1295
1296 dst.x = I.x - Float4(2.0f) * d * N.x;
1297 dst.y = I.y - Float4(2.0f) * d * N.y;
1298 dst.z = I.z - Float4(2.0f) * d * N.z;
1299 dst.w = I.w - Float4(2.0f) * d * N.w;
1300 }
1301
Alexis Hetuecad5192015-06-05 13:42:05 -04001302 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001303 {
1304 Float4 d = N.x * I.x;
1305 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1306 Int4 pos = CmpNLT(k, Float4(0.0f));
1307 Float4 t = (eta * d + Sqrt(k));
1308
1309 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1310 }
1311
Alexis Hetuecad5192015-06-05 13:42:05 -04001312 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001313 {
1314 Float4 d = dot2(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 }
1322
Alexis Hetuecad5192015-06-05 13:42:05 -04001323 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001324 {
1325 Float4 d = dot3(N, I);
1326 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1327 Int4 pos = CmpNLT(k, Float4(0.0f));
1328 Float4 t = (eta * d + Sqrt(k));
1329
1330 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1331 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1332 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1333 }
1334
Alexis Hetuecad5192015-06-05 13:42:05 -04001335 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001336 {
1337 Float4 d = dot4(N, I);
1338 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1339 Int4 pos = CmpNLT(k, Float4(0.0f));
1340 Float4 t = (eta * d + Sqrt(k));
1341
1342 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1343 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1344 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1345 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1346 }
1347
Alexis Hetuecad5192015-06-05 13:42:05 -04001348 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001349 {
1350 sgn(dst.x, src.x);
1351 sgn(dst.y, src.y);
1352 sgn(dst.z, src.z);
1353 sgn(dst.w, src.w);
1354 }
1355
Alexis Hetu0f448072016-03-18 10:56:08 -04001356 void ShaderCore::isgn(Vector4f &dst, const Vector4f &src)
1357 {
1358 isgn(dst.x, src.x);
1359 isgn(dst.y, src.y);
1360 isgn(dst.z, src.z);
1361 isgn(dst.w, src.w);
1362 }
1363
Alexis Hetuecad5192015-06-05 13:42:05 -04001364 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001365 {
1366 dst.x = Abs(src.x);
1367 dst.y = Abs(src.y);
1368 dst.z = Abs(src.z);
1369 dst.w = Abs(src.w);
1370 }
Alexis Hetu0f448072016-03-18 10:56:08 -04001371
1372 void ShaderCore::iabs(Vector4f &dst, const Vector4f &src)
1373 {
1374 dst.x = As<Float4>(Abs(As<Int4>(src.x)));
1375 dst.y = As<Float4>(Abs(As<Int4>(src.y)));
1376 dst.z = As<Float4>(Abs(As<Int4>(src.z)));
1377 dst.w = As<Float4>(Abs(As<Int4>(src.w)));
1378 }
1379
Alexis Hetuecad5192015-06-05 13:42:05 -04001380 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001381 {
1382 Float4 dot = dot2(src, src);
1383 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001384
John Bauman19bac1e2014-05-06 15:23:49 -04001385 dst.x = src.x * rsq;
1386 dst.y = src.y * rsq;
1387 dst.z = src.z * rsq;
1388 dst.w = src.w * rsq;
1389 }
1390
Alexis Hetuecad5192015-06-05 13:42:05 -04001391 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001392 {
1393 Float4 dot = dot3(src, src);
1394 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1395
1396 dst.x = src.x * rsq;
1397 dst.y = src.y * rsq;
1398 dst.z = src.z * rsq;
1399 dst.w = src.w * rsq;
1400 }
John Bauman19bac1e2014-05-06 15:23:49 -04001401
Alexis Hetuecad5192015-06-05 13:42:05 -04001402 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001403 {
John Bauman19bac1e2014-05-06 15:23:49 -04001404 Float4 dot = dot4(src, src);
1405 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001406
John Bauman19bac1e2014-05-06 15:23:49 -04001407 dst.x = src.x * rsq;
1408 dst.y = src.y * rsq;
1409 dst.z = src.z * rsq;
1410 dst.w = src.w * rsq;
1411 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001412
Alexis Hetuecad5192015-06-05 13:42:05 -04001413 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001414 {
1415 dst.x = cosine_pi(src.x, pp);
1416 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001417 }
1418
Alexis Hetuecad5192015-06-05 13:42:05 -04001419 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001420 {
1421 dst.x = cosine(src.x, pp);
1422 dst.y = cosine(src.y, pp);
1423 dst.z = cosine(src.z, pp);
1424 dst.w = cosine(src.w, pp);
1425 }
1426
Alexis Hetuecad5192015-06-05 13:42:05 -04001427 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001428 {
1429 dst.x = sine(src.x, pp);
1430 dst.y = sine(src.y, pp);
1431 dst.z = sine(src.z, pp);
1432 dst.w = sine(src.w, pp);
1433 }
1434
Alexis Hetuecad5192015-06-05 13:42:05 -04001435 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001436 {
1437 dst.x = tangent(src.x, pp);
1438 dst.y = tangent(src.y, pp);
1439 dst.z = tangent(src.z, pp);
1440 dst.w = tangent(src.w, pp);
1441 }
1442
Alexis Hetuecad5192015-06-05 13:42:05 -04001443 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001444 {
1445 dst.x = arccos(src.x, pp);
1446 dst.y = arccos(src.y, pp);
1447 dst.z = arccos(src.z, pp);
1448 dst.w = arccos(src.w, pp);
1449 }
1450
Alexis Hetuecad5192015-06-05 13:42:05 -04001451 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001452 {
1453 dst.x = arcsin(src.x, pp);
1454 dst.y = arcsin(src.y, pp);
1455 dst.z = arcsin(src.z, pp);
1456 dst.w = arcsin(src.w, pp);
1457 }
1458
Alexis Hetuecad5192015-06-05 13:42:05 -04001459 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001460 {
1461 dst.x = arctan(src.x, pp);
1462 dst.y = arctan(src.y, pp);
1463 dst.z = arctan(src.z, pp);
1464 dst.w = arctan(src.w, pp);
1465 }
1466
Alexis Hetuecad5192015-06-05 13:42:05 -04001467 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001468 {
1469 dst.x = arctan(src0.x, src1.x, pp);
1470 dst.y = arctan(src0.y, src1.y, pp);
1471 dst.z = arctan(src0.z, src1.z, pp);
1472 dst.w = arctan(src0.w, src1.w, pp);
1473 }
1474
Alexis Hetuecad5192015-06-05 13:42:05 -04001475 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001476 {
1477 dst.x = cosineh(src.x, pp);
1478 dst.y = cosineh(src.y, pp);
1479 dst.z = cosineh(src.z, pp);
1480 dst.w = cosineh(src.w, pp);
1481 }
1482
Alexis Hetuecad5192015-06-05 13:42:05 -04001483 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001484 {
1485 dst.x = sineh(src.x, pp);
1486 dst.y = sineh(src.y, pp);
1487 dst.z = sineh(src.z, pp);
1488 dst.w = sineh(src.w, pp);
1489 }
1490
Alexis Hetuecad5192015-06-05 13:42:05 -04001491 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001492 {
1493 dst.x = tangenth(src.x, pp);
1494 dst.y = tangenth(src.y, pp);
1495 dst.z = tangenth(src.z, pp);
1496 dst.w = tangenth(src.w, pp);
1497 }
1498
Alexis Hetuecad5192015-06-05 13:42:05 -04001499 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001500 {
1501 dst.x = arccosh(src.x, pp);
1502 dst.y = arccosh(src.y, pp);
1503 dst.z = arccosh(src.z, pp);
1504 dst.w = arccosh(src.w, pp);
1505 }
1506
Alexis Hetuecad5192015-06-05 13:42:05 -04001507 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001508 {
1509 dst.x = arcsinh(src.x, pp);
1510 dst.y = arcsinh(src.y, pp);
1511 dst.z = arcsinh(src.z, pp);
1512 dst.w = arcsinh(src.w, pp);
1513 }
1514
Alexis Hetuecad5192015-06-05 13:42:05 -04001515 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001516 {
1517 dst.x = arctanh(src.x, pp);
1518 dst.y = arctanh(src.y, pp);
1519 dst.z = arctanh(src.z, pp);
1520 dst.w = arctanh(src.w, pp);
1521 }
1522
Alexis Hetuecad5192015-06-05 13:42:05 -04001523 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001524 {
1525 if(version < 0x0200)
1526 {
John Bauman19bac1e2014-05-06 15:23:49 -04001527 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001528 Float4 floor = src.x - frc;
1529
John Bauman19bac1e2014-05-06 15:23:49 -04001530 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001531 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001532 dst.z = exponential2(src.x, true);
1533 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001534 }
1535 else // Version >= 2.0
1536 {
John Bauman19bac1e2014-05-06 15:23:49 -04001537 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001538 }
1539 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001540
Alexis Hetuecad5192015-06-05 13:42:05 -04001541 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001542 {
1543 if(version < 0x0200)
1544 {
1545 Float4 tmp0;
1546 Float4 tmp1;
1547 Float4 t;
1548 Int4 r;
1549
1550 tmp0 = Abs(src.x);
1551 tmp1 = tmp0;
1552
1553 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001554 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001555 dst.x = Float4(r);
1556
1557 // Y component
1558 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1559
1560 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001561 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001562
1563 // W component
1564 dst.w = 1.0f;
1565 }
1566 else
1567 {
John Bauman19bac1e2014-05-06 15:23:49 -04001568 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001569 }
1570 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001571
Alexis Hetuecad5192015-06-05 13:42:05 -04001572 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001573 {
John Bauman19bac1e2014-05-06 15:23:49 -04001574 cmp0(dst.x, src0.x, src1.x, src2.x);
1575 cmp0(dst.y, src0.y, src1.y, src2.y);
1576 cmp0(dst.z, src0.z, src1.z, src2.z);
1577 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001578 }
John Bauman89401822014-05-06 15:04:28 -04001579
Alexis Hetuecad5192015-06-05 13:42:05 -04001580 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001581 {
1582 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1583 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1584 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1585 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1586 }
1587
Alexis Hetuecad5192015-06-05 13:42:05 -04001588 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001589 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001590 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1591 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1592 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001593 }
1594
Alexis Hetuecad5192015-06-05 13:42:05 -04001595 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001596 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001597 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1598 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1599 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1600 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001601 }
1602
Alexis Hetuecad5192015-06-05 13:42:05 -04001603 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001604 {
John Bauman19bac1e2014-05-06 15:23:49 -04001605 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1606 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001607 dst = As<Float4>(neg | pos);
1608 }
1609
Alexis Hetu0f448072016-03-18 10:56:08 -04001610 void ShaderCore::isgn(Float4 &dst, const Float4 &src)
1611 {
1612 Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1);
1613 Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1);
1614 dst = As<Float4>(neg | pos);
1615 }
1616
Alexis Hetuecad5192015-06-05 13:42:05 -04001617 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001618 {
John Bauman19bac1e2014-05-06 15:23:49 -04001619 Int4 pos = CmpLE(Float4(0.0f), src0);
1620 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001621 }
1622
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001623 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1624 {
1625 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1626 select(dst, pos, src1, src2);
1627 }
1628
Alexis Hetuecad5192015-06-05 13:42:05 -04001629 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001630 {
1631 // FIXME: LLVM vector select
1632 dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2));
1633 }
1634
Alexis Hetuecad5192015-06-05 13:42:05 -04001635 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001636 {
1637 switch(control)
1638 {
John Bauman19bac1e2014-05-06 15:23:49 -04001639 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001640 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1641 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1642 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1643 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1644 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001645 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001646 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1647 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1648 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1649 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1650 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001651 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001652 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1653 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1654 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1655 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1656 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001657 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001658 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1659 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1660 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1661 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1662 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001663 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001664 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1665 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1666 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1667 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1668 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001669 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001670 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1671 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1672 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1673 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1674 break;
1675 default:
1676 ASSERT(false);
1677 }
1678 }
John Bauman19bac1e2014-05-06 15:23:49 -04001679
Alexis Hetuecad5192015-06-05 13:42:05 -04001680 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001681 {
1682 switch(control)
1683 {
1684 case Shader::CONTROL_GT:
1685 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1686 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1687 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1688 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1689 break;
1690 case Shader::CONTROL_EQ:
1691 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1692 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1693 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1694 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1695 break;
1696 case Shader::CONTROL_GE:
1697 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1698 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1699 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1700 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1701 break;
1702 case Shader::CONTROL_LT:
1703 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1704 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1705 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1706 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1707 break;
1708 case Shader::CONTROL_NE:
1709 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1710 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1711 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1712 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1713 break;
1714 case Shader::CONTROL_LE:
1715 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1716 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1717 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1718 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1719 break;
1720 default:
1721 ASSERT(false);
1722 }
1723 }
1724
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001725 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1726 {
1727 switch(control)
1728 {
1729 case Shader::CONTROL_GT:
1730 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1731 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1732 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1733 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1734 break;
1735 case Shader::CONTROL_EQ:
1736 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1737 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1738 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1739 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1740 break;
1741 case Shader::CONTROL_GE:
1742 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1743 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1744 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1745 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1746 break;
1747 case Shader::CONTROL_LT:
1748 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1749 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1750 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1751 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1752 break;
1753 case Shader::CONTROL_NE:
1754 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1755 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1756 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1757 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1758 break;
1759 case Shader::CONTROL_LE:
1760 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1761 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1762 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1763 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1764 break;
1765 default:
1766 ASSERT(false);
1767 }
1768 }
1769
Alexis Hetuecad5192015-06-05 13:42:05 -04001770 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001771 {
1772 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1773 }
1774
Alexis Hetuecad5192015-06-05 13:42:05 -04001775 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001776 {
1777 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1778 }
1779
Alexis Hetu24f454e2016-08-31 17:22:13 -04001780 void ShaderCore::bitwise_not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001781 {
1782 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1783 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1784 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1785 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1786 }
1787
Alexis Hetu24f454e2016-08-31 17:22:13 -04001788 void ShaderCore::bitwise_or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001789 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001790 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1791 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1792 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1793 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001794 }
1795
Alexis Hetu24f454e2016-08-31 17:22:13 -04001796 void ShaderCore::bitwise_xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001797 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001798 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1799 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1800 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1801 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001802 }
1803
Alexis Hetu24f454e2016-08-31 17:22:13 -04001804 void ShaderCore::bitwise_and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001805 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001806 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1807 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1808 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1809 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1810 }
1811
1812 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1813 {
1814 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1815 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1816 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1817 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1818 dst.y = dst.x;
1819 dst.z = dst.x;
1820 dst.w = dst.x;
1821 }
1822
1823 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1824 {
1825 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1826 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1827 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1828 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1829 dst.y = dst.x;
1830 dst.z = dst.x;
1831 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001832 }
John Bauman89401822014-05-06 15:04:28 -04001833}