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 "Pragma.hpp"
20 #include "Routine.hpp"
21 #include "Swizzle.hpp"
22 #include "Traits.hpp"
23
24 #include <array>
25 #include <cassert>
26 #include <cmath>
27 #include <cstddef>
28 #include <cstdio>
29 #include <limits>
30 #include <tuple>
31 #include <unordered_map>
32
33 #ifdef ENABLE_RR_DEBUG_INFO
34 // Functions used for generating JIT debug info.
35 // See docs/ReactorDebugInfo.md for more information.
36 namespace rr {
37 // Update the current source location for debug.
38 void EmitDebugLocation();
39 // Bind value to its symbolic name taken from the backtrace.
40 void EmitDebugVariable(class Value *value);
41 // Flush any pending variable bindings before the line ends.
42 void FlushDebug();
43 } // namespace rr
44 # define RR_DEBUG_INFO_UPDATE_LOC() rr::EmitDebugLocation()
45 # define RR_DEBUG_INFO_EMIT_VAR(value) rr::EmitDebugVariable(value)
46 # define RR_DEBUG_INFO_FLUSH() rr::FlushDebug()
47 #else
48 # define RR_DEBUG_INFO_UPDATE_LOC()
49 # define RR_DEBUG_INFO_EMIT_VAR(value)
50 # define RR_DEBUG_INFO_FLUSH()
51 #endif // ENABLE_RR_DEBUG_INFO
52
53 #ifdef ENABLE_RR_PRINT
54 namespace rr {
55 int DebugPrintf(const char *format, ...);
56 }
57 #endif
58
59 // A Clang extension to determine compiler features.
60 // We use it to detect Sanitizer builds (e.g. -fsanitize=memory).
61 #ifndef __has_feature
62 # define __has_feature(x) 0
63 #endif
64
65 namespace rr {
66
67 struct Caps
68 {
69 static std::string backendName();
70 static bool coroutinesSupported(); // Support for rr::Coroutine<F>
71 static bool fmaIsFast(); // rr::FMA() is faster than `x * y + z`
72 };
73
74 class Bool;
75 class Byte;
76 class SByte;
77 class Byte4;
78 class SByte4;
79 class Byte8;
80 class SByte8;
81 class Byte16;
82 class SByte16;
83 class Short;
84 class UShort;
85 class Short2;
86 class UShort2;
87 class Short4;
88 class UShort4;
89 class Short8;
90 class UShort8;
91 class Int;
92 class UInt;
93 class Int2;
94 class UInt2;
95 class Int4;
96 class UInt4;
97 class Long;
98 class Half;
99 class Float;
100 class Float2;
101 class Float4;
102
103 namespace SIMD {
104 class Int;
105 class UInt;
106 class Float;
107 } // namespace SIMD
108
109 template<>
110 struct Scalar<Float4>
111 {
112 using Type = Float;
113 };
114
115 template<>
116 struct Scalar<Int4>
117 {
118 using Type = Int;
119 };
120
121 template<>
122 struct Scalar<UInt4>
123 {
124 using Type = UInt;
125 };
126
127 template<>
128 struct Scalar<SIMD::Float>
129 {
130 using Type = Float;
131 };
132
133 template<>
134 struct Scalar<SIMD::Int>
135 {
136 using Type = Int;
137 };
138
139 template<>
140 struct Scalar<SIMD::UInt>
141 {
142 using Type = UInt;
143 };
144
145 class Void
146 {
147 public:
148 static Type *type();
149 };
150
151 template<class T>
152 class RValue;
153
154 template<class T>
155 class Pointer;
156
157 class Variable
158 {
159 friend class Nucleus;
160
161 Variable() = delete;
162 Variable &operator=(const Variable &) = delete;
163
164 public:
165 void materialize() const;
166
167 Value *loadValue() const;
168 Value *storeValue(Value *value) const;
169
170 Value *getBaseAddress() const;
171 Value *getElementPointer(Value *index, bool unsignedIndex) const;
172
getType() const173 Type *getType() const { return type; }
getArraySize() const174 int getArraySize() const { return arraySize; }
175
176 // This function is only public for testing purposes, as it affects performance.
177 // It is not considered part of Reactor's public API.
178 static void materializeAll();
179
180 protected:
181 Variable(Type *type, int arraySize);
182 Variable(const Variable &) = default;
183
184 virtual ~Variable();
185
186 private:
187 static void killUnmaterialized();
188
189 // Set of variables that do not have a stack location yet.
190 class UnmaterializedVariables
191 {
192 public:
193 void add(const Variable *v);
194 void remove(const Variable *v);
195 void clear();
196 void materializeAll();
197
198 private:
199 int counter = 0;
200 std::unordered_map<const Variable *, int> variables;
201 };
202
203 // This has to be a raw pointer because glibc 2.17 doesn't support __cxa_thread_atexit_impl
204 // for destructing objects at exit. See crbug.com/1074222
205 static thread_local UnmaterializedVariables *unmaterializedVariables;
206
207 Type *const type;
208 const int arraySize;
209 mutable Value *rvalue = nullptr;
210 mutable Value *address = nullptr;
211 };
212
213 template<class T>
214 class LValue : public Variable
215 {
216 public:
217 LValue(int arraySize = 0);
218
219 RValue<Pointer<T>> operator&();
220
load() const221 RValue<T> load() const
222 {
223 return RValue<T>(this->loadValue());
224 }
225
store(RValue<T> rvalue) const226 RValue<T> store(RValue<T> rvalue) const
227 {
228 this->storeValue(rvalue.value());
229
230 return rvalue;
231 }
232
233 // self() returns the this pointer to this LValue<T> object.
234 // This function exists because operator&() is overloaded.
self()235 inline LValue<T> *self() { return this; }
236 };
237
238 template<class T>
239 class Reference
240 {
241 public:
242 using reference_underlying_type = T;
243
244 explicit Reference(Value *pointer, int alignment = 1);
245 Reference(const Reference<T> &ref) = default;
246
247 RValue<T> operator=(RValue<T> rhs) const;
248 RValue<T> operator=(const Reference<T> &ref) const;
249
250 RValue<T> operator+=(RValue<T> rhs) const;
251
operator &() const252 RValue<Pointer<T>> operator&() const { return RValue<Pointer<T>>(address); }
253
254 Value *loadValue() const;
255 RValue<T> load() const;
256 int getAlignment() const;
257
258 private:
259 Value *const address;
260
261 const int alignment;
262 };
263
264 template<class T>
265 struct BoolLiteral
266 {
267 struct Type;
268 };
269
270 template<>
271 struct BoolLiteral<Bool>
272 {
273 using Type = bool;
274 };
275
276 template<class T>
277 struct IntLiteral
278 {
279 struct Type;
280 };
281
282 template<>
283 struct IntLiteral<Int>
284 {
285 using Type = int;
286 };
287
288 template<>
289 struct IntLiteral<UInt>
290 {
291 using Type = unsigned int;
292 };
293
294 template<class T>
295 struct LongLiteral
296 {
297 struct Type;
298 };
299
300 template<>
301 struct LongLiteral<Long>
302 {
303 using Type = int64_t;
304 };
305
306 template<class T>
307 struct FloatLiteral
308 {
309 struct Type;
310 };
311
312 template<>
313 struct FloatLiteral<Float>
314 {
315 using Type = float;
316 };
317
318 template<class T>
319 struct BroadcastLiteral
320 {
321 struct Type;
322 };
323
324 template<>
325 struct BroadcastLiteral<Int4>
326 {
327 using Type = int;
328 };
329
330 template<>
331 struct BroadcastLiteral<UInt4>
332 {
333 using Type = unsigned int;
334 };
335
336 template<>
337 struct BroadcastLiteral<Float4>
338 {
339 using Type = float;
340 };
341
342 template<>
343 struct BroadcastLiteral<SIMD::Int>
344 {
345 using Type = int;
346 };
347
348 template<>
349 struct BroadcastLiteral<SIMD::UInt>
350 {
351 using Type = unsigned int;
352 };
353
354 template<>
355 struct BroadcastLiteral<SIMD::Float>
356 {
357 using Type = float;
358 };
359
360 template<class T>
361 class RValue
362 {
363 public:
364 using rvalue_underlying_type = T;
365
366 explicit RValue(Value *rvalue);
367
368 RValue(const RValue<T> &rvalue);
369 RValue(const T &lvalue);
370 RValue(typename BoolLiteral<T>::Type b);
371 RValue(typename IntLiteral<T>::Type i);
372 RValue(typename LongLiteral<T>::Type i);
373 RValue(typename FloatLiteral<T>::Type f);
374 RValue(typename BroadcastLiteral<T>::Type x);
375 RValue(const Reference<T> &rhs);
376
377 // Rvalues cannot be assigned to: "(a + b) = c;"
378 RValue<T> &operator=(const RValue<T> &) = delete;
379
value() const380 Value *value() const { return val; }
381
element_count()382 static int element_count() { return T::element_count(); }
383
384 private:
385 Value *const val;
386 };
387
388 template<typename T>
389 class Argument
390 {
391 public:
Argument(Value * val)392 explicit Argument(Value *val)
393 : val(val)
394 {}
395
rvalue() const396 RValue<T> rvalue() const { return RValue<T>(val); }
397
398 private:
399 Value *const val;
400 };
401
402 class Bool : public LValue<Bool>
403 {
404 public:
405 Bool(Argument<Bool> argument);
406
407 Bool() = default;
408 Bool(bool x);
409 Bool(RValue<Bool> rhs);
410 Bool(const Bool &rhs);
411 Bool(const Reference<Bool> &rhs);
412
413 // RValue<Bool> operator=(bool rhs); // FIXME: Implement
414 RValue<Bool> operator=(RValue<Bool> rhs);
415 RValue<Bool> operator=(const Bool &rhs);
416 RValue<Bool> operator=(const Reference<Bool> &rhs);
417
418 static Type *type();
419 };
420
421 RValue<Bool> operator!(RValue<Bool> val);
422 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs);
423 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs);
424 RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs);
425 RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs);
426
427 class Byte : public LValue<Byte>
428 {
429 public:
430 Byte(Argument<Byte> argument);
431
432 explicit Byte(RValue<Int> cast);
433 explicit Byte(RValue<UInt> cast);
434 explicit Byte(RValue<UShort> cast);
435
436 Byte() = default;
437 Byte(int x);
438 Byte(unsigned char x);
439 Byte(RValue<Byte> rhs);
440 Byte(const Byte &rhs);
441 Byte(const Reference<Byte> &rhs);
442
443 // RValue<Byte> operator=(unsigned char rhs); // FIXME: Implement
444 RValue<Byte> operator=(RValue<Byte> rhs);
445 RValue<Byte> operator=(const Byte &rhs);
446 RValue<Byte> operator=(const Reference<Byte> &rhs);
447
448 static Type *type();
449 };
450
451 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs);
452 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs);
453 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs);
454 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs);
455 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs);
456 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs);
457 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs);
458 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs);
459 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs);
460 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs);
461 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs);
462 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs);
463 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs);
464 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs);
465 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs);
466 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs);
467 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs);
468 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs);
469 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs);
470 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs);
471 RValue<Byte> operator+(RValue<Byte> val);
472 RValue<Byte> operator-(RValue<Byte> val);
473 RValue<Byte> operator~(RValue<Byte> val);
474 RValue<Byte> operator++(Byte &val, int); // Post-increment
475 const Byte &operator++(Byte &val); // Pre-increment
476 RValue<Byte> operator--(Byte &val, int); // Post-decrement
477 const Byte &operator--(Byte &val); // Pre-decrement
478 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs);
479 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs);
480 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs);
481 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs);
482 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs);
483 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs);
484
485 class SByte : public LValue<SByte>
486 {
487 public:
488 SByte(Argument<SByte> argument);
489
490 explicit SByte(RValue<Int> cast);
491 explicit SByte(RValue<Short> cast);
492
493 SByte() = default;
494 SByte(signed char x);
495 SByte(RValue<SByte> rhs);
496 SByte(const SByte &rhs);
497 SByte(const Reference<SByte> &rhs);
498
499 // RValue<SByte> operator=(signed char rhs); // FIXME: Implement
500 RValue<SByte> operator=(RValue<SByte> rhs);
501 RValue<SByte> operator=(const SByte &rhs);
502 RValue<SByte> operator=(const Reference<SByte> &rhs);
503
504 static Type *type();
505 };
506
507 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs);
508 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs);
509 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs);
510 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs);
511 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs);
512 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs);
513 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs);
514 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs);
515 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs);
516 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs);
517 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs);
518 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs);
519 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs);
520 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs);
521 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs);
522 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs);
523 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs);
524 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs);
525 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs);
526 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs);
527 RValue<SByte> operator+(RValue<SByte> val);
528 RValue<SByte> operator-(RValue<SByte> val);
529 RValue<SByte> operator~(RValue<SByte> val);
530 RValue<SByte> operator++(SByte &val, int); // Post-increment
531 const SByte &operator++(SByte &val); // Pre-increment
532 RValue<SByte> operator--(SByte &val, int); // Post-decrement
533 const SByte &operator--(SByte &val); // Pre-decrement
534 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs);
535 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs);
536 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs);
537 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs);
538 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs);
539 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs);
540
541 class Short : public LValue<Short>
542 {
543 public:
544 Short(Argument<Short> argument);
545
546 explicit Short(RValue<Int> cast);
547
548 Short() = default;
549 Short(short x);
550 Short(RValue<Short> rhs);
551 Short(const Short &rhs);
552 Short(const Reference<Short> &rhs);
553
554 // RValue<Short> operator=(short rhs); // FIXME: Implement
555 RValue<Short> operator=(RValue<Short> rhs);
556 RValue<Short> operator=(const Short &rhs);
557 RValue<Short> operator=(const Reference<Short> &rhs);
558
559 static Type *type();
560 };
561
562 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs);
563 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs);
564 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs);
565 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs);
566 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs);
567 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs);
568 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs);
569 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs);
570 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs);
571 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs);
572 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs);
573 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs);
574 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs);
575 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs);
576 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs);
577 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs);
578 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs);
579 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs);
580 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs);
581 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs);
582 RValue<Short> operator+(RValue<Short> val);
583 RValue<Short> operator-(RValue<Short> val);
584 RValue<Short> operator~(RValue<Short> val);
585 RValue<Short> operator++(Short &val, int); // Post-increment
586 const Short &operator++(Short &val); // Pre-increment
587 RValue<Short> operator--(Short &val, int); // Post-decrement
588 const Short &operator--(Short &val); // Pre-decrement
589 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs);
590 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs);
591 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs);
592 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs);
593 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs);
594 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs);
595
596 class UShort : public LValue<UShort>
597 {
598 public:
599 UShort(Argument<UShort> argument);
600
601 explicit UShort(RValue<UInt> cast);
602 explicit UShort(RValue<Int> cast);
603 explicit UShort(RValue<Byte> cast);
604
605 UShort() = default;
606 UShort(unsigned short x);
607 UShort(RValue<UShort> rhs);
608 UShort(const UShort &rhs);
609 UShort(const Reference<UShort> &rhs);
610
611 // RValue<UShort> operator=(unsigned short rhs); // FIXME: Implement
612 RValue<UShort> operator=(RValue<UShort> rhs);
613 RValue<UShort> operator=(const UShort &rhs);
614 RValue<UShort> operator=(const Reference<UShort> &rhs);
615
616 static Type *type();
617 };
618
619 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs);
620 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs);
621 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs);
622 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs);
623 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs);
624 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs);
625 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs);
626 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs);
627 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs);
628 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs);
629 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs);
630 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs);
631 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs);
632 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs);
633 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs);
634 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs);
635 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs);
636 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs);
637 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs);
638 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs);
639 RValue<UShort> operator+(RValue<UShort> val);
640 RValue<UShort> operator-(RValue<UShort> val);
641 RValue<UShort> operator~(RValue<UShort> val);
642 RValue<UShort> operator++(UShort &val, int); // Post-increment
643 const UShort &operator++(UShort &val); // Pre-increment
644 RValue<UShort> operator--(UShort &val, int); // Post-decrement
645 const UShort &operator--(UShort &val); // Pre-decrement
646 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs);
647 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs);
648 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs);
649 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs);
650 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs);
651 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs);
652
653 class Byte4 : public LValue<Byte4>
654 {
655 public:
656 explicit Byte4(RValue<Byte8> cast);
657 explicit Byte4(RValue<UShort4> cast);
658 explicit Byte4(RValue<Short4> cast);
659 explicit Byte4(RValue<UInt4> cast);
660 explicit Byte4(RValue<Int4> cast);
661
662 Byte4() = default;
663 // Byte4(int x, int y, int z, int w);
664 Byte4(RValue<Byte4> rhs);
665 Byte4(const Byte4 &rhs);
666 Byte4(const Reference<Byte4> &rhs);
667
668 RValue<Byte4> operator=(RValue<Byte4> rhs);
669 RValue<Byte4> operator=(const Byte4 &rhs);
670 // RValue<Byte4> operator=(const Reference<Byte4> &rhs);
671
672 static Type *type();
element_count()673 static int element_count() { return 4; }
674 };
675
676 RValue<Byte4> Insert(RValue<Byte4> val, RValue<Byte> element, int i);
677
678 // RValue<Byte4> operator+(RValue<Byte4> lhs, RValue<Byte4> rhs);
679 // RValue<Byte4> operator-(RValue<Byte4> lhs, RValue<Byte4> rhs);
680 // RValue<Byte4> operator*(RValue<Byte4> lhs, RValue<Byte4> rhs);
681 // RValue<Byte4> operator/(RValue<Byte4> lhs, RValue<Byte4> rhs);
682 // RValue<Byte4> operator%(RValue<Byte4> lhs, RValue<Byte4> rhs);
683 // RValue<Byte4> operator&(RValue<Byte4> lhs, RValue<Byte4> rhs);
684 // RValue<Byte4> operator|(RValue<Byte4> lhs, RValue<Byte4> rhs);
685 // RValue<Byte4> operator^(RValue<Byte4> lhs, RValue<Byte4> rhs);
686 // RValue<Byte4> operator<<(RValue<Byte4> lhs, RValue<Byte4> rhs);
687 // RValue<Byte4> operator>>(RValue<Byte4> lhs, RValue<Byte4> rhs);
688 // RValue<Byte4> operator+=(Byte4 &lhs, RValue<Byte4> rhs);
689 // RValue<Byte4> operator-=(Byte4 &lhs, RValue<Byte4> rhs);
690 // RValue<Byte4> operator*=(Byte4 &lhs, RValue<Byte4> rhs);
691 // RValue<Byte4> operator/=(Byte4 &lhs, RValue<Byte4> rhs);
692 // RValue<Byte4> operator%=(Byte4 &lhs, RValue<Byte4> rhs);
693 // RValue<Byte4> operator&=(Byte4 &lhs, RValue<Byte4> rhs);
694 // RValue<Byte4> operator|=(Byte4 &lhs, RValue<Byte4> rhs);
695 // RValue<Byte4> operator^=(Byte4 &lhs, RValue<Byte4> rhs);
696 // RValue<Byte4> operator<<=(Byte4 &lhs, RValue<Byte4> rhs);
697 // RValue<Byte4> operator>>=(Byte4 &lhs, RValue<Byte4> rhs);
698 // RValue<Byte4> operator+(RValue<Byte4> val);
699 // RValue<Byte4> operator-(RValue<Byte4> val);
700 // RValue<Byte4> operator~(RValue<Byte4> val);
701 // RValue<Byte4> operator++(Byte4 &val, int); // Post-increment
702 // const Byte4 &operator++(Byte4 &val); // Pre-increment
703 // RValue<Byte4> operator--(Byte4 &val, int); // Post-decrement
704 // const Byte4 &operator--(Byte4 &val); // Pre-decrement
705
706 class SByte4 : public LValue<SByte4>
707 {
708 public:
709 SByte4() = default;
710 // SByte4(int x, int y, int z, int w);
711 // SByte4(RValue<SByte4> rhs);
712 // SByte4(const SByte4 &rhs);
713 // SByte4(const Reference<SByte4> &rhs);
714
715 // RValue<SByte4> operator=(RValue<SByte4> rhs);
716 // RValue<SByte4> operator=(const SByte4 &rhs);
717 // RValue<SByte4> operator=(const Reference<SByte4> &rhs);
718
719 static Type *type();
element_count()720 static int element_count() { return 4; }
721 };
722
723 // RValue<SByte4> operator+(RValue<SByte4> lhs, RValue<SByte4> rhs);
724 // RValue<SByte4> operator-(RValue<SByte4> lhs, RValue<SByte4> rhs);
725 // RValue<SByte4> operator*(RValue<SByte4> lhs, RValue<SByte4> rhs);
726 // RValue<SByte4> operator/(RValue<SByte4> lhs, RValue<SByte4> rhs);
727 // RValue<SByte4> operator%(RValue<SByte4> lhs, RValue<SByte4> rhs);
728 // RValue<SByte4> operator&(RValue<SByte4> lhs, RValue<SByte4> rhs);
729 // RValue<SByte4> operator|(RValue<SByte4> lhs, RValue<SByte4> rhs);
730 // RValue<SByte4> operator^(RValue<SByte4> lhs, RValue<SByte4> rhs);
731 // RValue<SByte4> operator<<(RValue<SByte4> lhs, RValue<SByte4> rhs);
732 // RValue<SByte4> operator>>(RValue<SByte4> lhs, RValue<SByte4> rhs);
733 // RValue<SByte4> operator+=(SByte4 &lhs, RValue<SByte4> rhs);
734 // RValue<SByte4> operator-=(SByte4 &lhs, RValue<SByte4> rhs);
735 // RValue<SByte4> operator*=(SByte4 &lhs, RValue<SByte4> rhs);
736 // RValue<SByte4> operator/=(SByte4 &lhs, RValue<SByte4> rhs);
737 // RValue<SByte4> operator%=(SByte4 &lhs, RValue<SByte4> rhs);
738 // RValue<SByte4> operator&=(SByte4 &lhs, RValue<SByte4> rhs);
739 // RValue<SByte4> operator|=(SByte4 &lhs, RValue<SByte4> rhs);
740 // RValue<SByte4> operator^=(SByte4 &lhs, RValue<SByte4> rhs);
741 // RValue<SByte4> operator<<=(SByte4 &lhs, RValue<SByte4> rhs);
742 // RValue<SByte4> operator>>=(SByte4 &lhs, RValue<SByte4> rhs);
743 // RValue<SByte4> operator+(RValue<SByte4> val);
744 // RValue<SByte4> operator-(RValue<SByte4> val);
745 // RValue<SByte4> operator~(RValue<SByte4> val);
746 // RValue<SByte4> operator++(SByte4 &val, int); // Post-increment
747 // const SByte4 &operator++(SByte4 &val); // Pre-increment
748 // RValue<SByte4> operator--(SByte4 &val, int); // Post-decrement
749 // const SByte4 &operator--(SByte4 &val); // Pre-decrement
750
751 class Byte8 : public LValue<Byte8>
752 {
753 public:
754 Byte8() = default;
755 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);
756 Byte8(RValue<Byte8> rhs);
757 Byte8(const Byte8 &rhs);
758 Byte8(const Reference<Byte8> &rhs);
759
760 RValue<Byte8> operator=(RValue<Byte8> rhs);
761 RValue<Byte8> operator=(const Byte8 &rhs);
762 RValue<Byte8> operator=(const Reference<Byte8> &rhs);
763
764 static Type *type();
element_count()765 static int element_count() { return 8; }
766 };
767
768 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs);
769 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs);
770 // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs);
771 // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs);
772 // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs);
773 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs);
774 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs);
775 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs);
776 // RValue<Byte8> operator<<(RValue<Byte8> lhs, RValue<Byte8> rhs);
777 // RValue<Byte8> operator>>(RValue<Byte8> lhs, RValue<Byte8> rhs);
778 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs);
779 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs);
780 // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs);
781 // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs);
782 // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs);
783 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs);
784 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs);
785 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs);
786 // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs);
787 // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs);
788 // RValue<Byte8> operator+(RValue<Byte8> val);
789 // RValue<Byte8> operator-(RValue<Byte8> val);
790 RValue<Byte8> operator~(RValue<Byte8> val);
791 // RValue<Byte8> operator++(Byte8 &val, int); // Post-increment
792 // const Byte8 &operator++(Byte8 &val); // Pre-increment
793 // RValue<Byte8> operator--(Byte8 &val, int); // Post-decrement
794 // const Byte8 &operator--(Byte8 &val); // Pre-decrement
795
796 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y);
797 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y);
798 RValue<Short4> Unpack(RValue<Byte4> x);
799 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y);
800 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y);
801 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y);
802 RValue<Int> SignMask(RValue<Byte8> x);
803 // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y);
804 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y);
805 RValue<Byte8> Swizzle(RValue<Byte8> x, uint32_t select);
806
807 class SByte8 : public LValue<SByte8>
808 {
809 public:
810 SByte8() = default;
811 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);
812 SByte8(RValue<SByte8> rhs);
813 SByte8(const SByte8 &rhs);
814 SByte8(const Reference<SByte8> &rhs);
815
816 RValue<SByte8> operator=(RValue<SByte8> rhs);
817 RValue<SByte8> operator=(const SByte8 &rhs);
818 RValue<SByte8> operator=(const Reference<SByte8> &rhs);
819
820 static Type *type();
element_count()821 static int element_count() { return 8; }
822 };
823
824 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs);
825 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs);
826 // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs);
827 // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs);
828 // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs);
829 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs);
830 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs);
831 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs);
832 // RValue<SByte8> operator<<(RValue<SByte8> lhs, RValue<SByte8> rhs);
833 // RValue<SByte8> operator>>(RValue<SByte8> lhs, RValue<SByte8> rhs);
834 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs);
835 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs);
836 // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs);
837 // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs);
838 // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs);
839 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs);
840 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs);
841 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs);
842 // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs);
843 // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs);
844 // RValue<SByte8> operator+(RValue<SByte8> val);
845 // RValue<SByte8> operator-(RValue<SByte8> val);
846 RValue<SByte8> operator~(RValue<SByte8> val);
847 // RValue<SByte8> operator++(SByte8 &val, int); // Post-increment
848 // const SByte8 &operator++(SByte8 &val); // Pre-increment
849 // RValue<SByte8> operator--(SByte8 &val, int); // Post-decrement
850 // const SByte8 &operator--(SByte8 &val); // Pre-decrement
851
852 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y);
853 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y);
854 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y);
855 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y);
856 RValue<Int> SignMask(RValue<SByte8> x);
857 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y);
858 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y);
859
860 class Byte16 : public LValue<Byte16>
861 {
862 public:
863 Byte16() = default;
864 Byte16(RValue<Byte16> rhs);
865 Byte16(const Byte16 &rhs);
866 Byte16(const Reference<Byte16> &rhs);
867
868 RValue<Byte16> operator=(RValue<Byte16> rhs);
869 RValue<Byte16> operator=(const Byte16 &rhs);
870 RValue<Byte16> operator=(const Reference<Byte16> &rhs);
871
872 static Type *type();
element_count()873 static int element_count() { return 16; }
874 };
875
876 // RValue<Byte16> operator+(RValue<Byte16> lhs, RValue<Byte16> rhs);
877 // RValue<Byte16> operator-(RValue<Byte16> lhs, RValue<Byte16> rhs);
878 // RValue<Byte16> operator*(RValue<Byte16> lhs, RValue<Byte16> rhs);
879 // RValue<Byte16> operator/(RValue<Byte16> lhs, RValue<Byte16> rhs);
880 // RValue<Byte16> operator%(RValue<Byte16> lhs, RValue<Byte16> rhs);
881 // RValue<Byte16> operator&(RValue<Byte16> lhs, RValue<Byte16> rhs);
882 // RValue<Byte16> operator|(RValue<Byte16> lhs, RValue<Byte16> rhs);
883 // RValue<Byte16> operator^(RValue<Byte16> lhs, RValue<Byte16> rhs);
884 // RValue<Byte16> operator<<(RValue<Byte16> lhs, RValue<Byte16> rhs);
885 // RValue<Byte16> operator>>(RValue<Byte16> lhs, RValue<Byte16> rhs);
886 // RValue<Byte16> operator+=(Byte16 &lhs, RValue<Byte16> rhs);
887 // RValue<Byte16> operator-=(Byte16 &lhs, RValue<Byte16> rhs);
888 // RValue<Byte16> operator*=(Byte16 &lhs, RValue<Byte16> rhs);
889 // RValue<Byte16> operator/=(Byte16 &lhs, RValue<Byte16> rhs);
890 // RValue<Byte16> operator%=(Byte16 &lhs, RValue<Byte16> rhs);
891 // RValue<Byte16> operator&=(Byte16 &lhs, RValue<Byte16> rhs);
892 // RValue<Byte16> operator|=(Byte16 &lhs, RValue<Byte16> rhs);
893 // RValue<Byte16> operator^=(Byte16 &lhs, RValue<Byte16> rhs);
894 // RValue<Byte16> operator<<=(Byte16 &lhs, RValue<Byte16> rhs);
895 // RValue<Byte16> operator>>=(Byte16 &lhs, RValue<Byte16> rhs);
896 // RValue<Byte16> operator+(RValue<Byte16> val);
897 // RValue<Byte16> operator-(RValue<Byte16> val);
898 // RValue<Byte16> operator~(RValue<Byte16> val);
899 // RValue<Byte16> operator++(Byte16 &val, int); // Post-increment
900 // const Byte16 &operator++(Byte16 &val); // Pre-increment
901 // RValue<Byte16> operator--(Byte16 &val, int); // Post-decrement
902 // const Byte16 &operator--(Byte16 &val); // Pre-decrement
903 RValue<Byte16> Swizzle(RValue<Byte16> x, uint64_t select);
904
905 class SByte16 : public LValue<SByte16>
906 {
907 public:
908 SByte16() = default;
909 // SByte16(int x, int y, int z, int w);
910 // SByte16(RValue<SByte16> rhs);
911 // SByte16(const SByte16 &rhs);
912 // SByte16(const Reference<SByte16> &rhs);
913
914 // RValue<SByte16> operator=(RValue<SByte16> rhs);
915 // RValue<SByte16> operator=(const SByte16 &rhs);
916 // RValue<SByte16> operator=(const Reference<SByte16> &rhs);
917
918 static Type *type();
element_count()919 static int element_count() { return 16; }
920 };
921
922 // RValue<SByte16> operator+(RValue<SByte16> lhs, RValue<SByte16> rhs);
923 // RValue<SByte16> operator-(RValue<SByte16> lhs, RValue<SByte16> rhs);
924 // RValue<SByte16> operator*(RValue<SByte16> lhs, RValue<SByte16> rhs);
925 // RValue<SByte16> operator/(RValue<SByte16> lhs, RValue<SByte16> rhs);
926 // RValue<SByte16> operator%(RValue<SByte16> lhs, RValue<SByte16> rhs);
927 // RValue<SByte16> operator&(RValue<SByte16> lhs, RValue<SByte16> rhs);
928 // RValue<SByte16> operator|(RValue<SByte16> lhs, RValue<SByte16> rhs);
929 // RValue<SByte16> operator^(RValue<SByte16> lhs, RValue<SByte16> rhs);
930 // RValue<SByte16> operator<<(RValue<SByte16> lhs, RValue<SByte16> rhs);
931 // RValue<SByte16> operator>>(RValue<SByte16> lhs, RValue<SByte16> rhs);
932 // RValue<SByte16> operator+=(SByte16 &lhs, RValue<SByte16> rhs);
933 // RValue<SByte16> operator-=(SByte16 &lhs, RValue<SByte16> rhs);
934 // RValue<SByte16> operator*=(SByte16 &lhs, RValue<SByte16> rhs);
935 // RValue<SByte16> operator/=(SByte16 &lhs, RValue<SByte16> rhs);
936 // RValue<SByte16> operator%=(SByte16 &lhs, RValue<SByte16> rhs);
937 // RValue<SByte16> operator&=(SByte16 &lhs, RValue<SByte16> rhs);
938 // RValue<SByte16> operator|=(SByte16 &lhs, RValue<SByte16> rhs);
939 // RValue<SByte16> operator^=(SByte16 &lhs, RValue<SByte16> rhs);
940 // RValue<SByte16> operator<<=(SByte16 &lhs, RValue<SByte16> rhs);
941 // RValue<SByte16> operator>>=(SByte16 &lhs, RValue<SByte16> rhs);
942 // RValue<SByte16> operator+(RValue<SByte16> val);
943 // RValue<SByte16> operator-(RValue<SByte16> val);
944 // RValue<SByte16> operator~(RValue<SByte16> val);
945 // RValue<SByte16> operator++(SByte16 &val, int); // Post-increment
946 // const SByte16 &operator++(SByte16 &val); // Pre-increment
947 // RValue<SByte16> operator--(SByte16 &val, int); // Post-decrement
948 // const SByte16 &operator--(SByte16 &val); // Pre-decrement
949
950 class Short2 : public LValue<Short2>
951 {
952 public:
953 explicit Short2(RValue<Short4> cast);
954
955 static Type *type();
element_count()956 static int element_count() { return 2; }
957 };
958
959 class UShort2 : public LValue<UShort2>
960 {
961 public:
962 explicit UShort2(RValue<UShort4> cast);
963
964 static Type *type();
element_count()965 static int element_count() { return 2; }
966 };
967
968 class Short4 : public LValue<Short4>
969 {
970 public:
971 explicit Short4(RValue<Int> cast);
972 explicit Short4(RValue<Int4> cast);
973 explicit Short4(RValue<UInt4> cast);
974 // explicit Short4(RValue<Float> cast);
975 explicit Short4(RValue<Float4> cast);
976
977 Short4() = default;
978 Short4(short xyzw);
979 Short4(short x, short y, short z, short w);
980 Short4(RValue<Short4> rhs);
981 Short4(const Short4 &rhs);
982 Short4(const Reference<Short4> &rhs);
983 Short4(RValue<UShort4> rhs);
984 Short4(const UShort4 &rhs);
985 Short4(const Reference<UShort4> &rhs);
986
987 RValue<Short4> operator=(RValue<Short4> rhs);
988 RValue<Short4> operator=(const Short4 &rhs);
989 RValue<Short4> operator=(const Reference<Short4> &rhs);
990 RValue<Short4> operator=(RValue<UShort4> rhs);
991 RValue<Short4> operator=(const UShort4 &rhs);
992 RValue<Short4> operator=(const Reference<UShort4> &rhs);
993
994 static Type *type();
element_count()995 static int element_count() { return 4; }
996 };
997
998 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs);
999 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs);
1000 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs);
1001 // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs);
1002 // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs);
1003 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs);
1004 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs);
1005 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs);
1006 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs);
1007 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs);
1008 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs);
1009 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs);
1010 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs);
1011 // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs);
1012 // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs);
1013 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs);
1014 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs);
1015 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs);
1016 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs);
1017 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs);
1018 // RValue<Short4> operator+(RValue<Short4> val);
1019 RValue<Short4> operator-(RValue<Short4> val);
1020 RValue<Short4> operator~(RValue<Short4> val);
1021 // RValue<Short4> operator++(Short4 &val, int); // Post-increment
1022 // const Short4 &operator++(Short4 &val); // Pre-increment
1023 // RValue<Short4> operator--(Short4 &val, int); // Post-decrement
1024 // const Short4 &operator--(Short4 &val); // Pre-decrement
1025 // RValue<Bool> operator<(RValue<Short4> lhs, RValue<Short4> rhs);
1026 // RValue<Bool> operator<=(RValue<Short4> lhs, RValue<Short4> rhs);
1027 // RValue<Bool> operator>(RValue<Short4> lhs, RValue<Short4> rhs);
1028 // RValue<Bool> operator>=(RValue<Short4> lhs, RValue<Short4> rhs);
1029 // RValue<Bool> operator!=(RValue<Short4> lhs, RValue<Short4> rhs);
1030 // RValue<Bool> operator==(RValue<Short4> lhs, RValue<Short4> rhs);
1031
1032 RValue<Short4> RoundShort4(RValue<Float4> cast);
1033 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y);
1034 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y);
1035 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y);
1036 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y);
1037 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y);
1038 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y);
1039 RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y);
1040 RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y);
1041 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y);
1042 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y);
1043 RValue<Short4> Swizzle(RValue<Short4> x, uint16_t select);
1044 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i);
1045 RValue<Short> Extract(RValue<Short4> val, int i);
1046 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y);
1047 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y);
1048
1049 class UShort4 : public LValue<UShort4>
1050 {
1051 public:
1052 explicit UShort4(RValue<UInt4> cast);
1053 explicit UShort4(RValue<Int4> cast);
1054 explicit UShort4(RValue<Float4> cast, bool saturate = false);
1055
1056 UShort4() = default;
1057 UShort4(unsigned short xyzw);
1058 UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
1059 UShort4(RValue<UShort4> rhs);
1060 UShort4(const UShort4 &rhs);
1061 UShort4(const Reference<UShort4> &rhs);
1062 UShort4(RValue<Short4> rhs);
1063 UShort4(const Short4 &rhs);
1064 UShort4(const Reference<Short4> &rhs);
1065
1066 RValue<UShort4> operator=(RValue<UShort4> rhs);
1067 RValue<UShort4> operator=(const UShort4 &rhs);
1068 RValue<UShort4> operator=(const Reference<UShort4> &rhs);
1069 RValue<UShort4> operator=(RValue<Short4> rhs);
1070 RValue<UShort4> operator=(const Short4 &rhs);
1071 RValue<UShort4> operator=(const Reference<Short4> &rhs);
1072
1073 static Type *type();
element_count()1074 static int element_count() { return 4; }
1075 };
1076
1077 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs);
1078 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs);
1079 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs);
1080 // RValue<UShort4> operator/(RValue<UShort4> lhs, RValue<UShort4> rhs);
1081 // RValue<UShort4> operator%(RValue<UShort4> lhs, RValue<UShort4> rhs);
1082 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs);
1083 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs);
1084 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs);
1085 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs);
1086 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs);
1087 // RValue<UShort4> operator+=(UShort4 &lhs, RValue<UShort4> rhs);
1088 // RValue<UShort4> operator-=(UShort4 &lhs, RValue<UShort4> rhs);
1089 // RValue<UShort4> operator*=(UShort4 &lhs, RValue<UShort4> rhs);
1090 // RValue<UShort4> operator/=(UShort4 &lhs, RValue<UShort4> rhs);
1091 // RValue<UShort4> operator%=(UShort4 &lhs, RValue<UShort4> rhs);
1092 // RValue<UShort4> operator&=(UShort4 &lhs, RValue<UShort4> rhs);
1093 // RValue<UShort4> operator|=(UShort4 &lhs, RValue<UShort4> rhs);
1094 // RValue<UShort4> operator^=(UShort4 &lhs, RValue<UShort4> rhs);
1095 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs);
1096 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs);
1097 // RValue<UShort4> operator+(RValue<UShort4> val);
1098 // RValue<UShort4> operator-(RValue<UShort4> val);
1099 RValue<UShort4> operator~(RValue<UShort4> val);
1100 // RValue<UShort4> operator++(UShort4 &val, int); // Post-increment
1101 // const UShort4 &operator++(UShort4 &val); // Pre-increment
1102 // RValue<UShort4> operator--(UShort4 &val, int); // Post-decrement
1103 // const UShort4 &operator--(UShort4 &val); // Pre-decrement
1104
1105 RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i);
1106 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y);
1107 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y);
1108 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y);
1109 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y);
1110 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y);
1111 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y);
1112
1113 class Short8 : public LValue<Short8>
1114 {
1115 public:
1116 Short8() = default;
1117 Short8(short c);
1118 Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7);
1119 Short8(RValue<Short8> rhs);
1120 // Short8(const Short8 &rhs);
1121 Short8(const Reference<Short8> &rhs);
1122 Short8(RValue<Short4> lo, RValue<Short4> hi);
1123
1124 RValue<Short8> operator=(RValue<Short8> rhs);
1125 RValue<Short8> operator=(const Short8 &rhs);
1126 RValue<Short8> operator=(const Reference<Short8> &rhs);
1127
1128 static Type *type();
element_count()1129 static int element_count() { return 8; }
1130 };
1131
1132 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs);
1133 // RValue<Short8> operator-(RValue<Short8> lhs, RValue<Short8> rhs);
1134 // RValue<Short8> operator*(RValue<Short8> lhs, RValue<Short8> rhs);
1135 // RValue<Short8> operator/(RValue<Short8> lhs, RValue<Short8> rhs);
1136 // RValue<Short8> operator%(RValue<Short8> lhs, RValue<Short8> rhs);
1137 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs);
1138 // RValue<Short8> operator|(RValue<Short8> lhs, RValue<Short8> rhs);
1139 // RValue<Short8> operator^(RValue<Short8> lhs, RValue<Short8> rhs);
1140 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs);
1141 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs);
1142 // RValue<Short8> operator<<(RValue<Short8> lhs, RValue<Short8> rhs);
1143 // RValue<Short8> operator>>(RValue<Short8> lhs, RValue<Short8> rhs);
1144 // RValue<Short8> operator+=(Short8 &lhs, RValue<Short8> rhs);
1145 // RValue<Short8> operator-=(Short8 &lhs, RValue<Short8> rhs);
1146 // RValue<Short8> operator*=(Short8 &lhs, RValue<Short8> rhs);
1147 // RValue<Short8> operator/=(Short8 &lhs, RValue<Short8> rhs);
1148 // RValue<Short8> operator%=(Short8 &lhs, RValue<Short8> rhs);
1149 // RValue<Short8> operator&=(Short8 &lhs, RValue<Short8> rhs);
1150 // RValue<Short8> operator|=(Short8 &lhs, RValue<Short8> rhs);
1151 // RValue<Short8> operator^=(Short8 &lhs, RValue<Short8> rhs);
1152 // RValue<Short8> operator<<=(Short8 &lhs, RValue<Short8> rhs);
1153 // RValue<Short8> operator>>=(Short8 &lhs, RValue<Short8> rhs);
1154 // RValue<Short8> operator+(RValue<Short8> val);
1155 // RValue<Short8> operator-(RValue<Short8> val);
1156 // RValue<Short8> operator~(RValue<Short8> val);
1157 // RValue<Short8> operator++(Short8 &val, int); // Post-increment
1158 // const Short8 &operator++(Short8 &val); // Pre-increment
1159 // RValue<Short8> operator--(Short8 &val, int); // Post-decrement
1160 // const Short8 &operator--(Short8 &val); // Pre-decrement
1161 // RValue<Bool> operator<(RValue<Short8> lhs, RValue<Short8> rhs);
1162 // RValue<Bool> operator<=(RValue<Short8> lhs, RValue<Short8> rhs);
1163 // RValue<Bool> operator>(RValue<Short8> lhs, RValue<Short8> rhs);
1164 // RValue<Bool> operator>=(RValue<Short8> lhs, RValue<Short8> rhs);
1165 // RValue<Bool> operator!=(RValue<Short8> lhs, RValue<Short8> rhs);
1166 // RValue<Bool> operator==(RValue<Short8> lhs, RValue<Short8> rhs);
1167
1168 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y);
1169 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y);
1170
1171 class UShort8 : public LValue<UShort8>
1172 {
1173 public:
1174 UShort8() = default;
1175 UShort8(unsigned short c);
1176 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);
1177 UShort8(RValue<UShort8> rhs);
1178 // UShort8(const UShort8 &rhs);
1179 UShort8(const Reference<UShort8> &rhs);
1180 UShort8(RValue<UShort4> lo, RValue<UShort4> hi);
1181
1182 RValue<UShort8> operator=(RValue<UShort8> rhs);
1183 RValue<UShort8> operator=(const UShort8 &rhs);
1184 RValue<UShort8> operator=(const Reference<UShort8> &rhs);
1185
1186 static Type *type();
element_count()1187 static int element_count() { return 8; }
1188 };
1189
1190 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs);
1191 // RValue<UShort8> operator-(RValue<UShort8> lhs, RValue<UShort8> rhs);
1192 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs);
1193 // RValue<UShort8> operator/(RValue<UShort8> lhs, RValue<UShort8> rhs);
1194 // RValue<UShort8> operator%(RValue<UShort8> lhs, RValue<UShort8> rhs);
1195 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs);
1196 // RValue<UShort8> operator|(RValue<UShort8> lhs, RValue<UShort8> rhs);
1197 // RValue<UShort8> operator^(RValue<UShort8> lhs, RValue<UShort8> rhs);
1198 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs);
1199 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs);
1200 // RValue<UShort8> operator<<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1201 // RValue<UShort8> operator>>(RValue<UShort8> lhs, RValue<UShort8> rhs);
1202 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs);
1203 // RValue<UShort8> operator-=(UShort8 &lhs, RValue<UShort8> rhs);
1204 // RValue<UShort8> operator*=(UShort8 &lhs, RValue<UShort8> rhs);
1205 // RValue<UShort8> operator/=(UShort8 &lhs, RValue<UShort8> rhs);
1206 // RValue<UShort8> operator%=(UShort8 &lhs, RValue<UShort8> rhs);
1207 // RValue<UShort8> operator&=(UShort8 &lhs, RValue<UShort8> rhs);
1208 // RValue<UShort8> operator|=(UShort8 &lhs, RValue<UShort8> rhs);
1209 // RValue<UShort8> operator^=(UShort8 &lhs, RValue<UShort8> rhs);
1210 // RValue<UShort8> operator<<=(UShort8 &lhs, RValue<UShort8> rhs);
1211 // RValue<UShort8> operator>>=(UShort8 &lhs, RValue<UShort8> rhs);
1212 // RValue<UShort8> operator+(RValue<UShort8> val);
1213 // RValue<UShort8> operator-(RValue<UShort8> val);
1214 RValue<UShort8> operator~(RValue<UShort8> val);
1215 // RValue<UShort8> operator++(UShort8 &val, int); // Post-increment
1216 // const UShort8 &operator++(UShort8 &val); // Pre-increment
1217 // RValue<UShort8> operator--(UShort8 &val, int); // Post-decrement
1218 // const UShort8 &operator--(UShort8 &val); // Pre-decrement
1219 // RValue<Bool> operator<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1220 // RValue<Bool> operator<=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1221 // RValue<Bool> operator>(RValue<UShort8> lhs, RValue<UShort8> rhs);
1222 // RValue<Bool> operator>=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1223 // RValue<Bool> operator!=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1224 // RValue<Bool> operator==(RValue<UShort8> lhs, RValue<UShort8> rhs);
1225
1226 RValue<UShort8> Swizzle(RValue<UShort8> x, uint32_t select);
1227 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y);
1228
1229 class Int : public LValue<Int>
1230 {
1231 public:
1232 Int(Argument<Int> argument);
1233
1234 explicit Int(RValue<Byte> cast);
1235 explicit Int(RValue<SByte> cast);
1236 explicit Int(RValue<Short> cast);
1237 explicit Int(RValue<UShort> cast);
1238 explicit Int(RValue<Int2> cast);
1239 explicit Int(RValue<Long> cast);
1240 explicit Int(RValue<Float> cast);
1241
1242 Int() = default;
1243 Int(int x);
1244 Int(RValue<Int> rhs);
1245 Int(RValue<UInt> rhs);
1246 Int(const Int &rhs);
1247 Int(const UInt &rhs);
1248 Int(const Reference<Int> &rhs);
1249 Int(const Reference<UInt> &rhs);
1250
1251 template<int T>
1252 Int(const SwizzleMask1<Int4, T> &rhs);
1253
1254 RValue<Int> operator=(int rhs);
1255 RValue<Int> operator=(RValue<Int> rhs);
1256 RValue<Int> operator=(RValue<UInt> rhs);
1257 RValue<Int> operator=(const Int &rhs);
1258 RValue<Int> operator=(const UInt &rhs);
1259 RValue<Int> operator=(const Reference<Int> &rhs);
1260 RValue<Int> operator=(const Reference<UInt> &rhs);
1261
1262 template<int T>
1263 RValue<Int> operator=(const SwizzleMask1<Int4, T> &rhs);
1264
1265 static Type *type();
1266 };
1267
1268 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs);
1269 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs);
1270 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs);
1271 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs);
1272 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs);
1273 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs);
1274 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs);
1275 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs);
1276 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs);
1277 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs);
1278 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs);
1279 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs);
1280 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs);
1281 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs);
1282 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs);
1283 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs);
1284 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs);
1285 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs);
1286 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs);
1287 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs);
1288 RValue<Int> operator+(RValue<Int> val);
1289 RValue<Int> operator-(RValue<Int> val);
1290 RValue<Int> operator~(RValue<Int> val);
1291 RValue<Int> operator++(Int &val, int); // Post-increment
1292 const Int &operator++(Int &val); // Pre-increment
1293 RValue<Int> operator--(Int &val, int); // Post-decrement
1294 const Int &operator--(Int &val); // Pre-decrement
1295 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs);
1296 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs);
1297 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs);
1298 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs);
1299 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs);
1300 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs);
1301
1302 RValue<Int> Max(RValue<Int> x, RValue<Int> y);
1303 RValue<Int> Min(RValue<Int> x, RValue<Int> y);
1304 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max);
1305 RValue<Int> RoundInt(RValue<Float> cast);
1306
1307 class Long : public LValue<Long>
1308 {
1309 public:
1310 // Long(Argument<Long> argument);
1311
1312 // explicit Long(RValue<Short> cast);
1313 // explicit Long(RValue<UShort> cast);
1314 explicit Long(RValue<Int> cast);
1315 explicit Long(RValue<UInt> cast);
1316 // explicit Long(RValue<Float> cast);
1317
1318 Long() = default;
1319 // Long(qword x);
1320 Long(RValue<Long> rhs);
1321 // Long(RValue<ULong> rhs);
1322 // Long(const Long &rhs);
1323 // Long(const Reference<Long> &rhs);
1324 // Long(const ULong &rhs);
1325 // Long(const Reference<ULong> &rhs);
1326
1327 RValue<Long> operator=(int64_t rhs);
1328 RValue<Long> operator=(RValue<Long> rhs);
1329 // RValue<Long> operator=(RValue<ULong> rhs);
1330 RValue<Long> operator=(const Long &rhs);
1331 RValue<Long> operator=(const Reference<Long> &rhs);
1332 // RValue<Long> operator=(const ULong &rhs);
1333 // RValue<Long> operator=(const Reference<ULong> &rhs);
1334
1335 static Type *type();
1336 };
1337
1338 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs);
1339 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs);
1340 RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs);
1341 // RValue<Long> operator/(RValue<Long> lhs, RValue<Long> rhs);
1342 // RValue<Long> operator%(RValue<Long> lhs, RValue<Long> rhs);
1343 // RValue<Long> operator&(RValue<Long> lhs, RValue<Long> rhs);
1344 // RValue<Long> operator|(RValue<Long> lhs, RValue<Long> rhs);
1345 // RValue<Long> operator^(RValue<Long> lhs, RValue<Long> rhs);
1346 // RValue<Long> operator<<(RValue<Long> lhs, RValue<Long> rhs);
1347 RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs);
1348 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs);
1349 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs);
1350 // RValue<Long> operator*=(Long &lhs, RValue<Long> rhs);
1351 // RValue<Long> operator/=(Long &lhs, RValue<Long> rhs);
1352 // RValue<Long> operator%=(Long &lhs, RValue<Long> rhs);
1353 // RValue<Long> operator&=(Long &lhs, RValue<Long> rhs);
1354 // RValue<Long> operator|=(Long &lhs, RValue<Long> rhs);
1355 // RValue<Long> operator^=(Long &lhs, RValue<Long> rhs);
1356 // RValue<Long> operator<<=(Long &lhs, RValue<Long> rhs);
1357 // RValue<Long> operator>>=(Long &lhs, RValue<Long> rhs);
1358 // RValue<Long> operator+(RValue<Long> val);
1359 // RValue<Long> operator-(RValue<Long> val);
1360 // RValue<Long> operator~(RValue<Long> val);
1361 // RValue<Long> operator++(Long &val, int); // Post-increment
1362 // const Long &operator++(Long &val); // Pre-increment
1363 // RValue<Long> operator--(Long &val, int); // Post-decrement
1364 // const Long &operator--(Long &val); // Pre-decrement
1365 // RValue<Bool> operator<(RValue<Long> lhs, RValue<Long> rhs);
1366 // RValue<Bool> operator<=(RValue<Long> lhs, RValue<Long> rhs);
1367 // RValue<Bool> operator>(RValue<Long> lhs, RValue<Long> rhs);
1368 // RValue<Bool> operator>=(RValue<Long> lhs, RValue<Long> rhs);
1369 // RValue<Bool> operator!=(RValue<Long> lhs, RValue<Long> rhs);
1370 // RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs);
1371
1372 // RValue<Long> RoundLong(RValue<Float> cast);
1373 RValue<Long> AddAtomic(RValue<Pointer<Long>> x, RValue<Long> y);
1374
1375 class UInt : public LValue<UInt>
1376 {
1377 public:
1378 UInt(Argument<UInt> argument);
1379
1380 explicit UInt(RValue<UShort> cast);
1381 explicit UInt(RValue<Long> cast);
1382 explicit UInt(RValue<Float> cast);
1383
1384 UInt() = default;
1385 UInt(int x);
1386 UInt(unsigned int x);
1387 UInt(RValue<UInt> rhs);
1388 UInt(RValue<Int> rhs);
1389 UInt(const UInt &rhs);
1390 UInt(const Int &rhs);
1391 UInt(const Reference<UInt> &rhs);
1392 UInt(const Reference<Int> &rhs);
1393
1394 RValue<UInt> operator=(unsigned int rhs);
1395 RValue<UInt> operator=(RValue<UInt> rhs);
1396 RValue<UInt> operator=(RValue<Int> rhs);
1397 RValue<UInt> operator=(const UInt &rhs);
1398 RValue<UInt> operator=(const Int &rhs);
1399 RValue<UInt> operator=(const Reference<UInt> &rhs);
1400 RValue<UInt> operator=(const Reference<Int> &rhs);
1401
1402 static Type *type();
1403 };
1404
1405 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs);
1406 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs);
1407 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs);
1408 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs);
1409 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs);
1410 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs);
1411 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs);
1412 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs);
1413 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs);
1414 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs);
1415 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs);
1416 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs);
1417 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs);
1418 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs);
1419 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs);
1420 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs);
1421 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs);
1422 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs);
1423 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs);
1424 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs);
1425 RValue<UInt> operator+(RValue<UInt> val);
1426 RValue<UInt> operator-(RValue<UInt> val);
1427 RValue<UInt> operator~(RValue<UInt> val);
1428 RValue<UInt> operator++(UInt &val, int); // Post-increment
1429 const UInt &operator++(UInt &val); // Pre-increment
1430 RValue<UInt> operator--(UInt &val, int); // Post-decrement
1431 const UInt &operator--(UInt &val); // Pre-decrement
1432 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs);
1433 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs);
1434 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs);
1435 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs);
1436 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs);
1437 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs);
1438
1439 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y);
1440 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y);
1441 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max);
1442
1443 RValue<UInt> AddAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1444 RValue<UInt> SubAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1445 RValue<UInt> AndAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1446 RValue<UInt> OrAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1447 RValue<UInt> XorAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1448 RValue<Int> MinAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1449 RValue<Int> MaxAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1450 RValue<UInt> MinAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1451 RValue<UInt> MaxAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1452 RValue<UInt> ExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1453 RValue<UInt> CompareExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, RValue<UInt> compare, std::memory_order memoryOrderEqual, std::memory_order memoryOrderUnequal);
1454
1455 // RValue<UInt> RoundUInt(RValue<Float> cast);
1456
1457 class Int2 : public LValue<Int2>
1458 {
1459 public:
1460 // explicit Int2(RValue<Int> cast);
1461 explicit Int2(RValue<Int4> cast);
1462
1463 Int2() = default;
1464 Int2(int x, int y);
1465 Int2(RValue<Int2> rhs);
1466 Int2(const Int2 &rhs);
1467 Int2(const Reference<Int2> &rhs);
1468 Int2(RValue<Int> lo, RValue<Int> hi);
1469
1470 RValue<Int2> operator=(RValue<Int2> rhs);
1471 RValue<Int2> operator=(const Int2 &rhs);
1472 RValue<Int2> operator=(const Reference<Int2> &rhs);
1473
1474 static Type *type();
element_count()1475 static int element_count() { return 2; }
1476 };
1477
1478 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs);
1479 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs);
1480 // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs);
1481 // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs);
1482 // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs);
1483 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs);
1484 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs);
1485 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs);
1486 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs);
1487 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs);
1488 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs);
1489 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs);
1490 // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs);
1491 // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs);
1492 // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs);
1493 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs);
1494 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs);
1495 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs);
1496 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs);
1497 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs);
1498 // RValue<Int2> operator+(RValue<Int2> val);
1499 // RValue<Int2> operator-(RValue<Int2> val);
1500 RValue<Int2> operator~(RValue<Int2> val);
1501 // RValue<Int2> operator++(Int2 &val, int); // Post-increment
1502 // const Int2 &operator++(Int2 &val); // Pre-increment
1503 // RValue<Int2> operator--(Int2 &val, int); // Post-decrement
1504 // const Int2 &operator--(Int2 &val); // Pre-decrement
1505 // RValue<Bool> operator<(RValue<Int2> lhs, RValue<Int2> rhs);
1506 // RValue<Bool> operator<=(RValue<Int2> lhs, RValue<Int2> rhs);
1507 // RValue<Bool> operator>(RValue<Int2> lhs, RValue<Int2> rhs);
1508 // RValue<Bool> operator>=(RValue<Int2> lhs, RValue<Int2> rhs);
1509 // RValue<Bool> operator!=(RValue<Int2> lhs, RValue<Int2> rhs);
1510 // RValue<Bool> operator==(RValue<Int2> lhs, RValue<Int2> rhs);
1511
1512 // RValue<Int2> RoundInt(RValue<Float4> cast);
1513 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y);
1514 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y);
1515 RValue<Int> Extract(RValue<Int2> val, int i);
1516 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i);
1517
1518 class UInt2 : public LValue<UInt2>
1519 {
1520 public:
1521 UInt2() = default;
1522 UInt2(unsigned int x, unsigned int y);
1523 UInt2(RValue<UInt2> rhs);
1524 UInt2(const UInt2 &rhs);
1525 UInt2(const Reference<UInt2> &rhs);
1526
1527 RValue<UInt2> operator=(RValue<UInt2> rhs);
1528 RValue<UInt2> operator=(const UInt2 &rhs);
1529 RValue<UInt2> operator=(const Reference<UInt2> &rhs);
1530
1531 static Type *type();
element_count()1532 static int element_count() { return 2; }
1533 };
1534
1535 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs);
1536 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs);
1537 // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs);
1538 // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs);
1539 // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs);
1540 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs);
1541 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs);
1542 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs);
1543 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs);
1544 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs);
1545 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs);
1546 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs);
1547 // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs);
1548 // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs);
1549 // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs);
1550 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs);
1551 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs);
1552 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs);
1553 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs);
1554 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs);
1555 // RValue<UInt2> operator+(RValue<UInt2> val);
1556 // RValue<UInt2> operator-(RValue<UInt2> val);
1557 RValue<UInt2> operator~(RValue<UInt2> val);
1558 // RValue<UInt2> operator++(UInt2 &val, int); // Post-increment
1559 // const UInt2 &operator++(UInt2 &val); // Pre-increment
1560 // RValue<UInt2> operator--(UInt2 &val, int); // Post-decrement
1561 // const UInt2 &operator--(UInt2 &val); // Pre-decrement
1562 // RValue<Bool> operator<(RValue<UInt2> lhs, RValue<UInt2> rhs);
1563 // RValue<Bool> operator<=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1564 // RValue<Bool> operator>(RValue<UInt2> lhs, RValue<UInt2> rhs);
1565 // RValue<Bool> operator>=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1566 // RValue<Bool> operator!=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1567 // RValue<Bool> operator==(RValue<UInt2> lhs, RValue<UInt2> rhs);
1568
1569 // RValue<UInt2> RoundInt(RValue<Float4> cast);
1570 RValue<UInt> Extract(RValue<UInt2> val, int i);
1571 RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i);
1572
1573 class Int4 : public LValue<Int4>, public XYZW<Int4>
1574 {
1575 public:
1576 explicit Int4(RValue<Byte4> cast);
1577 explicit Int4(RValue<SByte4> cast);
1578 explicit Int4(RValue<Float4> cast);
1579 explicit Int4(RValue<Short4> cast);
1580 explicit Int4(RValue<UShort4> cast);
1581
1582 Int4();
1583 Int4(int xyzw);
1584 Int4(int x, int yzw);
1585 Int4(int x, int y, int zw);
1586 Int4(int x, int y, int z, int w);
1587 Int4(RValue<Int4> rhs);
1588 Int4(const Int4 &rhs);
1589 Int4(const Reference<Int4> &rhs);
1590 Int4(RValue<UInt4> rhs);
1591 Int4(const UInt4 &rhs);
1592 Int4(const Reference<UInt4> &rhs);
1593 Int4(RValue<Int2> lo, RValue<Int2> hi);
1594 Int4(RValue<Int> rhs);
1595 Int4(const Int &rhs);
1596 Int4(const Reference<Int> &rhs);
1597
1598 template<int T>
1599 Int4(const SwizzleMask1<Int4, T> &rhs);
1600
1601 RValue<Int4> operator=(int broadcast);
1602 RValue<Int4> operator=(RValue<Int4> rhs);
1603 RValue<Int4> operator=(const Int4 &rhs);
1604 RValue<Int4> operator=(const Reference<Int4> &rhs);
1605
1606 static Type *type();
element_count()1607 static int element_count() { return 4; }
1608
1609 private:
1610 void constant(int x, int y, int z, int w);
1611 };
1612
1613 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs);
1614 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs);
1615 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs);
1616 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs);
1617 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs);
1618 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs);
1619 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs);
1620 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs);
1621 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs);
1622 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs);
1623 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs);
1624 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs);
1625 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs);
1626 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs);
1627 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs);
1628 // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs);
1629 // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs);
1630 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs);
1631 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs);
1632 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs);
1633 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs);
1634 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs);
1635 RValue<Int4> operator+(RValue<Int4> val);
1636 RValue<Int4> operator-(RValue<Int4> val);
1637 RValue<Int4> operator~(RValue<Int4> val);
1638 // RValue<Int4> operator++(Int4 &val, int); // Post-increment
1639 // const Int4 &operator++(Int4 &val); // Pre-increment
1640 // RValue<Int4> operator--(Int4 &val, int); // Post-decrement
1641 // const Int4 &operator--(Int4 &val); // Pre-decrement
1642 // RValue<Bool> operator<(RValue<Int4> lhs, RValue<Int4> rhs);
1643 // RValue<Bool> operator<=(RValue<Int4> lhs, RValue<Int4> rhs);
1644 // RValue<Bool> operator>(RValue<Int4> lhs, RValue<Int4> rhs);
1645 // RValue<Bool> operator>=(RValue<Int4> lhs, RValue<Int4> rhs);
1646 // RValue<Bool> operator!=(RValue<Int4> lhs, RValue<Int4> rhs);
1647 // RValue<Bool> operator==(RValue<Int4> lhs, RValue<Int4> rhs);
1648
1649 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y);
1650 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y);
1651 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y);
1652 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y);
1653 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y);
1654 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y);
CmpGT(RValue<Int4> x,RValue<Int4> y)1655 inline RValue<Int4> CmpGT(RValue<Int4> x, RValue<Int4> y)
1656 {
1657 return CmpNLE(x, y);
1658 }
CmpGE(RValue<Int4> x,RValue<Int4> y)1659 inline RValue<Int4> CmpGE(RValue<Int4> x, RValue<Int4> y)
1660 {
1661 return CmpNLT(x, y);
1662 }
1663 RValue<Int4> Abs(RValue<Int4> x);
1664 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y);
1665 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y);
1666 // Convert to nearest integer. If a converted value is outside of the integer
1667 // range, the returned result is undefined.
1668 RValue<Int4> RoundInt(RValue<Float4> cast);
1669 // Rounds to the nearest integer, but clamps very large values to an
1670 // implementation-dependent range.
1671 // Specifically, on x86, values larger than 2147483583.0 are converted to
1672 // 2147483583 (0x7FFFFFBF) instead of producing 0x80000000.
1673 RValue<Int4> RoundIntClamped(RValue<Float4> cast);
1674 RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y);
1675 RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y);
1676 RValue<Int> Extract(RValue<Int4> val, int i);
1677 RValue<Int4> Insert(RValue<Int4> val, RValue<Int> element, int i);
1678 RValue<Int> SignMask(RValue<Int4> x);
1679 RValue<Int4> Swizzle(RValue<Int4> x, uint16_t select);
1680 RValue<Int4> Shuffle(RValue<Int4> x, RValue<Int4> y, uint16_t select);
1681 RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y);
1682
1683 class UInt4 : public LValue<UInt4>, public XYZW<UInt4>
1684 {
1685 public:
1686 explicit UInt4(RValue<Float4> cast);
1687
1688 UInt4();
1689 UInt4(int xyzw);
1690 UInt4(int x, int yzw);
1691 UInt4(int x, int y, int zw);
1692 UInt4(int x, int y, int z, int w);
1693 UInt4(RValue<UInt4> rhs);
1694 UInt4(const UInt4 &rhs);
1695 UInt4(const Reference<UInt4> &rhs);
1696 UInt4(RValue<Int4> rhs);
1697 UInt4(const Int4 &rhs);
1698 UInt4(const Reference<Int4> &rhs);
1699 UInt4(RValue<UInt2> lo, RValue<UInt2> hi);
1700 UInt4(RValue<UInt> rhs);
1701 UInt4(const UInt &rhs);
1702 UInt4(const Reference<UInt> &rhs);
1703
1704 RValue<UInt4> operator=(RValue<UInt4> rhs);
1705 RValue<UInt4> operator=(const UInt4 &rhs);
1706 RValue<UInt4> operator=(const Reference<UInt4> &rhs);
1707
1708 static Type *type();
element_count()1709 static int element_count() { return 4; }
1710
1711 private:
1712 void constant(int x, int y, int z, int w);
1713 };
1714
1715 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs);
1716 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs);
1717 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs);
1718 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs);
1719 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs);
1720 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs);
1721 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs);
1722 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs);
1723 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs);
1724 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs);
1725 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs);
1726 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs);
1727 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs);
1728 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs);
1729 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs);
1730 // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs);
1731 // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs);
1732 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs);
1733 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs);
1734 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs);
1735 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs);
1736 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs);
1737 RValue<UInt4> operator+(RValue<UInt4> val);
1738 RValue<UInt4> operator-(RValue<UInt4> val);
1739 RValue<UInt4> operator~(RValue<UInt4> val);
1740 // RValue<UInt4> operator++(UInt4 &val, int); // Post-increment
1741 // const UInt4 &operator++(UInt4 &val); // Pre-increment
1742 // RValue<UInt4> operator--(UInt4 &val, int); // Post-decrement
1743 // const UInt4 &operator--(UInt4 &val); // Pre-decrement
1744 // RValue<Bool> operator<(RValue<UInt4> lhs, RValue<UInt4> rhs);
1745 // RValue<Bool> operator<=(RValue<UInt4> lhs, RValue<UInt4> rhs);
1746 // RValue<Bool> operator>(RValue<UInt4> lhs, RValue<UInt4> rhs);
1747 // RValue<Bool> operator>=(RValue<UInt4> lhs, RValue<UInt4> rhs);
1748 // RValue<Bool> operator!=(RValue<UInt4> lhs, RValue<UInt4> rhs);
1749 // RValue<Bool> operator==(RValue<UInt4> lhs, RValue<UInt4> rhs);
1750
1751 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y);
1752 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y);
1753 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y);
1754 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y);
1755 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y);
1756 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y);
CmpGT(RValue<UInt4> x,RValue<UInt4> y)1757 inline RValue<UInt4> CmpGT(RValue<UInt4> x, RValue<UInt4> y)
1758 {
1759 return CmpNLE(x, y);
1760 }
CmpGE(RValue<UInt4> x,RValue<UInt4> y)1761 inline RValue<UInt4> CmpGE(RValue<UInt4> x, RValue<UInt4> y)
1762 {
1763 return CmpNLT(x, y);
1764 }
1765 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y);
1766 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y);
1767 RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y);
1768 RValue<UInt> Extract(RValue<UInt4> val, int i);
1769 RValue<UInt4> Insert(RValue<UInt4> val, RValue<UInt> element, int i);
1770 // RValue<UInt4> RoundInt(RValue<Float4> cast);
1771 RValue<UInt4> Swizzle(RValue<UInt4> x, uint16_t select);
1772 RValue<UInt4> Shuffle(RValue<UInt4> x, RValue<UInt4> y, uint16_t select);
1773
1774 class Half : public LValue<Half>
1775 {
1776 public:
1777 explicit Half(RValue<Float> cast);
1778
1779 static Type *type();
1780 };
1781
1782 class Float : public LValue<Float>
1783 {
1784 public:
1785 explicit Float(RValue<Int> cast);
1786 explicit Float(RValue<UInt> cast);
1787 explicit Float(RValue<Half> cast);
1788
1789 Float() = default;
1790 Float(float x);
1791 Float(RValue<Float> rhs);
1792 Float(const Float &rhs);
1793 Float(const Reference<Float> &rhs);
1794 Float(Argument<Float> argument);
1795
1796 template<int T>
1797 Float(const SwizzleMask1<Float4, T> &rhs);
1798
1799 RValue<Float> operator=(float rhs);
1800 RValue<Float> operator=(RValue<Float> rhs);
1801 RValue<Float> operator=(const Float &rhs);
1802 RValue<Float> operator=(const Reference<Float> &rhs);
1803
1804 template<int T>
1805 RValue<Float> operator=(const SwizzleMask1<Float4, T> &rhs);
1806
1807 static Float infinity();
1808
1809 static Type *type();
1810 };
1811
1812 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs);
1813 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs);
1814 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs);
1815 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs);
1816 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs);
1817 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs);
1818 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs);
1819 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs);
1820 RValue<Float> operator+(RValue<Float> val);
1821 RValue<Float> operator-(RValue<Float> val);
1822 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs);
1823 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs);
1824 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs);
1825 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs);
1826 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs);
1827 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs);
1828
1829 RValue<Float> Abs(RValue<Float> x);
1830 RValue<Float> Max(RValue<Float> x, RValue<Float> y);
1831 RValue<Float> Min(RValue<Float> x, RValue<Float> y);
1832 RValue<Float> Rcp(RValue<Float> x, bool relaxedPrecision, bool exactAtPow2 = false);
1833 RValue<Float> RcpSqrt(RValue<Float> x, bool relaxedPrecision);
1834 RValue<Float> Sqrt(RValue<Float> x);
1835
1836 // RValue<Int4> IsInf(RValue<Float> x);
1837 // RValue<Int4> IsNan(RValue<Float> x);
1838 RValue<Float> Round(RValue<Float> x);
1839 RValue<Float> Trunc(RValue<Float> x);
1840 RValue<Float> Frac(RValue<Float> x);
1841 RValue<Float> Floor(RValue<Float> x);
1842 RValue<Float> Ceil(RValue<Float> x);
1843
1844 // Trigonometric functions
1845 // TODO: Currently unimplemented for Subzero.
1846 // RValue<Float> Sin(RValue<Float> x);
1847 // RValue<Float> Cos(RValue<Float> x);
1848 // RValue<Float> Tan(RValue<Float> x);
1849 // RValue<Float> Asin(RValue<Float> x);
1850 // RValue<Float> Acos(RValue<Float> x);
1851 // RValue<Float> Atan(RValue<Float> x);
1852 // RValue<Float> Sinh(RValue<Float> x);
1853 // RValue<Float> Cosh(RValue<Float> x);
1854 // RValue<Float> Tanh(RValue<Float> x);
1855 // RValue<Float> Asinh(RValue<Float> x);
1856 // RValue<Float> Acosh(RValue<Float> x);
1857 // RValue<Float> Atanh(RValue<Float> x);
1858 // RValue<Float> Atan2(RValue<Float> x, RValue<Float> y);
1859
1860 // Exponential functions
1861 // TODO: Currently unimplemented for Subzero.
1862 // RValue<Float> Pow(RValue<Float> x, RValue<Float> y);
1863 // RValue<Float> Exp(RValue<Float> x);
1864 // RValue<Float> Log(RValue<Float> x);
1865 RValue<Float> Exp2(RValue<Float> x);
1866 RValue<Float> Log2(RValue<Float> x);
1867
1868 class Float2 : public LValue<Float2>
1869 {
1870 public:
1871 // explicit Float2(RValue<Byte2> cast);
1872 // explicit Float2(RValue<Short2> cast);
1873 // explicit Float2(RValue<UShort2> cast);
1874 // explicit Float2(RValue<Int2> cast);
1875 // explicit Float2(RValue<UInt2> cast);
1876 explicit Float2(RValue<Float4> cast);
1877
1878 Float2() = default;
1879 // Float2(float x, float y);
1880 // Float2(RValue<Float2> rhs);
1881 // Float2(const Float2 &rhs);
1882 // Float2(const Reference<Float2> &rhs);
1883 // Float2(RValue<Float> rhs);
1884 // Float2(const Float &rhs);
1885 // Float2(const Reference<Float> &rhs);
1886
1887 // template<int T>
1888 // Float2(const SwizzleMask1<T> &rhs);
1889
1890 // RValue<Float2> operator=(float broadcast);
1891 // RValue<Float2> operator=(RValue<Float2> rhs);
1892 // RValue<Float2> operator=(const Float2 &rhs);
1893 // RValue<Float2> operator=(const Reference<Float2> &rhs);
1894 // RValue<Float2> operator=(RValue<Float> rhs);
1895 // RValue<Float2> operator=(const Float &rhs);
1896 // RValue<Float2> operator=(const Reference<Float> &rhs);
1897
1898 // template<int T>
1899 // RValue<Float2> operator=(const SwizzleMask1<T> &rhs);
1900
1901 static Type *type();
element_count()1902 static int element_count() { return 2; }
1903 };
1904
1905 // RValue<Float2> operator+(RValue<Float2> lhs, RValue<Float2> rhs);
1906 // RValue<Float2> operator-(RValue<Float2> lhs, RValue<Float2> rhs);
1907 // RValue<Float2> operator*(RValue<Float2> lhs, RValue<Float2> rhs);
1908 // RValue<Float2> operator/(RValue<Float2> lhs, RValue<Float2> rhs);
1909 // RValue<Float2> operator%(RValue<Float2> lhs, RValue<Float2> rhs);
1910 // RValue<Float2> operator+=(Float2 &lhs, RValue<Float2> rhs);
1911 // RValue<Float2> operator-=(Float2 &lhs, RValue<Float2> rhs);
1912 // RValue<Float2> operator*=(Float2 &lhs, RValue<Float2> rhs);
1913 // RValue<Float2> operator/=(Float2 &lhs, RValue<Float2> rhs);
1914 // RValue<Float2> operator%=(Float2 &lhs, RValue<Float2> rhs);
1915 // RValue<Float2> operator+(RValue<Float2> val);
1916 // RValue<Float2> operator-(RValue<Float2> val);
1917
1918 // RValue<Float2> Abs(RValue<Float2> x);
1919 // RValue<Float2> Max(RValue<Float2> x, RValue<Float2> y);
1920 // RValue<Float2> Min(RValue<Float2> x, RValue<Float2> y);
1921 // RValue<Float2> Swizzle(RValue<Float2> x, uint16_t select);
1922 // RValue<Float2> Mask(Float2 &lhs, RValue<Float2> rhs, uint16_t select);
1923
1924 class Float4 : public LValue<Float4>, public XYZW<Float4>
1925 {
1926 public:
1927 explicit Float4(RValue<Byte4> cast);
1928 explicit Float4(RValue<SByte4> cast);
1929 explicit Float4(RValue<Short4> cast);
1930 explicit Float4(RValue<UShort4> cast);
1931 explicit Float4(RValue<Int4> cast);
1932 explicit Float4(RValue<UInt4> cast);
1933
1934 Float4();
1935 Float4(float xyzw);
1936 Float4(float x, float yzw);
1937 Float4(float x, float y, float zw);
1938 Float4(float x, float y, float z, float w);
1939 Float4(RValue<Float4> rhs);
1940 Float4(const Float4 &rhs);
1941 Float4(const Reference<Float4> &rhs);
1942 Float4(RValue<Float> rhs);
1943 Float4(const Float &rhs);
1944 Float4(const Reference<Float> &rhs);
1945
1946 template<int T>
1947 Float4(const SwizzleMask1<Float4, T> &rhs);
1948 template<int T>
1949 Float4(const Swizzle4<Float4, T> &rhs);
1950 template<int X, int Y>
1951 Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
1952 template<int X, int Y>
1953 Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
1954 template<int X, int Y>
1955 Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
1956 template<int X, int Y>
1957 Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
1958 Float4(RValue<Float2> lo, RValue<Float2> hi);
1959
1960 RValue<Float4> operator=(float broadcast);
1961 RValue<Float4> operator=(RValue<Float4> rhs);
1962 RValue<Float4> operator=(const Float4 &rhs);
1963 RValue<Float4> operator=(const Reference<Float4> &rhs);
1964 RValue<Float4> operator=(RValue<Float> rhs);
1965 RValue<Float4> operator=(const Float &rhs);
1966 RValue<Float4> operator=(const Reference<Float> &rhs);
1967
1968 template<int T>
1969 RValue<Float4> operator=(const SwizzleMask1<Float4, T> &rhs);
1970 template<int T>
1971 RValue<Float4> operator=(const Swizzle4<Float4, T> &rhs);
1972
1973 static Float4 infinity();
1974
1975 static Type *type();
element_count()1976 static int element_count() { return 4; }
1977
1978 private:
1979 void constant(float x, float y, float z, float w);
1980 };
1981
1982 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs);
1983 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs);
1984 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs);
1985 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs);
1986 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs);
1987 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs);
1988 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs);
1989 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs);
1990 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs);
1991 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs);
1992 RValue<Float4> operator+(RValue<Float4> val);
1993 RValue<Float4> operator-(RValue<Float4> val);
1994
1995 // Computes `x * y + z`, which may be fused into one operation to produce a higher-precision result.
1996 RValue<Float4> MulAdd(RValue<Float4> x, RValue<Float4> y, RValue<Float4> z);
1997 // Computes a fused `x * y + z` operation. Caps::fmaIsFast indicates whether it emits an FMA instruction.
1998 RValue<Float4> FMA(RValue<Float4> x, RValue<Float4> y, RValue<Float4> z);
1999
2000 RValue<Float4> Abs(RValue<Float4> x);
2001 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y);
2002 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y);
2003
2004 RValue<Float4> Rcp(RValue<Float4> x, bool relaxedPrecision, bool exactAtPow2 = false);
2005 RValue<Float4> RcpSqrt(RValue<Float4> x, bool relaxedPrecision);
2006 RValue<Float4> Sqrt(RValue<Float4> x);
2007 RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i);
2008 RValue<Float> Extract(RValue<Float4> x, int i);
2009 RValue<Float4> Swizzle(RValue<Float4> x, uint16_t select);
2010 RValue<Float4> Shuffle(RValue<Float4> x, RValue<Float4> y, uint16_t select);
2011 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, uint16_t imm);
2012 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y);
2013 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y);
2014 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, uint16_t select);
2015 RValue<Int> SignMask(RValue<Float4> x);
2016
2017 // Ordered comparison functions
2018 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y);
2019 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y);
2020 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y);
2021 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y);
2022 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y);
2023 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y);
CmpGT(RValue<Float4> x,RValue<Float4> y)2024 inline RValue<Int4> CmpGT(RValue<Float4> x, RValue<Float4> y)
2025 {
2026 return CmpNLE(x, y);
2027 }
CmpGE(RValue<Float4> x,RValue<Float4> y)2028 inline RValue<Int4> CmpGE(RValue<Float4> x, RValue<Float4> y)
2029 {
2030 return CmpNLT(x, y);
2031 }
2032
2033 // Unordered comparison functions
2034 RValue<Int4> CmpUEQ(RValue<Float4> x, RValue<Float4> y);
2035 RValue<Int4> CmpULT(RValue<Float4> x, RValue<Float4> y);
2036 RValue<Int4> CmpULE(RValue<Float4> x, RValue<Float4> y);
2037 RValue<Int4> CmpUNEQ(RValue<Float4> x, RValue<Float4> y);
2038 RValue<Int4> CmpUNLT(RValue<Float4> x, RValue<Float4> y);
2039 RValue<Int4> CmpUNLE(RValue<Float4> x, RValue<Float4> y);
CmpUGT(RValue<Float4> x,RValue<Float4> y)2040 inline RValue<Int4> CmpUGT(RValue<Float4> x, RValue<Float4> y)
2041 {
2042 return CmpUNLE(x, y);
2043 }
CmpUGE(RValue<Float4> x,RValue<Float4> y)2044 inline RValue<Int4> CmpUGE(RValue<Float4> x, RValue<Float4> y)
2045 {
2046 return CmpUNLT(x, y);
2047 }
2048
2049 RValue<Int4> IsInf(RValue<Float4> x);
2050 RValue<Int4> IsNan(RValue<Float4> x);
2051 RValue<Float4> Round(RValue<Float4> x);
2052 RValue<Float4> Trunc(RValue<Float4> x);
2053 RValue<Float4> Frac(RValue<Float4> x);
2054 RValue<Float4> Floor(RValue<Float4> x);
2055 RValue<Float4> Ceil(RValue<Float4> x);
2056
2057 // Trigonometric functions
2058 RValue<Float4> Sin(RValue<Float4> x);
2059 RValue<Float4> Cos(RValue<Float4> x);
2060 RValue<Float4> Tan(RValue<Float4> x);
2061 RValue<Float4> Asin(RValue<Float4> x);
2062 RValue<Float4> Acos(RValue<Float4> x);
2063 RValue<Float4> Atan(RValue<Float4> x);
2064 RValue<Float4> Sinh(RValue<Float4> x);
2065 RValue<Float4> Cosh(RValue<Float4> x);
2066 RValue<Float4> Tanh(RValue<Float4> x);
2067 RValue<Float4> Asinh(RValue<Float4> x);
2068 RValue<Float4> Acosh(RValue<Float4> x);
2069 RValue<Float4> Atanh(RValue<Float4> x);
2070 RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y);
2071
2072 // Exponential functions
2073 RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y);
2074 RValue<Float4> Exp(RValue<Float4> x);
2075 RValue<Float4> Log(RValue<Float4> x);
2076 RValue<Float4> Exp2(RValue<Float4> x);
2077 RValue<Float4> Log2(RValue<Float4> x);
2078
2079 // Call a unary C function on each element of a vector type.
2080 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x)2081 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x)
2082 {
2083 T result;
2084 for(int i = 0; i < T::element_count(); i++)
2085 {
2086 result = Insert(result, Call(func, Extract(x, i)), i);
2087 }
2088
2089 return result;
2090 }
2091
2092 // Call a binary C function on each element of a vector type.
2093 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x,const RValue<T> & y)2094 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x, const RValue<T> &y)
2095 {
2096 T result;
2097 for(int i = 0; i < T::element_count(); i++)
2098 {
2099 result = Insert(result, Call(func, Extract(x, i), Extract(y, i)), i);
2100 }
2101
2102 return result;
2103 }
2104
2105 // Call a ternary C function on each element of a vector type.
2106 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x,const RValue<T> & y,const RValue<T> & z)2107 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x, const RValue<T> &y, const RValue<T> &z)
2108 {
2109 T result;
2110 for(int i = 0; i < T::element_count(); i++)
2111 {
2112 result = Insert(result, Call(func, Extract(x, i), Extract(y, i), Extract(z, i)), i);
2113 }
2114
2115 return result;
2116 }
2117
2118 // Invoke a unary lambda expression on each element of a vector type.
2119 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x)2120 inline RValue<T> Scalarize(Func func, const RValue<T> &x)
2121 {
2122 T result;
2123 for(int i = 0; i < T::element_count(); i++)
2124 {
2125 result = Insert(result, func(Extract(x, i)), i);
2126 }
2127
2128 return result;
2129 }
2130
2131 // Invoke a binary lambda expression on each element of a vector type.
2132 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x,const RValue<T> & y)2133 inline RValue<T> Scalarize(Func func, const RValue<T> &x, const RValue<T> &y)
2134 {
2135 T result;
2136 for(int i = 0; i < T::element_count(); i++)
2137 {
2138 result = Insert(result, func(Extract(x, i), Extract(y, i)), i);
2139 }
2140
2141 return result;
2142 }
2143
2144 // Invoke a ternary lambda expression on each element of a vector type.
2145 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x,const RValue<T> & y,const RValue<T> & z)2146 inline RValue<T> Scalarize(Func func, const RValue<T> &x, const RValue<T> &y, const RValue<T> &z)
2147 {
2148 T result;
2149 for(int i = 0; i < T::element_count(); i++)
2150 {
2151 result = Insert(result, func(Extract(x, i), Extract(y, i), Extract(z, i)), i);
2152 }
2153
2154 return result;
2155 }
2156
2157 // Bit Manipulation functions.
2158 // TODO: Currently unimplemented for Subzero.
2159
2160 // Count leading zeros.
2161 // Returns 32 when: !isZeroUndef && x == 0.
2162 // Returns an undefined value when: isZeroUndef && x == 0.
2163 RValue<UInt> Ctlz(RValue<UInt> x, bool isZeroUndef);
2164 RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
2165
2166 // Count trailing zeros.
2167 // Returns 32 when: !isZeroUndef && x == 0.
2168 // Returns an undefined value when: isZeroUndef && x == 0.
2169 RValue<UInt> Cttz(RValue<UInt> x, bool isZeroUndef);
2170 RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
2171
2172 template<class T>
2173 class Pointer : public LValue<Pointer<T>>
2174 {
2175 public:
2176 template<class S>
Pointer(RValue<Pointer<S>> pointerS,int alignment=1)2177 Pointer(RValue<Pointer<S>> pointerS, int alignment = 1)
2178 : alignment(alignment)
2179 {
2180 Value *pointerT = Nucleus::createBitCast(pointerS.value(), Nucleus::getPointerType(T::type()));
2181 this->storeValue(pointerT);
2182 }
2183
2184 template<class S>
Pointer(const Pointer<S> & pointer,int alignment=1)2185 Pointer(const Pointer<S> &pointer, int alignment = 1)
2186 : alignment(alignment)
2187 {
2188 Value *pointerS = pointer.loadValue();
2189 Value *pointerT = Nucleus::createBitCast(pointerS, Nucleus::getPointerType(T::type()));
2190 this->storeValue(pointerT);
2191 }
2192
2193 Pointer(Argument<Pointer<T>> argument);
2194
2195 Pointer();
2196 Pointer(RValue<Pointer<T>> rhs);
2197 Pointer(const Pointer<T> &rhs);
2198 Pointer(const Reference<Pointer<T>> &rhs);
2199 Pointer(std::nullptr_t);
2200
2201 RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs);
2202 RValue<Pointer<T>> operator=(const Pointer<T> &rhs);
2203 RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs);
2204 RValue<Pointer<T>> operator=(std::nullptr_t);
2205
2206 Reference<T> operator*() const;
2207 Reference<T> operator[](int index) const;
2208 Reference<T> operator[](unsigned int index) const;
2209 Reference<T> operator[](RValue<Int> index) const;
2210 Reference<T> operator[](RValue<UInt> index) const;
2211
2212 static Type *type();
2213
2214 private:
2215 const int alignment;
2216 };
2217
2218 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);
2219 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2220 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2221 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset);
2222 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset);
2223 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset);
2224
2225 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);
2226 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2227 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2228 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset);
2229 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset);
2230 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset);
2231
2232 template<typename T>
operator ==(const Pointer<T> & lhs,const Pointer<T> & rhs)2233 RValue<Bool> operator==(const Pointer<T> &lhs, const Pointer<T> &rhs)
2234 {
2235 return RValue<Bool>(Nucleus::createICmpEQ(lhs.loadValue(), rhs.loadValue()));
2236 }
2237
2238 template<typename T>
operator !=(const Pointer<T> & lhs,const Pointer<T> & rhs)2239 RValue<Bool> operator!=(const Pointer<T> &lhs, const Pointer<T> &rhs)
2240 {
2241 return RValue<Bool>(Nucleus::createICmpNE(lhs.loadValue(), rhs.loadValue()));
2242 }
2243
2244 template<typename T>
Load(RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2245 RValue<T> Load(RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2246 {
2247 return RValue<T>(Nucleus::createLoad(pointer.value(), T::type(), false, alignment, atomic, memoryOrder));
2248 }
2249
2250 template<typename T>
Load(Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2251 RValue<T> Load(Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2252 {
2253 return Load(RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2254 }
2255
2256 // TODO: Use SIMD to template these.
2257 // TODO(b/155867273): These can be undeprecated if implemented for Subzero.
2258 [[deprecated]] RValue<Float4> MaskedLoad(RValue<Pointer<Float4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2259 [[deprecated]] RValue<Int4> MaskedLoad(RValue<Pointer<Int4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2260 [[deprecated]] void MaskedStore(RValue<Pointer<Float4>> base, RValue<Float4> val, RValue<Int4> mask, unsigned int alignment);
2261 [[deprecated]] void MaskedStore(RValue<Pointer<Int4>> base, RValue<Int4> val, RValue<Int4> mask, unsigned int alignment);
2262
2263 template<typename T>
Store(RValue<T> value,RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2264 void Store(RValue<T> value, RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2265 {
2266 Nucleus::createStore(value.value(), pointer.value(), T::type(), false, alignment, atomic, memoryOrder);
2267 }
2268
2269 template<typename T>
Store(RValue<T> value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2270 void Store(RValue<T> value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2271 {
2272 Store(value, RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2273 }
2274
2275 template<typename T>
Store(T value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2276 void Store(T value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2277 {
2278 Store(RValue<T>(value), RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2279 }
2280
2281 enum class OutOfBoundsBehavior
2282 {
2283 Nullify, // Loads become zero, stores are elided.
2284 RobustBufferAccess, // As defined by the Vulkan spec (in short: access anywhere within bounds, or zeroing).
2285 UndefinedValue, // Only for load operations. Not secure. No program termination.
2286 UndefinedBehavior, // Program may terminate.
2287 };
2288
2289 RValue<Bool> AnyTrue(const RValue<Int4> &bools);
2290 RValue<Bool> AnyFalse(const RValue<Int4> &bools);
2291 RValue<Bool> AllTrue(const RValue<Int4> &bools);
2292 RValue<Bool> AllFalse(const RValue<Int4> &bools);
2293
2294 RValue<Bool> Divergent(const RValue<Int4> &ints);
2295 RValue<Bool> Divergent(const RValue<Float4> &floats);
2296 RValue<Bool> Uniform(const RValue<Int4> &ints);
2297 RValue<Bool> Uniform(const RValue<Float4> &floats);
2298
2299 // Fence adds a memory barrier that enforces ordering constraints on memory
2300 // operations. memoryOrder can only be one of:
2301 // std::memory_order_acquire, std::memory_order_release,
2302 // std::memory_order_acq_rel, or std::memory_order_seq_cst.
2303 void Fence(std::memory_order memoryOrder);
2304
2305 template<class T, int S = 1>
2306 class Array : public LValue<T>
2307 {
2308 public:
2309 Array(int size = S);
2310
2311 Reference<T> operator[](int index);
2312 Reference<T> operator[](unsigned int index);
2313 Reference<T> operator[](RValue<Int> index);
2314 Reference<T> operator[](RValue<UInt> index);
2315
2316 // self() returns the this pointer to this Array object.
2317 // This function exists because operator&() is overloaded by LValue<T>.
self()2318 inline Array *self() { return this; }
2319 };
2320
2321 // RValue<Array<T>> operator++(Array<T> &val, int); // Post-increment
2322 // const Array<T> &operator++(Array<T> &val); // Pre-increment
2323 // RValue<Array<T>> operator--(Array<T> &val, int); // Post-decrement
2324 // const Array<T> &operator--(Array<T> &val); // Pre-decrement
2325
2326 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB);
2327
2328 // ValueOf returns a rr::Value* for the given C-type, RValue<T>, LValue<T>
2329 // or Reference<T>.
2330 template<typename T>
ValueOf(const T & v)2331 inline Value *ValueOf(const T &v)
2332 {
2333 return ReactorType<T>::cast(v).loadValue();
2334 }
2335
2336 void Return();
2337
2338 template<class T>
Return(const T & ret)2339 void Return(const T &ret)
2340 {
2341 static_assert(CanBeUsedAsReturn<ReactorTypeT<T>>::value, "Unsupported type for Return()");
2342 Nucleus::createRet(ValueOf<T>(ret));
2343 // Place any unreachable instructions in an unreferenced block.
2344 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
2345 }
2346
2347 // Generic template, leave undefined!
2348 template<typename FunctionType>
2349 class Function;
2350
2351 // Specialized for function types
2352 template<typename Return, typename... Arguments>
2353 class Function<Return(Arguments...)>
2354 {
2355 // Static assert that the function signature is valid.
2356 static_assert(sizeof(AssertFunctionSignatureIsValid<Return(Arguments...)>) >= 0, "Invalid function signature");
2357
2358 public:
2359 Function();
2360
2361 template<int index>
Arg() const2362 Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type> Arg() const
2363 {
2364 Value *arg = Nucleus::getArgument(index);
2365 return Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type>(arg);
2366 }
2367
2368 std::shared_ptr<Routine> operator()(const char *name, ...);
2369
2370 protected:
2371 std::unique_ptr<Nucleus> core;
2372 std::vector<Type *> arguments;
2373 };
2374
2375 template<typename Return>
2376 class Function<Return()> : public Function<Return(Void)>
2377 {
2378 };
2379
2380 // FunctionT accepts a C-style function type template argument, allowing it to return a type-safe RoutineT wrapper
2381 template<typename FunctionType>
2382 class FunctionT;
2383
2384 template<typename Return, typename... Arguments>
2385 class FunctionT<Return(Arguments...)> : public Function<CToReactorT<Return>(CToReactorT<Arguments>...)>
2386 {
2387 public:
2388 // Type of base class
2389 using BaseType = Function<CToReactorT<Return>(CToReactorT<Arguments>...)>;
2390
2391 // Function type, e.g. void(int,float)
2392 using CFunctionType = Return(Arguments...);
2393
2394 // Reactor function type, e.g. Void(Int, Float)
2395 using ReactorFunctionType = CToReactorT<Return>(CToReactorT<Arguments>...);
2396
2397 // Returned RoutineT type
2398 using RoutineType = RoutineT<CFunctionType>;
2399
2400 // Hide base implementations of operator()
2401
2402 template<typename... VarArgs>
operator ()(const char * name,VarArgs...varArgs)2403 RoutineType operator()(const char *name, VarArgs... varArgs)
2404 {
2405 return RoutineType(BaseType::operator()(name, std::forward<VarArgs>(varArgs)...));
2406 }
2407 };
2408
2409 RValue<Long> Ticks();
2410
2411 } // namespace rr
2412
2413 /* Inline implementations */
2414
2415 namespace rr {
2416
2417 template<class T>
LValue(int arraySize)2418 LValue<T>::LValue(int arraySize)
2419 : Variable(T::type(), arraySize)
2420 {
2421 #ifdef ENABLE_RR_DEBUG_INFO
2422 materialize();
2423 #endif // ENABLE_RR_DEBUG_INFO
2424 }
2425
2426 template<class T>
operator &()2427 RValue<Pointer<T>> LValue<T>::operator&()
2428 {
2429 return RValue<Pointer<T>>(this->getBaseAddress());
2430 }
2431
2432 template<class T>
Reference(Value * pointer,int alignment)2433 Reference<T>::Reference(Value *pointer, int alignment)
2434 : address(pointer)
2435 , alignment(alignment)
2436 {
2437 }
2438
2439 template<class T>
operator =(RValue<T> rhs) const2440 RValue<T> Reference<T>::operator=(RValue<T> rhs) const
2441 {
2442 Nucleus::createStore(rhs.value(), address, T::type(), false, alignment);
2443
2444 return rhs;
2445 }
2446
2447 template<class T>
operator =(const Reference<T> & ref) const2448 RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
2449 {
2450 Value *tmp = Nucleus::createLoad(ref.address, T::type(), false, ref.alignment);
2451 Nucleus::createStore(tmp, address, T::type(), false, alignment);
2452
2453 return RValue<T>(tmp);
2454 }
2455
2456 template<class T>
operator +=(RValue<T> rhs) const2457 RValue<T> Reference<T>::operator+=(RValue<T> rhs) const
2458 {
2459 return *this = *this + rhs;
2460 }
2461
2462 template<class T>
loadValue() const2463 Value *Reference<T>::loadValue() const
2464 {
2465 return Nucleus::createLoad(address, T::type(), false, alignment);
2466 }
2467
2468 template<class T>
load() const2469 RValue<T> Reference<T>::load() const
2470 {
2471 return RValue<T>(loadValue());
2472 }
2473
2474 template<class T>
getAlignment() const2475 int Reference<T>::getAlignment() const
2476 {
2477 return alignment;
2478 }
2479
2480 template<class T>
RValue(const RValue<T> & rvalue)2481 RValue<T>::RValue(const RValue<T> &rvalue)
2482 : val(rvalue.val)
2483 {
2484 RR_DEBUG_INFO_EMIT_VAR(val);
2485 }
2486
2487 template<class T>
RValue(Value * value)2488 RValue<T>::RValue(Value *value)
2489 : val(value)
2490 {
2491 assert(Nucleus::createBitCast(value, T::type()) == value); // Run-time type should match T, so bitcast is no-op.
2492 RR_DEBUG_INFO_EMIT_VAR(val);
2493 }
2494
2495 template<class T>
RValue(const T & lvalue)2496 RValue<T>::RValue(const T &lvalue)
2497 : val(lvalue.loadValue())
2498 {
2499 RR_DEBUG_INFO_EMIT_VAR(val);
2500 }
2501
2502 template<>
RValue(bool b)2503 inline RValue<Bool>::RValue(bool b)
2504 : val(Nucleus::createConstantBool(b))
2505 {
2506 RR_DEBUG_INFO_EMIT_VAR(val);
2507 }
2508
2509 template<class T>
RValue(typename IntLiteral<T>::Type i)2510 RValue<T>::RValue(typename IntLiteral<T>::Type i)
2511 : val(Nucleus::createConstantInt(i))
2512 {
2513 RR_DEBUG_INFO_EMIT_VAR(val);
2514 }
2515
2516 template<>
RValue(int64_t i)2517 inline RValue<Long>::RValue(int64_t i)
2518 : val(Nucleus::createConstantLong(i))
2519 {
2520 RR_DEBUG_INFO_EMIT_VAR(val);
2521 }
2522
2523 template<>
RValue(float f)2524 inline RValue<Float>::RValue(float f)
2525 : val(Nucleus::createConstantFloat(f))
2526 {
2527 RR_DEBUG_INFO_EMIT_VAR(val);
2528 }
2529
broadcast(int i,Type * type)2530 inline Value *broadcast(int i, Type *type)
2531 {
2532 std::vector<int64_t> constantVector = { i };
2533 return Nucleus::createConstantVector(constantVector, type);
2534 }
2535
2536 template<>
RValue(int i)2537 inline RValue<Int4>::RValue(int i)
2538 : val(broadcast(i, Int4::type()))
2539 {
2540 RR_DEBUG_INFO_EMIT_VAR(val);
2541 }
2542
2543 template<>
RValue(unsigned int i)2544 inline RValue<UInt4>::RValue(unsigned int i)
2545 : val(broadcast(int(i), UInt4::type()))
2546 {
2547 RR_DEBUG_INFO_EMIT_VAR(val);
2548 }
2549
broadcast(float f,Type * type)2550 inline Value *broadcast(float f, Type *type)
2551 {
2552 // See Float(float) constructor for the rationale behind this assert.
2553 assert(std::isfinite(f));
2554
2555 std::vector<double> constantVector = { f };
2556 return Nucleus::createConstantVector(constantVector, type);
2557 }
2558
2559 template<>
RValue(float f)2560 inline RValue<Float4>::RValue(float f)
2561 : val(broadcast(f, Float4::type()))
2562 {
2563 RR_DEBUG_INFO_EMIT_VAR(val);
2564 }
2565
2566 template<class T>
RValue(const Reference<T> & ref)2567 RValue<T>::RValue(const Reference<T> &ref)
2568 : val(ref.loadValue())
2569 {
2570 RR_DEBUG_INFO_EMIT_VAR(val);
2571 }
2572
2573 template<class Vector4, int T>
operator RValue<Vector4>() const2574 Swizzle2<Vector4, T>::operator RValue<Vector4>() const
2575 {
2576 RR_DEBUG_INFO_UPDATE_LOC();
2577 Value *vector = parent->loadValue();
2578
2579 return Swizzle(RValue<Vector4>(vector), T);
2580 }
2581
2582 template<class Vector4, int T>
operator RValue<Vector4>() const2583 Swizzle4<Vector4, T>::operator RValue<Vector4>() const
2584 {
2585 RR_DEBUG_INFO_UPDATE_LOC();
2586 Value *vector = parent->loadValue();
2587
2588 return Swizzle(RValue<Vector4>(vector), T);
2589 }
2590
2591 template<class Vector4, int T>
operator RValue<Vector4>() const2592 SwizzleMask4<Vector4, T>::operator RValue<Vector4>() const
2593 {
2594 RR_DEBUG_INFO_UPDATE_LOC();
2595 Value *vector = parent->loadValue();
2596
2597 return Swizzle(RValue<Vector4>(vector), T);
2598 }
2599
2600 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2601 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<Vector4> rhs)
2602 {
2603 RR_DEBUG_INFO_UPDATE_LOC();
2604 return Mask(*parent, rhs, T);
2605 }
2606
2607 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2608 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)
2609 {
2610 RR_DEBUG_INFO_UPDATE_LOC();
2611 return Mask(*parent, Vector4(rhs), T);
2612 }
2613
2614 template<class Vector4, int T>
operator RValue<typename Scalar<Vector4>::Type>() const2615 SwizzleMask1<Vector4, T>::operator RValue<typename Scalar<Vector4>::Type>() const // FIXME: Call a non-template function
2616 {
2617 RR_DEBUG_INFO_UPDATE_LOC();
2618 return Extract(*parent, T & 0x3);
2619 }
2620
2621 template<class Vector4, int T>
operator RValue<Vector4>() const2622 SwizzleMask1<Vector4, T>::operator RValue<Vector4>() const
2623 {
2624 RR_DEBUG_INFO_UPDATE_LOC();
2625 Value *vector = parent->loadValue();
2626
2627 return Swizzle(RValue<Vector4>(vector), T);
2628 }
2629
2630 template<class Vector4, int T>
operator =(float x)2631 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(float x)
2632 {
2633 RR_DEBUG_INFO_UPDATE_LOC();
2634 return *parent = Insert(*parent, Float(x), T & 0x3);
2635 }
2636
2637 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2638 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<Vector4> rhs)
2639 {
2640 RR_DEBUG_INFO_UPDATE_LOC();
2641 return Mask(*parent, Float4(rhs), T);
2642 }
2643
2644 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2645 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs) // FIXME: Call a non-template function
2646 {
2647 RR_DEBUG_INFO_UPDATE_LOC();
2648 return *parent = Insert(*parent, rhs, T & 0x3);
2649 }
2650
2651 template<class Vector4, int T>
operator RValue<Vector4>() const2652 SwizzleMask2<Vector4, T>::operator RValue<Vector4>() const
2653 {
2654 RR_DEBUG_INFO_UPDATE_LOC();
2655 Value *vector = parent->loadValue();
2656
2657 return Swizzle(RValue<Float4>(vector), T);
2658 }
2659
2660 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2661 RValue<Vector4> SwizzleMask2<Vector4, T>::operator=(RValue<Vector4> rhs)
2662 {
2663 RR_DEBUG_INFO_UPDATE_LOC();
2664 return Mask(*parent, Float4(rhs), T);
2665 }
2666
2667 template<int T>
Int(const SwizzleMask1<Int4,T> & rhs)2668 Int::Int(const SwizzleMask1<Int4, T> &rhs)
2669 {
2670 *this = rhs.operator RValue<Int>();
2671 }
2672
2673 template<int T>
operator =(const SwizzleMask1<Int4,T> & rhs)2674 RValue<Int> Int::operator=(const SwizzleMask1<Int4, T> &rhs)
2675 {
2676 return *this = rhs.operator RValue<Int>();
2677 }
2678
2679 template<int T>
Float(const SwizzleMask1<Float4,T> & rhs)2680 Float::Float(const SwizzleMask1<Float4, T> &rhs)
2681 {
2682 *this = rhs.operator RValue<Float>();
2683 }
2684
2685 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2686 RValue<Float> Float::operator=(const SwizzleMask1<Float4, T> &rhs)
2687 {
2688 return *this = rhs.operator RValue<Float>();
2689 }
2690
2691 template<int T>
Int4(const SwizzleMask1<Int4,T> & rhs)2692 Int4::Int4(const SwizzleMask1<Int4, T> &rhs)
2693 : XYZW(this)
2694 {
2695 *this = rhs.operator RValue<Int4>();
2696 }
2697
2698 template<int T>
Float4(const SwizzleMask1<Float4,T> & rhs)2699 Float4::Float4(const SwizzleMask1<Float4, T> &rhs)
2700 : XYZW(this)
2701 {
2702 *this = rhs.operator RValue<Float4>();
2703 }
2704
2705 template<int T>
Float4(const Swizzle4<Float4,T> & rhs)2706 Float4::Float4(const Swizzle4<Float4, T> &rhs)
2707 : XYZW(this)
2708 {
2709 *this = rhs.operator RValue<Float4>();
2710 }
2711
2712 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2713 Float4::Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2714 : XYZW(this)
2715 {
2716 RR_DEBUG_INFO_UPDATE_LOC();
2717 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2718 }
2719
2720 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2721 Float4::Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2722 : XYZW(this)
2723 {
2724 RR_DEBUG_INFO_UPDATE_LOC();
2725 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2726 }
2727
2728 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2729 Float4::Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2730 : XYZW(this)
2731 {
2732 RR_DEBUG_INFO_UPDATE_LOC();
2733 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2734 }
2735
2736 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2737 Float4::Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2738 : XYZW(this)
2739 {
2740 RR_DEBUG_INFO_UPDATE_LOC();
2741 *this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2742 }
2743
2744 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2745 RValue<Float4> Float4::operator=(const SwizzleMask1<Float4, T> &rhs)
2746 {
2747 return *this = rhs.operator RValue<Float4>();
2748 }
2749
2750 template<int T>
operator =(const Swizzle4<Float4,T> & rhs)2751 RValue<Float4> Float4::operator=(const Swizzle4<Float4, T> &rhs)
2752 {
2753 return *this = rhs.operator RValue<Float4>();
2754 }
2755
2756 // Returns a reactor pointer to the fixed-address ptr.
2757 RValue<Pointer<Byte>> ConstantPointer(const void *ptr);
2758
2759 // Returns a reactor pointer to an immutable copy of the data of size bytes.
2760 RValue<Pointer<Byte>> ConstantData(const void *data, size_t size);
2761
2762 template<class T>
Pointer(Argument<Pointer<T>> argument)2763 Pointer<T>::Pointer(Argument<Pointer<T>> argument)
2764 : alignment(1)
2765 {
2766 this->store(argument.rvalue());
2767 }
2768
2769 template<class T>
Pointer()2770 Pointer<T>::Pointer()
2771 : alignment(1)
2772 {}
2773
2774 template<class T>
Pointer(RValue<Pointer<T>> rhs)2775 Pointer<T>::Pointer(RValue<Pointer<T>> rhs)
2776 : alignment(1)
2777 {
2778 this->store(rhs);
2779 }
2780
2781 template<class T>
Pointer(const Pointer<T> & rhs)2782 Pointer<T>::Pointer(const Pointer<T> &rhs)
2783 : alignment(rhs.alignment)
2784 {
2785 this->store(rhs.load());
2786 }
2787
2788 template<class T>
Pointer(const Reference<Pointer<T>> & rhs)2789 Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs)
2790 : alignment(rhs.getAlignment())
2791 {
2792 this->store(rhs.load());
2793 }
2794
2795 template<class T>
Pointer(std::nullptr_t)2796 Pointer<T>::Pointer(std::nullptr_t)
2797 : alignment(1)
2798 {
2799 Value *value = Nucleus::createNullPointer(T::type());
2800 this->storeValue(value);
2801 }
2802
2803 template<class T>
operator =(RValue<Pointer<T>> rhs)2804 RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs)
2805 {
2806 return this->store(rhs);
2807 }
2808
2809 template<class T>
operator =(const Pointer<T> & rhs)2810 RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs)
2811 {
2812 return this->store(rhs.load());
2813 }
2814
2815 template<class T>
operator =(const Reference<Pointer<T>> & rhs)2816 RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs)
2817 {
2818 return this->store(rhs.load());
2819 }
2820
2821 template<class T>
operator =(std::nullptr_t)2822 RValue<Pointer<T>> Pointer<T>::operator=(std::nullptr_t)
2823 {
2824 Value *value = Nucleus::createNullPointer(T::type());
2825 this->storeValue(value);
2826
2827 return RValue<Pointer<T>>(this);
2828 }
2829
2830 template<class T>
operator *() const2831 Reference<T> Pointer<T>::operator*() const
2832 {
2833 return Reference<T>(this->loadValue(), alignment);
2834 }
2835
2836 template<class T>
operator [](int index) const2837 Reference<T> Pointer<T>::operator[](int index) const
2838 {
2839 RR_DEBUG_INFO_UPDATE_LOC();
2840 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), false);
2841
2842 return Reference<T>(element, alignment);
2843 }
2844
2845 template<class T>
operator [](unsigned int index) const2846 Reference<T> Pointer<T>::operator[](unsigned int index) const
2847 {
2848 RR_DEBUG_INFO_UPDATE_LOC();
2849 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), true);
2850
2851 return Reference<T>(element, alignment);
2852 }
2853
2854 template<class T>
operator [](RValue<Int> index) const2855 Reference<T> Pointer<T>::operator[](RValue<Int> index) const
2856 {
2857 RR_DEBUG_INFO_UPDATE_LOC();
2858 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), false);
2859
2860 return Reference<T>(element, alignment);
2861 }
2862
2863 template<class T>
operator [](RValue<UInt> index) const2864 Reference<T> Pointer<T>::operator[](RValue<UInt> index) const
2865 {
2866 RR_DEBUG_INFO_UPDATE_LOC();
2867 Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), true);
2868
2869 return Reference<T>(element, alignment);
2870 }
2871
2872 template<class T>
type()2873 Type *Pointer<T>::type()
2874 {
2875 return Nucleus::getPointerType(T::type());
2876 }
2877
2878 template<class T, int S>
Array(int size)2879 Array<T, S>::Array(int size)
2880 : LValue<T>(size)
2881 {
2882 }
2883
2884 template<class T, int S>
operator [](int index)2885 Reference<T> Array<T, S>::operator[](int index)
2886 {
2887 assert(index < Variable::getArraySize());
2888 Value *element = this->getElementPointer(Nucleus::createConstantInt(index), false);
2889
2890 return Reference<T>(element);
2891 }
2892
2893 template<class T, int S>
operator [](unsigned int index)2894 Reference<T> Array<T, S>::operator[](unsigned int index)
2895 {
2896 assert(index < static_cast<unsigned int>(Variable::getArraySize()));
2897 Value *element = this->getElementPointer(Nucleus::createConstantInt(index), true);
2898
2899 return Reference<T>(element);
2900 }
2901
2902 template<class T, int S>
operator [](RValue<Int> index)2903 Reference<T> Array<T, S>::operator[](RValue<Int> index)
2904 {
2905 Value *element = this->getElementPointer(index.value(), false);
2906
2907 return Reference<T>(element);
2908 }
2909
2910 template<class T, int S>
operator [](RValue<UInt> index)2911 Reference<T> Array<T, S>::operator[](RValue<UInt> index)
2912 {
2913 Value *element = this->getElementPointer(index.value(), true);
2914
2915 return Reference<T>(element);
2916 }
2917
2918 // template<class T>
2919 // RValue<Array<T>> operator++(Array<T> &val, int)
2920 // {
2921 // // FIXME: Requires storing the address of the array
2922 // }
2923
2924 // template<class T>
2925 // const Array<T> &operator++(Array<T> &val)
2926 // {
2927 // // FIXME: Requires storing the address of the array
2928 // }
2929
2930 // template<class T>
2931 // RValue<Array<T>> operator--(Array<T> &val, int)
2932 // {
2933 // // FIXME: Requires storing the address of the array
2934 // }
2935
2936 // template<class T>
2937 // const Array<T> &operator--(Array<T> &val)
2938 // {
2939 // // FIXME: Requires storing the address of the array
2940 // }
2941
2942 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,RValue<T> ifFalse)2943 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, RValue<T> ifFalse)
2944 {
2945 RR_DEBUG_INFO_UPDATE_LOC();
2946 return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), ifFalse.value()));
2947 }
2948
2949 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,RValue<T> ifFalse)2950 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, RValue<T> ifFalse)
2951 {
2952 RR_DEBUG_INFO_UPDATE_LOC();
2953 Value *trueValue = ifTrue.loadValue();
2954
2955 return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, ifFalse.value()));
2956 }
2957
2958 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,const T & ifFalse)2959 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, const T &ifFalse)
2960 {
2961 RR_DEBUG_INFO_UPDATE_LOC();
2962 Value *falseValue = ifFalse.loadValue();
2963
2964 return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), falseValue));
2965 }
2966
2967 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,const T & ifFalse)2968 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, const T &ifFalse)
2969 {
2970 RR_DEBUG_INFO_UPDATE_LOC();
2971 Value *trueValue = ifTrue.loadValue();
2972 Value *falseValue = ifFalse.loadValue();
2973
2974 return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, falseValue));
2975 }
2976
2977 template<typename Return, typename... Arguments>
Function()2978 Function<Return(Arguments...)>::Function()
2979 : core(new Nucleus())
2980 {
2981 Type *types[] = { Arguments::type()... };
2982 for(Type *type : types)
2983 {
2984 if(type != Void::type())
2985 {
2986 arguments.push_back(type);
2987 }
2988 }
2989
2990 Nucleus::createFunction(Return::type(), arguments);
2991 }
2992
2993 template<typename Return, typename... Arguments>
operator ()(const char * name,...)2994 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const char *name, ...)
2995 {
2996 char fullName[1024 + 1];
2997
2998 va_list vararg;
2999 va_start(vararg, name);
3000 vsnprintf(fullName, 1024, name, vararg);
3001 va_end(vararg);
3002
3003 auto routine = core->acquireRoutine(fullName);
3004 core.reset(nullptr);
3005
3006 return routine;
3007 }
3008
3009 template<class T, class S>
ReinterpretCast(RValue<S> val)3010 RValue<T> ReinterpretCast(RValue<S> val)
3011 {
3012 RR_DEBUG_INFO_UPDATE_LOC();
3013 return RValue<T>(Nucleus::createBitCast(val.value(), T::type()));
3014 }
3015
3016 template<class T, class S>
ReinterpretCast(const LValue<S> & var)3017 RValue<T> ReinterpretCast(const LValue<S> &var)
3018 {
3019 RR_DEBUG_INFO_UPDATE_LOC();
3020 Value *val = var.loadValue();
3021
3022 return RValue<T>(Nucleus::createBitCast(val, T::type()));
3023 }
3024
3025 template<class T, class S>
ReinterpretCast(const Reference<S> & var)3026 RValue<T> ReinterpretCast(const Reference<S> &var)
3027 {
3028 return ReinterpretCast<T>(RValue<S>(var));
3029 }
3030
3031 template<class T>
As(Value * val)3032 RValue<T> As(Value *val)
3033 {
3034 RR_DEBUG_INFO_UPDATE_LOC();
3035 return RValue<T>(Nucleus::createBitCast(val, T::type()));
3036 }
3037
3038 template<class T, class S>
As(RValue<S> val)3039 RValue<T> As(RValue<S> val)
3040 {
3041 return ReinterpretCast<T>(val);
3042 }
3043
3044 template<class T, class S>
As(const LValue<S> & var)3045 RValue<T> As(const LValue<S> &var)
3046 {
3047 return ReinterpretCast<T>(var);
3048 }
3049
3050 template<class T, class S>
As(const Reference<S> & val)3051 RValue<T> As(const Reference<S> &val)
3052 {
3053 return ReinterpretCast<T>(val);
3054 }
3055
3056 // Calls the function pointer fptr with the given arguments, return type
3057 // and parameter types. Returns the call's return value if the function has
3058 // a non-void return type.
3059 Value *Call(RValue<Pointer<Byte>> fptr, Type *retTy, std::initializer_list<Value *> args, std::initializer_list<Type *> paramTys);
3060
3061 template<typename F>
3062 class CallHelper
3063 {};
3064
3065 template<typename Return, typename... Arguments>
3066 class CallHelper<Return(Arguments...)>
3067 {
3068 public:
3069 using RReturn = CToReactorT<Return>;
3070
Call(Return (fptr)(Arguments...),CToReactorT<Arguments>...args)3071 static inline RReturn Call(Return(fptr)(Arguments...), CToReactorT<Arguments>... args)
3072 {
3073 return RValue<RReturn>(rr::Call(
3074 ConstantPointer(reinterpret_cast<void *>(fptr)),
3075 RReturn::type(),
3076 { ValueOf(args)... },
3077 { CToReactorT<Arguments>::type()... }));
3078 }
3079
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3080 static inline RReturn Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3081 {
3082 return RValue<RReturn>(rr::Call(
3083 fptr,
3084 RReturn::type(),
3085 { ValueOf(args)... },
3086 { CToReactorT<Arguments>::type()... }));
3087 }
3088 };
3089
3090 template<typename... Arguments>
3091 class CallHelper<void(Arguments...)>
3092 {
3093 public:
Call(void (fptr)(Arguments...),CToReactorT<Arguments>...args)3094 static inline void Call(void(fptr)(Arguments...), CToReactorT<Arguments>... args)
3095 {
3096 rr::Call(ConstantPointer(reinterpret_cast<void *>(fptr)),
3097 Void::type(),
3098 { ValueOf(args)... },
3099 { CToReactorT<Arguments>::type()... });
3100 }
3101
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3102 static inline void Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3103 {
3104 rr::Call(fptr,
3105 Void::type(),
3106 { ValueOf(args)... },
3107 { CToReactorT<Arguments>::type()... });
3108 }
3109 };
3110
3111 template<typename T>
CastToReactor(const T & v)3112 inline ReactorTypeT<T> CastToReactor(const T &v)
3113 {
3114 return ReactorType<T>::cast(v);
3115 }
3116
3117 // Calls the static function pointer fptr with the given arguments args.
3118 template<typename Return, typename... CArgs, typename... RArgs>
Call(Return (fptr)(CArgs...),RArgs &&...args)3119 inline CToReactorT<Return> Call(Return(fptr)(CArgs...), RArgs &&...args)
3120 {
3121 return CallHelper<Return(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3122 }
3123
3124 // Calls the static function pointer fptr with the given arguments args.
3125 // Overload for calling functions with void return type.
3126 template<typename... CArgs, typename... RArgs>
Call(void (fptr)(CArgs...),RArgs &&...args)3127 inline void Call(void(fptr)(CArgs...), RArgs &&...args)
3128 {
3129 CallHelper<void(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3130 }
3131
3132 // Calls the member function pointer fptr with the given arguments args.
3133 // object can be a Class*, or a Pointer<Byte>.
3134 template<typename Return, typename Class, typename C, typename... CArgs, typename... RArgs>
Call(Return (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3135 inline CToReactorT<Return> Call(Return (Class::*fptr)(CArgs...), C &&object, RArgs &&...args)
3136 {
3137 using Helper = CallHelper<Return(Class *, void *, CArgs...)>;
3138 using fptrTy = decltype(fptr);
3139
3140 struct Static
3141 {
3142 static inline Return Call(Class *object, void *fptrptr, CArgs... args)
3143 {
3144 auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3145 return (object->*fptr)(std::forward<CArgs>(args)...);
3146 }
3147 };
3148
3149 return Helper::Call(&Static::Call,
3150 CastToReactor(object),
3151 ConstantData(&fptr, sizeof(fptr)),
3152 CastToReactor(std::forward<RArgs>(args))...);
3153 }
3154
3155 // Calls the member function pointer fptr with the given arguments args.
3156 // Overload for calling functions with void return type.
3157 // object can be a Class*, or a Pointer<Byte>.
3158 template<typename Class, typename C, typename... CArgs, typename... RArgs>
Call(void (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3159 inline void Call(void (Class::*fptr)(CArgs...), C &&object, RArgs &&...args)
3160 {
3161 using Helper = CallHelper<void(Class *, void *, CArgs...)>;
3162 using fptrTy = decltype(fptr);
3163
3164 struct Static
3165 {
3166 static inline void Call(Class *object, void *fptrptr, CArgs... args)
3167 {
3168 auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3169 (object->*fptr)(std::forward<CArgs>(args)...);
3170 }
3171 };
3172
3173 Helper::Call(&Static::Call,
3174 CastToReactor(object),
3175 ConstantData(&fptr, sizeof(fptr)),
3176 CastToReactor(std::forward<RArgs>(args))...);
3177 }
3178
3179 // NonVoidFunction<F> and VoidFunction<F> are helper classes which define ReturnType
3180 // when F matches a non-void fuction signature or void function signature, respectively,
3181 // as the function's return type.
3182 template<typename F>
3183 struct NonVoidFunction
3184 {};
3185
3186 template<typename Return, typename... Arguments>
3187 struct NonVoidFunction<Return(Arguments...)>
3188 {
3189 using ReturnType = Return;
3190 };
3191
3192 template<typename... Arguments>
3193 struct NonVoidFunction<void(Arguments...)>
3194 {
3195 };
3196
3197 template<typename F>
3198 using NonVoidFunctionReturnType = typename NonVoidFunction<F>::ReturnType;
3199
3200 template<typename F>
3201 struct VoidFunction
3202 {};
3203
3204 template<typename... Arguments>
3205 struct VoidFunction<void(Arguments...)>
3206 {
3207 using ReturnType = void;
3208 };
3209
3210 template<typename F>
3211 using VoidFunctionReturnType = typename VoidFunction<F>::ReturnType;
3212
3213 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3214 // Overload for calling functions with non-void return type.
3215 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3216 inline CToReactorT<NonVoidFunctionReturnType<FUNCTION_SIGNATURE>> Call(Pointer<Byte> fptr, RArgs &&...args)
3217 {
3218 return CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3219 }
3220
3221 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3222 // Overload for calling functions with void return type.
3223 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3224 inline VoidFunctionReturnType<FUNCTION_SIGNATURE> Call(Pointer<Byte> fptr, RArgs &&...args)
3225 {
3226 CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3227 }
3228
3229 // Breakpoint emits an instruction that will cause the application to trap.
3230 // This can be used to stop an attached debugger at the given call.
3231 void Breakpoint();
3232
3233 class ForData
3234 {
3235 public:
ForData(bool init)3236 ForData(bool init)
3237 : loopOnce(init)
3238 {
3239 }
3240
operator bool()3241 operator bool()
3242 {
3243 return loopOnce;
3244 }
3245
operator =(bool value)3246 bool operator=(bool value)
3247 {
3248 return loopOnce = value;
3249 }
3250
setup()3251 bool setup()
3252 {
3253 RR_DEBUG_INFO_FLUSH();
3254 if(Nucleus::getInsertBlock() != endBB)
3255 {
3256 testBB = Nucleus::createBasicBlock();
3257
3258 Nucleus::createBr(testBB);
3259 Nucleus::setInsertBlock(testBB);
3260
3261 return true;
3262 }
3263
3264 return false;
3265 }
3266
test(RValue<Bool> cmp)3267 bool test(RValue<Bool> cmp)
3268 {
3269 BasicBlock *bodyBB = Nucleus::createBasicBlock();
3270 endBB = Nucleus::createBasicBlock();
3271
3272 Nucleus::createCondBr(cmp.value(), bodyBB, endBB);
3273 Nucleus::setInsertBlock(bodyBB);
3274
3275 return true;
3276 }
3277
end()3278 void end()
3279 {
3280 Nucleus::createBr(testBB);
3281 Nucleus::setInsertBlock(endBB);
3282 }
3283
3284 private:
3285 BasicBlock *testBB = nullptr;
3286 BasicBlock *endBB = nullptr;
3287 bool loopOnce = true;
3288 };
3289
3290 class IfElseData
3291 {
3292 public:
IfElseData(RValue<Bool> cmp)3293 IfElseData(RValue<Bool> cmp)
3294 {
3295 trueBB = Nucleus::createBasicBlock();
3296 falseBB = Nucleus::createBasicBlock();
3297 endBB = falseBB; // Until we encounter an Else statement, these are the same.
3298
3299 Nucleus::createCondBr(cmp.value(), trueBB, falseBB);
3300 Nucleus::setInsertBlock(trueBB);
3301 }
3302
~IfElseData()3303 ~IfElseData()
3304 {
3305 Nucleus::createBr(endBB);
3306 Nucleus::setInsertBlock(endBB);
3307 }
3308
operator int()3309 operator int()
3310 {
3311 return iteration;
3312 }
3313
operator ++()3314 IfElseData &operator++()
3315 {
3316 ++iteration;
3317
3318 return *this;
3319 }
3320
elseClause()3321 void elseClause()
3322 {
3323 endBB = Nucleus::createBasicBlock();
3324 Nucleus::createBr(endBB);
3325
3326 Nucleus::setInsertBlock(falseBB);
3327 }
3328
3329 private:
3330 BasicBlock *trueBB = nullptr;
3331 BasicBlock *falseBB = nullptr;
3332 BasicBlock *endBB = nullptr;
3333 int iteration = 0;
3334 };
3335
3336 #define For(init, cond, inc) \
3337 for(ForData for__ = true; for__; for__ = false) \
3338 for(init; for__.setup() && for__.test(cond); inc, for__.end())
3339
3340 #define While(cond) For((void)0, cond, (void)0)
3341
3342 #define Do \
3343 { \
3344 BasicBlock *body__ = Nucleus::createBasicBlock(); \
3345 Nucleus::createBr(body__); \
3346 Nucleus::setInsertBlock(body__);
3347
3348 #define Until(cond) \
3349 BasicBlock *end__ = Nucleus::createBasicBlock(); \
3350 Nucleus::createCondBr((cond).value(), end__, body__); \
3351 Nucleus::setInsertBlock(end__); \
3352 } \
3353 do \
3354 { \
3355 } while(false) // Require a semi-colon at the end of the Until()
3356
3357 enum
3358 {
3359 IF_BLOCK__,
3360 ELSE_CLAUSE__,
3361 ELSE_BLOCK__,
3362 IFELSE_NUM__
3363 };
3364
3365 #define If(cond) \
3366 for(IfElseData ifElse__{ cond }; ifElse__ < IFELSE_NUM__; ++ifElse__) \
3367 if(ifElse__ == IF_BLOCK__)
3368
3369 #define Else \
3370 else if(ifElse__ == ELSE_CLAUSE__) \
3371 { \
3372 ifElse__.elseClause(); \
3373 } \
3374 else // ELSE_BLOCK__
3375
3376 // The OFFSET macro is a generalization of the offsetof() macro defined in <cstddef>.
3377 // It allows e.g. getting the offset of array elements, even when indexed dynamically.
3378 // We cast the address '32' and subtract it again, because null-dereference is undefined behavior.
3379 #define OFFSET(s, m) ((int)(size_t) & reinterpret_cast<const volatile char &>((((s *)32)->m)) - 32)
3380
3381 } // namespace rr
3382
3383 #include "Traits.inl"
3384
3385 #endif // rr_Reactor_hpp
3386