blob: dfe3e78fa3bec695f0631a2851216b79b1301e8b [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));
Tom Anderson69bc6e82017-03-20 11:54:29 -0700334 Float4 y = As<Float4>((O & As<Int4>(Float4(1.0f) / x)) | (~O & As<Int4>(x))); // FIXME: Vector select
John Bauman19bac1e2014-05-06 15:23:49 -0400335
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
Tom Anderson69bc6e82017-03-20 11:54:29 -0700342 theta = As<Float4>((O & As<Int4>(sgnPi_2 - theta)) | (~O & As<Int4>(theta))); // FIXME: Vector select
John Bauman19bac1e2014-05-06 15:23:49 -0400343
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
Tom Anderson69bc6e82017-03-20 11:54:29 -0700358 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
John Bauman19bac1e2014-05-06 15:23:49 -0400360
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
Tom Anderson69bc6e82017-03-20 11:54:29 -0700364 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
John Bauman19bac1e2014-05-06 15:23:49 -0400366
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 {
Nicolas Capens54ac5e82016-12-09 14:07:50 -0500478 Float4 tmp01 = UnpackLow(row0, row1);
479 Float4 tmp23 = UnpackHigh(row0, row1);
John Bauman19bac1e2014-05-06 15:23:49 -0400480
Nicolas Capens54ac5e82016-12-09 14:07:50 -0500481 row0 = tmp01;
482 row1 = Float4(tmp01.zw, row1.zw);
483 row2 = tmp23;
484 row3 = Float4(tmp23.zw, row3.zw);
John Bauman19bac1e2014-05-06 15:23:49 -0400485 }
486
487 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
488 {
489 switch(N)
490 {
491 case 1: transpose4x1(row0, row1, row2, row3); break;
492 case 2: transpose4x2(row0, row1, row2, row3); break;
493 case 3: transpose4x3(row0, row1, row2, row3); break;
494 case 4: transpose4x4(row0, row1, row2, row3); break;
495 }
496 }
497
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400498 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400499 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400500 if(integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400501 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400502 dst.x = As<Float4>(RoundInt(src.x));
503 dst.y = As<Float4>(RoundInt(src.y));
504 dst.z = As<Float4>(RoundInt(src.z));
505 dst.w = As<Float4>(RoundInt(src.w));
John Bauman89401822014-05-06 15:04:28 -0400506 }
507 else
508 {
509 dst = src;
510 }
511 }
512
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400513 void ShaderCore::neg(Vector4f &dst, const Vector4f &src)
514 {
515 dst.x = -src.x;
516 dst.y = -src.y;
517 dst.z = -src.z;
518 dst.w = -src.w;
519 }
520
521 void ShaderCore::ineg(Vector4f &dst, const Vector4f &src)
522 {
523 dst.x = As<Float4>(-As<Int4>(src.x));
524 dst.y = As<Float4>(-As<Int4>(src.y));
525 dst.z = As<Float4>(-As<Int4>(src.z));
526 dst.w = As<Float4>(-As<Int4>(src.w));
527 }
528
Alexis Hetuecad5192015-06-05 13:42:05 -0400529 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400530 {
531 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
532 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
533 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
534 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
535 }
536
Alexis Hetuecad5192015-06-05 13:42:05 -0400537 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400538 {
539 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
540 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
541 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
542 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
543 }
544
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400545 void ShaderCore::f2i(Vector4f &dst, const Vector4f &src)
546 {
547 dst.x = As<Float4>(Int4(src.x));
548 dst.y = As<Float4>(Int4(src.y));
549 dst.z = As<Float4>(Int4(src.z));
550 dst.w = As<Float4>(Int4(src.w));
551 }
552
553 void ShaderCore::i2f(Vector4f &dst, const Vector4f &src)
554 {
555 dst.x = Float4(As<Int4>(src.x));
556 dst.y = Float4(As<Int4>(src.y));
557 dst.z = Float4(As<Int4>(src.z));
558 dst.w = Float4(As<Int4>(src.w));
559 }
560
561 void ShaderCore::f2u(Vector4f &dst, const Vector4f &src)
562 {
563 dst.x = As<Float4>(UInt4(src.x));
564 dst.y = As<Float4>(UInt4(src.y));
565 dst.z = As<Float4>(UInt4(src.z));
566 dst.w = As<Float4>(UInt4(src.w));
567 }
568
569 void ShaderCore::u2f(Vector4f &dst, const Vector4f &src)
570 {
571 dst.x = Float4(As<UInt4>(src.x));
572 dst.y = Float4(As<UInt4>(src.y));
573 dst.z = Float4(As<UInt4>(src.z));
574 dst.w = Float4(As<UInt4>(src.w));
575 }
576
577 void ShaderCore::i2b(Vector4f &dst, const Vector4f &src)
578 {
579 dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0)));
580 dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0)));
581 dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0)));
582 dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0)));
583 }
584
585 void ShaderCore::b2i(Vector4f &dst, const Vector4f &src)
586 {
587 dst.x = As<Float4>(As<Int4>(src.x) & Int4(1));
588 dst.y = As<Float4>(As<Int4>(src.y) & Int4(1));
589 dst.z = As<Float4>(As<Int4>(src.z) & Int4(1));
590 dst.w = As<Float4>(As<Int4>(src.w) & Int4(1));
591 }
592
Alexis Hetuecad5192015-06-05 13:42:05 -0400593 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400594 {
595 dst.x = src0.x + src1.x;
596 dst.y = src0.y + src1.y;
597 dst.z = src0.z + src1.z;
598 dst.w = src0.w + src1.w;
599 }
600
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400601 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
602 {
603 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
604 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
605 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
606 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
607 }
608
Alexis Hetuecad5192015-06-05 13:42:05 -0400609 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400610 {
611 dst.x = src0.x - src1.x;
612 dst.y = src0.y - src1.y;
613 dst.z = src0.z - src1.z;
614 dst.w = src0.w - src1.w;
615 }
616
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400617 void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
618 {
619 dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x));
620 dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y));
621 dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z));
622 dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w));
623 }
624
Alexis Hetuecad5192015-06-05 13:42:05 -0400625 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400626 {
627 dst.x = src0.x * src1.x + src2.x;
628 dst.y = src0.y * src1.y + src2.y;
629 dst.z = src0.z * src1.z + src2.z;
630 dst.w = src0.w * src1.w + src2.w;
631 }
632
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400633 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
634 {
635 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
636 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
637 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
638 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
639 }
640
Alexis Hetuecad5192015-06-05 13:42:05 -0400641 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400642 {
643 dst.x = src0.x * src1.x;
644 dst.y = src0.y * src1.y;
645 dst.z = src0.z * src1.z;
646 dst.w = src0.w * src1.w;
647 }
648
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400649 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
650 {
651 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
652 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
653 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
654 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
655 }
656
Alexis Hetuecad5192015-06-05 13:42:05 -0400657 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400658 {
659 Float4 rcp = reciprocal(src.x, pp, true);
660
661 dst.x = rcp;
662 dst.y = rcp;
663 dst.z = rcp;
664 dst.w = rcp;
665 }
666
Alexis Hetuecad5192015-06-05 13:42:05 -0400667 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400668 {
669 dst.x = src0.x / src1.x;
670 dst.y = src0.y / src1.y;
671 dst.z = src0.z / src1.z;
672 dst.w = src0.w / src1.w;
673 }
674
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400675 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
676 {
677 Float4 intMax(As<Float4>(Int4(INT_MAX)));
678 cmp0i(dst.x, src1.x, intMax, src1.x);
679 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
680 cmp0i(dst.y, src1.y, intMax, src1.y);
681 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
682 cmp0i(dst.z, src1.z, intMax, src1.z);
683 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
684 cmp0i(dst.w, src1.w, intMax, src1.w);
685 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
686 }
687
688 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
689 {
690 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
691 cmp0i(dst.x, src1.x, uintMax, src1.x);
692 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
693 cmp0i(dst.y, src1.y, uintMax, src1.y);
694 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
695 cmp0i(dst.z, src1.z, uintMax, src1.z);
696 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
697 cmp0i(dst.w, src1.w, uintMax, src1.w);
698 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
699 }
700
Alexis Hetuecad5192015-06-05 13:42:05 -0400701 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400702 {
703 dst.x = modulo(src0.x, src1.x);
704 dst.y = modulo(src0.y, src1.y);
705 dst.z = modulo(src0.z, src1.z);
706 dst.w = modulo(src0.w, src1.w);
707 }
708
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400709 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
710 {
Alexis Hetu28958102017-10-02 13:48:19 -0400711 Float4 intMax(As<Float4>(Int4(INT_MAX)));
712 cmp0i(dst.x, src1.x, intMax, src1.x);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400713 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
Alexis Hetu28958102017-10-02 13:48:19 -0400714 cmp0i(dst.y, src1.y, intMax, src1.y);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400715 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
Alexis Hetu28958102017-10-02 13:48:19 -0400716 cmp0i(dst.z, src1.z, intMax, src1.z);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400717 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
Alexis Hetu28958102017-10-02 13:48:19 -0400718 cmp0i(dst.w, src1.w, intMax, src1.w);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400719 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
720 }
Alexis Hetu28958102017-10-02 13:48:19 -0400721
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400722 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
723 {
Alexis Hetu28958102017-10-02 13:48:19 -0400724 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
725 cmp0i(dst.x, src1.x, uintMax, src1.x);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400726 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
Alexis Hetu28958102017-10-02 13:48:19 -0400727 cmp0i(dst.y, src1.y, uintMax, src1.y);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400728 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
Alexis Hetu28958102017-10-02 13:48:19 -0400729 cmp0i(dst.z, src1.z, uintMax, src1.z);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400730 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
Alexis Hetu28958102017-10-02 13:48:19 -0400731 cmp0i(dst.w, src1.w, uintMax, src1.w);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400732 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
733 }
734
735 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
736 {
737 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
738 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
739 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
740 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
741 }
742
743 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
744 {
745 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
746 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
747 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
748 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
749 }
750
751 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
752 {
753 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
754 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
755 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
756 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
757 }
758
Alexis Hetuecad5192015-06-05 13:42:05 -0400759 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400760 {
761 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
762
John Bauman19bac1e2014-05-06 15:23:49 -0400763 dst.x = rsq;
764 dst.y = rsq;
765 dst.z = rsq;
766 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400767 }
768
Alexis Hetuecad5192015-06-05 13:42:05 -0400769 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400770 {
771 dst.x = Sqrt(src.x);
772 dst.y = Sqrt(src.y);
773 dst.z = Sqrt(src.z);
774 dst.w = Sqrt(src.w);
775 }
776
Alexis Hetuecad5192015-06-05 13:42:05 -0400777 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400778 {
779 dst.x = reciprocalSquareRoot(src.x, false, pp);
780 dst.y = reciprocalSquareRoot(src.y, false, pp);
781 dst.z = reciprocalSquareRoot(src.z, false, pp);
782 dst.w = reciprocalSquareRoot(src.w, false, pp);
783 }
784
Alexis Hetuecad5192015-06-05 13:42:05 -0400785 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400786 {
787 dst = Sqrt(dot2(src, src));
788 }
789
Alexis Hetuecad5192015-06-05 13:42:05 -0400790 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400791 {
792 dst = Sqrt(dot3(src, src));
793 }
794
Alexis Hetuecad5192015-06-05 13:42:05 -0400795 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400796 {
797 dst = Sqrt(dot4(src, src));
798 }
799
Alexis Hetuecad5192015-06-05 13:42:05 -0400800 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400801 {
802 dst = Abs(src0.x - src1.x);
803 }
804
Alexis Hetuecad5192015-06-05 13:42:05 -0400805 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400806 {
807 Float4 dx = src0.x - src1.x;
808 Float4 dy = src0.y - src1.y;
809 Float4 dot2 = dx * dx + dy * dy;
810 dst = Sqrt(dot2);
811 }
812
Alexis Hetuecad5192015-06-05 13:42:05 -0400813 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400814 {
815 Float4 dx = src0.x - src1.x;
816 Float4 dy = src0.y - src1.y;
817 Float4 dz = src0.z - src1.z;
818 Float4 dot3 = dx * dx + dy * dy + dz * dz;
819 dst = Sqrt(dot3);
820 }
821
Alexis Hetuecad5192015-06-05 13:42:05 -0400822 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400823 {
824 Float4 dx = src0.x - src1.x;
825 Float4 dy = src0.y - src1.y;
826 Float4 dz = src0.z - src1.z;
827 Float4 dw = src0.w - src1.w;
828 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
829 dst = Sqrt(dot4);
830 }
831
Alexis Hetuecad5192015-06-05 13:42:05 -0400832 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400833 {
834 Float4 t = src0.x * src1.x;
835
836 dst.x = t;
837 dst.y = t;
838 dst.z = t;
839 dst.w = t;
840 }
841
Alexis Hetuecad5192015-06-05 13:42:05 -0400842 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400843 {
844 Float4 t = dot2(src0, src1);
845
846 dst.x = t;
847 dst.y = t;
848 dst.z = t;
849 dst.w = t;
850 }
851
Alexis Hetuecad5192015-06-05 13:42:05 -0400852 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400853 {
854 Float4 t = dot2(src0, src1) + src2.x;
855
856 dst.x = t;
857 dst.y = t;
858 dst.z = t;
859 dst.w = t;
860 }
861
Alexis Hetuecad5192015-06-05 13:42:05 -0400862 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400863 {
864 Float4 dot = dot3(src0, src1);
865
866 dst.x = dot;
867 dst.y = dot;
868 dst.z = dot;
869 dst.w = dot;
870 }
871
Alexis Hetuecad5192015-06-05 13:42:05 -0400872 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400873 {
874 Float4 dot = dot4(src0, src1);
875
876 dst.x = dot;
877 dst.y = dot;
878 dst.z = dot;
879 dst.w = dot;
880 }
881
Alexis Hetuecad5192015-06-05 13:42:05 -0400882 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400883 {
884 dst.x = Min(src0.x, src1.x);
885 dst.y = Min(src0.y, src1.y);
886 dst.z = Min(src0.z, src1.z);
887 dst.w = Min(src0.w, src1.w);
888 }
889
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400890 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
891 {
892 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
893 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
894 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
895 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
896 }
897
898 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
899 {
900 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
901 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
902 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
903 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
904 }
905
Alexis Hetuecad5192015-06-05 13:42:05 -0400906 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400907 {
908 dst.x = Max(src0.x, src1.x);
909 dst.y = Max(src0.y, src1.y);
910 dst.z = Max(src0.z, src1.z);
911 dst.w = Max(src0.w, src1.w);
912 }
913
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400914 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
915 {
916 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
917 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
918 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
919 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
920 }
921
922 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
923 {
924 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
925 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
926 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
927 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
928 }
929
Alexis Hetuecad5192015-06-05 13:42:05 -0400930 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400931 {
John Bauman19bac1e2014-05-06 15:23:49 -0400932 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
933 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
934 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
935 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400936 }
937
Alexis Hetuecad5192015-06-05 13:42:05 -0400938 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -0400939 {
John Bauman19bac1e2014-05-06 15:23:49 -0400940 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
941 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
942 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
943 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400944 }
945
Alexis Hetuecad5192015-06-05 13:42:05 -0400946 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
Nicolas Capens0bac2852016-05-07 06:09:58 -0400947 {
John Bauman19bac1e2014-05-06 15:23:49 -0400948 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -0400949
950 dst.x = exp;
951 dst.y = exp;
952 dst.z = exp;
953 dst.w = exp;
954 }
955
Alexis Hetuecad5192015-06-05 13:42:05 -0400956 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400957 {
John Bauman19bac1e2014-05-06 15:23:49 -0400958 dst.x = exponential2(src.x, pp);
959 dst.y = exponential2(src.y, pp);
960 dst.z = exponential2(src.z, pp);
961 dst.w = exponential2(src.w, pp);
962 }
963
Alexis Hetuecad5192015-06-05 13:42:05 -0400964 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400965 {
966 dst.x = exponential(src.x, pp);
967 dst.y = exponential(src.y, pp);
968 dst.z = exponential(src.z, pp);
969 dst.w = exponential(src.w, pp);
970 }
971
Alexis Hetuecad5192015-06-05 13:42:05 -0400972 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400973 {
974 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -0400975
976 dst.x = log;
977 dst.y = log;
978 dst.z = log;
979 dst.w = log;
980 }
981
Alexis Hetuecad5192015-06-05 13:42:05 -0400982 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400983 {
Alexis Hetua781af72017-07-06 17:12:47 -0400984 dst.x = logarithm2(src.x, false, pp);
985 dst.y = logarithm2(src.y, false, pp);
986 dst.z = logarithm2(src.z, false, pp);
987 dst.w = logarithm2(src.w, false, pp);
John Bauman19bac1e2014-05-06 15:23:49 -0400988 }
989
Alexis Hetuecad5192015-06-05 13:42:05 -0400990 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400991 {
992 dst.x = logarithm(src.x, false, pp);
993 dst.y = logarithm(src.y, false, pp);
994 dst.z = logarithm(src.z, false, pp);
995 dst.w = logarithm(src.w, false, pp);
996 }
997
Alexis Hetuecad5192015-06-05 13:42:05 -0400998 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400999 {
1000 dst.x = Float4(1.0f);
1001 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001002
1003 Float4 pow;
1004
1005 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001006 pow = Min(pow, Float4(127.9961f));
1007 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001008
1009 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001010 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1011 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001012
John Bauman19bac1e2014-05-06 15:23:49 -04001013 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001014 }
1015
Alexis Hetuecad5192015-06-05 13:42:05 -04001016 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001017 {
John Bauman19bac1e2014-05-06 15:23:49 -04001018 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001019 dst.x = 1;
1020 dst.y = src0.y * src1.y;
1021 dst.z = src0.z;
1022 dst.w = src1.w;
1023 }
1024
Alexis Hetuecad5192015-06-05 13:42:05 -04001025 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001026 {
1027 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1028 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1029 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1030 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1031 }
1032
Alexis Hetu8ef6d102017-11-09 15:49:09 -05001033 void ShaderCore::isinf(Vector4f &dst, const Vector4f &src)
1034 {
1035 dst.x = As<Float4>(IsInf(src.x));
1036 dst.y = As<Float4>(IsInf(src.y));
1037 dst.z = As<Float4>(IsInf(src.z));
1038 dst.w = As<Float4>(IsInf(src.w));
1039 }
1040
1041 void ShaderCore::isnan(Vector4f &dst, const Vector4f &src)
1042 {
1043 dst.x = As<Float4>(IsNan(src.x));
1044 dst.y = As<Float4>(IsNan(src.y));
1045 dst.z = As<Float4>(IsNan(src.z));
1046 dst.w = As<Float4>(IsNan(src.w));
1047 }
1048
Alexis Hetuecad5192015-06-05 13:42:05 -04001049 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001050 {
John Bauman19bac1e2014-05-06 15:23:49 -04001051 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);
1052 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);
1053 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);
1054 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 -04001055 }
1056
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001057 void ShaderCore::floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits)
1058 {
1059 static const uint32_t mask_sign = 0x80000000u;
1060 static const uint32_t mask_round = ~0xfffu;
1061 static const uint32_t c_f32infty = 255 << 23;
1062 static const uint32_t c_magic = 15 << 23;
1063 static const uint32_t c_nanbit = 0x200;
1064 static const uint32_t c_infty_as_fp16 = 0x7c00;
1065 static const uint32_t c_clamp = (31 << 23) - 0x1000;
Nicolas Capens0bac2852016-05-07 06:09:58 -04001066
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001067 UInt4 justsign = UInt4(mask_sign) & As<UInt4>(floatBits);
1068 UInt4 absf = As<UInt4>(floatBits) ^ justsign;
1069 UInt4 b_isnormal = CmpNLE(UInt4(c_f32infty), absf);
1070
1071 // 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
1072 // instead of nearest even, since that's fine for GLSL ES 3.0's needs (see section 2.1.1 Floating-Point Computation)
1073 UInt4 joined = ((((As<UInt4>(Min(As<Float4>(absf & UInt4(mask_round)) * As<Float4>(UInt4(c_magic)),
1074 As<Float4>(UInt4(c_clamp))))) - UInt4(mask_round)) >> 13) & b_isnormal) |
1075 ((b_isnormal ^ UInt4(0xFFFFFFFF)) & ((CmpNLE(absf, UInt4(c_f32infty)) & UInt4(c_nanbit)) |
1076 UInt4(c_infty_as_fp16)));
1077
1078 dst = As<Float4>(storeInUpperBits ? As<UInt4>(dst) | ((joined << 16) | justsign) : joined | (justsign >> 16));
1079 }
1080
1081 void ShaderCore::halfToFloatBits(Float4& dst, const Float4& halfBits)
1082 {
1083 static const uint32_t mask_nosign = 0x7FFF;
1084 static const uint32_t magic = (254 - 15) << 23;
1085 static const uint32_t was_infnan = 0x7BFF;
1086 static const uint32_t exp_infnan = 255 << 23;
1087
1088 UInt4 expmant = As<UInt4>(halfBits) & UInt4(mask_nosign);
1089 dst = As<Float4>(As<UInt4>(As<Float4>(expmant << 13) * As<Float4>(UInt4(magic))) |
1090 ((As<UInt4>(halfBits) ^ UInt4(expmant)) << 16) |
1091 (CmpNLE(As<UInt4>(expmant), UInt4(was_infnan)) & UInt4(exp_infnan)));
1092 }
1093
1094 void ShaderCore::packHalf2x16(Vector4f &d, const Vector4f &s0)
1095 {
1096 // half2 | half1
1097 floatToHalfBits(d.x, s0.x, false);
1098 floatToHalfBits(d.x, s0.y, true);
1099 }
1100
1101 void ShaderCore::unpackHalf2x16(Vector4f &dst, const Vector4f &s0)
1102 {
1103 // half2 | half1
1104 halfToFloatBits(dst.x, As<Float4>(As<UInt4>(s0.x) & UInt4(0x0000FFFF)));
1105 halfToFloatBits(dst.y, As<Float4>((As<UInt4>(s0.x) & UInt4(0xFFFF0000)) >> 16));
1106 }
1107
Alexis Hetu9cde9742016-04-06 13:03:38 -04001108 void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0)
1109 {
1110 // round(clamp(c, -1.0, 1.0) * 32767.0)
1111 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) |
1112 ((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16));
1113 }
1114
1115 void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0)
1116 {
1117 // round(clamp(c, 0.0, 1.0) * 65535.0)
1118 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) |
1119 ((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16));
1120 }
1121
1122 void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0)
1123 {
1124 // clamp(f / 32727.0, -1.0, 1.0)
1125 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));
1126 dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1127 }
1128
1129 void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0)
1130 {
1131 // f / 65535.0
1132 dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000));
1133 dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000));
1134 }
1135
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001136 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1137 {
1138 dst.x = src0.x * src1.y - src0.y * src1.x;
1139 dst.y = dst.z = dst.w = dst.x;
1140 }
1141
1142 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1143 {
1144 crs(dst, src1, src2);
1145 dp3(dst, dst, src0);
1146 }
1147
1148 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1149 {
1150 dst.x = src2.z * src3.w - src2.w * src3.z;
1151 dst.y = src1.w * src3.z - src1.z * src3.w;
1152 dst.z = src1.z * src2.w - src1.w * src2.z;
1153 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1154 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1155 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1156 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1157 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1158 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1159 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1160 src3.x * (src1.z * src2.y - src1.y * src2.z));
1161 dst.y = dst.z = dst.w = dst.x;
1162 }
1163
Alexis Hetuecad5192015-06-05 13:42:05 -04001164 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001165 {
1166 dst.x = Frac(src.x);
1167 dst.y = Frac(src.y);
1168 dst.z = Frac(src.z);
1169 dst.w = Frac(src.w);
1170 }
1171
Alexis Hetuecad5192015-06-05 13:42:05 -04001172 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001173 {
1174 dst.x = Trunc(src.x);
1175 dst.y = Trunc(src.y);
1176 dst.z = Trunc(src.z);
1177 dst.w = Trunc(src.w);
1178 }
1179
Alexis Hetuecad5192015-06-05 13:42:05 -04001180 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001181 {
1182 dst.x = Floor(src.x);
1183 dst.y = Floor(src.y);
1184 dst.z = Floor(src.z);
1185 dst.w = Floor(src.w);
1186 }
1187
Alexis Hetuecad5192015-06-05 13:42:05 -04001188 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001189 {
1190 dst.x = Round(src.x);
1191 dst.y = Round(src.y);
1192 dst.z = Round(src.z);
1193 dst.w = Round(src.w);
1194 }
1195
Alexis Hetuecad5192015-06-05 13:42:05 -04001196 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001197 {
1198 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1199 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1200 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1201 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1202 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1203 // Even if the round implementation rounds the other way:
1204 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1205 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1206 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1207 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1208 round(dst, src);
1209 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));
1210 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));
1211 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));
1212 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));
1213 }
1214
Alexis Hetuecad5192015-06-05 13:42:05 -04001215 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001216 {
1217 dst.x = Ceil(src.x);
1218 dst.y = Ceil(src.y);
1219 dst.z = Ceil(src.z);
1220 dst.w = Ceil(src.w);
1221 }
1222
Alexis Hetuecad5192015-06-05 13:42:05 -04001223 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001224 {
1225 Float4 pow = power(src0.x, src1.x, pp);
1226
1227 dst.x = pow;
1228 dst.y = pow;
1229 dst.z = pow;
1230 dst.w = pow;
1231 }
1232
Alexis Hetuecad5192015-06-05 13:42:05 -04001233 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001234 {
1235 dst.x = power(src0.x, src1.x, pp);
1236 dst.y = power(src0.y, src1.y, pp);
1237 dst.z = power(src0.z, src1.z, pp);
1238 dst.w = power(src0.w, src1.w, pp);
1239 }
1240
Alexis Hetuecad5192015-06-05 13:42:05 -04001241 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001242 {
1243 dst.x = src0.y * src1.z - src0.z * src1.y;
1244 dst.y = src0.z * src1.x - src0.x * src1.z;
1245 dst.z = src0.x * src1.y - src0.y * src1.x;
1246 }
1247
Alexis Hetuecad5192015-06-05 13:42:05 -04001248 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001249 {
1250 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1251
1252 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1253 }
1254
Alexis Hetuecad5192015-06-05 13:42:05 -04001255 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001256 {
1257 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1258
1259 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1260 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1261 }
1262
Alexis Hetuecad5192015-06-05 13:42:05 -04001263 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001264 {
1265 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1266
1267 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1268 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1269 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1270 }
1271
Alexis Hetuecad5192015-06-05 13:42:05 -04001272 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001273 {
1274 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1275
1276 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1277 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1278 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1279 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1280 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001281
Alexis Hetuecad5192015-06-05 13:42:05 -04001282 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001283 {
1284 Float4 d = N.x * I.x;
1285
1286 dst.x = I.x - Float4(2.0f) * d * N.x;
1287 }
1288
Alexis Hetuecad5192015-06-05 13:42:05 -04001289 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001290 {
1291 Float4 d = dot2(N, I);
1292
1293 dst.x = I.x - Float4(2.0f) * d * N.x;
1294 dst.y = I.y - Float4(2.0f) * d * N.y;
1295 }
1296
Alexis Hetuecad5192015-06-05 13:42:05 -04001297 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001298 {
1299 Float4 d = dot3(N, I);
1300
1301 dst.x = I.x - Float4(2.0f) * d * N.x;
1302 dst.y = I.y - Float4(2.0f) * d * N.y;
1303 dst.z = I.z - Float4(2.0f) * d * N.z;
1304 }
1305
Alexis Hetuecad5192015-06-05 13:42:05 -04001306 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001307 {
1308 Float4 d = dot4(N, I);
1309
1310 dst.x = I.x - Float4(2.0f) * d * N.x;
1311 dst.y = I.y - Float4(2.0f) * d * N.y;
1312 dst.z = I.z - Float4(2.0f) * d * N.z;
1313 dst.w = I.w - Float4(2.0f) * d * N.w;
1314 }
1315
Alexis Hetuecad5192015-06-05 13:42:05 -04001316 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001317 {
1318 Float4 d = N.x * I.x;
1319 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1320 Int4 pos = CmpNLT(k, Float4(0.0f));
1321 Float4 t = (eta * d + Sqrt(k));
1322
1323 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1324 }
1325
Alexis Hetuecad5192015-06-05 13:42:05 -04001326 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001327 {
1328 Float4 d = dot2(N, I);
1329 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1330 Int4 pos = CmpNLT(k, Float4(0.0f));
1331 Float4 t = (eta * d + Sqrt(k));
1332
1333 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1334 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1335 }
1336
Alexis Hetuecad5192015-06-05 13:42:05 -04001337 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001338 {
1339 Float4 d = dot3(N, I);
1340 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1341 Int4 pos = CmpNLT(k, Float4(0.0f));
1342 Float4 t = (eta * d + Sqrt(k));
1343
1344 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1345 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1346 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1347 }
1348
Alexis Hetuecad5192015-06-05 13:42:05 -04001349 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001350 {
1351 Float4 d = dot4(N, I);
1352 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1353 Int4 pos = CmpNLT(k, Float4(0.0f));
1354 Float4 t = (eta * d + Sqrt(k));
1355
1356 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1357 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1358 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1359 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1360 }
1361
Alexis Hetuecad5192015-06-05 13:42:05 -04001362 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001363 {
1364 sgn(dst.x, src.x);
1365 sgn(dst.y, src.y);
1366 sgn(dst.z, src.z);
1367 sgn(dst.w, src.w);
1368 }
1369
Alexis Hetu0f448072016-03-18 10:56:08 -04001370 void ShaderCore::isgn(Vector4f &dst, const Vector4f &src)
1371 {
1372 isgn(dst.x, src.x);
1373 isgn(dst.y, src.y);
1374 isgn(dst.z, src.z);
1375 isgn(dst.w, src.w);
1376 }
1377
Alexis Hetuecad5192015-06-05 13:42:05 -04001378 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001379 {
1380 dst.x = Abs(src.x);
1381 dst.y = Abs(src.y);
1382 dst.z = Abs(src.z);
1383 dst.w = Abs(src.w);
1384 }
Alexis Hetu0f448072016-03-18 10:56:08 -04001385
1386 void ShaderCore::iabs(Vector4f &dst, const Vector4f &src)
1387 {
1388 dst.x = As<Float4>(Abs(As<Int4>(src.x)));
1389 dst.y = As<Float4>(Abs(As<Int4>(src.y)));
1390 dst.z = As<Float4>(Abs(As<Int4>(src.z)));
1391 dst.w = As<Float4>(Abs(As<Int4>(src.w)));
1392 }
1393
Alexis Hetuecad5192015-06-05 13:42:05 -04001394 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001395 {
1396 Float4 dot = dot2(src, src);
1397 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001398
John Bauman19bac1e2014-05-06 15:23:49 -04001399 dst.x = src.x * rsq;
1400 dst.y = src.y * rsq;
1401 dst.z = src.z * rsq;
1402 dst.w = src.w * rsq;
1403 }
1404
Alexis Hetuecad5192015-06-05 13:42:05 -04001405 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001406 {
1407 Float4 dot = dot3(src, src);
1408 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1409
1410 dst.x = src.x * rsq;
1411 dst.y = src.y * rsq;
1412 dst.z = src.z * rsq;
1413 dst.w = src.w * rsq;
1414 }
John Bauman19bac1e2014-05-06 15:23:49 -04001415
Alexis Hetuecad5192015-06-05 13:42:05 -04001416 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001417 {
John Bauman19bac1e2014-05-06 15:23:49 -04001418 Float4 dot = dot4(src, src);
1419 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001420
John Bauman19bac1e2014-05-06 15:23:49 -04001421 dst.x = src.x * rsq;
1422 dst.y = src.y * rsq;
1423 dst.z = src.z * rsq;
1424 dst.w = src.w * rsq;
1425 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001426
Alexis Hetuecad5192015-06-05 13:42:05 -04001427 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001428 {
1429 dst.x = cosine_pi(src.x, pp);
1430 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001431 }
1432
Alexis Hetuecad5192015-06-05 13:42:05 -04001433 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001434 {
1435 dst.x = cosine(src.x, pp);
1436 dst.y = cosine(src.y, pp);
1437 dst.z = cosine(src.z, pp);
1438 dst.w = cosine(src.w, pp);
1439 }
1440
Alexis Hetuecad5192015-06-05 13:42:05 -04001441 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001442 {
1443 dst.x = sine(src.x, pp);
1444 dst.y = sine(src.y, pp);
1445 dst.z = sine(src.z, pp);
1446 dst.w = sine(src.w, pp);
1447 }
1448
Alexis Hetuecad5192015-06-05 13:42:05 -04001449 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001450 {
1451 dst.x = tangent(src.x, pp);
1452 dst.y = tangent(src.y, pp);
1453 dst.z = tangent(src.z, pp);
1454 dst.w = tangent(src.w, pp);
1455 }
1456
Alexis Hetuecad5192015-06-05 13:42:05 -04001457 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001458 {
1459 dst.x = arccos(src.x, pp);
1460 dst.y = arccos(src.y, pp);
1461 dst.z = arccos(src.z, pp);
1462 dst.w = arccos(src.w, pp);
1463 }
1464
Alexis Hetuecad5192015-06-05 13:42:05 -04001465 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001466 {
1467 dst.x = arcsin(src.x, pp);
1468 dst.y = arcsin(src.y, pp);
1469 dst.z = arcsin(src.z, pp);
1470 dst.w = arcsin(src.w, pp);
1471 }
1472
Alexis Hetuecad5192015-06-05 13:42:05 -04001473 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001474 {
1475 dst.x = arctan(src.x, pp);
1476 dst.y = arctan(src.y, pp);
1477 dst.z = arctan(src.z, pp);
1478 dst.w = arctan(src.w, pp);
1479 }
1480
Alexis Hetuecad5192015-06-05 13:42:05 -04001481 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001482 {
1483 dst.x = arctan(src0.x, src1.x, pp);
1484 dst.y = arctan(src0.y, src1.y, pp);
1485 dst.z = arctan(src0.z, src1.z, pp);
1486 dst.w = arctan(src0.w, src1.w, pp);
1487 }
1488
Alexis Hetuecad5192015-06-05 13:42:05 -04001489 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001490 {
1491 dst.x = cosineh(src.x, pp);
1492 dst.y = cosineh(src.y, pp);
1493 dst.z = cosineh(src.z, pp);
1494 dst.w = cosineh(src.w, pp);
1495 }
1496
Alexis Hetuecad5192015-06-05 13:42:05 -04001497 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001498 {
1499 dst.x = sineh(src.x, pp);
1500 dst.y = sineh(src.y, pp);
1501 dst.z = sineh(src.z, pp);
1502 dst.w = sineh(src.w, pp);
1503 }
1504
Alexis Hetuecad5192015-06-05 13:42:05 -04001505 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001506 {
1507 dst.x = tangenth(src.x, pp);
1508 dst.y = tangenth(src.y, pp);
1509 dst.z = tangenth(src.z, pp);
1510 dst.w = tangenth(src.w, pp);
1511 }
1512
Alexis Hetuecad5192015-06-05 13:42:05 -04001513 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001514 {
1515 dst.x = arccosh(src.x, pp);
1516 dst.y = arccosh(src.y, pp);
1517 dst.z = arccosh(src.z, pp);
1518 dst.w = arccosh(src.w, pp);
1519 }
1520
Alexis Hetuecad5192015-06-05 13:42:05 -04001521 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001522 {
1523 dst.x = arcsinh(src.x, pp);
1524 dst.y = arcsinh(src.y, pp);
1525 dst.z = arcsinh(src.z, pp);
1526 dst.w = arcsinh(src.w, pp);
1527 }
1528
Alexis Hetuecad5192015-06-05 13:42:05 -04001529 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001530 {
1531 dst.x = arctanh(src.x, pp);
1532 dst.y = arctanh(src.y, pp);
1533 dst.z = arctanh(src.z, pp);
1534 dst.w = arctanh(src.w, pp);
1535 }
1536
Alexis Hetuecad5192015-06-05 13:42:05 -04001537 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001538 {
1539 if(version < 0x0200)
1540 {
John Bauman19bac1e2014-05-06 15:23:49 -04001541 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001542 Float4 floor = src.x - frc;
1543
John Bauman19bac1e2014-05-06 15:23:49 -04001544 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001545 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001546 dst.z = exponential2(src.x, true);
1547 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001548 }
1549 else // Version >= 2.0
1550 {
John Bauman19bac1e2014-05-06 15:23:49 -04001551 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001552 }
1553 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001554
Alexis Hetuecad5192015-06-05 13:42:05 -04001555 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001556 {
1557 if(version < 0x0200)
1558 {
1559 Float4 tmp0;
1560 Float4 tmp1;
1561 Float4 t;
1562 Int4 r;
1563
1564 tmp0 = Abs(src.x);
1565 tmp1 = tmp0;
1566
1567 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001568 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001569 dst.x = Float4(r);
1570
1571 // Y component
1572 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1573
1574 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001575 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001576
1577 // W component
1578 dst.w = 1.0f;
1579 }
1580 else
1581 {
John Bauman19bac1e2014-05-06 15:23:49 -04001582 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001583 }
1584 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001585
Alexis Hetuecad5192015-06-05 13:42:05 -04001586 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001587 {
John Bauman19bac1e2014-05-06 15:23:49 -04001588 cmp0(dst.x, src0.x, src1.x, src2.x);
1589 cmp0(dst.y, src0.y, src1.y, src2.y);
1590 cmp0(dst.z, src0.z, src1.z, src2.z);
1591 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001592 }
John Bauman89401822014-05-06 15:04:28 -04001593
Alexis Hetuecad5192015-06-05 13:42:05 -04001594 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001595 {
1596 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1597 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1598 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1599 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1600 }
1601
Alexis Hetuecad5192015-06-05 13:42:05 -04001602 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001603 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001604 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1605 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1606 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001607 }
1608
Alexis Hetuecad5192015-06-05 13:42:05 -04001609 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001610 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001611 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1612 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1613 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1614 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001615 }
1616
Alexis Hetuecad5192015-06-05 13:42:05 -04001617 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001618 {
John Bauman19bac1e2014-05-06 15:23:49 -04001619 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1620 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001621 dst = As<Float4>(neg | pos);
1622 }
1623
Alexis Hetu0f448072016-03-18 10:56:08 -04001624 void ShaderCore::isgn(Float4 &dst, const Float4 &src)
1625 {
1626 Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1);
1627 Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1);
1628 dst = As<Float4>(neg | pos);
1629 }
1630
Alexis Hetuecad5192015-06-05 13:42:05 -04001631 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001632 {
John Bauman19bac1e2014-05-06 15:23:49 -04001633 Int4 pos = CmpLE(Float4(0.0f), src0);
1634 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001635 }
1636
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001637 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1638 {
1639 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1640 select(dst, pos, src1, src2);
1641 }
1642
Alexis Hetuecad5192015-06-05 13:42:05 -04001643 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001644 {
1645 // FIXME: LLVM vector select
Tom Anderson69bc6e82017-03-20 11:54:29 -07001646 dst = As<Float4>((src0 & As<Int4>(src1)) | (~src0 & As<Int4>(src2)));
John Bauman19bac1e2014-05-06 15:23:49 -04001647 }
1648
Alexis Hetuecad5192015-06-05 13:42:05 -04001649 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001650 {
1651 switch(control)
1652 {
John Bauman19bac1e2014-05-06 15:23:49 -04001653 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001654 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1655 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1656 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1657 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1658 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001659 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001660 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1661 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1662 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1663 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1664 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001665 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001666 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1667 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1668 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1669 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1670 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001671 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001672 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1673 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1674 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1675 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1676 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001677 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001678 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1679 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1680 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1681 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1682 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001683 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001684 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1685 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1686 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1687 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1688 break;
1689 default:
1690 ASSERT(false);
1691 }
1692 }
John Bauman19bac1e2014-05-06 15:23:49 -04001693
Alexis Hetuecad5192015-06-05 13:42:05 -04001694 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001695 {
1696 switch(control)
1697 {
1698 case Shader::CONTROL_GT:
1699 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1700 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1701 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1702 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1703 break;
1704 case Shader::CONTROL_EQ:
1705 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1706 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1707 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1708 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1709 break;
1710 case Shader::CONTROL_GE:
1711 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1712 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1713 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1714 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1715 break;
1716 case Shader::CONTROL_LT:
1717 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1718 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1719 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1720 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1721 break;
1722 case Shader::CONTROL_NE:
1723 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1724 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1725 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1726 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1727 break;
1728 case Shader::CONTROL_LE:
1729 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1730 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1731 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1732 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1733 break;
1734 default:
1735 ASSERT(false);
1736 }
1737 }
1738
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001739 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1740 {
1741 switch(control)
1742 {
1743 case Shader::CONTROL_GT:
1744 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1745 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1746 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1747 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1748 break;
1749 case Shader::CONTROL_EQ:
1750 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1751 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1752 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1753 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1754 break;
1755 case Shader::CONTROL_GE:
1756 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1757 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1758 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1759 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1760 break;
1761 case Shader::CONTROL_LT:
1762 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1763 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1764 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1765 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1766 break;
1767 case Shader::CONTROL_NE:
1768 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1769 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1770 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1771 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1772 break;
1773 case Shader::CONTROL_LE:
1774 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1775 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1776 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1777 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1778 break;
1779 default:
1780 ASSERT(false);
1781 }
1782 }
1783
Alexis Hetuecad5192015-06-05 13:42:05 -04001784 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001785 {
1786 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1787 }
1788
Alexis Hetuecad5192015-06-05 13:42:05 -04001789 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001790 {
1791 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1792 }
1793
Alexis Hetu24f454e2016-08-31 17:22:13 -04001794 void ShaderCore::bitwise_not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001795 {
1796 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1797 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1798 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1799 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1800 }
1801
Alexis Hetu24f454e2016-08-31 17:22:13 -04001802 void ShaderCore::bitwise_or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001803 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001804 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1805 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1806 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1807 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001808 }
1809
Alexis Hetu24f454e2016-08-31 17:22:13 -04001810 void ShaderCore::bitwise_xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001811 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001812 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1813 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1814 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1815 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001816 }
1817
Alexis Hetu24f454e2016-08-31 17:22:13 -04001818 void ShaderCore::bitwise_and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001819 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001820 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1821 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1822 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1823 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1824 }
1825
1826 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1827 {
1828 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1829 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1830 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1831 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1832 dst.y = dst.x;
1833 dst.z = dst.x;
1834 dst.w = dst.x;
1835 }
1836
1837 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1838 {
1839 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1840 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1841 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1842 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1843 dst.y = dst.x;
1844 dst.z = dst.x;
1845 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001846 }
John Bauman89401822014-05-06 15:04:28 -04001847}