1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // 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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // 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.
14
15 #ifndef rr_Reactor_hpp
16 #define rr_Reactor_hpp
17
18 #include "Nucleus.hpp"
19 #include "Routine.hpp"
20 #include "Traits.hpp"
21
22 #include <cassert>
23 #include <cstddef>
24 #include <cstdio>
25 #include <limits>
26 #include <tuple>
27 #include <unordered_map>
28
29 #ifdef ENABLE_RR_DEBUG_INFO
30 // Functions used for generating JIT debug info.
31 // See docs/ReactorDebugInfo.md for more information.
32 namespace rr {
33 // Update the current source location for debug.
34 void EmitDebugLocation();
35 // Bind value to its symbolic name taken from the backtrace.
36 void EmitDebugVariable(class Value *value);
37 // Flush any pending variable bindings before the line ends.
38 void FlushDebug();
39 } // namespace rr
40 # define RR_DEBUG_INFO_UPDATE_LOC() rr::EmitDebugLocation()
41 # define RR_DEBUG_INFO_EMIT_VAR(value) rr::EmitDebugVariable(value)
42 # define RR_DEBUG_INFO_FLUSH() rr::FlushDebug()
43 #else
44 # define RR_DEBUG_INFO_UPDATE_LOC()
45 # define RR_DEBUG_INFO_EMIT_VAR(value)
46 # define RR_DEBUG_INFO_FLUSH()
47 #endif // ENABLE_RR_DEBUG_INFO
48
49 #ifdef ENABLE_RR_PRINT
50 namespace rr {
51 int DebugPrintf(const char *format, ...);
52 }
53 #endif
54
55 // A Clang extension to determine compiler features.
56 // We use it to detect Sanitizer builds (e.g. -fsanitize=memory).
57 #ifndef __has_feature
58 # define __has_feature(x) 0
59 #endif
60
61 // Whether Reactor routine instrumentation is enabled for MSan builds.
62 // TODO(b/155148722): Remove when unconditionally instrumenting for all build systems.
63 #if !defined REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION
64 # define REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION 0
65 #endif
66
67 namespace rr {
68
69 // These generally map to the precision types as specified by the Vulkan specification.
70 // See https://www.khronos.org/registry/vulkan/specs/1.2/html/chap37.html#spirvenv-precision-operation
71 enum class Precision
72 {
73 /*Exact,*/ // 0 ULP with correct rounding (i.e. Math.h)
74 Full, // Single precision, but not relaxed
75 Relaxed, // Single precision, relaxed
76 /*Half,*/ // Half precision
77 };
78
79 std::string BackendName();
80
81 struct Capabilities
82 {
83 bool CoroutinesSupported; // Support for rr::Coroutine<F>
84 };
85 extern const Capabilities Caps;
86
87 class Bool;
88 class Byte;
89 class SByte;
90 class Byte4;
91 class SByte4;
92 class Byte8;
93 class SByte8;
94 class Byte16;
95 class SByte16;
96 class Short;
97 class UShort;
98 class Short2;
99 class UShort2;
100 class Short4;
101 class UShort4;
102 class Short8;
103 class UShort8;
104 class Int;
105 class UInt;
106 class Int2;
107 class UInt2;
108 class Int4;
109 class UInt4;
110 class Long;
111 class Half;
112 class Float;
113 class Float2;
114 class Float4;
115
116 class Void
117 {
118 public:
119 static Type *type();
120 };
121
122 template<class T>
123 class RValue;
124
125 template<class T>
126 class Pointer;
127
128 class Variable
129 {
130 friend class Nucleus;
131
132 Variable() = delete;
133 Variable &operator=(const Variable &) = delete;
134
135 public:
136 void materialize() const;
137
138 Value *loadValue() const;
139 Value *storeValue(Value *value) const;
140
141 Value *getBaseAddress() const;
142 Value *getElementPointer(Value *index, bool unsignedIndex) const;
143
getType() const144 Type *getType() const { return type; }
getArraySize() const145 int getArraySize() const { return arraySize; }
146
147 // This function is only public for testing purposes, as it affects performance.
148 // It is not considered part of Reactor's public API.
149 static void materializeAll();
150
151 protected:
152 Variable(Type *type, int arraySize);
153 Variable(const Variable &) = default;
154
155 virtual ~Variable();
156
157 private:
158 static void killUnmaterialized();
159
160 // Set of variables that do not have a stack location yet.
161 class UnmaterializedVariables
162 {
163 public:
164 void add(const Variable *v);
165 void remove(const Variable *v);
166 void clear();
167 void materializeAll();
168
169 private:
170 int counter = 0;
171 std::unordered_map<const Variable *, int> variables;
172 };
173
174 // This has to be a raw pointer because glibc 2.17 doesn't support __cxa_thread_atexit_impl
175 // for destructing objects at exit. See crbug.com/1074222
176 static thread_local UnmaterializedVariables *unmaterializedVariables;
177
178 Type *const type;
179 const int arraySize;
180 mutable Value *rvalue = nullptr;
181 mutable Value *address = nullptr;
182 };
183
184 template<class T>
185 class LValue : public Variable
186 {
187 public:
188 LValue(int arraySize = 0);
189
190 RValue<Pointer<T>> operator&();
191
load() const192 RValue<T> load() const
193 {
194 return RValue<T>(this->loadValue());
195 }
196
store(RValue<T> rvalue) const197 RValue<T> store(RValue<T> rvalue) const
198 {
199 this->storeValue(rvalue.value());
200
201 return rvalue;
202 }
203
204 // self() returns the this pointer to this LValue<T> object.
205 // This function exists because operator&() is overloaded.
self()206 inline LValue<T> *self() { return this; }
207 };
208
209 template<class T>
210 class Reference
211 {
212 public:
213 using reference_underlying_type = T;
214
215 explicit Reference(Value *pointer, int alignment = 1);
216
217 RValue<T> operator=(RValue<T> rhs) const;
218 RValue<T> operator=(const Reference<T> &ref) const;
219
220 RValue<T> operator+=(RValue<T> rhs) const;
221
operator &() const222 RValue<Pointer<T>> operator&() const { return RValue<Pointer<T>>(address); }
223
224 Value *loadValue() const;
225 RValue<T> load() const;
226 int getAlignment() const;
227
228 private:
229 Value *address;
230
231 const int alignment;
232 };
233
234 template<class T>
235 struct BoolLiteral
236 {
237 struct type;
238 };
239
240 template<>
241 struct BoolLiteral<Bool>
242 {
243 typedef bool type;
244 };
245
246 template<class T>
247 struct IntLiteral
248 {
249 struct type;
250 };
251
252 template<>
253 struct IntLiteral<Int>
254 {
255 typedef int type;
256 };
257
258 template<>
259 struct IntLiteral<UInt>
260 {
261 typedef unsigned int type;
262 };
263
264 template<>
265 struct IntLiteral<Long>
266 {
267 typedef int64_t type;
268 };
269
270 template<class T>
271 struct FloatLiteral
272 {
273 struct type;
274 };
275
276 template<>
277 struct FloatLiteral<Float>
278 {
279 typedef float type;
280 };
281
282 template<class T>
283 class RValue
284 {
285 public:
286 using rvalue_underlying_type = T;
287
288 explicit RValue(Value *rvalue);
289
290 RValue(const RValue<T> &rvalue);
291 RValue(const T &lvalue);
292 RValue(typename BoolLiteral<T>::type i);
293 RValue(typename IntLiteral<T>::type i);
294 RValue(typename FloatLiteral<T>::type f);
295 RValue(const Reference<T> &rhs);
296
297 // Rvalues cannot be assigned to: "(a + b) = c;"
298 RValue<T> &operator=(const RValue<T> &) = delete;
299
value() const300 Value *value() const { return val; }
301
302 private:
303 Value *const val;
304 };
305
306 template<typename T>
307 class Argument
308 {
309 public:
Argument(Value * val)310 explicit Argument(Value *val)
311 : val(val)
312 {}
313
rvalue() const314 RValue<T> rvalue() const { return RValue<T>(val); }
315
316 private:
317 Value *const val;
318 };
319
320 class Bool : public LValue<Bool>
321 {
322 public:
323 Bool(Argument<Bool> argument);
324
325 Bool() = default;
326 Bool(bool x);
327 Bool(RValue<Bool> rhs);
328 Bool(const Bool &rhs);
329 Bool(const Reference<Bool> &rhs);
330
331 // RValue<Bool> operator=(bool rhs); // FIXME: Implement
332 RValue<Bool> operator=(RValue<Bool> rhs);
333 RValue<Bool> operator=(const Bool &rhs);
334 RValue<Bool> operator=(const Reference<Bool> &rhs);
335
336 static Type *type();
337 };
338
339 RValue<Bool> operator!(RValue<Bool> val);
340 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs);
341 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs);
342 RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs);
343 RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs);
344
345 class Byte : public LValue<Byte>
346 {
347 public:
348 Byte(Argument<Byte> argument);
349
350 explicit Byte(RValue<Int> cast);
351 explicit Byte(RValue<UInt> cast);
352 explicit Byte(RValue<UShort> cast);
353
354 Byte() = default;
355 Byte(int x);
356 Byte(unsigned char x);
357 Byte(RValue<Byte> rhs);
358 Byte(const Byte &rhs);
359 Byte(const Reference<Byte> &rhs);
360
361 // RValue<Byte> operator=(unsigned char rhs); // FIXME: Implement
362 RValue<Byte> operator=(RValue<Byte> rhs);
363 RValue<Byte> operator=(const Byte &rhs);
364 RValue<Byte> operator=(const Reference<Byte> &rhs);
365
366 static Type *type();
367 };
368
369 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs);
370 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs);
371 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs);
372 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs);
373 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs);
374 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs);
375 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs);
376 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs);
377 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs);
378 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs);
379 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs);
380 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs);
381 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs);
382 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs);
383 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs);
384 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs);
385 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs);
386 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs);
387 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs);
388 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs);
389 RValue<Byte> operator+(RValue<Byte> val);
390 RValue<Byte> operator-(RValue<Byte> val);
391 RValue<Byte> operator~(RValue<Byte> val);
392 RValue<Byte> operator++(Byte &val, int); // Post-increment
393 const Byte &operator++(Byte &val); // Pre-increment
394 RValue<Byte> operator--(Byte &val, int); // Post-decrement
395 const Byte &operator--(Byte &val); // Pre-decrement
396 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs);
397 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs);
398 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs);
399 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs);
400 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs);
401 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs);
402
403 class SByte : public LValue<SByte>
404 {
405 public:
406 SByte(Argument<SByte> argument);
407
408 explicit SByte(RValue<Int> cast);
409 explicit SByte(RValue<Short> cast);
410
411 SByte() = default;
412 SByte(signed char x);
413 SByte(RValue<SByte> rhs);
414 SByte(const SByte &rhs);
415 SByte(const Reference<SByte> &rhs);
416
417 // RValue<SByte> operator=(signed char rhs); // FIXME: Implement
418 RValue<SByte> operator=(RValue<SByte> rhs);
419 RValue<SByte> operator=(const SByte &rhs);
420 RValue<SByte> operator=(const Reference<SByte> &rhs);
421
422 static Type *type();
423 };
424
425 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs);
426 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs);
427 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs);
428 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs);
429 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs);
430 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs);
431 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs);
432 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs);
433 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs);
434 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs);
435 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs);
436 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs);
437 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs);
438 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs);
439 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs);
440 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs);
441 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs);
442 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs);
443 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs);
444 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs);
445 RValue<SByte> operator+(RValue<SByte> val);
446 RValue<SByte> operator-(RValue<SByte> val);
447 RValue<SByte> operator~(RValue<SByte> val);
448 RValue<SByte> operator++(SByte &val, int); // Post-increment
449 const SByte &operator++(SByte &val); // Pre-increment
450 RValue<SByte> operator--(SByte &val, int); // Post-decrement
451 const SByte &operator--(SByte &val); // Pre-decrement
452 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs);
453 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs);
454 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs);
455 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs);
456 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs);
457 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs);
458
459 class Short : public LValue<Short>
460 {
461 public:
462 Short(Argument<Short> argument);
463
464 explicit Short(RValue<Int> cast);
465
466 Short() = default;
467 Short(short x);
468 Short(RValue<Short> rhs);
469 Short(const Short &rhs);
470 Short(const Reference<Short> &rhs);
471
472 // RValue<Short> operator=(short rhs); // FIXME: Implement
473 RValue<Short> operator=(RValue<Short> rhs);
474 RValue<Short> operator=(const Short &rhs);
475 RValue<Short> operator=(const Reference<Short> &rhs);
476
477 static Type *type();
478 };
479
480 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs);
481 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs);
482 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs);
483 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs);
484 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs);
485 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs);
486 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs);
487 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs);
488 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs);
489 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs);
490 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs);
491 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs);
492 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs);
493 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs);
494 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs);
495 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs);
496 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs);
497 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs);
498 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs);
499 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs);
500 RValue<Short> operator+(RValue<Short> val);
501 RValue<Short> operator-(RValue<Short> val);
502 RValue<Short> operator~(RValue<Short> val);
503 RValue<Short> operator++(Short &val, int); // Post-increment
504 const Short &operator++(Short &val); // Pre-increment
505 RValue<Short> operator--(Short &val, int); // Post-decrement
506 const Short &operator--(Short &val); // Pre-decrement
507 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs);
508 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs);
509 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs);
510 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs);
511 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs);
512 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs);
513
514 class UShort : public LValue<UShort>
515 {
516 public:
517 UShort(Argument<UShort> argument);
518
519 explicit UShort(RValue<UInt> cast);
520 explicit UShort(RValue<Int> cast);
521
522 UShort() = default;
523 UShort(unsigned short x);
524 UShort(RValue<UShort> rhs);
525 UShort(const UShort &rhs);
526 UShort(const Reference<UShort> &rhs);
527
528 // RValue<UShort> operator=(unsigned short rhs); // FIXME: Implement
529 RValue<UShort> operator=(RValue<UShort> rhs);
530 RValue<UShort> operator=(const UShort &rhs);
531 RValue<UShort> operator=(const Reference<UShort> &rhs);
532
533 static Type *type();
534 };
535
536 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs);
537 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs);
538 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs);
539 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs);
540 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs);
541 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs);
542 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs);
543 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs);
544 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs);
545 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs);
546 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs);
547 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs);
548 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs);
549 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs);
550 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs);
551 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs);
552 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs);
553 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs);
554 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs);
555 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs);
556 RValue<UShort> operator+(RValue<UShort> val);
557 RValue<UShort> operator-(RValue<UShort> val);
558 RValue<UShort> operator~(RValue<UShort> val);
559 RValue<UShort> operator++(UShort &val, int); // Post-increment
560 const UShort &operator++(UShort &val); // Pre-increment
561 RValue<UShort> operator--(UShort &val, int); // Post-decrement
562 const UShort &operator--(UShort &val); // Pre-decrement
563 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs);
564 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs);
565 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs);
566 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs);
567 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs);
568 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs);
569
570 class Byte4 : public LValue<Byte4>
571 {
572 public:
573 explicit Byte4(RValue<Byte8> cast);
574 explicit Byte4(RValue<UShort4> cast);
575 explicit Byte4(RValue<Short4> cast);
576 explicit Byte4(RValue<UInt4> cast);
577 explicit Byte4(RValue<Int4> cast);
578
579 Byte4() = default;
580 // Byte4(int x, int y, int z, int w);
581 Byte4(RValue<Byte4> rhs);
582 Byte4(const Byte4 &rhs);
583 Byte4(const Reference<Byte4> &rhs);
584
585 RValue<Byte4> operator=(RValue<Byte4> rhs);
586 RValue<Byte4> operator=(const Byte4 &rhs);
587 // RValue<Byte4> operator=(const Reference<Byte4> &rhs);
588
589 static Type *type();
590 };
591
592 // RValue<Byte4> operator+(RValue<Byte4> lhs, RValue<Byte4> rhs);
593 // RValue<Byte4> operator-(RValue<Byte4> lhs, RValue<Byte4> rhs);
594 // RValue<Byte4> operator*(RValue<Byte4> lhs, RValue<Byte4> rhs);
595 // RValue<Byte4> operator/(RValue<Byte4> lhs, RValue<Byte4> rhs);
596 // RValue<Byte4> operator%(RValue<Byte4> lhs, RValue<Byte4> rhs);
597 // RValue<Byte4> operator&(RValue<Byte4> lhs, RValue<Byte4> rhs);
598 // RValue<Byte4> operator|(RValue<Byte4> lhs, RValue<Byte4> rhs);
599 // RValue<Byte4> operator^(RValue<Byte4> lhs, RValue<Byte4> rhs);
600 // RValue<Byte4> operator<<(RValue<Byte4> lhs, RValue<Byte4> rhs);
601 // RValue<Byte4> operator>>(RValue<Byte4> lhs, RValue<Byte4> rhs);
602 // RValue<Byte4> operator+=(Byte4 &lhs, RValue<Byte4> rhs);
603 // RValue<Byte4> operator-=(Byte4 &lhs, RValue<Byte4> rhs);
604 // RValue<Byte4> operator*=(Byte4 &lhs, RValue<Byte4> rhs);
605 // RValue<Byte4> operator/=(Byte4 &lhs, RValue<Byte4> rhs);
606 // RValue<Byte4> operator%=(Byte4 &lhs, RValue<Byte4> rhs);
607 // RValue<Byte4> operator&=(Byte4 &lhs, RValue<Byte4> rhs);
608 // RValue<Byte4> operator|=(Byte4 &lhs, RValue<Byte4> rhs);
609 // RValue<Byte4> operator^=(Byte4 &lhs, RValue<Byte4> rhs);
610 // RValue<Byte4> operator<<=(Byte4 &lhs, RValue<Byte4> rhs);
611 // RValue<Byte4> operator>>=(Byte4 &lhs, RValue<Byte4> rhs);
612 // RValue<Byte4> operator+(RValue<Byte4> val);
613 // RValue<Byte4> operator-(RValue<Byte4> val);
614 // RValue<Byte4> operator~(RValue<Byte4> val);
615 // RValue<Byte4> operator++(Byte4 &val, int); // Post-increment
616 // const Byte4 &operator++(Byte4 &val); // Pre-increment
617 // RValue<Byte4> operator--(Byte4 &val, int); // Post-decrement
618 // const Byte4 &operator--(Byte4 &val); // Pre-decrement
619
620 class SByte4 : public LValue<SByte4>
621 {
622 public:
623 SByte4() = default;
624 // SByte4(int x, int y, int z, int w);
625 // SByte4(RValue<SByte4> rhs);
626 // SByte4(const SByte4 &rhs);
627 // SByte4(const Reference<SByte4> &rhs);
628
629 // RValue<SByte4> operator=(RValue<SByte4> rhs);
630 // RValue<SByte4> operator=(const SByte4 &rhs);
631 // RValue<SByte4> operator=(const Reference<SByte4> &rhs);
632
633 static Type *type();
634 };
635
636 // RValue<SByte4> operator+(RValue<SByte4> lhs, RValue<SByte4> rhs);
637 // RValue<SByte4> operator-(RValue<SByte4> lhs, RValue<SByte4> rhs);
638 // RValue<SByte4> operator*(RValue<SByte4> lhs, RValue<SByte4> rhs);
639 // RValue<SByte4> operator/(RValue<SByte4> lhs, RValue<SByte4> rhs);
640 // RValue<SByte4> operator%(RValue<SByte4> lhs, RValue<SByte4> rhs);
641 // RValue<SByte4> operator&(RValue<SByte4> lhs, RValue<SByte4> rhs);
642 // RValue<SByte4> operator|(RValue<SByte4> lhs, RValue<SByte4> rhs);
643 // RValue<SByte4> operator^(RValue<SByte4> lhs, RValue<SByte4> rhs);
644 // RValue<SByte4> operator<<(RValue<SByte4> lhs, RValue<SByte4> rhs);
645 // RValue<SByte4> operator>>(RValue<SByte4> lhs, RValue<SByte4> rhs);
646 // RValue<SByte4> operator+=(SByte4 &lhs, RValue<SByte4> rhs);
647 // RValue<SByte4> operator-=(SByte4 &lhs, RValue<SByte4> rhs);
648 // RValue<SByte4> operator*=(SByte4 &lhs, RValue<SByte4> rhs);
649 // RValue<SByte4> operator/=(SByte4 &lhs, RValue<SByte4> rhs);
650 // RValue<SByte4> operator%=(SByte4 &lhs, RValue<SByte4> rhs);
651 // RValue<SByte4> operator&=(SByte4 &lhs, RValue<SByte4> rhs);
652 // RValue<SByte4> operator|=(SByte4 &lhs, RValue<SByte4> rhs);
653 // RValue<SByte4> operator^=(SByte4 &lhs, RValue<SByte4> rhs);
654 // RValue<SByte4> operator<<=(SByte4 &lhs, RValue<SByte4> rhs);
655 // RValue<SByte4> operator>>=(SByte4 &lhs, RValue<SByte4> rhs);
656 // RValue<SByte4> operator+(RValue<SByte4> val);
657 // RValue<SByte4> operator-(RValue<SByte4> val);
658 // RValue<SByte4> operator~(RValue<SByte4> val);
659 // RValue<SByte4> operator++(SByte4 &val, int); // Post-increment
660 // const SByte4 &operator++(SByte4 &val); // Pre-increment
661 // RValue<SByte4> operator--(SByte4 &val, int); // Post-decrement
662 // const SByte4 &operator--(SByte4 &val); // Pre-decrement
663
664 class Byte8 : public LValue<Byte8>
665 {
666 public:
667 Byte8() = default;
668 Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7);
669 Byte8(RValue<Byte8> rhs);
670 Byte8(const Byte8 &rhs);
671 Byte8(const Reference<Byte8> &rhs);
672
673 RValue<Byte8> operator=(RValue<Byte8> rhs);
674 RValue<Byte8> operator=(const Byte8 &rhs);
675 RValue<Byte8> operator=(const Reference<Byte8> &rhs);
676
677 static Type *type();
678 };
679
680 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs);
681 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs);
682 // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs);
683 // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs);
684 // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs);
685 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs);
686 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs);
687 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs);
688 // RValue<Byte8> operator<<(RValue<Byte8> lhs, RValue<Byte8> rhs);
689 // RValue<Byte8> operator>>(RValue<Byte8> lhs, RValue<Byte8> rhs);
690 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs);
691 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs);
692 // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs);
693 // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs);
694 // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs);
695 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs);
696 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs);
697 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs);
698 // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs);
699 // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs);
700 // RValue<Byte8> operator+(RValue<Byte8> val);
701 // RValue<Byte8> operator-(RValue<Byte8> val);
702 RValue<Byte8> operator~(RValue<Byte8> val);
703 // RValue<Byte8> operator++(Byte8 &val, int); // Post-increment
704 // const Byte8 &operator++(Byte8 &val); // Pre-increment
705 // RValue<Byte8> operator--(Byte8 &val, int); // Post-decrement
706 // const Byte8 &operator--(Byte8 &val); // Pre-decrement
707
708 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y);
709 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y);
710 RValue<Short4> Unpack(RValue<Byte4> x);
711 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y);
712 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y);
713 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y);
714 RValue<Int> SignMask(RValue<Byte8> x);
715 // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y);
716 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y);
717 RValue<Byte8> Swizzle(RValue<Byte8> x, uint32_t select);
718
719 class SByte8 : public LValue<SByte8>
720 {
721 public:
722 SByte8() = default;
723 SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7);
724 SByte8(RValue<SByte8> rhs);
725 SByte8(const SByte8 &rhs);
726 SByte8(const Reference<SByte8> &rhs);
727
728 RValue<SByte8> operator=(RValue<SByte8> rhs);
729 RValue<SByte8> operator=(const SByte8 &rhs);
730 RValue<SByte8> operator=(const Reference<SByte8> &rhs);
731
732 static Type *type();
733 };
734
735 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs);
736 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs);
737 // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs);
738 // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs);
739 // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs);
740 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs);
741 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs);
742 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs);
743 // RValue<SByte8> operator<<(RValue<SByte8> lhs, RValue<SByte8> rhs);
744 // RValue<SByte8> operator>>(RValue<SByte8> lhs, RValue<SByte8> rhs);
745 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs);
746 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs);
747 // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs);
748 // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs);
749 // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs);
750 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs);
751 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs);
752 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs);
753 // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs);
754 // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs);
755 // RValue<SByte8> operator+(RValue<SByte8> val);
756 // RValue<SByte8> operator-(RValue<SByte8> val);
757 RValue<SByte8> operator~(RValue<SByte8> val);
758 // RValue<SByte8> operator++(SByte8 &val, int); // Post-increment
759 // const SByte8 &operator++(SByte8 &val); // Pre-increment
760 // RValue<SByte8> operator--(SByte8 &val, int); // Post-decrement
761 // const SByte8 &operator--(SByte8 &val); // Pre-decrement
762
763 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y);
764 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y);
765 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y);
766 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y);
767 RValue<Int> SignMask(RValue<SByte8> x);
768 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y);
769 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y);
770
771 class Byte16 : public LValue<Byte16>
772 {
773 public:
774 Byte16() = default;
775 Byte16(RValue<Byte16> rhs);
776 Byte16(const Byte16 &rhs);
777 Byte16(const Reference<Byte16> &rhs);
778
779 RValue<Byte16> operator=(RValue<Byte16> rhs);
780 RValue<Byte16> operator=(const Byte16 &rhs);
781 RValue<Byte16> operator=(const Reference<Byte16> &rhs);
782
783 static Type *type();
784 };
785
786 // RValue<Byte16> operator+(RValue<Byte16> lhs, RValue<Byte16> rhs);
787 // RValue<Byte16> operator-(RValue<Byte16> lhs, RValue<Byte16> rhs);
788 // RValue<Byte16> operator*(RValue<Byte16> lhs, RValue<Byte16> rhs);
789 // RValue<Byte16> operator/(RValue<Byte16> lhs, RValue<Byte16> rhs);
790 // RValue<Byte16> operator%(RValue<Byte16> lhs, RValue<Byte16> rhs);
791 // RValue<Byte16> operator&(RValue<Byte16> lhs, RValue<Byte16> rhs);
792 // RValue<Byte16> operator|(RValue<Byte16> lhs, RValue<Byte16> rhs);
793 // RValue<Byte16> operator^(RValue<Byte16> lhs, RValue<Byte16> rhs);
794 // RValue<Byte16> operator<<(RValue<Byte16> lhs, RValue<Byte16> rhs);
795 // RValue<Byte16> operator>>(RValue<Byte16> lhs, RValue<Byte16> rhs);
796 // RValue<Byte16> operator+=(Byte16 &lhs, RValue<Byte16> rhs);
797 // RValue<Byte16> operator-=(Byte16 &lhs, RValue<Byte16> rhs);
798 // RValue<Byte16> operator*=(Byte16 &lhs, RValue<Byte16> rhs);
799 // RValue<Byte16> operator/=(Byte16 &lhs, RValue<Byte16> rhs);
800 // RValue<Byte16> operator%=(Byte16 &lhs, RValue<Byte16> rhs);
801 // RValue<Byte16> operator&=(Byte16 &lhs, RValue<Byte16> rhs);
802 // RValue<Byte16> operator|=(Byte16 &lhs, RValue<Byte16> rhs);
803 // RValue<Byte16> operator^=(Byte16 &lhs, RValue<Byte16> rhs);
804 // RValue<Byte16> operator<<=(Byte16 &lhs, RValue<Byte16> rhs);
805 // RValue<Byte16> operator>>=(Byte16 &lhs, RValue<Byte16> rhs);
806 // RValue<Byte16> operator+(RValue<Byte16> val);
807 // RValue<Byte16> operator-(RValue<Byte16> val);
808 // RValue<Byte16> operator~(RValue<Byte16> val);
809 // RValue<Byte16> operator++(Byte16 &val, int); // Post-increment
810 // const Byte16 &operator++(Byte16 &val); // Pre-increment
811 // RValue<Byte16> operator--(Byte16 &val, int); // Post-decrement
812 // const Byte16 &operator--(Byte16 &val); // Pre-decrement
813 RValue<Byte16> Swizzle(RValue<Byte16> x, uint64_t select);
814
815 class SByte16 : public LValue<SByte16>
816 {
817 public:
818 SByte16() = default;
819 // SByte16(int x, int y, int z, int w);
820 // SByte16(RValue<SByte16> rhs);
821 // SByte16(const SByte16 &rhs);
822 // SByte16(const Reference<SByte16> &rhs);
823
824 // RValue<SByte16> operator=(RValue<SByte16> rhs);
825 // RValue<SByte16> operator=(const SByte16 &rhs);
826 // RValue<SByte16> operator=(const Reference<SByte16> &rhs);
827
828 static Type *type();
829 };
830
831 // RValue<SByte16> operator+(RValue<SByte16> lhs, RValue<SByte16> rhs);
832 // RValue<SByte16> operator-(RValue<SByte16> lhs, RValue<SByte16> rhs);
833 // RValue<SByte16> operator*(RValue<SByte16> lhs, RValue<SByte16> rhs);
834 // RValue<SByte16> operator/(RValue<SByte16> lhs, RValue<SByte16> rhs);
835 // RValue<SByte16> operator%(RValue<SByte16> lhs, RValue<SByte16> rhs);
836 // RValue<SByte16> operator&(RValue<SByte16> lhs, RValue<SByte16> rhs);
837 // RValue<SByte16> operator|(RValue<SByte16> lhs, RValue<SByte16> rhs);
838 // RValue<SByte16> operator^(RValue<SByte16> lhs, RValue<SByte16> rhs);
839 // RValue<SByte16> operator<<(RValue<SByte16> lhs, RValue<SByte16> rhs);
840 // RValue<SByte16> operator>>(RValue<SByte16> lhs, RValue<SByte16> rhs);
841 // RValue<SByte16> operator+=(SByte16 &lhs, RValue<SByte16> rhs);
842 // RValue<SByte16> operator-=(SByte16 &lhs, RValue<SByte16> rhs);
843 // RValue<SByte16> operator*=(SByte16 &lhs, RValue<SByte16> rhs);
844 // RValue<SByte16> operator/=(SByte16 &lhs, RValue<SByte16> rhs);
845 // RValue<SByte16> operator%=(SByte16 &lhs, RValue<SByte16> rhs);
846 // RValue<SByte16> operator&=(SByte16 &lhs, RValue<SByte16> rhs);
847 // RValue<SByte16> operator|=(SByte16 &lhs, RValue<SByte16> rhs);
848 // RValue<SByte16> operator^=(SByte16 &lhs, RValue<SByte16> rhs);
849 // RValue<SByte16> operator<<=(SByte16 &lhs, RValue<SByte16> rhs);
850 // RValue<SByte16> operator>>=(SByte16 &lhs, RValue<SByte16> rhs);
851 // RValue<SByte16> operator+(RValue<SByte16> val);
852 // RValue<SByte16> operator-(RValue<SByte16> val);
853 // RValue<SByte16> operator~(RValue<SByte16> val);
854 // RValue<SByte16> operator++(SByte16 &val, int); // Post-increment
855 // const SByte16 &operator++(SByte16 &val); // Pre-increment
856 // RValue<SByte16> operator--(SByte16 &val, int); // Post-decrement
857 // const SByte16 &operator--(SByte16 &val); // Pre-decrement
858
859 class Short2 : public LValue<Short2>
860 {
861 public:
862 explicit Short2(RValue<Short4> cast);
863
864 static Type *type();
865 };
866
867 class UShort2 : public LValue<UShort2>
868 {
869 public:
870 explicit UShort2(RValue<UShort4> cast);
871
872 static Type *type();
873 };
874
875 class Short4 : public LValue<Short4>
876 {
877 public:
878 explicit Short4(RValue<Int> cast);
879 explicit Short4(RValue<Int4> cast);
880 // explicit Short4(RValue<Float> cast);
881 explicit Short4(RValue<Float4> cast);
882
883 Short4() = default;
884 Short4(short xyzw);
885 Short4(short x, short y, short z, short w);
886 Short4(RValue<Short4> rhs);
887 Short4(const Short4 &rhs);
888 Short4(const Reference<Short4> &rhs);
889 Short4(RValue<UShort4> rhs);
890 Short4(const UShort4 &rhs);
891 Short4(const Reference<UShort4> &rhs);
892
893 RValue<Short4> operator=(RValue<Short4> rhs);
894 RValue<Short4> operator=(const Short4 &rhs);
895 RValue<Short4> operator=(const Reference<Short4> &rhs);
896 RValue<Short4> operator=(RValue<UShort4> rhs);
897 RValue<Short4> operator=(const UShort4 &rhs);
898 RValue<Short4> operator=(const Reference<UShort4> &rhs);
899
900 static Type *type();
901 };
902
903 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs);
904 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs);
905 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs);
906 // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs);
907 // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs);
908 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs);
909 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs);
910 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs);
911 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs);
912 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs);
913 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs);
914 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs);
915 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs);
916 // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs);
917 // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs);
918 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs);
919 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs);
920 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs);
921 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs);
922 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs);
923 // RValue<Short4> operator+(RValue<Short4> val);
924 RValue<Short4> operator-(RValue<Short4> val);
925 RValue<Short4> operator~(RValue<Short4> val);
926 // RValue<Short4> operator++(Short4 &val, int); // Post-increment
927 // const Short4 &operator++(Short4 &val); // Pre-increment
928 // RValue<Short4> operator--(Short4 &val, int); // Post-decrement
929 // const Short4 &operator--(Short4 &val); // Pre-decrement
930 // RValue<Bool> operator<(RValue<Short4> lhs, RValue<Short4> rhs);
931 // RValue<Bool> operator<=(RValue<Short4> lhs, RValue<Short4> rhs);
932 // RValue<Bool> operator>(RValue<Short4> lhs, RValue<Short4> rhs);
933 // RValue<Bool> operator>=(RValue<Short4> lhs, RValue<Short4> rhs);
934 // RValue<Bool> operator!=(RValue<Short4> lhs, RValue<Short4> rhs);
935 // RValue<Bool> operator==(RValue<Short4> lhs, RValue<Short4> rhs);
936
937 RValue<Short4> RoundShort4(RValue<Float4> cast);
938 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y);
939 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y);
940 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y);
941 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y);
942 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y);
943 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y);
944 RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y);
945 RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y);
946 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y);
947 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y);
948 RValue<Short4> Swizzle(RValue<Short4> x, uint16_t select);
949 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i);
950 RValue<Short> Extract(RValue<Short4> val, int i);
951 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y);
952 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y);
953
954 class UShort4 : public LValue<UShort4>
955 {
956 public:
957 explicit UShort4(RValue<Int4> cast);
958 explicit UShort4(RValue<Float4> cast, bool saturate = false);
959
960 UShort4() = default;
961 UShort4(unsigned short xyzw);
962 UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
963 UShort4(RValue<UShort4> rhs);
964 UShort4(const UShort4 &rhs);
965 UShort4(const Reference<UShort4> &rhs);
966 UShort4(RValue<Short4> rhs);
967 UShort4(const Short4 &rhs);
968 UShort4(const Reference<Short4> &rhs);
969
970 RValue<UShort4> operator=(RValue<UShort4> rhs);
971 RValue<UShort4> operator=(const UShort4 &rhs);
972 RValue<UShort4> operator=(const Reference<UShort4> &rhs);
973 RValue<UShort4> operator=(RValue<Short4> rhs);
974 RValue<UShort4> operator=(const Short4 &rhs);
975 RValue<UShort4> operator=(const Reference<Short4> &rhs);
976
977 static Type *type();
978 };
979
980 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs);
981 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs);
982 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs);
983 // RValue<UShort4> operator/(RValue<UShort4> lhs, RValue<UShort4> rhs);
984 // RValue<UShort4> operator%(RValue<UShort4> lhs, RValue<UShort4> rhs);
985 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs);
986 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs);
987 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs);
988 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs);
989 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs);
990 // RValue<UShort4> operator+=(UShort4 &lhs, RValue<UShort4> rhs);
991 // RValue<UShort4> operator-=(UShort4 &lhs, RValue<UShort4> rhs);
992 // RValue<UShort4> operator*=(UShort4 &lhs, RValue<UShort4> rhs);
993 // RValue<UShort4> operator/=(UShort4 &lhs, RValue<UShort4> rhs);
994 // RValue<UShort4> operator%=(UShort4 &lhs, RValue<UShort4> rhs);
995 // RValue<UShort4> operator&=(UShort4 &lhs, RValue<UShort4> rhs);
996 // RValue<UShort4> operator|=(UShort4 &lhs, RValue<UShort4> rhs);
997 // RValue<UShort4> operator^=(UShort4 &lhs, RValue<UShort4> rhs);
998 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs);
999 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs);
1000 // RValue<UShort4> operator+(RValue<UShort4> val);
1001 // RValue<UShort4> operator-(RValue<UShort4> val);
1002 RValue<UShort4> operator~(RValue<UShort4> val);
1003 // RValue<UShort4> operator++(UShort4 &val, int); // Post-increment
1004 // const UShort4 &operator++(UShort4 &val); // Pre-increment
1005 // RValue<UShort4> operator--(UShort4 &val, int); // Post-decrement
1006 // const UShort4 &operator--(UShort4 &val); // Pre-decrement
1007
1008 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y);
1009 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y);
1010 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y);
1011 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y);
1012 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y);
1013 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y);
1014
1015 class Short8 : public LValue<Short8>
1016 {
1017 public:
1018 Short8() = default;
1019 Short8(short c);
1020 Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7);
1021 Short8(RValue<Short8> rhs);
1022 // Short8(const Short8 &rhs);
1023 Short8(const Reference<Short8> &rhs);
1024 Short8(RValue<Short4> lo, RValue<Short4> hi);
1025
1026 RValue<Short8> operator=(RValue<Short8> rhs);
1027 RValue<Short8> operator=(const Short8 &rhs);
1028 RValue<Short8> operator=(const Reference<Short8> &rhs);
1029
1030 static Type *type();
1031 };
1032
1033 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs);
1034 // RValue<Short8> operator-(RValue<Short8> lhs, RValue<Short8> rhs);
1035 // RValue<Short8> operator*(RValue<Short8> lhs, RValue<Short8> rhs);
1036 // RValue<Short8> operator/(RValue<Short8> lhs, RValue<Short8> rhs);
1037 // RValue<Short8> operator%(RValue<Short8> lhs, RValue<Short8> rhs);
1038 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs);
1039 // RValue<Short8> operator|(RValue<Short8> lhs, RValue<Short8> rhs);
1040 // RValue<Short8> operator^(RValue<Short8> lhs, RValue<Short8> rhs);
1041 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs);
1042 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs);
1043 // RValue<Short8> operator<<(RValue<Short8> lhs, RValue<Short8> rhs);
1044 // RValue<Short8> operator>>(RValue<Short8> lhs, RValue<Short8> rhs);
1045 // RValue<Short8> operator+=(Short8 &lhs, RValue<Short8> rhs);
1046 // RValue<Short8> operator-=(Short8 &lhs, RValue<Short8> rhs);
1047 // RValue<Short8> operator*=(Short8 &lhs, RValue<Short8> rhs);
1048 // RValue<Short8> operator/=(Short8 &lhs, RValue<Short8> rhs);
1049 // RValue<Short8> operator%=(Short8 &lhs, RValue<Short8> rhs);
1050 // RValue<Short8> operator&=(Short8 &lhs, RValue<Short8> rhs);
1051 // RValue<Short8> operator|=(Short8 &lhs, RValue<Short8> rhs);
1052 // RValue<Short8> operator^=(Short8 &lhs, RValue<Short8> rhs);
1053 // RValue<Short8> operator<<=(Short8 &lhs, RValue<Short8> rhs);
1054 // RValue<Short8> operator>>=(Short8 &lhs, RValue<Short8> rhs);
1055 // RValue<Short8> operator+(RValue<Short8> val);
1056 // RValue<Short8> operator-(RValue<Short8> val);
1057 // RValue<Short8> operator~(RValue<Short8> val);
1058 // RValue<Short8> operator++(Short8 &val, int); // Post-increment
1059 // const Short8 &operator++(Short8 &val); // Pre-increment
1060 // RValue<Short8> operator--(Short8 &val, int); // Post-decrement
1061 // const Short8 &operator--(Short8 &val); // Pre-decrement
1062 // RValue<Bool> operator<(RValue<Short8> lhs, RValue<Short8> rhs);
1063 // RValue<Bool> operator<=(RValue<Short8> lhs, RValue<Short8> rhs);
1064 // RValue<Bool> operator>(RValue<Short8> lhs, RValue<Short8> rhs);
1065 // RValue<Bool> operator>=(RValue<Short8> lhs, RValue<Short8> rhs);
1066 // RValue<Bool> operator!=(RValue<Short8> lhs, RValue<Short8> rhs);
1067 // RValue<Bool> operator==(RValue<Short8> lhs, RValue<Short8> rhs);
1068
1069 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y);
1070 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y);
1071 RValue<Int4> Abs(RValue<Int4> x);
1072
1073 class UShort8 : public LValue<UShort8>
1074 {
1075 public:
1076 UShort8() = default;
1077 UShort8(unsigned short c);
1078 UShort8(unsigned short c0, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short c4, unsigned short c5, unsigned short c6, unsigned short c7);
1079 UShort8(RValue<UShort8> rhs);
1080 // UShort8(const UShort8 &rhs);
1081 UShort8(const Reference<UShort8> &rhs);
1082 UShort8(RValue<UShort4> lo, RValue<UShort4> hi);
1083
1084 RValue<UShort8> operator=(RValue<UShort8> rhs);
1085 RValue<UShort8> operator=(const UShort8 &rhs);
1086 RValue<UShort8> operator=(const Reference<UShort8> &rhs);
1087
1088 static Type *type();
1089 };
1090
1091 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs);
1092 // RValue<UShort8> operator-(RValue<UShort8> lhs, RValue<UShort8> rhs);
1093 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs);
1094 // RValue<UShort8> operator/(RValue<UShort8> lhs, RValue<UShort8> rhs);
1095 // RValue<UShort8> operator%(RValue<UShort8> lhs, RValue<UShort8> rhs);
1096 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs);
1097 // RValue<UShort8> operator|(RValue<UShort8> lhs, RValue<UShort8> rhs);
1098 // RValue<UShort8> operator^(RValue<UShort8> lhs, RValue<UShort8> rhs);
1099 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs);
1100 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs);
1101 // RValue<UShort8> operator<<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1102 // RValue<UShort8> operator>>(RValue<UShort8> lhs, RValue<UShort8> rhs);
1103 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs);
1104 // RValue<UShort8> operator-=(UShort8 &lhs, RValue<UShort8> rhs);
1105 // RValue<UShort8> operator*=(UShort8 &lhs, RValue<UShort8> rhs);
1106 // RValue<UShort8> operator/=(UShort8 &lhs, RValue<UShort8> rhs);
1107 // RValue<UShort8> operator%=(UShort8 &lhs, RValue<UShort8> rhs);
1108 // RValue<UShort8> operator&=(UShort8 &lhs, RValue<UShort8> rhs);
1109 // RValue<UShort8> operator|=(UShort8 &lhs, RValue<UShort8> rhs);
1110 // RValue<UShort8> operator^=(UShort8 &lhs, RValue<UShort8> rhs);
1111 // RValue<UShort8> operator<<=(UShort8 &lhs, RValue<UShort8> rhs);
1112 // RValue<UShort8> operator>>=(UShort8 &lhs, RValue<UShort8> rhs);
1113 // RValue<UShort8> operator+(RValue<UShort8> val);
1114 // RValue<UShort8> operator-(RValue<UShort8> val);
1115 RValue<UShort8> operator~(RValue<UShort8> val);
1116 // RValue<UShort8> operator++(UShort8 &val, int); // Post-increment
1117 // const UShort8 &operator++(UShort8 &val); // Pre-increment
1118 // RValue<UShort8> operator--(UShort8 &val, int); // Post-decrement
1119 // const UShort8 &operator--(UShort8 &val); // Pre-decrement
1120 // RValue<Bool> operator<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1121 // RValue<Bool> operator<=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1122 // RValue<Bool> operator>(RValue<UShort8> lhs, RValue<UShort8> rhs);
1123 // RValue<Bool> operator>=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1124 // RValue<Bool> operator!=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1125 // RValue<Bool> operator==(RValue<UShort8> lhs, RValue<UShort8> rhs);
1126
1127 RValue<UShort8> Swizzle(RValue<UShort8> x, uint32_t select);
1128 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y);
1129
1130 class Int : public LValue<Int>
1131 {
1132 public:
1133 Int(Argument<Int> argument);
1134
1135 explicit Int(RValue<Byte> cast);
1136 explicit Int(RValue<SByte> cast);
1137 explicit Int(RValue<Short> cast);
1138 explicit Int(RValue<UShort> cast);
1139 explicit Int(RValue<Int2> cast);
1140 explicit Int(RValue<Long> cast);
1141 explicit Int(RValue<Float> cast);
1142
1143 Int() = default;
1144 Int(int x);
1145 Int(RValue<Int> rhs);
1146 Int(RValue<UInt> rhs);
1147 Int(const Int &rhs);
1148 Int(const UInt &rhs);
1149 Int(const Reference<Int> &rhs);
1150 Int(const Reference<UInt> &rhs);
1151
1152 RValue<Int> operator=(int rhs);
1153 RValue<Int> operator=(RValue<Int> rhs);
1154 RValue<Int> operator=(RValue<UInt> rhs);
1155 RValue<Int> operator=(const Int &rhs);
1156 RValue<Int> operator=(const UInt &rhs);
1157 RValue<Int> operator=(const Reference<Int> &rhs);
1158 RValue<Int> operator=(const Reference<UInt> &rhs);
1159
1160 static Type *type();
1161 };
1162
1163 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs);
1164 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs);
1165 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs);
1166 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs);
1167 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs);
1168 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs);
1169 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs);
1170 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs);
1171 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs);
1172 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs);
1173 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs);
1174 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs);
1175 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs);
1176 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs);
1177 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs);
1178 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs);
1179 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs);
1180 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs);
1181 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs);
1182 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs);
1183 RValue<Int> operator+(RValue<Int> val);
1184 RValue<Int> operator-(RValue<Int> val);
1185 RValue<Int> operator~(RValue<Int> val);
1186 RValue<Int> operator++(Int &val, int); // Post-increment
1187 const Int &operator++(Int &val); // Pre-increment
1188 RValue<Int> operator--(Int &val, int); // Post-decrement
1189 const Int &operator--(Int &val); // Pre-decrement
1190 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs);
1191 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs);
1192 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs);
1193 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs);
1194 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs);
1195 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs);
1196
1197 RValue<Int> Max(RValue<Int> x, RValue<Int> y);
1198 RValue<Int> Min(RValue<Int> x, RValue<Int> y);
1199 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max);
1200 RValue<Int> RoundInt(RValue<Float> cast);
1201
1202 class Long : public LValue<Long>
1203 {
1204 public:
1205 // Long(Argument<Long> argument);
1206
1207 // explicit Long(RValue<Short> cast);
1208 // explicit Long(RValue<UShort> cast);
1209 explicit Long(RValue<Int> cast);
1210 explicit Long(RValue<UInt> cast);
1211 // explicit Long(RValue<Float> cast);
1212
1213 Long() = default;
1214 // Long(qword x);
1215 Long(RValue<Long> rhs);
1216 // Long(RValue<ULong> rhs);
1217 // Long(const Long &rhs);
1218 // Long(const Reference<Long> &rhs);
1219 // Long(const ULong &rhs);
1220 // Long(const Reference<ULong> &rhs);
1221
1222 RValue<Long> operator=(int64_t rhs);
1223 RValue<Long> operator=(RValue<Long> rhs);
1224 // RValue<Long> operator=(RValue<ULong> rhs);
1225 RValue<Long> operator=(const Long &rhs);
1226 RValue<Long> operator=(const Reference<Long> &rhs);
1227 // RValue<Long> operator=(const ULong &rhs);
1228 // RValue<Long> operator=(const Reference<ULong> &rhs);
1229
1230 static Type *type();
1231 };
1232
1233 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs);
1234 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs);
1235 RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs);
1236 // RValue<Long> operator/(RValue<Long> lhs, RValue<Long> rhs);
1237 // RValue<Long> operator%(RValue<Long> lhs, RValue<Long> rhs);
1238 // RValue<Long> operator&(RValue<Long> lhs, RValue<Long> rhs);
1239 // RValue<Long> operator|(RValue<Long> lhs, RValue<Long> rhs);
1240 // RValue<Long> operator^(RValue<Long> lhs, RValue<Long> rhs);
1241 // RValue<Long> operator<<(RValue<Long> lhs, RValue<Long> rhs);
1242 RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs);
1243 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs);
1244 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs);
1245 // RValue<Long> operator*=(Long &lhs, RValue<Long> rhs);
1246 // RValue<Long> operator/=(Long &lhs, RValue<Long> rhs);
1247 // RValue<Long> operator%=(Long &lhs, RValue<Long> rhs);
1248 // RValue<Long> operator&=(Long &lhs, RValue<Long> rhs);
1249 // RValue<Long> operator|=(Long &lhs, RValue<Long> rhs);
1250 // RValue<Long> operator^=(Long &lhs, RValue<Long> rhs);
1251 // RValue<Long> operator<<=(Long &lhs, RValue<Long> rhs);
1252 // RValue<Long> operator>>=(Long &lhs, RValue<Long> rhs);
1253 // RValue<Long> operator+(RValue<Long> val);
1254 // RValue<Long> operator-(RValue<Long> val);
1255 // RValue<Long> operator~(RValue<Long> val);
1256 // RValue<Long> operator++(Long &val, int); // Post-increment
1257 // const Long &operator++(Long &val); // Pre-increment
1258 // RValue<Long> operator--(Long &val, int); // Post-decrement
1259 // const Long &operator--(Long &val); // Pre-decrement
1260 // RValue<Bool> operator<(RValue<Long> lhs, RValue<Long> rhs);
1261 // RValue<Bool> operator<=(RValue<Long> lhs, RValue<Long> rhs);
1262 // RValue<Bool> operator>(RValue<Long> lhs, RValue<Long> rhs);
1263 // RValue<Bool> operator>=(RValue<Long> lhs, RValue<Long> rhs);
1264 // RValue<Bool> operator!=(RValue<Long> lhs, RValue<Long> rhs);
1265 // RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs);
1266
1267 // RValue<Long> RoundLong(RValue<Float> cast);
1268 RValue<Long> AddAtomic(RValue<Pointer<Long>> x, RValue<Long> y);
1269
1270 class UInt : public LValue<UInt>
1271 {
1272 public:
1273 UInt(Argument<UInt> argument);
1274
1275 explicit UInt(RValue<UShort> cast);
1276 explicit UInt(RValue<Long> cast);
1277 explicit UInt(RValue<Float> cast);
1278
1279 UInt() = default;
1280 UInt(int x);
1281 UInt(unsigned int x);
1282 UInt(RValue<UInt> rhs);
1283 UInt(RValue<Int> rhs);
1284 UInt(const UInt &rhs);
1285 UInt(const Int &rhs);
1286 UInt(const Reference<UInt> &rhs);
1287 UInt(const Reference<Int> &rhs);
1288
1289 RValue<UInt> operator=(unsigned int rhs);
1290 RValue<UInt> operator=(RValue<UInt> rhs);
1291 RValue<UInt> operator=(RValue<Int> rhs);
1292 RValue<UInt> operator=(const UInt &rhs);
1293 RValue<UInt> operator=(const Int &rhs);
1294 RValue<UInt> operator=(const Reference<UInt> &rhs);
1295 RValue<UInt> operator=(const Reference<Int> &rhs);
1296
1297 static Type *type();
1298 };
1299
1300 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs);
1301 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs);
1302 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs);
1303 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs);
1304 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs);
1305 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs);
1306 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs);
1307 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs);
1308 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs);
1309 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs);
1310 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs);
1311 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs);
1312 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs);
1313 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs);
1314 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs);
1315 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs);
1316 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs);
1317 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs);
1318 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs);
1319 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs);
1320 RValue<UInt> operator+(RValue<UInt> val);
1321 RValue<UInt> operator-(RValue<UInt> val);
1322 RValue<UInt> operator~(RValue<UInt> val);
1323 RValue<UInt> operator++(UInt &val, int); // Post-increment
1324 const UInt &operator++(UInt &val); // Pre-increment
1325 RValue<UInt> operator--(UInt &val, int); // Post-decrement
1326 const UInt &operator--(UInt &val); // Pre-decrement
1327 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs);
1328 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs);
1329 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs);
1330 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs);
1331 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs);
1332 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs);
1333
1334 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y);
1335 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y);
1336 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max);
1337
1338 RValue<UInt> AddAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1339 RValue<UInt> SubAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1340 RValue<UInt> AndAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1341 RValue<UInt> OrAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1342 RValue<UInt> XorAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1343 RValue<Int> MinAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1344 RValue<Int> MaxAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1345 RValue<UInt> MinAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1346 RValue<UInt> MaxAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1347 RValue<UInt> ExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1348 RValue<UInt> CompareExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, RValue<UInt> compare, std::memory_order memoryOrderEqual, std::memory_order memoryOrderUnequal);
1349
1350 // RValue<UInt> RoundUInt(RValue<Float> cast);
1351
1352 class Int2 : public LValue<Int2>
1353 {
1354 public:
1355 // explicit Int2(RValue<Int> cast);
1356 explicit Int2(RValue<Int4> cast);
1357
1358 Int2() = default;
1359 Int2(int x, int y);
1360 Int2(RValue<Int2> rhs);
1361 Int2(const Int2 &rhs);
1362 Int2(const Reference<Int2> &rhs);
1363 Int2(RValue<Int> lo, RValue<Int> hi);
1364
1365 RValue<Int2> operator=(RValue<Int2> rhs);
1366 RValue<Int2> operator=(const Int2 &rhs);
1367 RValue<Int2> operator=(const Reference<Int2> &rhs);
1368
1369 static Type *type();
1370 };
1371
1372 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs);
1373 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs);
1374 // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs);
1375 // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs);
1376 // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs);
1377 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs);
1378 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs);
1379 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs);
1380 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs);
1381 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs);
1382 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs);
1383 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs);
1384 // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs);
1385 // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs);
1386 // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs);
1387 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs);
1388 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs);
1389 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs);
1390 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs);
1391 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs);
1392 // RValue<Int2> operator+(RValue<Int2> val);
1393 // RValue<Int2> operator-(RValue<Int2> val);
1394 RValue<Int2> operator~(RValue<Int2> val);
1395 // RValue<Int2> operator++(Int2 &val, int); // Post-increment
1396 // const Int2 &operator++(Int2 &val); // Pre-increment
1397 // RValue<Int2> operator--(Int2 &val, int); // Post-decrement
1398 // const Int2 &operator--(Int2 &val); // Pre-decrement
1399 // RValue<Bool> operator<(RValue<Int2> lhs, RValue<Int2> rhs);
1400 // RValue<Bool> operator<=(RValue<Int2> lhs, RValue<Int2> rhs);
1401 // RValue<Bool> operator>(RValue<Int2> lhs, RValue<Int2> rhs);
1402 // RValue<Bool> operator>=(RValue<Int2> lhs, RValue<Int2> rhs);
1403 // RValue<Bool> operator!=(RValue<Int2> lhs, RValue<Int2> rhs);
1404 // RValue<Bool> operator==(RValue<Int2> lhs, RValue<Int2> rhs);
1405
1406 // RValue<Int2> RoundInt(RValue<Float4> cast);
1407 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y);
1408 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y);
1409 RValue<Int> Extract(RValue<Int2> val, int i);
1410 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i);
1411
1412 class UInt2 : public LValue<UInt2>
1413 {
1414 public:
1415 UInt2() = default;
1416 UInt2(unsigned int x, unsigned int y);
1417 UInt2(RValue<UInt2> rhs);
1418 UInt2(const UInt2 &rhs);
1419 UInt2(const Reference<UInt2> &rhs);
1420
1421 RValue<UInt2> operator=(RValue<UInt2> rhs);
1422 RValue<UInt2> operator=(const UInt2 &rhs);
1423 RValue<UInt2> operator=(const Reference<UInt2> &rhs);
1424
1425 static Type *type();
1426 };
1427
1428 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs);
1429 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs);
1430 // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs);
1431 // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs);
1432 // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs);
1433 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs);
1434 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs);
1435 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs);
1436 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs);
1437 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs);
1438 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs);
1439 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs);
1440 // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs);
1441 // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs);
1442 // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs);
1443 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs);
1444 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs);
1445 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs);
1446 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs);
1447 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs);
1448 // RValue<UInt2> operator+(RValue<UInt2> val);
1449 // RValue<UInt2> operator-(RValue<UInt2> val);
1450 RValue<UInt2> operator~(RValue<UInt2> val);
1451 // RValue<UInt2> operator++(UInt2 &val, int); // Post-increment
1452 // const UInt2 &operator++(UInt2 &val); // Pre-increment
1453 // RValue<UInt2> operator--(UInt2 &val, int); // Post-decrement
1454 // const UInt2 &operator--(UInt2 &val); // Pre-decrement
1455 // RValue<Bool> operator<(RValue<UInt2> lhs, RValue<UInt2> rhs);
1456 // RValue<Bool> operator<=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1457 // RValue<Bool> operator>(RValue<UInt2> lhs, RValue<UInt2> rhs);
1458 // RValue<Bool> operator>=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1459 // RValue<Bool> operator!=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1460 // RValue<Bool> operator==(RValue<UInt2> lhs, RValue<UInt2> rhs);
1461
1462 // RValue<UInt2> RoundInt(RValue<Float4> cast);
1463 RValue<UInt> Extract(RValue<UInt2> val, int i);
1464 RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i);
1465
1466 template<class T>
1467 struct Scalar;
1468
1469 template<class Vector4>
1470 struct XYZW;
1471
1472 template<class Vector4, int T>
1473 class Swizzle2
1474 {
1475 friend Vector4;
1476
1477 public:
1478 operator RValue<Vector4>() const;
1479
1480 private:
1481 Vector4 *parent;
1482 };
1483
1484 template<class Vector4, int T>
1485 class Swizzle4
1486 {
1487 public:
1488 operator RValue<Vector4>() const;
1489
1490 private:
1491 Vector4 *parent;
1492 };
1493
1494 template<class Vector4, int T>
1495 class SwizzleMask4
1496 {
1497 friend XYZW<Vector4>;
1498
1499 public:
1500 operator RValue<Vector4>() const;
1501
1502 RValue<Vector4> operator=(RValue<Vector4> rhs);
1503 RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
1504
1505 private:
1506 Vector4 *parent;
1507 };
1508
1509 template<>
1510 struct Scalar<Float4>
1511 {
1512 using Type = Float;
1513 };
1514
1515 template<>
1516 struct Scalar<Int4>
1517 {
1518 using Type = Int;
1519 };
1520
1521 template<>
1522 struct Scalar<UInt4>
1523 {
1524 using Type = UInt;
1525 };
1526
1527 template<class Vector4, int T>
1528 class SwizzleMask1
1529 {
1530 public:
1531 operator RValue<typename Scalar<Vector4>::Type>() const;
1532 operator RValue<Vector4>() const;
1533
1534 RValue<Vector4> operator=(float x);
1535 RValue<Vector4> operator=(RValue<Vector4> rhs);
1536 RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
1537
1538 private:
1539 Vector4 *parent;
1540 };
1541
1542 template<class Vector4, int T>
1543 class SwizzleMask2
1544 {
1545 friend class Float4;
1546
1547 public:
1548 operator RValue<Vector4>() const;
1549
1550 RValue<Vector4> operator=(RValue<Vector4> rhs);
1551
1552 private:
1553 Float4 *parent;
1554 };
1555
1556 template<class Vector4>
1557 struct XYZW
1558 {
1559 friend Vector4;
1560
1561 private:
XYZWrr::XYZW1562 XYZW(Vector4 *parent)
1563 {
1564 xyzw.parent = parent;
1565 }
1566
1567 public:
1568 union
1569 {
1570 SwizzleMask1<Vector4, 0x0000> x;
1571 SwizzleMask1<Vector4, 0x1111> y;
1572 SwizzleMask1<Vector4, 0x2222> z;
1573 SwizzleMask1<Vector4, 0x3333> w;
1574 Swizzle2<Vector4, 0x0000> xx;
1575 Swizzle2<Vector4, 0x1000> yx;
1576 Swizzle2<Vector4, 0x2000> zx;
1577 Swizzle2<Vector4, 0x3000> wx;
1578 SwizzleMask2<Vector4, 0x0111> xy;
1579 Swizzle2<Vector4, 0x1111> yy;
1580 Swizzle2<Vector4, 0x2111> zy;
1581 Swizzle2<Vector4, 0x3111> wy;
1582 SwizzleMask2<Vector4, 0x0222> xz;
1583 SwizzleMask2<Vector4, 0x1222> yz;
1584 Swizzle2<Vector4, 0x2222> zz;
1585 Swizzle2<Vector4, 0x3222> wz;
1586 SwizzleMask2<Vector4, 0x0333> xw;
1587 SwizzleMask2<Vector4, 0x1333> yw;
1588 SwizzleMask2<Vector4, 0x2333> zw;
1589 Swizzle2<Vector4, 0x3333> ww;
1590 Swizzle4<Vector4, 0x0000> xxx;
1591 Swizzle4<Vector4, 0x1000> yxx;
1592 Swizzle4<Vector4, 0x2000> zxx;
1593 Swizzle4<Vector4, 0x3000> wxx;
1594 Swizzle4<Vector4, 0x0100> xyx;
1595 Swizzle4<Vector4, 0x1100> yyx;
1596 Swizzle4<Vector4, 0x2100> zyx;
1597 Swizzle4<Vector4, 0x3100> wyx;
1598 Swizzle4<Vector4, 0x0200> xzx;
1599 Swizzle4<Vector4, 0x1200> yzx;
1600 Swizzle4<Vector4, 0x2200> zzx;
1601 Swizzle4<Vector4, 0x3200> wzx;
1602 Swizzle4<Vector4, 0x0300> xwx;
1603 Swizzle4<Vector4, 0x1300> ywx;
1604 Swizzle4<Vector4, 0x2300> zwx;
1605 Swizzle4<Vector4, 0x3300> wwx;
1606 Swizzle4<Vector4, 0x0011> xxy;
1607 Swizzle4<Vector4, 0x1011> yxy;
1608 Swizzle4<Vector4, 0x2011> zxy;
1609 Swizzle4<Vector4, 0x3011> wxy;
1610 Swizzle4<Vector4, 0x0111> xyy;
1611 Swizzle4<Vector4, 0x1111> yyy;
1612 Swizzle4<Vector4, 0x2111> zyy;
1613 Swizzle4<Vector4, 0x3111> wyy;
1614 Swizzle4<Vector4, 0x0211> xzy;
1615 Swizzle4<Vector4, 0x1211> yzy;
1616 Swizzle4<Vector4, 0x2211> zzy;
1617 Swizzle4<Vector4, 0x3211> wzy;
1618 Swizzle4<Vector4, 0x0311> xwy;
1619 Swizzle4<Vector4, 0x1311> ywy;
1620 Swizzle4<Vector4, 0x2311> zwy;
1621 Swizzle4<Vector4, 0x3311> wwy;
1622 Swizzle4<Vector4, 0x0022> xxz;
1623 Swizzle4<Vector4, 0x1022> yxz;
1624 Swizzle4<Vector4, 0x2022> zxz;
1625 Swizzle4<Vector4, 0x3022> wxz;
1626 SwizzleMask4<Vector4, 0x0122> xyz;
1627 Swizzle4<Vector4, 0x1122> yyz;
1628 Swizzle4<Vector4, 0x2122> zyz;
1629 Swizzle4<Vector4, 0x3122> wyz;
1630 Swizzle4<Vector4, 0x0222> xzz;
1631 Swizzle4<Vector4, 0x1222> yzz;
1632 Swizzle4<Vector4, 0x2222> zzz;
1633 Swizzle4<Vector4, 0x3222> wzz;
1634 Swizzle4<Vector4, 0x0322> xwz;
1635 Swizzle4<Vector4, 0x1322> ywz;
1636 Swizzle4<Vector4, 0x2322> zwz;
1637 Swizzle4<Vector4, 0x3322> wwz;
1638 Swizzle4<Vector4, 0x0033> xxw;
1639 Swizzle4<Vector4, 0x1033> yxw;
1640 Swizzle4<Vector4, 0x2033> zxw;
1641 Swizzle4<Vector4, 0x3033> wxw;
1642 SwizzleMask4<Vector4, 0x0133> xyw;
1643 Swizzle4<Vector4, 0x1133> yyw;
1644 Swizzle4<Vector4, 0x2133> zyw;
1645 Swizzle4<Vector4, 0x3133> wyw;
1646 SwizzleMask4<Vector4, 0x0233> xzw;
1647 SwizzleMask4<Vector4, 0x1233> yzw;
1648 Swizzle4<Vector4, 0x2233> zzw;
1649 Swizzle4<Vector4, 0x3233> wzw;
1650 Swizzle4<Vector4, 0x0333> xww;
1651 Swizzle4<Vector4, 0x1333> yww;
1652 Swizzle4<Vector4, 0x2333> zww;
1653 Swizzle4<Vector4, 0x3333> www;
1654 Swizzle4<Vector4, 0x0000> xxxx;
1655 Swizzle4<Vector4, 0x1000> yxxx;
1656 Swizzle4<Vector4, 0x2000> zxxx;
1657 Swizzle4<Vector4, 0x3000> wxxx;
1658 Swizzle4<Vector4, 0x0100> xyxx;
1659 Swizzle4<Vector4, 0x1100> yyxx;
1660 Swizzle4<Vector4, 0x2100> zyxx;
1661 Swizzle4<Vector4, 0x3100> wyxx;
1662 Swizzle4<Vector4, 0x0200> xzxx;
1663 Swizzle4<Vector4, 0x1200> yzxx;
1664 Swizzle4<Vector4, 0x2200> zzxx;
1665 Swizzle4<Vector4, 0x3200> wzxx;
1666 Swizzle4<Vector4, 0x0300> xwxx;
1667 Swizzle4<Vector4, 0x1300> ywxx;
1668 Swizzle4<Vector4, 0x2300> zwxx;
1669 Swizzle4<Vector4, 0x3300> wwxx;
1670 Swizzle4<Vector4, 0x0010> xxyx;
1671 Swizzle4<Vector4, 0x1010> yxyx;
1672 Swizzle4<Vector4, 0x2010> zxyx;
1673 Swizzle4<Vector4, 0x3010> wxyx;
1674 Swizzle4<Vector4, 0x0110> xyyx;
1675 Swizzle4<Vector4, 0x1110> yyyx;
1676 Swizzle4<Vector4, 0x2110> zyyx;
1677 Swizzle4<Vector4, 0x3110> wyyx;
1678 Swizzle4<Vector4, 0x0210> xzyx;
1679 Swizzle4<Vector4, 0x1210> yzyx;
1680 Swizzle4<Vector4, 0x2210> zzyx;
1681 Swizzle4<Vector4, 0x3210> wzyx;
1682 Swizzle4<Vector4, 0x0310> xwyx;
1683 Swizzle4<Vector4, 0x1310> ywyx;
1684 Swizzle4<Vector4, 0x2310> zwyx;
1685 Swizzle4<Vector4, 0x3310> wwyx;
1686 Swizzle4<Vector4, 0x0020> xxzx;
1687 Swizzle4<Vector4, 0x1020> yxzx;
1688 Swizzle4<Vector4, 0x2020> zxzx;
1689 Swizzle4<Vector4, 0x3020> wxzx;
1690 Swizzle4<Vector4, 0x0120> xyzx;
1691 Swizzle4<Vector4, 0x1120> yyzx;
1692 Swizzle4<Vector4, 0x2120> zyzx;
1693 Swizzle4<Vector4, 0x3120> wyzx;
1694 Swizzle4<Vector4, 0x0220> xzzx;
1695 Swizzle4<Vector4, 0x1220> yzzx;
1696 Swizzle4<Vector4, 0x2220> zzzx;
1697 Swizzle4<Vector4, 0x3220> wzzx;
1698 Swizzle4<Vector4, 0x0320> xwzx;
1699 Swizzle4<Vector4, 0x1320> ywzx;
1700 Swizzle4<Vector4, 0x2320> zwzx;
1701 Swizzle4<Vector4, 0x3320> wwzx;
1702 Swizzle4<Vector4, 0x0030> xxwx;
1703 Swizzle4<Vector4, 0x1030> yxwx;
1704 Swizzle4<Vector4, 0x2030> zxwx;
1705 Swizzle4<Vector4, 0x3030> wxwx;
1706 Swizzle4<Vector4, 0x0130> xywx;
1707 Swizzle4<Vector4, 0x1130> yywx;
1708 Swizzle4<Vector4, 0x2130> zywx;
1709 Swizzle4<Vector4, 0x3130> wywx;
1710 Swizzle4<Vector4, 0x0230> xzwx;
1711 Swizzle4<Vector4, 0x1230> yzwx;
1712 Swizzle4<Vector4, 0x2230> zzwx;
1713 Swizzle4<Vector4, 0x3230> wzwx;
1714 Swizzle4<Vector4, 0x0330> xwwx;
1715 Swizzle4<Vector4, 0x1330> ywwx;
1716 Swizzle4<Vector4, 0x2330> zwwx;
1717 Swizzle4<Vector4, 0x3330> wwwx;
1718 Swizzle4<Vector4, 0x0001> xxxy;
1719 Swizzle4<Vector4, 0x1001> yxxy;
1720 Swizzle4<Vector4, 0x2001> zxxy;
1721 Swizzle4<Vector4, 0x3001> wxxy;
1722 Swizzle4<Vector4, 0x0101> xyxy;
1723 Swizzle4<Vector4, 0x1101> yyxy;
1724 Swizzle4<Vector4, 0x2101> zyxy;
1725 Swizzle4<Vector4, 0x3101> wyxy;
1726 Swizzle4<Vector4, 0x0201> xzxy;
1727 Swizzle4<Vector4, 0x1201> yzxy;
1728 Swizzle4<Vector4, 0x2201> zzxy;
1729 Swizzle4<Vector4, 0x3201> wzxy;
1730 Swizzle4<Vector4, 0x0301> xwxy;
1731 Swizzle4<Vector4, 0x1301> ywxy;
1732 Swizzle4<Vector4, 0x2301> zwxy;
1733 Swizzle4<Vector4, 0x3301> wwxy;
1734 Swizzle4<Vector4, 0x0011> xxyy;
1735 Swizzle4<Vector4, 0x1011> yxyy;
1736 Swizzle4<Vector4, 0x2011> zxyy;
1737 Swizzle4<Vector4, 0x3011> wxyy;
1738 Swizzle4<Vector4, 0x0111> xyyy;
1739 Swizzle4<Vector4, 0x1111> yyyy;
1740 Swizzle4<Vector4, 0x2111> zyyy;
1741 Swizzle4<Vector4, 0x3111> wyyy;
1742 Swizzle4<Vector4, 0x0211> xzyy;
1743 Swizzle4<Vector4, 0x1211> yzyy;
1744 Swizzle4<Vector4, 0x2211> zzyy;
1745 Swizzle4<Vector4, 0x3211> wzyy;
1746 Swizzle4<Vector4, 0x0311> xwyy;
1747 Swizzle4<Vector4, 0x1311> ywyy;
1748 Swizzle4<Vector4, 0x2311> zwyy;
1749 Swizzle4<Vector4, 0x3311> wwyy;
1750 Swizzle4<Vector4, 0x0021> xxzy;
1751 Swizzle4<Vector4, 0x1021> yxzy;
1752 Swizzle4<Vector4, 0x2021> zxzy;
1753 Swizzle4<Vector4, 0x3021> wxzy;
1754 Swizzle4<Vector4, 0x0121> xyzy;
1755 Swizzle4<Vector4, 0x1121> yyzy;
1756 Swizzle4<Vector4, 0x2121> zyzy;
1757 Swizzle4<Vector4, 0x3121> wyzy;
1758 Swizzle4<Vector4, 0x0221> xzzy;
1759 Swizzle4<Vector4, 0x1221> yzzy;
1760 Swizzle4<Vector4, 0x2221> zzzy;
1761 Swizzle4<Vector4, 0x3221> wzzy;
1762 Swizzle4<Vector4, 0x0321> xwzy;
1763 Swizzle4<Vector4, 0x1321> ywzy;
1764 Swizzle4<Vector4, 0x2321> zwzy;
1765 Swizzle4<Vector4, 0x3321> wwzy;
1766 Swizzle4<Vector4, 0x0031> xxwy;
1767 Swizzle4<Vector4, 0x1031> yxwy;
1768 Swizzle4<Vector4, 0x2031> zxwy;
1769 Swizzle4<Vector4, 0x3031> wxwy;
1770 Swizzle4<Vector4, 0x0131> xywy;
1771 Swizzle4<Vector4, 0x1131> yywy;
1772 Swizzle4<Vector4, 0x2131> zywy;
1773 Swizzle4<Vector4, 0x3131> wywy;
1774 Swizzle4<Vector4, 0x0231> xzwy;
1775 Swizzle4<Vector4, 0x1231> yzwy;
1776 Swizzle4<Vector4, 0x2231> zzwy;
1777 Swizzle4<Vector4, 0x3231> wzwy;
1778 Swizzle4<Vector4, 0x0331> xwwy;
1779 Swizzle4<Vector4, 0x1331> ywwy;
1780 Swizzle4<Vector4, 0x2331> zwwy;
1781 Swizzle4<Vector4, 0x3331> wwwy;
1782 Swizzle4<Vector4, 0x0002> xxxz;
1783 Swizzle4<Vector4, 0x1002> yxxz;
1784 Swizzle4<Vector4, 0x2002> zxxz;
1785 Swizzle4<Vector4, 0x3002> wxxz;
1786 Swizzle4<Vector4, 0x0102> xyxz;
1787 Swizzle4<Vector4, 0x1102> yyxz;
1788 Swizzle4<Vector4, 0x2102> zyxz;
1789 Swizzle4<Vector4, 0x3102> wyxz;
1790 Swizzle4<Vector4, 0x0202> xzxz;
1791 Swizzle4<Vector4, 0x1202> yzxz;
1792 Swizzle4<Vector4, 0x2202> zzxz;
1793 Swizzle4<Vector4, 0x3202> wzxz;
1794 Swizzle4<Vector4, 0x0302> xwxz;
1795 Swizzle4<Vector4, 0x1302> ywxz;
1796 Swizzle4<Vector4, 0x2302> zwxz;
1797 Swizzle4<Vector4, 0x3302> wwxz;
1798 Swizzle4<Vector4, 0x0012> xxyz;
1799 Swizzle4<Vector4, 0x1012> yxyz;
1800 Swizzle4<Vector4, 0x2012> zxyz;
1801 Swizzle4<Vector4, 0x3012> wxyz;
1802 Swizzle4<Vector4, 0x0112> xyyz;
1803 Swizzle4<Vector4, 0x1112> yyyz;
1804 Swizzle4<Vector4, 0x2112> zyyz;
1805 Swizzle4<Vector4, 0x3112> wyyz;
1806 Swizzle4<Vector4, 0x0212> xzyz;
1807 Swizzle4<Vector4, 0x1212> yzyz;
1808 Swizzle4<Vector4, 0x2212> zzyz;
1809 Swizzle4<Vector4, 0x3212> wzyz;
1810 Swizzle4<Vector4, 0x0312> xwyz;
1811 Swizzle4<Vector4, 0x1312> ywyz;
1812 Swizzle4<Vector4, 0x2312> zwyz;
1813 Swizzle4<Vector4, 0x3312> wwyz;
1814 Swizzle4<Vector4, 0x0022> xxzz;
1815 Swizzle4<Vector4, 0x1022> yxzz;
1816 Swizzle4<Vector4, 0x2022> zxzz;
1817 Swizzle4<Vector4, 0x3022> wxzz;
1818 Swizzle4<Vector4, 0x0122> xyzz;
1819 Swizzle4<Vector4, 0x1122> yyzz;
1820 Swizzle4<Vector4, 0x2122> zyzz;
1821 Swizzle4<Vector4, 0x3122> wyzz;
1822 Swizzle4<Vector4, 0x0222> xzzz;
1823 Swizzle4<Vector4, 0x1222> yzzz;
1824 Swizzle4<Vector4, 0x2222> zzzz;
1825 Swizzle4<Vector4, 0x3222> wzzz;
1826 Swizzle4<Vector4, 0x0322> xwzz;
1827 Swizzle4<Vector4, 0x1322> ywzz;
1828 Swizzle4<Vector4, 0x2322> zwzz;
1829 Swizzle4<Vector4, 0x3322> wwzz;
1830 Swizzle4<Vector4, 0x0032> xxwz;
1831 Swizzle4<Vector4, 0x1032> yxwz;
1832 Swizzle4<Vector4, 0x2032> zxwz;
1833 Swizzle4<Vector4, 0x3032> wxwz;
1834 Swizzle4<Vector4, 0x0132> xywz;
1835 Swizzle4<Vector4, 0x1132> yywz;
1836 Swizzle4<Vector4, 0x2132> zywz;
1837 Swizzle4<Vector4, 0x3132> wywz;
1838 Swizzle4<Vector4, 0x0232> xzwz;
1839 Swizzle4<Vector4, 0x1232> yzwz;
1840 Swizzle4<Vector4, 0x2232> zzwz;
1841 Swizzle4<Vector4, 0x3232> wzwz;
1842 Swizzle4<Vector4, 0x0332> xwwz;
1843 Swizzle4<Vector4, 0x1332> ywwz;
1844 Swizzle4<Vector4, 0x2332> zwwz;
1845 Swizzle4<Vector4, 0x3332> wwwz;
1846 Swizzle4<Vector4, 0x0003> xxxw;
1847 Swizzle4<Vector4, 0x1003> yxxw;
1848 Swizzle4<Vector4, 0x2003> zxxw;
1849 Swizzle4<Vector4, 0x3003> wxxw;
1850 Swizzle4<Vector4, 0x0103> xyxw;
1851 Swizzle4<Vector4, 0x1103> yyxw;
1852 Swizzle4<Vector4, 0x2103> zyxw;
1853 Swizzle4<Vector4, 0x3103> wyxw;
1854 Swizzle4<Vector4, 0x0203> xzxw;
1855 Swizzle4<Vector4, 0x1203> yzxw;
1856 Swizzle4<Vector4, 0x2203> zzxw;
1857 Swizzle4<Vector4, 0x3203> wzxw;
1858 Swizzle4<Vector4, 0x0303> xwxw;
1859 Swizzle4<Vector4, 0x1303> ywxw;
1860 Swizzle4<Vector4, 0x2303> zwxw;
1861 Swizzle4<Vector4, 0x3303> wwxw;
1862 Swizzle4<Vector4, 0x0013> xxyw;
1863 Swizzle4<Vector4, 0x1013> yxyw;
1864 Swizzle4<Vector4, 0x2013> zxyw;
1865 Swizzle4<Vector4, 0x3013> wxyw;
1866 Swizzle4<Vector4, 0x0113> xyyw;
1867 Swizzle4<Vector4, 0x1113> yyyw;
1868 Swizzle4<Vector4, 0x2113> zyyw;
1869 Swizzle4<Vector4, 0x3113> wyyw;
1870 Swizzle4<Vector4, 0x0213> xzyw;
1871 Swizzle4<Vector4, 0x1213> yzyw;
1872 Swizzle4<Vector4, 0x2213> zzyw;
1873 Swizzle4<Vector4, 0x3213> wzyw;
1874 Swizzle4<Vector4, 0x0313> xwyw;
1875 Swizzle4<Vector4, 0x1313> ywyw;
1876 Swizzle4<Vector4, 0x2313> zwyw;
1877 Swizzle4<Vector4, 0x3313> wwyw;
1878 Swizzle4<Vector4, 0x0023> xxzw;
1879 Swizzle4<Vector4, 0x1023> yxzw;
1880 Swizzle4<Vector4, 0x2023> zxzw;
1881 Swizzle4<Vector4, 0x3023> wxzw;
1882 SwizzleMask4<Vector4, 0x0123> xyzw;
1883 Swizzle4<Vector4, 0x1123> yyzw;
1884 Swizzle4<Vector4, 0x2123> zyzw;
1885 Swizzle4<Vector4, 0x3123> wyzw;
1886 Swizzle4<Vector4, 0x0223> xzzw;
1887 Swizzle4<Vector4, 0x1223> yzzw;
1888 Swizzle4<Vector4, 0x2223> zzzw;
1889 Swizzle4<Vector4, 0x3223> wzzw;
1890 Swizzle4<Vector4, 0x0323> xwzw;
1891 Swizzle4<Vector4, 0x1323> ywzw;
1892 Swizzle4<Vector4, 0x2323> zwzw;
1893 Swizzle4<Vector4, 0x3323> wwzw;
1894 Swizzle4<Vector4, 0x0033> xxww;
1895 Swizzle4<Vector4, 0x1033> yxww;
1896 Swizzle4<Vector4, 0x2033> zxww;
1897 Swizzle4<Vector4, 0x3033> wxww;
1898 Swizzle4<Vector4, 0x0133> xyww;
1899 Swizzle4<Vector4, 0x1133> yyww;
1900 Swizzle4<Vector4, 0x2133> zyww;
1901 Swizzle4<Vector4, 0x3133> wyww;
1902 Swizzle4<Vector4, 0x0233> xzww;
1903 Swizzle4<Vector4, 0x1233> yzww;
1904 Swizzle4<Vector4, 0x2233> zzww;
1905 Swizzle4<Vector4, 0x3233> wzww;
1906 Swizzle4<Vector4, 0x0333> xwww;
1907 Swizzle4<Vector4, 0x1333> ywww;
1908 Swizzle4<Vector4, 0x2333> zwww;
1909 Swizzle4<Vector4, 0x3333> wwww;
1910 };
1911 };
1912
1913 class Int4 : public LValue<Int4>, public XYZW<Int4>
1914 {
1915 public:
1916 explicit Int4(RValue<Byte4> cast);
1917 explicit Int4(RValue<SByte4> cast);
1918 explicit Int4(RValue<Float4> cast);
1919 explicit Int4(RValue<Short4> cast);
1920 explicit Int4(RValue<UShort4> cast);
1921
1922 Int4();
1923 Int4(int xyzw);
1924 Int4(int x, int yzw);
1925 Int4(int x, int y, int zw);
1926 Int4(int x, int y, int z, int w);
1927 Int4(RValue<Int4> rhs);
1928 Int4(const Int4 &rhs);
1929 Int4(const Reference<Int4> &rhs);
1930 Int4(RValue<UInt4> rhs);
1931 Int4(const UInt4 &rhs);
1932 Int4(const Reference<UInt4> &rhs);
1933 Int4(RValue<Int2> lo, RValue<Int2> hi);
1934 Int4(RValue<Int> rhs);
1935 Int4(const Int &rhs);
1936 Int4(const Reference<Int> &rhs);
1937
1938 RValue<Int4> operator=(RValue<Int4> rhs);
1939 RValue<Int4> operator=(const Int4 &rhs);
1940 RValue<Int4> operator=(const Reference<Int4> &rhs);
1941
1942 static Type *type();
1943
1944 private:
1945 void constant(int x, int y, int z, int w);
1946 };
1947
1948 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs);
1949 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs);
1950 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs);
1951 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs);
1952 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs);
1953 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs);
1954 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs);
1955 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs);
1956 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs);
1957 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs);
1958 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs);
1959 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs);
1960 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs);
1961 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs);
1962 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs);
1963 // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs);
1964 // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs);
1965 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs);
1966 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs);
1967 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs);
1968 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs);
1969 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs);
1970 RValue<Int4> operator+(RValue<Int4> val);
1971 RValue<Int4> operator-(RValue<Int4> val);
1972 RValue<Int4> operator~(RValue<Int4> val);
1973 // RValue<Int4> operator++(Int4 &val, int); // Post-increment
1974 // const Int4 &operator++(Int4 &val); // Pre-increment
1975 // RValue<Int4> operator--(Int4 &val, int); // Post-decrement
1976 // const Int4 &operator--(Int4 &val); // Pre-decrement
1977 // RValue<Bool> operator<(RValue<Int4> lhs, RValue<Int4> rhs);
1978 // RValue<Bool> operator<=(RValue<Int4> lhs, RValue<Int4> rhs);
1979 // RValue<Bool> operator>(RValue<Int4> lhs, RValue<Int4> rhs);
1980 // RValue<Bool> operator>=(RValue<Int4> lhs, RValue<Int4> rhs);
1981 // RValue<Bool> operator!=(RValue<Int4> lhs, RValue<Int4> rhs);
1982 // RValue<Bool> operator==(RValue<Int4> lhs, RValue<Int4> rhs);
1983
operator +(RValue<Int> lhs,RValue<Int4> rhs)1984 inline RValue<Int4> operator+(RValue<Int> lhs, RValue<Int4> rhs)
1985 {
1986 return Int4(lhs) + rhs;
1987 }
1988
operator +(RValue<Int4> lhs,RValue<Int> rhs)1989 inline RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int> rhs)
1990 {
1991 return lhs + Int4(rhs);
1992 }
1993
1994 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y);
1995 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y);
1996 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y);
1997 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y);
1998 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y);
1999 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y);
CmpGT(RValue<Int4> x,RValue<Int4> y)2000 inline RValue<Int4> CmpGT(RValue<Int4> x, RValue<Int4> y)
2001 {
2002 return CmpNLE(x, y);
2003 }
CmpGE(RValue<Int4> x,RValue<Int4> y)2004 inline RValue<Int4> CmpGE(RValue<Int4> x, RValue<Int4> y)
2005 {
2006 return CmpNLT(x, y);
2007 }
2008 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y);
2009 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y);
2010 // Convert to nearest integer. If a converted value is outside of the integer
2011 // range, the returned result is undefined.
2012 RValue<Int4> RoundInt(RValue<Float4> cast);
2013 // Rounds to the nearest integer, but clamps very large values to an
2014 // implementation-dependent range.
2015 // Specifically, on x86, values larger than 2147483583.0 are converted to
2016 // 2147483583 (0x7FFFFFBF) instead of producing 0x80000000.
2017 RValue<Int4> RoundIntClamped(RValue<Float4> cast);
2018 RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y);
2019 RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y);
2020 RValue<Int> Extract(RValue<Int4> val, int i);
2021 RValue<Int4> Insert(RValue<Int4> val, RValue<Int> element, int i);
2022 RValue<Int> SignMask(RValue<Int4> x);
2023 RValue<Int4> Swizzle(RValue<Int4> x, uint16_t select);
2024 RValue<Int4> Shuffle(RValue<Int4> x, RValue<Int4> y, uint16_t select);
2025 RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y);
2026
2027 class UInt4 : public LValue<UInt4>, public XYZW<UInt4>
2028 {
2029 public:
2030 explicit UInt4(RValue<Float4> cast);
2031
2032 UInt4();
2033 UInt4(int xyzw);
2034 UInt4(int x, int yzw);
2035 UInt4(int x, int y, int zw);
2036 UInt4(int x, int y, int z, int w);
2037 UInt4(RValue<UInt4> rhs);
2038 UInt4(const UInt4 &rhs);
2039 UInt4(const Reference<UInt4> &rhs);
2040 UInt4(RValue<Int4> rhs);
2041 UInt4(const Int4 &rhs);
2042 UInt4(const Reference<Int4> &rhs);
2043 UInt4(RValue<UInt2> lo, RValue<UInt2> hi);
2044 UInt4(RValue<UInt> rhs);
2045 UInt4(const UInt &rhs);
2046 UInt4(const Reference<UInt> &rhs);
2047
2048 RValue<UInt4> operator=(RValue<UInt4> rhs);
2049 RValue<UInt4> operator=(const UInt4 &rhs);
2050 RValue<UInt4> operator=(const Reference<UInt4> &rhs);
2051
2052 static Type *type();
2053
2054 private:
2055 void constant(int x, int y, int z, int w);
2056 };
2057
2058 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs);
2059 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs);
2060 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs);
2061 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs);
2062 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs);
2063 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs);
2064 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs);
2065 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs);
2066 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs);
2067 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs);
2068 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs);
2069 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs);
2070 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs);
2071 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs);
2072 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs);
2073 // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs);
2074 // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs);
2075 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs);
2076 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs);
2077 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs);
2078 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs);
2079 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs);
2080 RValue<UInt4> operator+(RValue<UInt4> val);
2081 RValue<UInt4> operator-(RValue<UInt4> val);
2082 RValue<UInt4> operator~(RValue<UInt4> val);
2083 // RValue<UInt4> operator++(UInt4 &val, int); // Post-increment
2084 // const UInt4 &operator++(UInt4 &val); // Pre-increment
2085 // RValue<UInt4> operator--(UInt4 &val, int); // Post-decrement
2086 // const UInt4 &operator--(UInt4 &val); // Pre-decrement
2087 // RValue<Bool> operator<(RValue<UInt4> lhs, RValue<UInt4> rhs);
2088 // RValue<Bool> operator<=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2089 // RValue<Bool> operator>(RValue<UInt4> lhs, RValue<UInt4> rhs);
2090 // RValue<Bool> operator>=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2091 // RValue<Bool> operator!=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2092 // RValue<Bool> operator==(RValue<UInt4> lhs, RValue<UInt4> rhs);
2093
2094 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y);
2095 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y);
2096 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y);
2097 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y);
2098 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y);
2099 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y);
CmpGT(RValue<UInt4> x,RValue<UInt4> y)2100 inline RValue<UInt4> CmpGT(RValue<UInt4> x, RValue<UInt4> y)
2101 {
2102 return CmpNLE(x, y);
2103 }
CmpGE(RValue<UInt4> x,RValue<UInt4> y)2104 inline RValue<UInt4> CmpGE(RValue<UInt4> x, RValue<UInt4> y)
2105 {
2106 return CmpNLT(x, y);
2107 }
2108 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y);
2109 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y);
2110 RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y);
2111 RValue<UInt> Extract(RValue<UInt4> val, int i);
2112 RValue<UInt4> Insert(RValue<UInt4> val, RValue<UInt> element, int i);
2113 // RValue<UInt4> RoundInt(RValue<Float4> cast);
2114 RValue<UInt4> Swizzle(RValue<UInt4> x, uint16_t select);
2115 RValue<UInt4> Shuffle(RValue<UInt4> x, RValue<UInt4> y, uint16_t select);
2116
2117 class Half : public LValue<Half>
2118 {
2119 public:
2120 explicit Half(RValue<Float> cast);
2121
2122 static Type *type();
2123 };
2124
2125 class Float : public LValue<Float>
2126 {
2127 public:
2128 explicit Float(RValue<Int> cast);
2129 explicit Float(RValue<UInt> cast);
2130 explicit Float(RValue<Half> cast);
2131
2132 Float() = default;
2133 Float(float x);
2134 Float(RValue<Float> rhs);
2135 Float(const Float &rhs);
2136 Float(const Reference<Float> &rhs);
2137 Float(Argument<Float> argument);
2138
2139 template<int T>
2140 Float(const SwizzleMask1<Float4, T> &rhs);
2141
2142 RValue<Float> operator=(float rhs);
2143 RValue<Float> operator=(RValue<Float> rhs);
2144 RValue<Float> operator=(const Float &rhs);
2145 RValue<Float> operator=(const Reference<Float> &rhs);
2146
2147 template<int T>
2148 RValue<Float> operator=(const SwizzleMask1<Float4, T> &rhs);
2149
2150 static Float infinity();
2151
2152 static Type *type();
2153 };
2154
2155 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs);
2156 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs);
2157 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs);
2158 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs);
2159 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs);
2160 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs);
2161 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs);
2162 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs);
2163 RValue<Float> operator+(RValue<Float> val);
2164 RValue<Float> operator-(RValue<Float> val);
2165 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs);
2166 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs);
2167 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs);
2168 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs);
2169 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs);
2170 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs);
2171
2172 RValue<Float> Abs(RValue<Float> x);
2173 RValue<Float> Max(RValue<Float> x, RValue<Float> y);
2174 RValue<Float> Min(RValue<Float> x, RValue<Float> y);
2175 // Deprecated: use Rcp
2176 // TODO(b/147516027): Remove when GLES frontend is removed
2177 RValue<Float> Rcp_pp(RValue<Float> val, bool exactAtPow2 = false);
2178 // Deprecated: use RcpSqrt
2179 // TODO(b/147516027): Remove when GLES frontend is removed
2180 RValue<Float> RcpSqrt_pp(RValue<Float> val);
2181 RValue<Float> Rcp(RValue<Float> x, Precision p = Precision::Full, bool finite = false, bool exactAtPow2 = false);
2182 RValue<Float> RcpSqrt(RValue<Float> x, Precision p = Precision::Full);
2183 RValue<Float> Sqrt(RValue<Float> x);
2184
2185 // RValue<Int4> IsInf(RValue<Float> x);
2186 // RValue<Int4> IsNan(RValue<Float> x);
2187 RValue<Float> Round(RValue<Float> x);
2188 RValue<Float> Trunc(RValue<Float> x);
2189 RValue<Float> Frac(RValue<Float> x);
2190 RValue<Float> Floor(RValue<Float> x);
2191 RValue<Float> Ceil(RValue<Float> x);
2192
2193 // Trigonometric functions
2194 // TODO: Currently unimplemented for Subzero.
2195 // RValue<Float> Sin(RValue<Float> x);
2196 // RValue<Float> Cos(RValue<Float> x);
2197 // RValue<Float> Tan(RValue<Float> x);
2198 // RValue<Float> Asin(RValue<Float> x);
2199 // RValue<Float> Acos(RValue<Float> x);
2200 // RValue<Float> Atan(RValue<Float> x);
2201 // RValue<Float> Sinh(RValue<Float> x);
2202 // RValue<Float> Cosh(RValue<Float> x);
2203 // RValue<Float> Tanh(RValue<Float> x);
2204 // RValue<Float> Asinh(RValue<Float> x);
2205 // RValue<Float> Acosh(RValue<Float> x);
2206 // RValue<Float> Atanh(RValue<Float> x);
2207 // RValue<Float> Atan2(RValue<Float> x, RValue<Float> y);
2208
2209 // Exponential functions
2210 // TODO: Currently unimplemented for Subzero.
2211 // RValue<Float> Pow(RValue<Float> x, RValue<Float> y);
2212 // RValue<Float> Exp(RValue<Float> x);
2213 // RValue<Float> Log(RValue<Float> x);
2214 RValue<Float> Exp2(RValue<Float> x);
2215 RValue<Float> Log2(RValue<Float> x);
2216
2217 class Float2 : public LValue<Float2>
2218 {
2219 public:
2220 // explicit Float2(RValue<Byte2> cast);
2221 // explicit Float2(RValue<Short2> cast);
2222 // explicit Float2(RValue<UShort2> cast);
2223 // explicit Float2(RValue<Int2> cast);
2224 // explicit Float2(RValue<UInt2> cast);
2225 explicit Float2(RValue<Float4> cast);
2226
2227 Float2() = default;
2228 // Float2(float x, float y);
2229 // Float2(RValue<Float2> rhs);
2230 // Float2(const Float2 &rhs);
2231 // Float2(const Reference<Float2> &rhs);
2232 // Float2(RValue<Float> rhs);
2233 // Float2(const Float &rhs);
2234 // Float2(const Reference<Float> &rhs);
2235
2236 // template<int T>
2237 // Float2(const SwizzleMask1<T> &rhs);
2238
2239 // RValue<Float2> operator=(float replicate);
2240 // RValue<Float2> operator=(RValue<Float2> rhs);
2241 // RValue<Float2> operator=(const Float2 &rhs);
2242 // RValue<Float2> operator=(const Reference<Float2> &rhs);
2243 // RValue<Float2> operator=(RValue<Float> rhs);
2244 // RValue<Float2> operator=(const Float &rhs);
2245 // RValue<Float2> operator=(const Reference<Float> &rhs);
2246
2247 // template<int T>
2248 // RValue<Float2> operator=(const SwizzleMask1<T> &rhs);
2249
2250 static Type *type();
2251 };
2252
2253 // RValue<Float2> operator+(RValue<Float2> lhs, RValue<Float2> rhs);
2254 // RValue<Float2> operator-(RValue<Float2> lhs, RValue<Float2> rhs);
2255 // RValue<Float2> operator*(RValue<Float2> lhs, RValue<Float2> rhs);
2256 // RValue<Float2> operator/(RValue<Float2> lhs, RValue<Float2> rhs);
2257 // RValue<Float2> operator%(RValue<Float2> lhs, RValue<Float2> rhs);
2258 // RValue<Float2> operator+=(Float2 &lhs, RValue<Float2> rhs);
2259 // RValue<Float2> operator-=(Float2 &lhs, RValue<Float2> rhs);
2260 // RValue<Float2> operator*=(Float2 &lhs, RValue<Float2> rhs);
2261 // RValue<Float2> operator/=(Float2 &lhs, RValue<Float2> rhs);
2262 // RValue<Float2> operator%=(Float2 &lhs, RValue<Float2> rhs);
2263 // RValue<Float2> operator+(RValue<Float2> val);
2264 // RValue<Float2> operator-(RValue<Float2> val);
2265
2266 // RValue<Float2> Abs(RValue<Float2> x);
2267 // RValue<Float2> Max(RValue<Float2> x, RValue<Float2> y);
2268 // RValue<Float2> Min(RValue<Float2> x, RValue<Float2> y);
2269 // RValue<Float2> Swizzle(RValue<Float2> x, uint16_t select);
2270 // RValue<Float2> Mask(Float2 &lhs, RValue<Float2> rhs, uint16_t select);
2271
2272 class Float4 : public LValue<Float4>, public XYZW<Float4>
2273 {
2274 public:
2275 explicit Float4(RValue<Byte4> cast);
2276 explicit Float4(RValue<SByte4> cast);
2277 explicit Float4(RValue<Short4> cast);
2278 explicit Float4(RValue<UShort4> cast);
2279 explicit Float4(RValue<Int4> cast);
2280 explicit Float4(RValue<UInt4> cast);
2281
2282 Float4();
2283 Float4(float xyzw);
2284 Float4(float x, float yzw);
2285 Float4(float x, float y, float zw);
2286 Float4(float x, float y, float z, float w);
2287 Float4(RValue<Float4> rhs);
2288 Float4(const Float4 &rhs);
2289 Float4(const Reference<Float4> &rhs);
2290 Float4(RValue<Float> rhs);
2291 Float4(const Float &rhs);
2292 Float4(const Reference<Float> &rhs);
2293
2294 template<int T>
2295 Float4(const SwizzleMask1<Float4, T> &rhs);
2296 template<int T>
2297 Float4(const Swizzle4<Float4, T> &rhs);
2298 template<int X, int Y>
2299 Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
2300 template<int X, int Y>
2301 Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
2302 template<int X, int Y>
2303 Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
2304 template<int X, int Y>
2305 Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
2306 Float4(RValue<Float2> lo, RValue<Float2> hi);
2307
2308 RValue<Float4> operator=(float replicate);
2309 RValue<Float4> operator=(RValue<Float4> rhs);
2310 RValue<Float4> operator=(const Float4 &rhs);
2311 RValue<Float4> operator=(const Reference<Float4> &rhs);
2312 RValue<Float4> operator=(RValue<Float> rhs);
2313 RValue<Float4> operator=(const Float &rhs);
2314 RValue<Float4> operator=(const Reference<Float> &rhs);
2315
2316 template<int T>
2317 RValue<Float4> operator=(const SwizzleMask1<Float4, T> &rhs);
2318 template<int T>
2319 RValue<Float4> operator=(const Swizzle4<Float4, T> &rhs);
2320
2321 static Float4 infinity();
2322
2323 static Type *type();
2324
2325 private:
2326 void constant(float x, float y, float z, float w);
2327 };
2328
2329 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs);
2330 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs);
2331 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs);
2332 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs);
2333 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs);
2334 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs);
2335 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs);
2336 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs);
2337 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs);
2338 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs);
2339 RValue<Float4> operator+(RValue<Float4> val);
2340 RValue<Float4> operator-(RValue<Float4> val);
2341
2342 RValue<Float4> Abs(RValue<Float4> x);
2343 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y);
2344 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y);
2345
2346 // Deprecated: use Rcp
2347 // TODO(b/147516027): Remove when GLES frontend is removed
2348 RValue<Float4> Rcp_pp(RValue<Float4> val, bool exactAtPow2 = false);
2349 // Deprecated: use RcpSqrt
2350 // TODO(b/147516027): Remove when GLES frontend is removed
2351 RValue<Float4> RcpSqrt_pp(RValue<Float4> val);
2352 RValue<Float4> Rcp(RValue<Float4> x, Precision p = Precision::Full, bool finite = false, bool exactAtPow2 = false);
2353 RValue<Float4> RcpSqrt(RValue<Float4> x, Precision p = Precision::Full);
2354 RValue<Float4> Sqrt(RValue<Float4> x);
2355 RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i);
2356 RValue<Float> Extract(RValue<Float4> x, int i);
2357 RValue<Float4> Swizzle(RValue<Float4> x, uint16_t select);
2358 RValue<Float4> Shuffle(RValue<Float4> x, RValue<Float4> y, uint16_t select);
2359 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, uint16_t imm);
2360 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y);
2361 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y);
2362 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, uint16_t select);
2363 RValue<Int> SignMask(RValue<Float4> x);
2364
2365 // Ordered comparison functions
2366 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y);
2367 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y);
2368 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y);
2369 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y);
2370 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y);
2371 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y);
CmpGT(RValue<Float4> x,RValue<Float4> y)2372 inline RValue<Int4> CmpGT(RValue<Float4> x, RValue<Float4> y)
2373 {
2374 return CmpNLE(x, y);
2375 }
CmpGE(RValue<Float4> x,RValue<Float4> y)2376 inline RValue<Int4> CmpGE(RValue<Float4> x, RValue<Float4> y)
2377 {
2378 return CmpNLT(x, y);
2379 }
2380
2381 // Unordered comparison functions
2382 RValue<Int4> CmpUEQ(RValue<Float4> x, RValue<Float4> y);
2383 RValue<Int4> CmpULT(RValue<Float4> x, RValue<Float4> y);
2384 RValue<Int4> CmpULE(RValue<Float4> x, RValue<Float4> y);
2385 RValue<Int4> CmpUNEQ(RValue<Float4> x, RValue<Float4> y);
2386 RValue<Int4> CmpUNLT(RValue<Float4> x, RValue<Float4> y);
2387 RValue<Int4> CmpUNLE(RValue<Float4> x, RValue<Float4> y);
CmpUGT(RValue<Float4> x,RValue<Float4> y)2388 inline RValue<Int4> CmpUGT(RValue<Float4> x, RValue<Float4> y)
2389 {
2390 return CmpUNLE(x, y);
2391 }
CmpUGE(RValue<Float4> x,RValue<Float4> y)2392 inline RValue<Int4> CmpUGE(RValue<Float4> x, RValue<Float4> y)
2393 {
2394 return CmpUNLT(x, y);
2395 }
2396
2397 RValue<Int4> IsInf(RValue<Float4> x);
2398 RValue<Int4> IsNan(RValue<Float4> x);
2399 RValue<Float4> Round(RValue<Float4> x);
2400 RValue<Float4> Trunc(RValue<Float4> x);
2401 RValue<Float4> Frac(RValue<Float4> x);
2402 RValue<Float4> Floor(RValue<Float4> x);
2403 RValue<Float4> Ceil(RValue<Float4> x);
2404
2405 // Trigonometric functions
2406 // TODO: Currently unimplemented for Subzero.
2407 RValue<Float4> Sin(RValue<Float4> x);
2408 RValue<Float4> Cos(RValue<Float4> x);
2409 RValue<Float4> Tan(RValue<Float4> x);
2410 RValue<Float4> Asin(RValue<Float4> x, Precision p);
2411 RValue<Float4> Acos(RValue<Float4> x, Precision p);
2412 RValue<Float4> Atan(RValue<Float4> x);
2413 RValue<Float4> Sinh(RValue<Float4> x);
2414 RValue<Float4> Cosh(RValue<Float4> x);
2415 RValue<Float4> Tanh(RValue<Float4> x);
2416 RValue<Float4> Asinh(RValue<Float4> x);
2417 RValue<Float4> Acosh(RValue<Float4> x);
2418 RValue<Float4> Atanh(RValue<Float4> x);
2419 RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y);
2420
2421 // Exponential functions
2422 // TODO: Currently unimplemented for Subzero.
2423 RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y);
2424 RValue<Float4> Exp(RValue<Float4> x);
2425 RValue<Float4> Log(RValue<Float4> x);
2426 RValue<Float4> Exp2(RValue<Float4> x);
2427 RValue<Float4> Log2(RValue<Float4> x);
2428
2429 // Bit Manipulation functions.
2430 // TODO: Currently unimplemented for Subzero.
2431
2432 // Count leading zeros.
2433 // Returns 32 when: !isZeroUndef && x == 0.
2434 // Returns an undefined value when: isZeroUndef && x == 0.
2435 RValue<UInt> Ctlz(RValue<UInt> x, bool isZeroUndef);
2436 RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
2437
2438 // Count trailing zeros.
2439 // Returns 32 when: !isZeroUndef && x == 0.
2440 // Returns an undefined value when: isZeroUndef && x == 0.
2441 RValue<UInt> Cttz(RValue<UInt> x, bool isZeroUndef);
2442 RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
2443
2444 template<class T>
2445 class Pointer : public LValue<Pointer<T>>
2446 {
2447 public:
2448 template<class S>
Pointer(RValue<Pointer<S>> pointerS,int alignment=1)2449 Pointer(RValue<Pointer<S>> pointerS, int alignment = 1)
2450 : alignment(alignment)
2451 {
2452 Value *pointerT = Nucleus::createBitCast(pointerS.value(), Nucleus::getPointerType(T::type()));
2453 this->storeValue(pointerT);
2454 }
2455
2456 template<class S>
Pointer(const Pointer<S> & pointer,int alignment=1)2457 Pointer(const Pointer<S> &pointer, int alignment = 1)
2458 : alignment(alignment)
2459 {
2460 Value *pointerS = pointer.loadValue();
2461 Value *pointerT = Nucleus::createBitCast(pointerS, Nucleus::getPointerType(T::type()));
2462 this->storeValue(pointerT);
2463 }
2464
2465 Pointer(Argument<Pointer<T>> argument);
2466
2467 Pointer();
2468 Pointer(RValue<Pointer<T>> rhs);
2469 Pointer(const Pointer<T> &rhs);
2470 Pointer(const Reference<Pointer<T>> &rhs);
2471 Pointer(std::nullptr_t);
2472
2473 RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs);
2474 RValue<Pointer<T>> operator=(const Pointer<T> &rhs);
2475 RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs);
2476 RValue<Pointer<T>> operator=(std::nullptr_t);
2477
2478 Reference<T> operator*();
2479 Reference<T> operator[](int index);
2480 Reference<T> operator[](unsigned int index);
2481 Reference<T> operator[](RValue<Int> index);
2482 Reference<T> operator[](RValue<UInt> index);
2483
2484 static Type *type();
2485
2486 private:
2487 const int alignment;
2488 };
2489
2490 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);
2491 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2492 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2493 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset);
2494 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset);
2495 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset);
2496
2497 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);
2498 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2499 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2500 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset);
2501 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset);
2502 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset);
2503
2504 template<typename T>
operator ==(const Pointer<T> & lhs,const Pointer<T> & rhs)2505 RValue<Bool> operator==(const Pointer<T> &lhs, const Pointer<T> &rhs)
2506 {
2507 return RValue<Bool>(Nucleus::createICmpEQ(lhs.loadValue(), rhs.loadValue()));
2508 }
2509
2510 template<typename T>
operator !=(const Pointer<T> & lhs,const Pointer<T> & rhs)2511 RValue<Bool> operator!=(const Pointer<T> &lhs, const Pointer<T> &rhs)
2512 {
2513 return RValue<Bool>(Nucleus::createICmpNE(lhs.loadValue(), rhs.loadValue()));
2514 }
2515
2516 template<typename T>
Load(RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2517 RValue<T> Load(RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2518 {
2519 return RValue<T>(Nucleus::createLoad(pointer.value(), T::type(), false, alignment, atomic, memoryOrder));
2520 }
2521
2522 template<typename T>
Load(Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2523 RValue<T> Load(Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2524 {
2525 return Load(RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2526 }
2527
2528 // TODO: Use SIMD to template these.
2529 RValue<Float4> MaskedLoad(RValue<Pointer<Float4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2530 RValue<Int4> MaskedLoad(RValue<Pointer<Int4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2531 void MaskedStore(RValue<Pointer<Float4>> base, RValue<Float4> val, RValue<Int4> mask, unsigned int alignment);
2532 void MaskedStore(RValue<Pointer<Int4>> base, RValue<Int4> val, RValue<Int4> mask, unsigned int alignment);
2533
2534 RValue<Float4> Gather(RValue<Pointer<Float>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2535 RValue<Int4> Gather(RValue<Pointer<Int>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2536 void Scatter(RValue<Pointer<Float>> base, RValue<Float4> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment);
2537 void Scatter(RValue<Pointer<Int>> base, RValue<Int4> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment);
2538
2539 template<typename T>
Store(RValue<T> value,RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2540 void Store(RValue<T> value, RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2541 {
2542 Nucleus::createStore(value.value(), pointer.value(), T::type(), false, alignment, atomic, memoryOrder);
2543 }
2544
2545 template<typename T>
Store(RValue<T> value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2546 void Store(RValue<T> value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2547 {
2548 Store(value, RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2549 }
2550
2551 template<typename T>
Store(T value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2552 void Store(T value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2553 {
2554 Store(RValue<T>(value), RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2555 }
2556
2557 // Fence adds a memory barrier that enforces ordering constraints on memory
2558 // operations. memoryOrder can only be one of:
2559 // std::memory_order_acquire, std::memory_order_release,
2560 // std::memory_order_acq_rel, or std::memory_order_seq_cst.
2561 void Fence(std::memory_order memoryOrder);
2562
2563 template<class T, int S = 1>
2564 class Array : public LValue<T>
2565 {
2566 public:
2567 Array(int size = S);
2568
2569 Reference<T> operator[](int index);
2570 Reference<T> operator[](unsigned int index);
2571 Reference<T> operator[](RValue<Int> index);
2572 Reference<T> operator[](RValue<UInt> index);
2573
2574 // self() returns the this pointer to this Array object.
2575 // This function exists because operator&() is overloaded by LValue<T>.
self()2576 inline Array *self() { return this; }
2577 };
2578
2579 // RValue<Array<T>> operator++(Array<T> &val, int); // Post-increment
2580 // const Array<T> &operator++(Array<T> &val); // Pre-increment
2581 // RValue<Array<T>> operator--(Array<T> &val, int); // Post-decrement
2582 // const Array<T> &operator--(Array<T> &val); // Pre-decrement
2583
2584 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB);
2585
2586 // ValueOf returns a rr::Value* for the given C-type, RValue<T>, LValue<T>
2587 // or Reference<T>.
2588 template<typename T>
ValueOf(const T & v)2589 inline Value *ValueOf(const T &v)
2590 {
2591 return ReactorType<T>::cast(v).loadValue();
2592 }
2593
2594 void Return();
2595
2596 template<class T>
Return(const T & ret)2597 void Return(const T &ret)
2598 {
2599 static_assert(CanBeUsedAsReturn<ReactorTypeT<T>>::value, "Unsupported type for Return()");
2600 Nucleus::createRet(ValueOf<T>(ret));
2601 // Place any unreachable instructions in an unreferenced block.
2602 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
2603 }
2604
2605 // Generic template, leave undefined!
2606 template<typename FunctionType>
2607 class Function;
2608
2609 // Specialized for function types
2610 template<typename Return, typename... Arguments>
2611 class Function<Return(Arguments...)>
2612 {
2613 // Static assert that the function signature is valid.
2614 static_assert(sizeof(AssertFunctionSignatureIsValid<Return(Arguments...)>) >= 0, "Invalid function signature");
2615
2616 public:
2617 Function();
2618
2619 template<int index>
Arg() const2620 Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type> Arg() const
2621 {
2622 Value *arg = Nucleus::getArgument(index);
2623 return Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type>(arg);
2624 }
2625
2626 std::shared_ptr<Routine> operator()(const char *name, ...);
2627 std::shared_ptr<Routine> operator()(const Config::Edit &cfg, const char *name, ...);
2628
2629 protected:
2630 std::unique_ptr<Nucleus> core;
2631 std::vector<Type *> arguments;
2632 };
2633
2634 template<typename Return>
2635 class Function<Return()> : public Function<Return(Void)>
2636 {
2637 };
2638
2639 // FunctionT accepts a C-style function type template argument, allowing it to return a type-safe RoutineT wrapper
2640 template<typename FunctionType>
2641 class FunctionT;
2642
2643 template<typename Return, typename... Arguments>
2644 class FunctionT<Return(Arguments...)> : public Function<CToReactorT<Return>(CToReactorT<Arguments>...)>
2645 {
2646 public:
2647 // Type of base class
2648 using BaseType = Function<CToReactorT<Return>(CToReactorT<Arguments>...)>;
2649
2650 // Function type, e.g. void(int,float)
2651 using CFunctionType = Return(Arguments...);
2652
2653 // Reactor function type, e.g. Void(Int, Float)
2654 using ReactorFunctionType = CToReactorT<Return>(CToReactorT<Arguments>...);
2655
2656 // Returned RoutineT type
2657 using RoutineType = RoutineT<CFunctionType>;
2658
2659 // Hide base implementations of operator()
2660
2661 template<typename... VarArgs>
operator ()(const char * name,VarArgs...varArgs)2662 RoutineType operator()(const char *name, VarArgs... varArgs)
2663 {
2664 return RoutineType(BaseType::operator()(name, std::forward<VarArgs>(varArgs)...));
2665 }
2666
2667 template<typename... VarArgs>
operator ()(const Config::Edit & cfg,const char * name,VarArgs...varArgs)2668 RoutineType operator()(const Config::Edit &cfg, const char *name, VarArgs... varArgs)
2669 {
2670 return RoutineType(BaseType::operator()(cfg, name, std::forward<VarArgs>(varArgs)...));
2671 }
2672 };
2673
2674 RValue<Long> Ticks();
2675
2676 } // namespace rr
2677
2678 /* Inline implementations */
2679
2680 namespace rr {
2681
2682 template<class T>
LValue(int arraySize)2683 LValue<T>::LValue(int arraySize)
2684 : Variable(T::type(), arraySize)
2685 {
2686 #ifdef ENABLE_RR_DEBUG_INFO
2687 materialize();
2688 #endif // ENABLE_RR_DEBUG_INFO
2689 }
2690
2691 template<class T>
operator &()2692 RValue<Pointer<T>> LValue<T>::operator&()
2693 {
2694 return RValue<Pointer<T>>(this->getBaseAddress());
2695 }
2696
2697 template<class T>
Reference(Value * pointer,int alignment)2698 Reference<T>::Reference(Value *pointer, int alignment)
2699 : alignment(alignment)
2700 {
2701 address = pointer;
2702 }
2703
2704 template<class T>
operator =(RValue<T> rhs) const2705 RValue<T> Reference<T>::operator=(RValue<T> rhs) const
2706 {
2707 Nucleus::createStore(rhs.value(), address, T::type(), false, alignment);
2708
2709 return rhs;
2710 }
2711
2712 template<class T>
operator =(const Reference<T> & ref) const2713 RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
2714 {
2715 Value *tmp = Nucleus::createLoad(ref.address, T::type(), false, ref.alignment);
2716 Nucleus::createStore(tmp, address, T::type(), false, alignment);
2717
2718 return RValue<T>(tmp);
2719 }
2720
2721 template<class T>
operator +=(RValue<T> rhs) const2722 RValue<T> Reference<T>::operator+=(RValue<T> rhs) const
2723 {
2724 return *this = *this + rhs;
2725 }
2726
2727 template<class T>
loadValue() const2728 Value *Reference<T>::loadValue() const
2729 {
2730 return Nucleus::createLoad(address, T::type(), false, alignment);
2731 }
2732
2733 template<class T>
load() const2734 RValue<T> Reference<T>::load() const
2735 {
2736 return RValue<T>(loadValue());
2737 }
2738
2739 template<class T>
getAlignment() const2740 int Reference<T>::getAlignment() const
2741 {
2742 return alignment;
2743 }
2744
2745 template<class T>
RValue(const RValue<T> & rvalue)2746 RValue<T>::RValue(const RValue<T> &rvalue)
2747 : val(rvalue.val)
2748 {
2749 RR_DEBUG_INFO_EMIT_VAR(val);
2750 }
2751
2752 template<class T>
RValue(Value * value)2753 RValue<T>::RValue(Value *value)
2754 : val(value)
2755 {
2756 assert(Nucleus::createBitCast(value, T::type()) == value); // Run-time type should match T, so bitcast is no-op.
2757 RR_DEBUG_INFO_EMIT_VAR(val);
2758 }
2759
2760 template<class T>
RValue(const T & lvalue)2761 RValue<T>::RValue(const T &lvalue)
2762 : val(lvalue.loadValue())
2763 {
2764 RR_DEBUG_INFO_EMIT_VAR(val);
2765 }
2766
2767 template<class T>
RValue(typename BoolLiteral<T>::type i)2768 RValue<T>::RValue(typename BoolLiteral<T>::type i)
2769 : val(Nucleus::createConstantBool(i))
2770 {
2771 RR_DEBUG_INFO_EMIT_VAR(val);
2772 }
2773
2774 template<class T>
RValue(typename IntLiteral<T>::type i)2775 RValue<T>::RValue(typename IntLiteral<T>::type i)
2776 : val(Nucleus::createConstantInt(i))
2777 {
2778 RR_DEBUG_INFO_EMIT_VAR(val);
2779 }
2780
2781 template<class T>
RValue(typename FloatLiteral<T>::type f)2782 RValue<T>::RValue(typename FloatLiteral<T>::type f)
2783 : val(Nucleus::createConstantFloat(f))
2784 {
2785 RR_DEBUG_INFO_EMIT_VAR(val);
2786 }
2787
2788 template<class T>
RValue(const Reference<T> & ref)2789 RValue<T>::RValue(const Reference<T> &ref)
2790 : val(ref.loadValue())
2791 {
2792 RR_DEBUG_INFO_EMIT_VAR(val);
2793 }
2794
2795 template<class Vector4, int T>
operator RValue<Vector4>() const2796 Swizzle2<Vector4, T>::operator RValue<Vector4>() const
2797 {
2798 RR_DEBUG_INFO_UPDATE_LOC();
2799 Value *vector = parent->loadValue();
2800
2801 return Swizzle(RValue<Vector4>(vector), T);
2802 }
2803
2804 template<class Vector4, int T>
operator RValue<Vector4>() const2805 Swizzle4<Vector4, T>::operator RValue<Vector4>() const
2806 {
2807 RR_DEBUG_INFO_UPDATE_LOC();
2808 Value *vector = parent->loadValue();
2809
2810 return Swizzle(RValue<Vector4>(vector), T);
2811 }
2812
2813 template<class Vector4, int T>
operator RValue<Vector4>() const2814 SwizzleMask4<Vector4, T>::operator RValue<Vector4>() const
2815 {
2816 RR_DEBUG_INFO_UPDATE_LOC();
2817 Value *vector = parent->loadValue();
2818
2819 return Swizzle(RValue<Vector4>(vector), T);
2820 }
2821
2822 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2823 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<Vector4> rhs)
2824 {
2825 RR_DEBUG_INFO_UPDATE_LOC();
2826 return Mask(*parent, rhs, T);
2827 }
2828
2829 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2830 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)
2831 {
2832 RR_DEBUG_INFO_UPDATE_LOC();
2833 return Mask(*parent, Vector4(rhs), T);
2834 }
2835
2836 template<class Vector4, int T>
operator RValue<typename Scalar<Vector4>::Type>() const2837 SwizzleMask1<Vector4, T>::operator RValue<typename Scalar<Vector4>::Type>() const // FIXME: Call a non-template function
2838 {
2839 RR_DEBUG_INFO_UPDATE_LOC();
2840 return Extract(*parent, T & 0x3);
2841 }
2842
2843 template<class Vector4, int T>
operator RValue<Vector4>() const2844 SwizzleMask1<Vector4, T>::operator RValue<Vector4>() const
2845 {
2846 RR_DEBUG_INFO_UPDATE_LOC();
2847 Value *vector = parent->loadValue();
2848
2849 return Swizzle(RValue<Vector4>(vector), T);
2850 }
2851
2852 template<class Vector4, int T>
operator =(float x)2853 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(float x)
2854 {
2855 RR_DEBUG_INFO_UPDATE_LOC();
2856 return *parent = Insert(*parent, Float(x), T & 0x3);
2857 }
2858
2859 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2860 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<Vector4> rhs)
2861 {
2862 RR_DEBUG_INFO_UPDATE_LOC();
2863 return Mask(*parent, Float4(rhs), T);
2864 }
2865
2866 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2867 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs) // FIXME: Call a non-template function
2868 {
2869 RR_DEBUG_INFO_UPDATE_LOC();
2870 return *parent = Insert(*parent, rhs, T & 0x3);
2871 }
2872
2873 template<class Vector4, int T>
operator RValue<Vector4>() const2874 SwizzleMask2<Vector4, T>::operator RValue<Vector4>() const
2875 {
2876 RR_DEBUG_INFO_UPDATE_LOC();
2877 Value *vector = parent->loadValue();
2878
2879 return Swizzle(RValue<Float4>(vector), T);
2880 }
2881
2882 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2883 RValue<Vector4> SwizzleMask2<Vector4, T>::operator=(RValue<Vector4> rhs)
2884 {
2885 RR_DEBUG_INFO_UPDATE_LOC();
2886 return Mask(*parent, Float4(rhs), T);
2887 }
2888
2889 template<int T>
Float(const SwizzleMask1<Float4,T> & rhs)2890 Float::Float(const SwizzleMask1<Float4, T> &rhs)
2891 {
2892 *this = rhs.operator RValue<Float>();
2893 }
2894
2895 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2896 RValue<Float> Float::operator=(const SwizzleMask1<Float4, T> &rhs)
2897 {
2898 return *this = rhs.operator RValue<Float>();
2899 }
2900
2901 template<int T>
Float4(const SwizzleMask1<Float4,T> & rhs)2902 Float4::Float4(const SwizzleMask1<Float4, T> &rhs)
2903 : XYZW(this)
2904 {
2905 *this = rhs.operator RValue<Float4>();
2906 }
2907
2908 template<int T>
Float4(const Swizzle4<Float4,T> & rhs)2909 Float4::Float4(const Swizzle4<Float4, T> &rhs)
2910 : XYZW(this)
2911 {
2912 *this = rhs.operator RValue<Float4>();
2913 }
2914
2915 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2916 Float4::Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2917 : XYZW(this)
2918 {
2919 RR_DEBUG_INFO_UPDATE_LOC();
2920 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2921 }
2922
2923 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2924 Float4::Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2925 : XYZW(this)
2926 {
2927 RR_DEBUG_INFO_UPDATE_LOC();
2928 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2929 }
2930
2931 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2932 Float4::Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2933 : XYZW(this)
2934 {
2935 RR_DEBUG_INFO_UPDATE_LOC();
2936 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2937 }
2938
2939 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2940 Float4::Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2941 : XYZW(this)
2942 {
2943 RR_DEBUG_INFO_UPDATE_LOC();
2944 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2945 }
2946
2947 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2948 RValue<Float4> Float4::operator=(const SwizzleMask1<Float4, T> &rhs)
2949 {
2950 return *this = rhs.operator RValue<Float4>();
2951 }
2952
2953 template<int T>
operator =(const Swizzle4<Float4,T> & rhs)2954 RValue<Float4> Float4::operator=(const Swizzle4<Float4, T> &rhs)
2955 {
2956 return *this = rhs.operator RValue<Float4>();
2957 }
2958
2959 // Returns a reactor pointer to the fixed-address ptr.
2960 RValue<Pointer<Byte>> ConstantPointer(void const *ptr);
2961
2962 // Returns a reactor pointer to an immutable copy of the data of size bytes.
2963 RValue<Pointer<Byte>> ConstantData(void const *data, size_t size);
2964
2965 template<class T>
Pointer(Argument<Pointer<T>> argument)2966 Pointer<T>::Pointer(Argument<Pointer<T>> argument)
2967 : alignment(1)
2968 {
2969 this->store(argument.rvalue());
2970 }
2971
2972 template<class T>
Pointer()2973 Pointer<T>::Pointer()
2974 : alignment(1)
2975 {}
2976
2977 template<class T>
Pointer(RValue<Pointer<T>> rhs)2978 Pointer<T>::Pointer(RValue<Pointer<T>> rhs)
2979 : alignment(1)
2980 {
2981 this->store(rhs);
2982 }
2983
2984 template<class T>
Pointer(const Pointer<T> & rhs)2985 Pointer<T>::Pointer(const Pointer<T> &rhs)
2986 : alignment(rhs.alignment)
2987 {
2988 this->store(rhs.load());
2989 }
2990
2991 template<class T>
Pointer(const Reference<Pointer<T>> & rhs)2992 Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs)
2993 : alignment(rhs.getAlignment())
2994 {
2995 this->store(rhs.load());
2996 }
2997
2998 template<class T>
Pointer(std::nullptr_t)2999 Pointer<T>::Pointer(std::nullptr_t)
3000 : alignment(1)
3001 {
3002 Value *value = Nucleus::createNullPointer(T::type());
3003 this->storeValue(value);
3004 }
3005
3006 template<class T>
operator =(RValue<Pointer<T>> rhs)3007 RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs)
3008 {
3009 return this->store(rhs);
3010 }
3011
3012 template<class T>
operator =(const Pointer<T> & rhs)3013 RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs)
3014 {
3015 return this->store(rhs.load());
3016 }
3017
3018 template<class T>
operator =(const Reference<Pointer<T>> & rhs)3019 RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs)
3020 {
3021 return this->store(rhs.load());
3022 }
3023
3024 template<class T>
operator =(std::nullptr_t)3025 RValue<Pointer<T>> Pointer<T>::operator=(std::nullptr_t)
3026 {
3027 Value *value = Nucleus::createNullPointer(T::type());
3028 this->storeValue(value);
3029
3030 return RValue<Pointer<T>>(this);
3031 }
3032
3033 template<class T>
operator *()3034 Reference<T> Pointer<T>::operator*()
3035 {
3036 return Reference<T>(this->loadValue(), alignment);
3037 }
3038
3039 template<class T>
operator [](int index)3040 Reference<T> Pointer<T>::operator[](int index)
3041 {
3042 RR_DEBUG_INFO_UPDATE_LOC();
3043 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), false);
3044
3045 return Reference<T>(element, alignment);
3046 }
3047
3048 template<class T>
operator [](unsigned int index)3049 Reference<T> Pointer<T>::operator[](unsigned int index)
3050 {
3051 RR_DEBUG_INFO_UPDATE_LOC();
3052 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), true);
3053
3054 return Reference<T>(element, alignment);
3055 }
3056
3057 template<class T>
operator [](RValue<Int> index)3058 Reference<T> Pointer<T>::operator[](RValue<Int> index)
3059 {
3060 RR_DEBUG_INFO_UPDATE_LOC();
3061 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), false);
3062
3063 return Reference<T>(element, alignment);
3064 }
3065
3066 template<class T>
operator [](RValue<UInt> index)3067 Reference<T> Pointer<T>::operator[](RValue<UInt> index)
3068 {
3069 RR_DEBUG_INFO_UPDATE_LOC();
3070 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), true);
3071
3072 return Reference<T>(element, alignment);
3073 }
3074
3075 template<class T>
type()3076 Type *Pointer<T>::type()
3077 {
3078 return Nucleus::getPointerType(T::type());
3079 }
3080
3081 template<class T, int S>
Array(int size)3082 Array<T, S>::Array(int size)
3083 : LValue<T>(size)
3084 {
3085 }
3086
3087 template<class T, int S>
operator [](int index)3088 Reference<T> Array<T, S>::operator[](int index)
3089 {
3090 assert(index < Variable::getArraySize());
3091 Value *element = this->getElementPointer(Nucleus::createConstantInt(index), false);
3092
3093 return Reference<T>(element);
3094 }
3095
3096 template<class T, int S>
operator [](unsigned int index)3097 Reference<T> Array<T, S>::operator[](unsigned int index)
3098 {
3099 assert(index < static_cast<unsigned int>(Variable::getArraySize()));
3100 Value *element = this->getElementPointer(Nucleus::createConstantInt(index), true);
3101
3102 return Reference<T>(element);
3103 }
3104
3105 template<class T, int S>
operator [](RValue<Int> index)3106 Reference<T> Array<T, S>::operator[](RValue<Int> index)
3107 {
3108 Value *element = this->getElementPointer(index.value(), false);
3109
3110 return Reference<T>(element);
3111 }
3112
3113 template<class T, int S>
operator [](RValue<UInt> index)3114 Reference<T> Array<T, S>::operator[](RValue<UInt> index)
3115 {
3116 Value *element = this->getElementPointer(index.value(), true);
3117
3118 return Reference<T>(element);
3119 }
3120
3121 // template<class T>
3122 // RValue<Array<T>> operator++(Array<T> &val, int)
3123 // {
3124 // // FIXME: Requires storing the address of the array
3125 // }
3126
3127 // template<class T>
3128 // const Array<T> &operator++(Array<T> &val)
3129 // {
3130 // // FIXME: Requires storing the address of the array
3131 // }
3132
3133 // template<class T>
3134 // RValue<Array<T>> operator--(Array<T> &val, int)
3135 // {
3136 // // FIXME: Requires storing the address of the array
3137 // }
3138
3139 // template<class T>
3140 // const Array<T> &operator--(Array<T> &val)
3141 // {
3142 // // FIXME: Requires storing the address of the array
3143 // }
3144
3145 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,RValue<T> ifFalse)3146 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, RValue<T> ifFalse)
3147 {
3148 RR_DEBUG_INFO_UPDATE_LOC();
3149 return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), ifFalse.value()));
3150 }
3151
3152 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,RValue<T> ifFalse)3153 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, RValue<T> ifFalse)
3154 {
3155 RR_DEBUG_INFO_UPDATE_LOC();
3156 Value *trueValue = ifTrue.loadValue();
3157
3158 return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, ifFalse.value()));
3159 }
3160
3161 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,const T & ifFalse)3162 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, const T &ifFalse)
3163 {
3164 RR_DEBUG_INFO_UPDATE_LOC();
3165 Value *falseValue = ifFalse.loadValue();
3166
3167 return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), falseValue));
3168 }
3169
3170 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,const T & ifFalse)3171 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, const T &ifFalse)
3172 {
3173 RR_DEBUG_INFO_UPDATE_LOC();
3174 Value *trueValue = ifTrue.loadValue();
3175 Value *falseValue = ifFalse.loadValue();
3176
3177 return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, falseValue));
3178 }
3179
3180 template<typename Return, typename... Arguments>
Function()3181 Function<Return(Arguments...)>::Function()
3182 : core(new Nucleus())
3183 {
3184 Type *types[] = { Arguments::type()... };
3185 for(Type *type : types)
3186 {
3187 if(type != Void::type())
3188 {
3189 arguments.push_back(type);
3190 }
3191 }
3192
3193 Nucleus::createFunction(Return::type(), arguments);
3194 }
3195
3196 template<typename Return, typename... Arguments>
operator ()(const char * name,...)3197 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const char *name, ...)
3198 {
3199 char fullName[1024 + 1];
3200
3201 va_list vararg;
3202 va_start(vararg, name);
3203 vsnprintf(fullName, 1024, name, vararg);
3204 va_end(vararg);
3205
3206 auto routine = core->acquireRoutine(fullName, Config::Edit::None);
3207 core.reset(nullptr);
3208
3209 return routine;
3210 }
3211
3212 template<typename Return, typename... Arguments>
operator ()(const Config::Edit & cfg,const char * name,...)3213 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const Config::Edit &cfg, const char *name, ...)
3214 {
3215 char fullName[1024 + 1];
3216
3217 va_list vararg;
3218 va_start(vararg, name);
3219 vsnprintf(fullName, 1024, name, vararg);
3220 va_end(vararg);
3221
3222 auto routine = core->acquireRoutine(fullName, cfg);
3223 core.reset(nullptr);
3224
3225 return routine;
3226 }
3227
3228 template<class T, class S>
ReinterpretCast(RValue<S> val)3229 RValue<T> ReinterpretCast(RValue<S> val)
3230 {
3231 RR_DEBUG_INFO_UPDATE_LOC();
3232 return RValue<T>(Nucleus::createBitCast(val.value(), T::type()));
3233 }
3234
3235 template<class T, class S>
ReinterpretCast(const LValue<S> & var)3236 RValue<T> ReinterpretCast(const LValue<S> &var)
3237 {
3238 RR_DEBUG_INFO_UPDATE_LOC();
3239 Value *val = var.loadValue();
3240
3241 return RValue<T>(Nucleus::createBitCast(val, T::type()));
3242 }
3243
3244 template<class T, class S>
ReinterpretCast(const Reference<S> & var)3245 RValue<T> ReinterpretCast(const Reference<S> &var)
3246 {
3247 return ReinterpretCast<T>(RValue<S>(var));
3248 }
3249
3250 template<class T>
As(Value * val)3251 RValue<T> As(Value *val)
3252 {
3253 RR_DEBUG_INFO_UPDATE_LOC();
3254 return RValue<T>(Nucleus::createBitCast(val, T::type()));
3255 }
3256
3257 template<class T, class S>
As(RValue<S> val)3258 RValue<T> As(RValue<S> val)
3259 {
3260 return ReinterpretCast<T>(val);
3261 }
3262
3263 template<class T, class S>
As(const LValue<S> & var)3264 RValue<T> As(const LValue<S> &var)
3265 {
3266 return ReinterpretCast<T>(var);
3267 }
3268
3269 template<class T, class S>
As(const Reference<S> & val)3270 RValue<T> As(const Reference<S> &val)
3271 {
3272 return ReinterpretCast<T>(val);
3273 }
3274
3275 // Calls the function pointer fptr with the given arguments, return type
3276 // and parameter types. Returns the call's return value if the function has
3277 // a non-void return type.
3278 Value *Call(RValue<Pointer<Byte>> fptr, Type *retTy, std::initializer_list<Value *> args, std::initializer_list<Type *> paramTys);
3279
3280 template<typename F>
3281 class CallHelper
3282 {};
3283
3284 template<typename Return, typename... Arguments>
3285 class CallHelper<Return(Arguments...)>
3286 {
3287 public:
3288 using RReturn = CToReactorT<Return>;
3289
Call(Return (fptr)(Arguments...),CToReactorT<Arguments>...args)3290 static inline RReturn Call(Return(fptr)(Arguments...), CToReactorT<Arguments>... args)
3291 {
3292 return RValue<RReturn>(rr::Call(
3293 ConstantPointer(reinterpret_cast<void *>(fptr)),
3294 RReturn::type(),
3295 { ValueOf(args)... },
3296 { CToReactorT<Arguments>::type()... }));
3297 }
3298
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3299 static inline RReturn Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3300 {
3301 return RValue<RReturn>(rr::Call(
3302 fptr,
3303 RReturn::type(),
3304 { ValueOf(args)... },
3305 { CToReactorT<Arguments>::type()... }));
3306 }
3307 };
3308
3309 template<typename... Arguments>
3310 class CallHelper<void(Arguments...)>
3311 {
3312 public:
Call(void (fptr)(Arguments...),CToReactorT<Arguments>...args)3313 static inline void Call(void(fptr)(Arguments...), CToReactorT<Arguments>... args)
3314 {
3315 rr::Call(ConstantPointer(reinterpret_cast<void *>(fptr)),
3316 Void::type(),
3317 { ValueOf(args)... },
3318 { CToReactorT<Arguments>::type()... });
3319 }
3320
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3321 static inline void Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3322 {
3323 rr::Call(fptr,
3324 Void::type(),
3325 { ValueOf(args)... },
3326 { CToReactorT<Arguments>::type()... });
3327 }
3328 };
3329
3330 template<typename T>
CastToReactor(const T & v)3331 inline ReactorTypeT<T> CastToReactor(const T &v)
3332 {
3333 return ReactorType<T>::cast(v);
3334 }
3335
3336 // Calls the static function pointer fptr with the given arguments args.
3337 template<typename Return, typename... CArgs, typename... RArgs>
Call(Return (fptr)(CArgs...),RArgs &&...args)3338 inline CToReactorT<Return> Call(Return(fptr)(CArgs...), RArgs &&... args)
3339 {
3340 return CallHelper<Return(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3341 }
3342
3343 // Calls the static function pointer fptr with the given arguments args.
3344 // Overload for calling functions with void return type.
3345 template<typename... CArgs, typename... RArgs>
Call(void (fptr)(CArgs...),RArgs &&...args)3346 inline void Call(void(fptr)(CArgs...), RArgs &&... args)
3347 {
3348 CallHelper<void(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3349 }
3350
3351 // Calls the member function pointer fptr with the given arguments args.
3352 // object can be a Class*, or a Pointer<Byte>.
3353 template<typename Return, typename Class, typename C, typename... CArgs, typename... RArgs>
Call(Return (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3354 inline CToReactorT<Return> Call(Return (Class::*fptr)(CArgs...), C &&object, RArgs &&... args)
3355 {
3356 using Helper = CallHelper<Return(Class *, void *, CArgs...)>;
3357 using fptrTy = decltype(fptr);
3358
3359 struct Static
3360 {
3361 static inline Return Call(Class *object, void *fptrptr, CArgs... args)
3362 {
3363 auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3364 return (object->*fptr)(std::forward<CArgs>(args)...);
3365 }
3366 };
3367
3368 return Helper::Call(&Static::Call,
3369 CastToReactor(object),
3370 ConstantData(&fptr, sizeof(fptr)),
3371 CastToReactor(std::forward<RArgs>(args))...);
3372 }
3373
3374 // Calls the member function pointer fptr with the given arguments args.
3375 // Overload for calling functions with void return type.
3376 // object can be a Class*, or a Pointer<Byte>.
3377 template<typename Class, typename C, typename... CArgs, typename... RArgs>
Call(void (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3378 inline void Call(void (Class::*fptr)(CArgs...), C &&object, RArgs &&... args)
3379 {
3380 using Helper = CallHelper<void(Class *, void *, CArgs...)>;
3381 using fptrTy = decltype(fptr);
3382
3383 struct Static
3384 {
3385 static inline void Call(Class *object, void *fptrptr, CArgs... args)
3386 {
3387 auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3388 (object->*fptr)(std::forward<CArgs>(args)...);
3389 }
3390 };
3391
3392 Helper::Call(&Static::Call,
3393 CastToReactor(object),
3394 ConstantData(&fptr, sizeof(fptr)),
3395 CastToReactor(std::forward<RArgs>(args))...);
3396 }
3397
3398 // NonVoidFunction<F> and VoidFunction<F> are helper classes which define ReturnType
3399 // when F matches a non-void fuction signature or void function signature, respectively,
3400 // as the function's return type.
3401 template<typename F>
3402 struct NonVoidFunction
3403 {};
3404
3405 template<typename Return, typename... Arguments>
3406 struct NonVoidFunction<Return(Arguments...)>
3407 {
3408 using ReturnType = Return;
3409 };
3410
3411 template<typename... Arguments>
3412 struct NonVoidFunction<void(Arguments...)>
3413 {
3414 };
3415
3416 template<typename F>
3417 using NonVoidFunctionReturnType = typename NonVoidFunction<F>::ReturnType;
3418
3419 template<typename F>
3420 struct VoidFunction
3421 {};
3422
3423 template<typename... Arguments>
3424 struct VoidFunction<void(Arguments...)>
3425 {
3426 using ReturnType = void;
3427 };
3428
3429 template<typename F>
3430 using VoidFunctionReturnType = typename VoidFunction<F>::ReturnType;
3431
3432 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3433 // Overload for calling functions with non-void return type.
3434 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3435 inline CToReactorT<NonVoidFunctionReturnType<FUNCTION_SIGNATURE>> Call(Pointer<Byte> fptr, RArgs &&... args)
3436 {
3437 return CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3438 }
3439
3440 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3441 // Overload for calling functions with void return type.
3442 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3443 inline VoidFunctionReturnType<FUNCTION_SIGNATURE> Call(Pointer<Byte> fptr, RArgs &&... args)
3444 {
3445 CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3446 }
3447
3448 // Breakpoint emits an instruction that will cause the application to trap.
3449 // This can be used to stop an attached debugger at the given call.
3450 void Breakpoint();
3451
3452 class ForData
3453 {
3454 public:
ForData(bool init)3455 ForData(bool init)
3456 : loopOnce(init)
3457 {
3458 }
3459
operator bool()3460 operator bool()
3461 {
3462 return loopOnce;
3463 }
3464
operator =(bool value)3465 bool operator=(bool value)
3466 {
3467 return loopOnce = value;
3468 }
3469
setup()3470 bool setup()
3471 {
3472 RR_DEBUG_INFO_FLUSH();
3473 if(Nucleus::getInsertBlock() != endBB)
3474 {
3475 testBB = Nucleus::createBasicBlock();
3476
3477 Nucleus::createBr(testBB);
3478 Nucleus::setInsertBlock(testBB);
3479
3480 return true;
3481 }
3482
3483 return false;
3484 }
3485
test(RValue<Bool> cmp)3486 bool test(RValue<Bool> cmp)
3487 {
3488 BasicBlock *bodyBB = Nucleus::createBasicBlock();
3489 endBB = Nucleus::createBasicBlock();
3490
3491 Nucleus::createCondBr(cmp.value(), bodyBB, endBB);
3492 Nucleus::setInsertBlock(bodyBB);
3493
3494 return true;
3495 }
3496
end()3497 void end()
3498 {
3499 Nucleus::createBr(testBB);
3500 Nucleus::setInsertBlock(endBB);
3501 }
3502
3503 private:
3504 BasicBlock *testBB = nullptr;
3505 BasicBlock *endBB = nullptr;
3506 bool loopOnce = true;
3507 };
3508
3509 class IfElseData
3510 {
3511 public:
IfElseData(RValue<Bool> cmp)3512 IfElseData(RValue<Bool> cmp)
3513 {
3514 trueBB = Nucleus::createBasicBlock();
3515 falseBB = Nucleus::createBasicBlock();
3516 endBB = falseBB; // Until we encounter an Else statement, these are the same.
3517
3518 Nucleus::createCondBr(cmp.value(), trueBB, falseBB);
3519 Nucleus::setInsertBlock(trueBB);
3520 }
3521
~IfElseData()3522 ~IfElseData()
3523 {
3524 Nucleus::createBr(endBB);
3525 Nucleus::setInsertBlock(endBB);
3526 }
3527
operator int()3528 operator int()
3529 {
3530 return iteration;
3531 }
3532
operator ++()3533 IfElseData &operator++()
3534 {
3535 ++iteration;
3536
3537 return *this;
3538 }
3539
elseClause()3540 void elseClause()
3541 {
3542 endBB = Nucleus::createBasicBlock();
3543 Nucleus::createBr(endBB);
3544
3545 Nucleus::setInsertBlock(falseBB);
3546 }
3547
3548 private:
3549 BasicBlock *trueBB = nullptr;
3550 BasicBlock *falseBB = nullptr;
3551 BasicBlock *endBB = nullptr;
3552 int iteration = 0;
3553 };
3554
3555 #define For(init, cond, inc) \
3556 for(ForData for__ = true; for__; for__ = false) \
3557 for(init; for__.setup() && for__.test(cond); inc, for__.end())
3558
3559 #define While(cond) For((void)0, cond, (void)0)
3560
3561 #define Do \
3562 { \
3563 BasicBlock *body__ = Nucleus::createBasicBlock(); \
3564 Nucleus::createBr(body__); \
3565 Nucleus::setInsertBlock(body__);
3566
3567 #define Until(cond) \
3568 BasicBlock *end__ = Nucleus::createBasicBlock(); \
3569 Nucleus::createCondBr((cond).value(), end__, body__); \
3570 Nucleus::setInsertBlock(end__); \
3571 } \
3572 do \
3573 { \
3574 } while(false) // Require a semi-colon at the end of the Until()
3575
3576 enum
3577 {
3578 IF_BLOCK__,
3579 ELSE_CLAUSE__,
3580 ELSE_BLOCK__,
3581 IFELSE_NUM__
3582 };
3583
3584 #define If(cond) \
3585 for(IfElseData ifElse__{ cond }; ifElse__ < IFELSE_NUM__; ++ifElse__) \
3586 if(ifElse__ == IF_BLOCK__)
3587
3588 #define Else \
3589 else if(ifElse__ == ELSE_CLAUSE__) \
3590 { \
3591 ifElse__.elseClause(); \
3592 } \
3593 else // ELSE_BLOCK__
3594
3595 // The OFFSET macro is a generalization of the offsetof() macro defined in <cstddef>.
3596 // It allows e.g. getting the offset of array elements, even when indexed dynamically.
3597 // We cast the address '32' and subtract it again, because null-dereference is undefined behavior.
3598 #define OFFSET(s, m) ((int)(size_t) & reinterpret_cast<const volatile char &>((((s *)32)->m)) - 32)
3599
3600 } // namespace rr
3601
3602 #include "Traits.inl"
3603
3604 #endif // rr_Reactor_hpp
3605