blob: 017d0f81e7506bfb6b23322680951c79ec124c4f [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
Alexis Hetu0b7003b2017-11-13 16:21:11 -0500169 Int4 pos_inf_x = CmpEQ(As<Int4>(x), Int4(0x7F800000));
170 return As<Float4>((pos_inf_x & As<Int4>(x)) | (~pos_inf_x & As<Int4>(x1)));
John Bauman19bac1e2014-05-06 15:23:49 -0400171 }
172
173 Float4 exponential(RValue<Float4> x, bool pp)
174 {
175 // FIXME: Propagate the constant
Alexis Hetu0b7003b2017-11-13 16:21:11 -0500176 return exponential2(Float4(1.44269504f) * x, pp); // 1/ln(2)
John Bauman19bac1e2014-05-06 15:23:49 -0400177 }
178
179 Float4 logarithm(RValue<Float4> x, bool absolute, bool pp)
180 {
181 // FIXME: Propagate the constant
182 return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2)
183 }
184
185 Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp)
186 {
187 Float4 log = logarithm2(x, true, pp);
188 log *= y;
189 return exponential2(log, pp);
190 }
191
Nicolas Capens05b3d662016-02-25 23:58:33 -0500192 Float4 reciprocal(RValue<Float4> x, bool pp, bool finite, bool exactAtPow2)
John Bauman19bac1e2014-05-06 15:23:49 -0400193 {
194 Float4 rcp;
195
196 if(!pp && rcpPrecision >= WHQL)
197 {
198 rcp = Float4(1.0f) / x;
199 }
200 else
201 {
Nicolas Capens05b3d662016-02-25 23:58:33 -0500202 rcp = Rcp_pp(x, exactAtPow2);
John Bauman19bac1e2014-05-06 15:23:49 -0400203
204 if(!pp)
205 {
206 rcp = (rcp + rcp) - (x * rcp * rcp);
207 }
208 }
209
210 if(finite)
211 {
212 int big = 0x7F7FFFFF;
213 rcp = Min(rcp, Float4((float&)big));
214 }
215
216 return rcp;
217 }
218
219 Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
220 {
221 Float4 abs = x;
222
223 if(absolute)
224 {
225 abs = Abs(abs);
226 }
227
228 Float4 rsq;
229
Alexis Hetua0ef97a2017-11-13 17:31:20 -0500230 if(!pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400231 {
232 rsq = Float4(1.0f) / Sqrt(abs);
233 }
234 else
235 {
236 rsq = RcpSqrt_pp(abs);
237
238 if(!pp)
239 {
240 rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
241 }
John Bauman19bac1e2014-05-06 15:23:49 -0400242
Alexis Hetua0ef97a2017-11-13 17:31:20 -0500243 rsq = As<Float4>(CmpNEQ(As<Int4>(abs), Int4(0x7F800000)) & As<Int4>(rsq));
244 }
John Bauman19bac1e2014-05-06 15:23:49 -0400245
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
Alexis Hetu929c6b02017-11-07 16:04:25 -0500290 if(!pp)
291 {
292 // From the paper: "A Fast, Vectorizable Algorithm for Producing Single-Precision Sine-Cosine Pairs"
293 // This implementation passes OpenGL ES 3.0 precision requirements, at the cost of more operations:
294 // !pp : 17 mul, 7 add, 1 sub, 1 reciprocal
295 // pp : 4 mul, 2 add, 2 abs
296
297 Float4 y2 = y * y;
298 Float4 c1 = y2 * (y2 * (y2 * Float4(-0.0204391631f) + Float4(0.2536086171f)) + Float4(-1.2336977925f)) + Float4(1.0f);
299 Float4 s1 = y * (y2 * (y2 * (y2 * Float4(-0.0046075748f) + Float4(0.0796819754f)) + Float4(-0.645963615f)) + Float4(1.5707963235f));
300 Float4 c2 = (c1 * c1) - (s1 * s1);
301 Float4 s2 = Float4(2.0f) * s1 * c1;
302 return Float4(2.0f) * s2 * c2 * reciprocal(s2 * s2 + c2 * c2, pp, true);
303 }
304
John Bauman19bac1e2014-05-06 15:23:49 -0400305 const Float4 A = Float4(-16.0f);
306 const Float4 B = Float4(8.0f);
307 const Float4 C = Float4(7.75160950e-1f);
308 const Float4 D = Float4(2.24839049e-1f);
309
310 // Parabola approximating sine
311 Float4 sin = y * (Abs(y) * A + B);
312
313 // Improve precision from 0.06 to 0.001
314 if(true)
315 {
316 sin = sin * (Abs(sin) * D + C);
317 }
318
319 return sin;
320 }
321
322 Float4 cosine(RValue<Float4> x, bool pp)
323 {
324 // cos(x) = sin(x + pi/2)
325 Float4 y = x + Float4(1.57079632e+0f);
326 return sine(y, pp);
327 }
328
329 Float4 tangent(RValue<Float4> x, bool pp)
330 {
331 return sine(x, pp) / cosine(x, pp);
332 }
333
334 Float4 arccos(RValue<Float4> x, bool pp)
335 {
336 // pi/2 - arcsin(x)
337 return Float4(1.57079632e+0f) - arcsin(x);
338 }
339
340 Float4 arcsin(RValue<Float4> x, bool pp)
341 {
342 // x*(pi/2-sqrt(1-x*x)*pi/5)
343 return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f));
344 }
345
346 Float4 arctan(RValue<Float4> x, bool pp)
347 {
348 Int4 O = CmpNLT(Abs(x), Float4(1.0f));
Tom Anderson69bc6e82017-03-20 11:54:29 -0700349 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 -0400350
351 // Approximation of atan in [-1..1]
352 Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
Nicolas Capens0bac2852016-05-07 06:09:58 -0400353
John Bauman19bac1e2014-05-06 15:23:49 -0400354 // +/-pi/2 depending on sign of x
355 Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
356
Tom Anderson69bc6e82017-03-20 11:54:29 -0700357 theta = As<Float4>((O & As<Int4>(sgnPi_2 - theta)) | (~O & As<Int4>(theta))); // FIXME: Vector select
John Bauman19bac1e2014-05-06 15:23:49 -0400358
359 return theta;
360 }
361
362 Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp)
363 {
364 // Rotate to upper semicircle when in lower semicircle
365 Int4 S = CmpLT(y, Float4(0.0f));
366 Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi
367 Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x));
368 Float4 y0 = Abs(y);
369
370 // Rotate to right quadrant when in left quadrant
371 Int4 Q = CmpLT(x0, Float4(0.0f));
372 theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2
Tom Anderson69bc6e82017-03-20 11:54:29 -0700373 Float4 x1 = As<Float4>((Q & As<Int4>(y0)) | (~Q & As<Int4>(x0))); // FIXME: Vector select
374 Float4 y1 = As<Float4>((Q & As<Int4>(-x0)) | (~Q & As<Int4>(y0))); // FIXME: Vector select
John Bauman19bac1e2014-05-06 15:23:49 -0400375
376 // Rotate to first octant when in second octant
377 Int4 O = CmpNLT(y1, x1);
378 theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4
Tom Anderson69bc6e82017-03-20 11:54:29 -0700379 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
380 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 -0400381
382 // Approximation of atan in [0..1]
383 Float4 y_x = y2 / x2;
384 theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f));
385
386 return theta;
387 }
388
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -0400389 Float4 sineh(RValue<Float4> x, bool pp)
390 {
391 return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f);
392 }
393
394 Float4 cosineh(RValue<Float4> x, bool pp)
395 {
396 return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f);
397 }
398
399 Float4 tangenth(RValue<Float4> x, bool pp)
400 {
401 Float4 e_x = exponential(x, pp);
402 Float4 e_minus_x = exponential(-x, pp);
403 return (e_x - e_minus_x) / (e_x + e_minus_x);
404 }
405
406 Float4 arccosh(RValue<Float4> x, bool pp)
407 {
408 return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp);
409 }
410
411 Float4 arcsinh(RValue<Float4> x, bool pp)
412 {
413 return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp);
414 }
415
416 Float4 arctanh(RValue<Float4> x, bool pp)
417 {
418 return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f);
419 }
420
Alexis Hetuecad5192015-06-05 13:42:05 -0400421 Float4 dot2(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400422 {
423 return v0.x * v1.x + v0.y * v1.y;
424 }
425
Alexis Hetuecad5192015-06-05 13:42:05 -0400426 Float4 dot3(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400427 {
428 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
429 }
430
Alexis Hetuecad5192015-06-05 13:42:05 -0400431 Float4 dot4(const Vector4f &v0, const Vector4f &v1)
John Bauman19bac1e2014-05-06 15:23:49 -0400432 {
433 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w;
434 }
435
436 void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
437 {
438 Int2 tmp0 = UnpackHigh(row0, row1);
439 Int2 tmp1 = UnpackHigh(row2, row3);
440 Int2 tmp2 = UnpackLow(row0, row1);
441 Int2 tmp3 = UnpackLow(row2, row3);
442
Nicolas Capens45f187a2016-12-02 15:30:56 -0500443 row0 = UnpackLow(tmp2, tmp3);
444 row1 = UnpackHigh(tmp2, tmp3);
445 row2 = UnpackLow(tmp0, tmp1);
446 row3 = UnpackHigh(tmp0, tmp1);
John Bauman19bac1e2014-05-06 15:23:49 -0400447 }
448
449 void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
450 {
451 Float4 tmp0 = UnpackLow(row0, row1);
452 Float4 tmp1 = UnpackLow(row2, row3);
453 Float4 tmp2 = UnpackHigh(row0, row1);
454 Float4 tmp3 = UnpackHigh(row2, row3);
455
456 row0 = Float4(tmp0.xy, tmp1.xy);
457 row1 = Float4(tmp0.zw, tmp1.zw);
458 row2 = Float4(tmp2.xy, tmp3.xy);
459 row3 = Float4(tmp2.zw, tmp3.zw);
460 }
461
462 void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
463 {
464 Float4 tmp0 = UnpackLow(row0, row1);
465 Float4 tmp1 = UnpackLow(row2, row3);
466 Float4 tmp2 = UnpackHigh(row0, row1);
467 Float4 tmp3 = UnpackHigh(row2, row3);
468
469 row0 = Float4(tmp0.xy, tmp1.xy);
470 row1 = Float4(tmp0.zw, tmp1.zw);
471 row2 = Float4(tmp2.xy, tmp3.xy);
472 }
473
474 void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
475 {
476 Float4 tmp0 = UnpackLow(row0, row1);
477 Float4 tmp1 = UnpackLow(row2, row3);
478
479 row0 = Float4(tmp0.xy, tmp1.xy);
480 row1 = Float4(tmp0.zw, tmp1.zw);
481 }
482
483 void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
484 {
485 Float4 tmp0 = UnpackLow(row0, row1);
486 Float4 tmp1 = UnpackLow(row2, row3);
487
488 row0 = Float4(tmp0.xy, tmp1.xy);
489 }
490
491 void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
492 {
Nicolas Capens54ac5e82016-12-09 14:07:50 -0500493 Float4 tmp01 = UnpackLow(row0, row1);
494 Float4 tmp23 = UnpackHigh(row0, row1);
John Bauman19bac1e2014-05-06 15:23:49 -0400495
Nicolas Capens54ac5e82016-12-09 14:07:50 -0500496 row0 = tmp01;
497 row1 = Float4(tmp01.zw, row1.zw);
498 row2 = tmp23;
499 row3 = Float4(tmp23.zw, row3.zw);
John Bauman19bac1e2014-05-06 15:23:49 -0400500 }
501
502 void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
503 {
504 switch(N)
505 {
506 case 1: transpose4x1(row0, row1, row2, row3); break;
507 case 2: transpose4x2(row0, row1, row2, row3); break;
508 case 3: transpose4x3(row0, row1, row2, row3); break;
509 case 4: transpose4x4(row0, row1, row2, row3); break;
510 }
511 }
512
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400513 void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400514 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400515 if(integerDestination)
John Bauman89401822014-05-06 15:04:28 -0400516 {
Alexis Hetu02a2bb82015-08-20 14:10:33 -0400517 dst.x = As<Float4>(RoundInt(src.x));
518 dst.y = As<Float4>(RoundInt(src.y));
519 dst.z = As<Float4>(RoundInt(src.z));
520 dst.w = As<Float4>(RoundInt(src.w));
John Bauman89401822014-05-06 15:04:28 -0400521 }
522 else
523 {
524 dst = src;
525 }
526 }
527
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400528 void ShaderCore::neg(Vector4f &dst, const Vector4f &src)
529 {
530 dst.x = -src.x;
531 dst.y = -src.y;
532 dst.z = -src.z;
533 dst.w = -src.w;
534 }
535
536 void ShaderCore::ineg(Vector4f &dst, const Vector4f &src)
537 {
538 dst.x = As<Float4>(-As<Int4>(src.x));
539 dst.y = As<Float4>(-As<Int4>(src.y));
540 dst.z = As<Float4>(-As<Int4>(src.z));
541 dst.w = As<Float4>(-As<Int4>(src.w));
542 }
543
Alexis Hetuecad5192015-06-05 13:42:05 -0400544 void ShaderCore::f2b(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400545 {
546 dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f)));
547 dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f)));
548 dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f)));
549 dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f)));
550 }
551
Alexis Hetuecad5192015-06-05 13:42:05 -0400552 void ShaderCore::b2f(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -0400553 {
554 dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f)));
555 dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f)));
556 dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f)));
557 dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f)));
558 }
559
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400560 void ShaderCore::f2i(Vector4f &dst, const Vector4f &src)
561 {
562 dst.x = As<Float4>(Int4(src.x));
563 dst.y = As<Float4>(Int4(src.y));
564 dst.z = As<Float4>(Int4(src.z));
565 dst.w = As<Float4>(Int4(src.w));
566 }
567
568 void ShaderCore::i2f(Vector4f &dst, const Vector4f &src)
569 {
570 dst.x = Float4(As<Int4>(src.x));
571 dst.y = Float4(As<Int4>(src.y));
572 dst.z = Float4(As<Int4>(src.z));
573 dst.w = Float4(As<Int4>(src.w));
574 }
575
576 void ShaderCore::f2u(Vector4f &dst, const Vector4f &src)
577 {
578 dst.x = As<Float4>(UInt4(src.x));
579 dst.y = As<Float4>(UInt4(src.y));
580 dst.z = As<Float4>(UInt4(src.z));
581 dst.w = As<Float4>(UInt4(src.w));
582 }
583
584 void ShaderCore::u2f(Vector4f &dst, const Vector4f &src)
585 {
586 dst.x = Float4(As<UInt4>(src.x));
587 dst.y = Float4(As<UInt4>(src.y));
588 dst.z = Float4(As<UInt4>(src.z));
589 dst.w = Float4(As<UInt4>(src.w));
590 }
591
592 void ShaderCore::i2b(Vector4f &dst, const Vector4f &src)
593 {
594 dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0)));
595 dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0)));
596 dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0)));
597 dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0)));
598 }
599
600 void ShaderCore::b2i(Vector4f &dst, const Vector4f &src)
601 {
602 dst.x = As<Float4>(As<Int4>(src.x) & Int4(1));
603 dst.y = As<Float4>(As<Int4>(src.y) & Int4(1));
604 dst.z = As<Float4>(As<Int4>(src.z) & Int4(1));
605 dst.w = As<Float4>(As<Int4>(src.w) & Int4(1));
606 }
607
Alexis Hetuecad5192015-06-05 13:42:05 -0400608 void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400609 {
610 dst.x = src0.x + src1.x;
611 dst.y = src0.y + src1.y;
612 dst.z = src0.z + src1.z;
613 dst.w = src0.w + src1.w;
614 }
615
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400616 void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
617 {
618 dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x));
619 dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y));
620 dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z));
621 dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w));
622 }
623
Alexis Hetuecad5192015-06-05 13:42:05 -0400624 void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400625 {
626 dst.x = src0.x - src1.x;
627 dst.y = src0.y - src1.y;
628 dst.z = src0.z - src1.z;
629 dst.w = src0.w - src1.w;
630 }
631
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400632 void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
633 {
634 dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x));
635 dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y));
636 dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z));
637 dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w));
638 }
639
Alexis Hetuecad5192015-06-05 13:42:05 -0400640 void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -0400641 {
642 dst.x = src0.x * src1.x + src2.x;
643 dst.y = src0.y * src1.y + src2.y;
644 dst.z = src0.z * src1.z + src2.z;
645 dst.w = src0.w * src1.w + src2.w;
646 }
647
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400648 void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
649 {
650 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x));
651 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y));
652 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z));
653 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w));
654 }
655
Alexis Hetuecad5192015-06-05 13:42:05 -0400656 void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400657 {
658 dst.x = src0.x * src1.x;
659 dst.y = src0.y * src1.y;
660 dst.z = src0.z * src1.z;
661 dst.w = src0.w * src1.w;
662 }
663
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400664 void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
665 {
666 dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x));
667 dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y));
668 dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z));
669 dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w));
670 }
671
Alexis Hetuecad5192015-06-05 13:42:05 -0400672 void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400673 {
674 Float4 rcp = reciprocal(src.x, pp, true);
675
676 dst.x = rcp;
677 dst.y = rcp;
678 dst.z = rcp;
679 dst.w = rcp;
680 }
681
Alexis Hetuecad5192015-06-05 13:42:05 -0400682 void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400683 {
684 dst.x = src0.x / src1.x;
685 dst.y = src0.y / src1.y;
686 dst.z = src0.z / src1.z;
687 dst.w = src0.w / src1.w;
688 }
689
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400690 void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
691 {
692 Float4 intMax(As<Float4>(Int4(INT_MAX)));
693 cmp0i(dst.x, src1.x, intMax, src1.x);
694 dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x));
695 cmp0i(dst.y, src1.y, intMax, src1.y);
696 dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y));
697 cmp0i(dst.z, src1.z, intMax, src1.z);
698 dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z));
699 cmp0i(dst.w, src1.w, intMax, src1.w);
700 dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w));
701 }
702
703 void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
704 {
705 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
706 cmp0i(dst.x, src1.x, uintMax, src1.x);
707 dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x));
708 cmp0i(dst.y, src1.y, uintMax, src1.y);
709 dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y));
710 cmp0i(dst.z, src1.z, uintMax, src1.z);
711 dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z));
712 cmp0i(dst.w, src1.w, uintMax, src1.w);
713 dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w));
714 }
715
Alexis Hetuecad5192015-06-05 13:42:05 -0400716 void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400717 {
718 dst.x = modulo(src0.x, src1.x);
719 dst.y = modulo(src0.y, src1.y);
720 dst.z = modulo(src0.z, src1.z);
721 dst.w = modulo(src0.w, src1.w);
722 }
723
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400724 void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
725 {
Alexis Hetu28958102017-10-02 13:48:19 -0400726 Float4 intMax(As<Float4>(Int4(INT_MAX)));
727 cmp0i(dst.x, src1.x, intMax, src1.x);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400728 dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x));
Alexis Hetu28958102017-10-02 13:48:19 -0400729 cmp0i(dst.y, src1.y, intMax, src1.y);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400730 dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y));
Alexis Hetu28958102017-10-02 13:48:19 -0400731 cmp0i(dst.z, src1.z, intMax, src1.z);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400732 dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z));
Alexis Hetu28958102017-10-02 13:48:19 -0400733 cmp0i(dst.w, src1.w, intMax, src1.w);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400734 dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w));
735 }
Alexis Hetu28958102017-10-02 13:48:19 -0400736
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400737 void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
738 {
Alexis Hetu28958102017-10-02 13:48:19 -0400739 Float4 uintMax(As<Float4>(UInt4(UINT_MAX)));
740 cmp0i(dst.x, src1.x, uintMax, src1.x);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400741 dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x));
Alexis Hetu28958102017-10-02 13:48:19 -0400742 cmp0i(dst.y, src1.y, uintMax, src1.y);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400743 dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y));
Alexis Hetu28958102017-10-02 13:48:19 -0400744 cmp0i(dst.z, src1.z, uintMax, src1.z);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400745 dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z));
Alexis Hetu28958102017-10-02 13:48:19 -0400746 cmp0i(dst.w, src1.w, uintMax, src1.w);
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400747 dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w));
748 }
749
750 void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
751 {
752 dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x));
753 dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y));
754 dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z));
755 dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w));
756 }
757
758 void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
759 {
760 dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x));
761 dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y));
762 dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z));
763 dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w));
764 }
765
766 void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
767 {
768 dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x));
769 dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y));
770 dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z));
771 dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w));
772 }
773
Alexis Hetuecad5192015-06-05 13:42:05 -0400774 void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400775 {
776 Float4 rsq = reciprocalSquareRoot(src.x, true, pp);
777
John Bauman19bac1e2014-05-06 15:23:49 -0400778 dst.x = rsq;
779 dst.y = rsq;
780 dst.z = rsq;
781 dst.w = rsq;
John Bauman89401822014-05-06 15:04:28 -0400782 }
783
Alexis Hetuecad5192015-06-05 13:42:05 -0400784 void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400785 {
786 dst.x = Sqrt(src.x);
787 dst.y = Sqrt(src.y);
788 dst.z = Sqrt(src.z);
789 dst.w = Sqrt(src.w);
790 }
791
Alexis Hetuecad5192015-06-05 13:42:05 -0400792 void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400793 {
794 dst.x = reciprocalSquareRoot(src.x, false, pp);
795 dst.y = reciprocalSquareRoot(src.y, false, pp);
796 dst.z = reciprocalSquareRoot(src.z, false, pp);
797 dst.w = reciprocalSquareRoot(src.w, false, pp);
798 }
799
Alexis Hetuecad5192015-06-05 13:42:05 -0400800 void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400801 {
802 dst = Sqrt(dot2(src, src));
803 }
804
Alexis Hetuecad5192015-06-05 13:42:05 -0400805 void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400806 {
807 dst = Sqrt(dot3(src, src));
808 }
809
Alexis Hetuecad5192015-06-05 13:42:05 -0400810 void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400811 {
812 dst = Sqrt(dot4(src, src));
813 }
814
Alexis Hetuecad5192015-06-05 13:42:05 -0400815 void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400816 {
817 dst = Abs(src0.x - src1.x);
818 }
819
Alexis Hetuecad5192015-06-05 13:42:05 -0400820 void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400821 {
822 Float4 dx = src0.x - src1.x;
823 Float4 dy = src0.y - src1.y;
824 Float4 dot2 = dx * dx + dy * dy;
825 dst = Sqrt(dot2);
826 }
827
Alexis Hetuecad5192015-06-05 13:42:05 -0400828 void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400829 {
830 Float4 dx = src0.x - src1.x;
831 Float4 dy = src0.y - src1.y;
832 Float4 dz = src0.z - src1.z;
833 Float4 dot3 = dx * dx + dy * dy + dz * dz;
834 dst = Sqrt(dot3);
835 }
836
Alexis Hetuecad5192015-06-05 13:42:05 -0400837 void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400838 {
839 Float4 dx = src0.x - src1.x;
840 Float4 dy = src0.y - src1.y;
841 Float4 dz = src0.z - src1.z;
842 Float4 dw = src0.w - src1.w;
843 Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw;
844 dst = Sqrt(dot4);
845 }
846
Alexis Hetuecad5192015-06-05 13:42:05 -0400847 void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400848 {
849 Float4 t = src0.x * src1.x;
850
851 dst.x = t;
852 dst.y = t;
853 dst.z = t;
854 dst.w = t;
855 }
856
Alexis Hetuecad5192015-06-05 13:42:05 -0400857 void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -0400858 {
859 Float4 t = dot2(src0, src1);
860
861 dst.x = t;
862 dst.y = t;
863 dst.z = t;
864 dst.w = t;
865 }
866
Alexis Hetuecad5192015-06-05 13:42:05 -0400867 void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -0400868 {
869 Float4 t = dot2(src0, src1) + src2.x;
870
871 dst.x = t;
872 dst.y = t;
873 dst.z = t;
874 dst.w = t;
875 }
876
Alexis Hetuecad5192015-06-05 13:42:05 -0400877 void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400878 {
879 Float4 dot = dot3(src0, src1);
880
881 dst.x = dot;
882 dst.y = dot;
883 dst.z = dot;
884 dst.w = dot;
885 }
886
Alexis Hetuecad5192015-06-05 13:42:05 -0400887 void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400888 {
889 Float4 dot = dot4(src0, src1);
890
891 dst.x = dot;
892 dst.y = dot;
893 dst.z = dot;
894 dst.w = dot;
895 }
896
Alexis Hetuecad5192015-06-05 13:42:05 -0400897 void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400898 {
899 dst.x = Min(src0.x, src1.x);
900 dst.y = Min(src0.y, src1.y);
901 dst.z = Min(src0.z, src1.z);
902 dst.w = Min(src0.w, src1.w);
903 }
904
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400905 void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
906 {
907 dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x)));
908 dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y)));
909 dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z)));
910 dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w)));
911 }
912
913 void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
914 {
915 dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x)));
916 dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y)));
917 dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z)));
918 dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w)));
919 }
920
Alexis Hetuecad5192015-06-05 13:42:05 -0400921 void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400922 {
923 dst.x = Max(src0.x, src1.x);
924 dst.y = Max(src0.y, src1.y);
925 dst.z = Max(src0.z, src1.z);
926 dst.w = Max(src0.w, src1.w);
927 }
928
Alexis Hetuc4f2c292015-08-18 15:43:09 -0400929 void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
930 {
931 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
932 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
933 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
934 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
935 }
936
937 void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
938 {
939 dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x)));
940 dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y)));
941 dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z)));
942 dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w)));
943 }
944
Alexis Hetuecad5192015-06-05 13:42:05 -0400945 void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -0400946 {
John Bauman19bac1e2014-05-06 15:23:49 -0400947 dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f)));
948 dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f)));
949 dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f)));
950 dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400951 }
952
Alexis Hetuecad5192015-06-05 13:42:05 -0400953 void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -0400954 {
John Bauman19bac1e2014-05-06 15:23:49 -0400955 dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f)));
956 dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f)));
957 dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f)));
958 dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f)));
John Bauman89401822014-05-06 15:04:28 -0400959 }
960
Alexis Hetuecad5192015-06-05 13:42:05 -0400961 void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
Nicolas Capens0bac2852016-05-07 06:09:58 -0400962 {
John Bauman19bac1e2014-05-06 15:23:49 -0400963 Float4 exp = exponential2(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -0400964
965 dst.x = exp;
966 dst.y = exp;
967 dst.z = exp;
968 dst.w = exp;
969 }
970
Alexis Hetuecad5192015-06-05 13:42:05 -0400971 void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400972 {
John Bauman19bac1e2014-05-06 15:23:49 -0400973 dst.x = exponential2(src.x, pp);
974 dst.y = exponential2(src.y, pp);
975 dst.z = exponential2(src.z, pp);
976 dst.w = exponential2(src.w, pp);
977 }
978
Alexis Hetuecad5192015-06-05 13:42:05 -0400979 void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400980 {
981 dst.x = exponential(src.x, pp);
982 dst.y = exponential(src.y, pp);
983 dst.z = exponential(src.z, pp);
984 dst.w = exponential(src.w, pp);
985 }
986
Alexis Hetuecad5192015-06-05 13:42:05 -0400987 void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -0400988 {
989 Float4 log = logarithm2(src.x, true, pp);
John Bauman89401822014-05-06 15:04:28 -0400990
991 dst.x = log;
992 dst.y = log;
993 dst.z = log;
994 dst.w = log;
995 }
996
Alexis Hetuecad5192015-06-05 13:42:05 -0400997 void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -0400998 {
Alexis Hetua781af72017-07-06 17:12:47 -0400999 dst.x = logarithm2(src.x, false, pp);
1000 dst.y = logarithm2(src.y, false, pp);
1001 dst.z = logarithm2(src.z, false, pp);
1002 dst.w = logarithm2(src.w, false, pp);
John Bauman19bac1e2014-05-06 15:23:49 -04001003 }
1004
Alexis Hetuecad5192015-06-05 13:42:05 -04001005 void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001006 {
1007 dst.x = logarithm(src.x, false, pp);
1008 dst.y = logarithm(src.y, false, pp);
1009 dst.z = logarithm(src.z, false, pp);
1010 dst.w = logarithm(src.w, false, pp);
1011 }
1012
Alexis Hetuecad5192015-06-05 13:42:05 -04001013 void ShaderCore::lit(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001014 {
1015 dst.x = Float4(1.0f);
1016 dst.y = Max(src.x, Float4(0.0f));
John Bauman89401822014-05-06 15:04:28 -04001017
1018 Float4 pow;
1019
1020 pow = src.w;
John Bauman19bac1e2014-05-06 15:23:49 -04001021 pow = Min(pow, Float4(127.9961f));
1022 pow = Max(pow, Float4(-127.9961f));
John Bauman89401822014-05-06 15:04:28 -04001023
1024 dst.z = power(src.y, pow);
John Bauman19bac1e2014-05-06 15:23:49 -04001025 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f)));
1026 dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f)));
John Bauman89401822014-05-06 15:04:28 -04001027
John Bauman19bac1e2014-05-06 15:23:49 -04001028 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001029 }
1030
Alexis Hetuecad5192015-06-05 13:42:05 -04001031 void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001032 {
John Bauman19bac1e2014-05-06 15:23:49 -04001033 // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d
John Bauman89401822014-05-06 15:04:28 -04001034 dst.x = 1;
1035 dst.y = src0.y * src1.y;
1036 dst.z = src0.z;
1037 dst.w = src1.w;
1038 }
1039
Alexis Hetuecad5192015-06-05 13:42:05 -04001040 void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001041 {
1042 dst.x = src0.x * (src1.x - src2.x) + src2.x;
1043 dst.y = src0.y * (src1.y - src2.y) + src2.y;
1044 dst.z = src0.z * (src1.z - src2.z) + src2.z;
1045 dst.w = src0.w * (src1.w - src2.w) + src2.w;
1046 }
1047
Alexis Hetu8ef6d102017-11-09 15:49:09 -05001048 void ShaderCore::isinf(Vector4f &dst, const Vector4f &src)
1049 {
1050 dst.x = As<Float4>(IsInf(src.x));
1051 dst.y = As<Float4>(IsInf(src.y));
1052 dst.z = As<Float4>(IsInf(src.z));
1053 dst.w = As<Float4>(IsInf(src.w));
1054 }
1055
1056 void ShaderCore::isnan(Vector4f &dst, const Vector4f &src)
1057 {
1058 dst.x = As<Float4>(IsNan(src.x));
1059 dst.y = As<Float4>(IsNan(src.y));
1060 dst.z = As<Float4>(IsNan(src.z));
1061 dst.w = As<Float4>(IsNan(src.w));
1062 }
1063
Alexis Hetuecad5192015-06-05 13:42:05 -04001064 void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x)
John Bauman89401822014-05-06 15:04:28 -04001065 {
John Bauman19bac1e2014-05-06 15:23:49 -04001066 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);
1067 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);
1068 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);
1069 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 -04001070 }
1071
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001072 void ShaderCore::floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits)
1073 {
1074 static const uint32_t mask_sign = 0x80000000u;
1075 static const uint32_t mask_round = ~0xfffu;
1076 static const uint32_t c_f32infty = 255 << 23;
1077 static const uint32_t c_magic = 15 << 23;
1078 static const uint32_t c_nanbit = 0x200;
1079 static const uint32_t c_infty_as_fp16 = 0x7c00;
1080 static const uint32_t c_clamp = (31 << 23) - 0x1000;
Nicolas Capens0bac2852016-05-07 06:09:58 -04001081
Alexis Hetuffb35eb2016-04-06 18:05:00 -04001082 UInt4 justsign = UInt4(mask_sign) & As<UInt4>(floatBits);
1083 UInt4 absf = As<UInt4>(floatBits) ^ justsign;
1084 UInt4 b_isnormal = CmpNLE(UInt4(c_f32infty), absf);
1085
1086 // 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
1087 // instead of nearest even, since that's fine for GLSL ES 3.0's needs (see section 2.1.1 Floating-Point Computation)
1088 UInt4 joined = ((((As<UInt4>(Min(As<Float4>(absf & UInt4(mask_round)) * As<Float4>(UInt4(c_magic)),
1089 As<Float4>(UInt4(c_clamp))))) - UInt4(mask_round)) >> 13) & b_isnormal) |
1090 ((b_isnormal ^ UInt4(0xFFFFFFFF)) & ((CmpNLE(absf, UInt4(c_f32infty)) & UInt4(c_nanbit)) |
1091 UInt4(c_infty_as_fp16)));
1092
1093 dst = As<Float4>(storeInUpperBits ? As<UInt4>(dst) | ((joined << 16) | justsign) : joined | (justsign >> 16));
1094 }
1095
1096 void ShaderCore::halfToFloatBits(Float4& dst, const Float4& halfBits)
1097 {
1098 static const uint32_t mask_nosign = 0x7FFF;
1099 static const uint32_t magic = (254 - 15) << 23;
1100 static const uint32_t was_infnan = 0x7BFF;
1101 static const uint32_t exp_infnan = 255 << 23;
1102
1103 UInt4 expmant = As<UInt4>(halfBits) & UInt4(mask_nosign);
1104 dst = As<Float4>(As<UInt4>(As<Float4>(expmant << 13) * As<Float4>(UInt4(magic))) |
1105 ((As<UInt4>(halfBits) ^ UInt4(expmant)) << 16) |
1106 (CmpNLE(As<UInt4>(expmant), UInt4(was_infnan)) & UInt4(exp_infnan)));
1107 }
1108
1109 void ShaderCore::packHalf2x16(Vector4f &d, const Vector4f &s0)
1110 {
1111 // half2 | half1
1112 floatToHalfBits(d.x, s0.x, false);
1113 floatToHalfBits(d.x, s0.y, true);
1114 }
1115
1116 void ShaderCore::unpackHalf2x16(Vector4f &dst, const Vector4f &s0)
1117 {
1118 // half2 | half1
1119 halfToFloatBits(dst.x, As<Float4>(As<UInt4>(s0.x) & UInt4(0x0000FFFF)));
1120 halfToFloatBits(dst.y, As<Float4>((As<UInt4>(s0.x) & UInt4(0xFFFF0000)) >> 16));
1121 }
1122
Alexis Hetu9cde9742016-04-06 13:03:38 -04001123 void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0)
1124 {
1125 // round(clamp(c, -1.0, 1.0) * 32767.0)
1126 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) |
1127 ((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16));
1128 }
1129
1130 void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0)
1131 {
1132 // round(clamp(c, 0.0, 1.0) * 65535.0)
1133 d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) |
1134 ((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16));
1135 }
1136
1137 void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0)
1138 {
1139 // clamp(f / 32727.0, -1.0, 1.0)
1140 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));
1141 dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
1142 }
1143
1144 void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0)
1145 {
1146 // f / 65535.0
1147 dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000));
1148 dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000));
1149 }
1150
Alexis Hetuc3d95f32015-09-23 12:27:32 -04001151 void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1152 {
1153 dst.x = src0.x * src1.y - src0.y * src1.x;
1154 dst.y = dst.z = dst.w = dst.x;
1155 }
1156
1157 void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
1158 {
1159 crs(dst, src1, src2);
1160 dp3(dst, dst, src0);
1161 }
1162
1163 void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3)
1164 {
1165 dst.x = src2.z * src3.w - src2.w * src3.z;
1166 dst.y = src1.w * src3.z - src1.z * src3.w;
1167 dst.z = src1.z * src2.w - src1.w * src2.z;
1168 dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) -
1169 src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) +
1170 src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) +
1171 src2.x * (src1.w * src3.y - src1.y * src3.w) +
1172 src3.x * (src1.y * src2.w - src1.w * src2.y)) +
1173 src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) +
1174 src2.x * (src1.y * src3.z - src1.z * src3.y) +
1175 src3.x * (src1.z * src2.y - src1.y * src2.z));
1176 dst.y = dst.z = dst.w = dst.x;
1177 }
1178
Alexis Hetuecad5192015-06-05 13:42:05 -04001179 void ShaderCore::frc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001180 {
1181 dst.x = Frac(src.x);
1182 dst.y = Frac(src.y);
1183 dst.z = Frac(src.z);
1184 dst.w = Frac(src.w);
1185 }
1186
Alexis Hetuecad5192015-06-05 13:42:05 -04001187 void ShaderCore::trunc(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001188 {
1189 dst.x = Trunc(src.x);
1190 dst.y = Trunc(src.y);
1191 dst.z = Trunc(src.z);
1192 dst.w = Trunc(src.w);
1193 }
1194
Alexis Hetuecad5192015-06-05 13:42:05 -04001195 void ShaderCore::floor(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001196 {
1197 dst.x = Floor(src.x);
1198 dst.y = Floor(src.y);
1199 dst.z = Floor(src.z);
1200 dst.w = Floor(src.w);
1201 }
1202
Alexis Hetuecad5192015-06-05 13:42:05 -04001203 void ShaderCore::round(Vector4f &dst, const Vector4f &src)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001204 {
1205 dst.x = Round(src.x);
1206 dst.y = Round(src.y);
1207 dst.z = Round(src.z);
1208 dst.w = Round(src.w);
1209 }
1210
Alexis Hetuecad5192015-06-05 13:42:05 -04001211 void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src)
Alexis Hetu8e851c12015-06-04 11:30:54 -04001212 {
1213 // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src));
1214 // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2
1215 // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2
1216 // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2
1217 // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2
1218 // Even if the round implementation rounds the other way:
1219 // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2
1220 // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2
1221 // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2
1222 // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2
1223 round(dst, src);
1224 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));
1225 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));
1226 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));
1227 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));
1228 }
1229
Alexis Hetuecad5192015-06-05 13:42:05 -04001230 void ShaderCore::ceil(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001231 {
1232 dst.x = Ceil(src.x);
1233 dst.y = Ceil(src.y);
1234 dst.z = Ceil(src.z);
1235 dst.w = Ceil(src.w);
1236 }
1237
Alexis Hetuecad5192015-06-05 13:42:05 -04001238 void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001239 {
1240 Float4 pow = power(src0.x, src1.x, pp);
1241
1242 dst.x = pow;
1243 dst.y = pow;
1244 dst.z = pow;
1245 dst.w = pow;
1246 }
1247
Alexis Hetuecad5192015-06-05 13:42:05 -04001248 void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001249 {
1250 dst.x = power(src0.x, src1.x, pp);
1251 dst.y = power(src0.y, src1.y, pp);
1252 dst.z = power(src0.z, src1.z, pp);
1253 dst.w = power(src0.w, src1.w, pp);
1254 }
1255
Alexis Hetuecad5192015-06-05 13:42:05 -04001256 void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman89401822014-05-06 15:04:28 -04001257 {
1258 dst.x = src0.y * src1.z - src0.z * src1.y;
1259 dst.y = src0.z * src1.x - src0.x * src1.z;
1260 dst.z = src0.x * src1.y - src0.y * src1.x;
1261 }
1262
Alexis Hetuecad5192015-06-05 13:42:05 -04001263 void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001264 {
1265 Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000);
1266
1267 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1268 }
1269
Alexis Hetuecad5192015-06-05 13:42:05 -04001270 void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001271 {
1272 Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1273
1274 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1275 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1276 }
1277
Alexis Hetuecad5192015-06-05 13:42:05 -04001278 void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001279 {
1280 Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1281
1282 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1283 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1284 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1285 }
1286
Alexis Hetuecad5192015-06-05 13:42:05 -04001287 void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref)
John Bauman19bac1e2014-05-06 15:23:49 -04001288 {
1289 Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000);
1290
1291 dst.x = As<Float4>(flip ^ As<Int4>(N.x));
1292 dst.y = As<Float4>(flip ^ As<Int4>(N.y));
1293 dst.z = As<Float4>(flip ^ As<Int4>(N.z));
1294 dst.w = As<Float4>(flip ^ As<Int4>(N.w));
1295 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001296
Alexis Hetuecad5192015-06-05 13:42:05 -04001297 void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001298 {
1299 Float4 d = N.x * I.x;
1300
1301 dst.x = I.x - Float4(2.0f) * d * N.x;
1302 }
1303
Alexis Hetuecad5192015-06-05 13:42:05 -04001304 void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001305 {
1306 Float4 d = dot2(N, I);
1307
1308 dst.x = I.x - Float4(2.0f) * d * N.x;
1309 dst.y = I.y - Float4(2.0f) * d * N.y;
1310 }
1311
Alexis Hetuecad5192015-06-05 13:42:05 -04001312 void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001313 {
1314 Float4 d = dot3(N, I);
1315
1316 dst.x = I.x - Float4(2.0f) * d * N.x;
1317 dst.y = I.y - Float4(2.0f) * d * N.y;
1318 dst.z = I.z - Float4(2.0f) * d * N.z;
1319 }
1320
Alexis Hetuecad5192015-06-05 13:42:05 -04001321 void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N)
John Bauman19bac1e2014-05-06 15:23:49 -04001322 {
1323 Float4 d = dot4(N, I);
1324
1325 dst.x = I.x - Float4(2.0f) * d * N.x;
1326 dst.y = I.y - Float4(2.0f) * d * N.y;
1327 dst.z = I.z - Float4(2.0f) * d * N.z;
1328 dst.w = I.w - Float4(2.0f) * d * N.w;
1329 }
1330
Alexis Hetuecad5192015-06-05 13:42:05 -04001331 void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001332 {
1333 Float4 d = N.x * I.x;
1334 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1335 Int4 pos = CmpNLT(k, Float4(0.0f));
1336 Float4 t = (eta * d + Sqrt(k));
1337
1338 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1339 }
1340
Alexis Hetuecad5192015-06-05 13:42:05 -04001341 void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001342 {
1343 Float4 d = dot2(N, I);
1344 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1345 Int4 pos = CmpNLT(k, Float4(0.0f));
1346 Float4 t = (eta * d + Sqrt(k));
1347
1348 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1349 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1350 }
1351
Alexis Hetuecad5192015-06-05 13:42:05 -04001352 void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001353 {
1354 Float4 d = dot3(N, I);
1355 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1356 Int4 pos = CmpNLT(k, Float4(0.0f));
1357 Float4 t = (eta * d + Sqrt(k));
1358
1359 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1360 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1361 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1362 }
1363
Alexis Hetuecad5192015-06-05 13:42:05 -04001364 void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta)
John Bauman19bac1e2014-05-06 15:23:49 -04001365 {
1366 Float4 d = dot4(N, I);
1367 Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d);
1368 Int4 pos = CmpNLT(k, Float4(0.0f));
1369 Float4 t = (eta * d + Sqrt(k));
1370
1371 dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x));
1372 dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y));
1373 dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z));
1374 dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w));
1375 }
1376
Alexis Hetuecad5192015-06-05 13:42:05 -04001377 void ShaderCore::sgn(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001378 {
1379 sgn(dst.x, src.x);
1380 sgn(dst.y, src.y);
1381 sgn(dst.z, src.z);
1382 sgn(dst.w, src.w);
1383 }
1384
Alexis Hetu0f448072016-03-18 10:56:08 -04001385 void ShaderCore::isgn(Vector4f &dst, const Vector4f &src)
1386 {
1387 isgn(dst.x, src.x);
1388 isgn(dst.y, src.y);
1389 isgn(dst.z, src.z);
1390 isgn(dst.w, src.w);
1391 }
1392
Alexis Hetuecad5192015-06-05 13:42:05 -04001393 void ShaderCore::abs(Vector4f &dst, const Vector4f &src)
John Bauman89401822014-05-06 15:04:28 -04001394 {
1395 dst.x = Abs(src.x);
1396 dst.y = Abs(src.y);
1397 dst.z = Abs(src.z);
1398 dst.w = Abs(src.w);
1399 }
Alexis Hetu0f448072016-03-18 10:56:08 -04001400
1401 void ShaderCore::iabs(Vector4f &dst, const Vector4f &src)
1402 {
1403 dst.x = As<Float4>(Abs(As<Int4>(src.x)));
1404 dst.y = As<Float4>(Abs(As<Int4>(src.y)));
1405 dst.z = As<Float4>(Abs(As<Int4>(src.z)));
1406 dst.w = As<Float4>(Abs(As<Int4>(src.w)));
1407 }
1408
Alexis Hetuecad5192015-06-05 13:42:05 -04001409 void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001410 {
1411 Float4 dot = dot2(src, src);
1412 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001413
John Bauman19bac1e2014-05-06 15:23:49 -04001414 dst.x = src.x * rsq;
1415 dst.y = src.y * rsq;
1416 dst.z = src.z * rsq;
1417 dst.w = src.w * rsq;
1418 }
1419
Alexis Hetuecad5192015-06-05 13:42:05 -04001420 void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001421 {
1422 Float4 dot = dot3(src, src);
1423 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
1424
1425 dst.x = src.x * rsq;
1426 dst.y = src.y * rsq;
1427 dst.z = src.z * rsq;
1428 dst.w = src.w * rsq;
1429 }
John Bauman19bac1e2014-05-06 15:23:49 -04001430
Alexis Hetuecad5192015-06-05 13:42:05 -04001431 void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman89401822014-05-06 15:04:28 -04001432 {
John Bauman19bac1e2014-05-06 15:23:49 -04001433 Float4 dot = dot4(src, src);
1434 Float4 rsq = reciprocalSquareRoot(dot, false, pp);
John Bauman89401822014-05-06 15:04:28 -04001435
John Bauman19bac1e2014-05-06 15:23:49 -04001436 dst.x = src.x * rsq;
1437 dst.y = src.y * rsq;
1438 dst.z = src.z * rsq;
1439 dst.w = src.w * rsq;
1440 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001441
Alexis Hetuecad5192015-06-05 13:42:05 -04001442 void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001443 {
1444 dst.x = cosine_pi(src.x, pp);
1445 dst.y = sine_pi(src.x, pp);
John Bauman89401822014-05-06 15:04:28 -04001446 }
1447
Alexis Hetuecad5192015-06-05 13:42:05 -04001448 void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001449 {
1450 dst.x = cosine(src.x, pp);
1451 dst.y = cosine(src.y, pp);
1452 dst.z = cosine(src.z, pp);
1453 dst.w = cosine(src.w, pp);
1454 }
1455
Alexis Hetuecad5192015-06-05 13:42:05 -04001456 void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001457 {
1458 dst.x = sine(src.x, pp);
1459 dst.y = sine(src.y, pp);
1460 dst.z = sine(src.z, pp);
1461 dst.w = sine(src.w, pp);
1462 }
1463
Alexis Hetuecad5192015-06-05 13:42:05 -04001464 void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001465 {
1466 dst.x = tangent(src.x, pp);
1467 dst.y = tangent(src.y, pp);
1468 dst.z = tangent(src.z, pp);
1469 dst.w = tangent(src.w, pp);
1470 }
1471
Alexis Hetuecad5192015-06-05 13:42:05 -04001472 void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001473 {
1474 dst.x = arccos(src.x, pp);
1475 dst.y = arccos(src.y, pp);
1476 dst.z = arccos(src.z, pp);
1477 dst.w = arccos(src.w, pp);
1478 }
1479
Alexis Hetuecad5192015-06-05 13:42:05 -04001480 void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001481 {
1482 dst.x = arcsin(src.x, pp);
1483 dst.y = arcsin(src.y, pp);
1484 dst.z = arcsin(src.z, pp);
1485 dst.w = arcsin(src.w, pp);
1486 }
1487
Alexis Hetuecad5192015-06-05 13:42:05 -04001488 void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001489 {
1490 dst.x = arctan(src.x, pp);
1491 dst.y = arctan(src.y, pp);
1492 dst.z = arctan(src.z, pp);
1493 dst.w = arctan(src.w, pp);
1494 }
1495
Alexis Hetuecad5192015-06-05 13:42:05 -04001496 void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp)
John Bauman19bac1e2014-05-06 15:23:49 -04001497 {
1498 dst.x = arctan(src0.x, src1.x, pp);
1499 dst.y = arctan(src0.y, src1.y, pp);
1500 dst.z = arctan(src0.z, src1.z, pp);
1501 dst.w = arctan(src0.w, src1.w, pp);
1502 }
1503
Alexis Hetuecad5192015-06-05 13:42:05 -04001504 void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001505 {
1506 dst.x = cosineh(src.x, pp);
1507 dst.y = cosineh(src.y, pp);
1508 dst.z = cosineh(src.z, pp);
1509 dst.w = cosineh(src.w, pp);
1510 }
1511
Alexis Hetuecad5192015-06-05 13:42:05 -04001512 void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001513 {
1514 dst.x = sineh(src.x, pp);
1515 dst.y = sineh(src.y, pp);
1516 dst.z = sineh(src.z, pp);
1517 dst.w = sineh(src.w, pp);
1518 }
1519
Alexis Hetuecad5192015-06-05 13:42:05 -04001520 void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001521 {
1522 dst.x = tangenth(src.x, pp);
1523 dst.y = tangenth(src.y, pp);
1524 dst.z = tangenth(src.z, pp);
1525 dst.w = tangenth(src.w, pp);
1526 }
1527
Alexis Hetuecad5192015-06-05 13:42:05 -04001528 void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001529 {
1530 dst.x = arccosh(src.x, pp);
1531 dst.y = arccosh(src.y, pp);
1532 dst.z = arccosh(src.z, pp);
1533 dst.w = arccosh(src.w, pp);
1534 }
1535
Alexis Hetuecad5192015-06-05 13:42:05 -04001536 void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001537 {
1538 dst.x = arcsinh(src.x, pp);
1539 dst.y = arcsinh(src.y, pp);
1540 dst.z = arcsinh(src.z, pp);
1541 dst.w = arcsinh(src.w, pp);
1542 }
1543
Alexis Hetuecad5192015-06-05 13:42:05 -04001544 void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp)
Alexis Hetu8b5f3ef2015-04-16 11:33:34 -04001545 {
1546 dst.x = arctanh(src.x, pp);
1547 dst.y = arctanh(src.y, pp);
1548 dst.z = arctanh(src.z, pp);
1549 dst.w = arctanh(src.w, pp);
1550 }
1551
Alexis Hetuecad5192015-06-05 13:42:05 -04001552 void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001553 {
1554 if(version < 0x0200)
1555 {
John Bauman19bac1e2014-05-06 15:23:49 -04001556 Float4 frc = Frac(src.x);
John Bauman89401822014-05-06 15:04:28 -04001557 Float4 floor = src.x - frc;
1558
John Bauman19bac1e2014-05-06 15:23:49 -04001559 dst.x = exponential2(floor, true);
John Bauman89401822014-05-06 15:04:28 -04001560 dst.y = frc;
John Bauman19bac1e2014-05-06 15:23:49 -04001561 dst.z = exponential2(src.x, true);
1562 dst.w = Float4(1.0f);
John Bauman89401822014-05-06 15:04:28 -04001563 }
1564 else // Version >= 2.0
1565 {
John Bauman19bac1e2014-05-06 15:23:49 -04001566 exp2x(dst, src, true); // FIXME: 10-bit precision suffices
John Bauman89401822014-05-06 15:04:28 -04001567 }
1568 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001569
Alexis Hetuecad5192015-06-05 13:42:05 -04001570 void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
John Bauman89401822014-05-06 15:04:28 -04001571 {
1572 if(version < 0x0200)
1573 {
1574 Float4 tmp0;
1575 Float4 tmp1;
1576 Float4 t;
1577 Int4 r;
1578
1579 tmp0 = Abs(src.x);
1580 tmp1 = tmp0;
1581
1582 // X component
John Bauman19bac1e2014-05-06 15:23:49 -04001583 r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127);
John Bauman89401822014-05-06 15:04:28 -04001584 dst.x = Float4(r);
1585
1586 // Y component
1587 dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
1588
1589 // Z component
John Bauman19bac1e2014-05-06 15:23:49 -04001590 dst.z = logarithm2(src.x, true, true);
John Bauman89401822014-05-06 15:04:28 -04001591
1592 // W component
1593 dst.w = 1.0f;
1594 }
1595 else
1596 {
John Bauman19bac1e2014-05-06 15:23:49 -04001597 log2x(dst, src, true);
John Bauman89401822014-05-06 15:04:28 -04001598 }
1599 }
Nicolas Capens0bac2852016-05-07 06:09:58 -04001600
Alexis Hetuecad5192015-06-05 13:42:05 -04001601 void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman89401822014-05-06 15:04:28 -04001602 {
John Bauman19bac1e2014-05-06 15:23:49 -04001603 cmp0(dst.x, src0.x, src1.x, src2.x);
1604 cmp0(dst.y, src0.y, src1.y, src2.y);
1605 cmp0(dst.z, src0.z, src1.z, src2.z);
1606 cmp0(dst.w, src0.w, src1.w, src2.w);
John Bauman89401822014-05-06 15:04:28 -04001607 }
John Bauman89401822014-05-06 15:04:28 -04001608
Alexis Hetuecad5192015-06-05 13:42:05 -04001609 void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001610 {
1611 select(dst.x, As<Int4>(src0.x), src1.x, src2.x);
1612 select(dst.y, As<Int4>(src0.y), src1.y, src2.y);
1613 select(dst.z, As<Int4>(src0.z), src1.z, src2.z);
1614 select(dst.w, As<Int4>(src0.w), src1.w, src2.w);
1615 }
1616
Alexis Hetuecad5192015-06-05 13:42:05 -04001617 void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001618 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001619 select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x);
1620 select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst);
1621 select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst);
John Bauman19bac1e2014-05-06 15:23:49 -04001622 }
1623
Alexis Hetuecad5192015-06-05 13:42:05 -04001624 void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index)
John Bauman19bac1e2014-05-06 15:23:49 -04001625 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001626 select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x);
1627 select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y);
1628 select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z);
1629 select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w);
John Bauman89401822014-05-06 15:04:28 -04001630 }
1631
Alexis Hetuecad5192015-06-05 13:42:05 -04001632 void ShaderCore::sgn(Float4 &dst, const Float4 &src)
John Bauman89401822014-05-06 15:04:28 -04001633 {
John Bauman19bac1e2014-05-06 15:23:49 -04001634 Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f));
1635 Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f));
John Bauman89401822014-05-06 15:04:28 -04001636 dst = As<Float4>(neg | pos);
1637 }
1638
Alexis Hetu0f448072016-03-18 10:56:08 -04001639 void ShaderCore::isgn(Float4 &dst, const Float4 &src)
1640 {
1641 Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1);
1642 Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1);
1643 dst = As<Float4>(neg | pos);
1644 }
1645
Alexis Hetuecad5192015-06-05 13:42:05 -04001646 void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
John Bauman89401822014-05-06 15:04:28 -04001647 {
John Bauman19bac1e2014-05-06 15:23:49 -04001648 Int4 pos = CmpLE(Float4(0.0f), src0);
1649 select(dst, pos, src1, src2);
John Bauman89401822014-05-06 15:04:28 -04001650 }
1651
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001652 void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2)
1653 {
1654 Int4 pos = CmpEQ(Int4(0), As<Int4>(src0));
1655 select(dst, pos, src1, src2);
1656 }
1657
Alexis Hetuecad5192015-06-05 13:42:05 -04001658 void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2)
John Bauman19bac1e2014-05-06 15:23:49 -04001659 {
1660 // FIXME: LLVM vector select
Tom Anderson69bc6e82017-03-20 11:54:29 -07001661 dst = As<Float4>((src0 & As<Int4>(src1)) | (~src0 & As<Int4>(src2)));
John Bauman19bac1e2014-05-06 15:23:49 -04001662 }
1663
Alexis Hetuecad5192015-06-05 13:42:05 -04001664 void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman89401822014-05-06 15:04:28 -04001665 {
1666 switch(control)
1667 {
John Bauman19bac1e2014-05-06 15:23:49 -04001668 case Shader::CONTROL_GT:
John Bauman89401822014-05-06 15:04:28 -04001669 dst.x = As<Float4>(CmpNLE(src0.x, src1.x));
1670 dst.y = As<Float4>(CmpNLE(src0.y, src1.y));
1671 dst.z = As<Float4>(CmpNLE(src0.z, src1.z));
1672 dst.w = As<Float4>(CmpNLE(src0.w, src1.w));
1673 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001674 case Shader::CONTROL_EQ:
John Bauman89401822014-05-06 15:04:28 -04001675 dst.x = As<Float4>(CmpEQ(src0.x, src1.x));
1676 dst.y = As<Float4>(CmpEQ(src0.y, src1.y));
1677 dst.z = As<Float4>(CmpEQ(src0.z, src1.z));
1678 dst.w = As<Float4>(CmpEQ(src0.w, src1.w));
1679 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001680 case Shader::CONTROL_GE:
John Bauman89401822014-05-06 15:04:28 -04001681 dst.x = As<Float4>(CmpNLT(src0.x, src1.x));
1682 dst.y = As<Float4>(CmpNLT(src0.y, src1.y));
1683 dst.z = As<Float4>(CmpNLT(src0.z, src1.z));
1684 dst.w = As<Float4>(CmpNLT(src0.w, src1.w));
1685 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001686 case Shader::CONTROL_LT:
John Bauman89401822014-05-06 15:04:28 -04001687 dst.x = As<Float4>(CmpLT(src0.x, src1.x));
1688 dst.y = As<Float4>(CmpLT(src0.y, src1.y));
1689 dst.z = As<Float4>(CmpLT(src0.z, src1.z));
1690 dst.w = As<Float4>(CmpLT(src0.w, src1.w));
1691 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001692 case Shader::CONTROL_NE:
John Bauman89401822014-05-06 15:04:28 -04001693 dst.x = As<Float4>(CmpNEQ(src0.x, src1.x));
1694 dst.y = As<Float4>(CmpNEQ(src0.y, src1.y));
1695 dst.z = As<Float4>(CmpNEQ(src0.z, src1.z));
1696 dst.w = As<Float4>(CmpNEQ(src0.w, src1.w));
1697 break;
John Bauman19bac1e2014-05-06 15:23:49 -04001698 case Shader::CONTROL_LE:
John Bauman89401822014-05-06 15:04:28 -04001699 dst.x = As<Float4>(CmpLE(src0.x, src1.x));
1700 dst.y = As<Float4>(CmpLE(src0.y, src1.y));
1701 dst.z = As<Float4>(CmpLE(src0.z, src1.z));
1702 dst.w = As<Float4>(CmpLE(src0.w, src1.w));
1703 break;
1704 default:
1705 ASSERT(false);
1706 }
1707 }
John Bauman19bac1e2014-05-06 15:23:49 -04001708
Alexis Hetuecad5192015-06-05 13:42:05 -04001709 void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
John Bauman19bac1e2014-05-06 15:23:49 -04001710 {
1711 switch(control)
1712 {
1713 case Shader::CONTROL_GT:
1714 dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1715 dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1716 dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1717 dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1718 break;
1719 case Shader::CONTROL_EQ:
1720 dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1721 dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1722 dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1723 dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1724 break;
1725 case Shader::CONTROL_GE:
1726 dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1727 dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1728 dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1729 dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1730 break;
1731 case Shader::CONTROL_LT:
1732 dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x)));
1733 dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y)));
1734 dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z)));
1735 dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w)));
1736 break;
1737 case Shader::CONTROL_NE:
1738 dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x)));
1739 dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y)));
1740 dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z)));
1741 dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w)));
1742 break;
1743 case Shader::CONTROL_LE:
1744 dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x)));
1745 dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y)));
1746 dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z)));
1747 dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w)));
1748 break;
1749 default:
1750 ASSERT(false);
1751 }
1752 }
1753
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001754 void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control)
1755 {
1756 switch(control)
1757 {
1758 case Shader::CONTROL_GT:
1759 dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1760 dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1761 dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1762 dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1763 break;
1764 case Shader::CONTROL_EQ:
1765 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1766 dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1767 dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1768 dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1769 break;
1770 case Shader::CONTROL_GE:
1771 dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1772 dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1773 dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1774 dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1775 break;
1776 case Shader::CONTROL_LT:
1777 dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1778 dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1779 dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1780 dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1781 break;
1782 case Shader::CONTROL_NE:
1783 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1784 dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1785 dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1786 dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1787 break;
1788 case Shader::CONTROL_LE:
1789 dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x)));
1790 dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y)));
1791 dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z)));
1792 dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1793 break;
1794 default:
1795 ASSERT(false);
1796 }
1797 }
1798
Alexis Hetuecad5192015-06-05 13:42:05 -04001799 void ShaderCore::all(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001800 {
1801 dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w));
1802 }
1803
Alexis Hetuecad5192015-06-05 13:42:05 -04001804 void ShaderCore::any(Float4 &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001805 {
1806 dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w));
1807 }
1808
Alexis Hetu24f454e2016-08-31 17:22:13 -04001809 void ShaderCore::bitwise_not(Vector4f &dst, const Vector4f &src)
John Bauman19bac1e2014-05-06 15:23:49 -04001810 {
1811 dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF));
1812 dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF));
1813 dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF));
1814 dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF));
1815 }
1816
Alexis Hetu24f454e2016-08-31 17:22:13 -04001817 void ShaderCore::bitwise_or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001818 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001819 dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x));
1820 dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y));
1821 dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z));
1822 dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001823 }
1824
Alexis Hetu24f454e2016-08-31 17:22:13 -04001825 void ShaderCore::bitwise_xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001826 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001827 dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x));
1828 dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y));
1829 dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z));
1830 dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w));
John Bauman19bac1e2014-05-06 15:23:49 -04001831 }
1832
Alexis Hetu24f454e2016-08-31 17:22:13 -04001833 void ShaderCore::bitwise_and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
John Bauman19bac1e2014-05-06 15:23:49 -04001834 {
Alexis Hetuc4f2c292015-08-18 15:43:09 -04001835 dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x));
1836 dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y));
1837 dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z));
1838 dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w));
1839 }
1840
1841 void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1842 {
1843 dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) &
1844 CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) &
1845 CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) &
1846 CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1847 dst.y = dst.x;
1848 dst.z = dst.x;
1849 dst.w = dst.x;
1850 }
1851
1852 void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
1853 {
1854 dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) |
1855 CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) |
1856 CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) |
1857 CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w)));
1858 dst.y = dst.x;
1859 dst.z = dst.x;
1860 dst.w = dst.x;
John Bauman19bac1e2014-05-06 15:23:49 -04001861 }
John Bauman89401822014-05-06 15:04:28 -04001862}