xref: /aosp_15_r20/external/swiftshader/src/Reactor/Reactor.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
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);
Mix(RValue<Float4> x,RValue<Float4> y,RValue<Float4> frac)2056 inline RValue<Float4> Mix(RValue<Float4> x, RValue<Float4> y, RValue<Float4> frac) {
2057 	return (x * (Float4(1.0f) - frac)) + (y * frac);
2058 }
2059 
2060 // Trigonometric functions
2061 RValue<Float4> Sin(RValue<Float4> x);
2062 RValue<Float4> Cos(RValue<Float4> x);
2063 RValue<Float4> Tan(RValue<Float4> x);
2064 RValue<Float4> Asin(RValue<Float4> x);
2065 RValue<Float4> Acos(RValue<Float4> x);
2066 RValue<Float4> Atan(RValue<Float4> x);
2067 RValue<Float4> Sinh(RValue<Float4> x);
2068 RValue<Float4> Cosh(RValue<Float4> x);
2069 RValue<Float4> Tanh(RValue<Float4> x);
2070 RValue<Float4> Asinh(RValue<Float4> x);
2071 RValue<Float4> Acosh(RValue<Float4> x);
2072 RValue<Float4> Atanh(RValue<Float4> x);
2073 RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y);
2074 
2075 // Exponential functions
2076 RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y);
2077 RValue<Float4> Exp(RValue<Float4> x);
2078 RValue<Float4> Log(RValue<Float4> x);
2079 RValue<Float4> Exp2(RValue<Float4> x);
2080 RValue<Float4> Log2(RValue<Float4> x);
2081 
2082 // Call a unary C function on each element of a vector type.
2083 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x)2084 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x)
2085 {
2086 	T result;
2087 	for(int i = 0; i < T::element_count(); i++)
2088 	{
2089 		result = Insert(result, Call(func, Extract(x, i)), i);
2090 	}
2091 
2092 	return result;
2093 }
2094 
2095 // Call a binary C function on each element of a vector type.
2096 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x,const RValue<T> & y)2097 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x, const RValue<T> &y)
2098 {
2099 	T result;
2100 	for(int i = 0; i < T::element_count(); i++)
2101 	{
2102 		result = Insert(result, Call(func, Extract(x, i), Extract(y, i)), i);
2103 	}
2104 
2105 	return result;
2106 }
2107 
2108 // Call a ternary C function on each element of a vector type.
2109 template<typename Func, typename T>
ScalarizeCall(Func func,const RValue<T> & x,const RValue<T> & y,const RValue<T> & z)2110 inline RValue<T> ScalarizeCall(Func func, const RValue<T> &x, const RValue<T> &y, const RValue<T> &z)
2111 {
2112 	T result;
2113 	for(int i = 0; i < T::element_count(); i++)
2114 	{
2115 		result = Insert(result, Call(func, Extract(x, i), Extract(y, i), Extract(z, i)), i);
2116 	}
2117 
2118 	return result;
2119 }
2120 
2121 // Invoke a unary lambda expression on each element of a vector type.
2122 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x)2123 inline RValue<T> Scalarize(Func func, const RValue<T> &x)
2124 {
2125 	T result;
2126 	for(int i = 0; i < T::element_count(); i++)
2127 	{
2128 		result = Insert(result, func(Extract(x, i)), i);
2129 	}
2130 
2131 	return result;
2132 }
2133 
2134 // Invoke a binary lambda expression on each element of a vector type.
2135 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x,const RValue<T> & y)2136 inline RValue<T> Scalarize(Func func, const RValue<T> &x, const RValue<T> &y)
2137 {
2138 	T result;
2139 	for(int i = 0; i < T::element_count(); i++)
2140 	{
2141 		result = Insert(result, func(Extract(x, i), Extract(y, i)), i);
2142 	}
2143 
2144 	return result;
2145 }
2146 
2147 // Invoke a ternary lambda expression on each element of a vector type.
2148 template<typename Func, typename T>
Scalarize(Func func,const RValue<T> & x,const RValue<T> & y,const RValue<T> & z)2149 inline RValue<T> Scalarize(Func func, const RValue<T> &x, const RValue<T> &y, const RValue<T> &z)
2150 {
2151 	T result;
2152 	for(int i = 0; i < T::element_count(); i++)
2153 	{
2154 		result = Insert(result, func(Extract(x, i), Extract(y, i), Extract(z, i)), i);
2155 	}
2156 
2157 	return result;
2158 }
2159 
2160 // Bit Manipulation functions.
2161 // TODO: Currently unimplemented for Subzero.
2162 
2163 // Count leading zeros.
2164 // Returns 32 when: !isZeroUndef && x == 0.
2165 // Returns an undefined value when: isZeroUndef && x == 0.
2166 RValue<UInt> Ctlz(RValue<UInt> x, bool isZeroUndef);
2167 RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
2168 
2169 // Count trailing zeros.
2170 // Returns 32 when: !isZeroUndef && x == 0.
2171 // Returns an undefined value when: isZeroUndef && x == 0.
2172 RValue<UInt> Cttz(RValue<UInt> x, bool isZeroUndef);
2173 RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
2174 
2175 template<class T>
2176 class Pointer : public LValue<Pointer<T>>
2177 {
2178 public:
2179 	template<class S>
Pointer(RValue<Pointer<S>> pointerS,int alignment=1)2180 	Pointer(RValue<Pointer<S>> pointerS, int alignment = 1)
2181 	    : alignment(alignment)
2182 	{
2183 		Value *pointerT = Nucleus::createBitCast(pointerS.value(), Nucleus::getPointerType(T::type()));
2184 		this->storeValue(pointerT);
2185 	}
2186 
2187 	template<class S>
Pointer(const Pointer<S> & pointer,int alignment=1)2188 	Pointer(const Pointer<S> &pointer, int alignment = 1)
2189 	    : alignment(alignment)
2190 	{
2191 		Value *pointerS = pointer.loadValue();
2192 		Value *pointerT = Nucleus::createBitCast(pointerS, Nucleus::getPointerType(T::type()));
2193 		this->storeValue(pointerT);
2194 	}
2195 
2196 	Pointer(Argument<Pointer<T>> argument);
2197 
2198 	Pointer();
2199 	Pointer(RValue<Pointer<T>> rhs);
2200 	Pointer(const Pointer<T> &rhs);
2201 	Pointer(const Reference<Pointer<T>> &rhs);
2202 	Pointer(std::nullptr_t);
2203 
2204 	RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs);
2205 	RValue<Pointer<T>> operator=(const Pointer<T> &rhs);
2206 	RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs);
2207 	RValue<Pointer<T>> operator=(std::nullptr_t);
2208 
2209 	Reference<T> operator*() const;
2210 	Reference<T> operator[](int index) const;
2211 	Reference<T> operator[](unsigned int index) const;
2212 	Reference<T> operator[](RValue<Int> index) const;
2213 	Reference<T> operator[](RValue<UInt> index) const;
2214 
2215 	static Type *type();
2216 
2217 private:
2218 	const int alignment;
2219 };
2220 
2221 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);
2222 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2223 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2224 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset);
2225 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset);
2226 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset);
2227 
2228 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);
2229 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2230 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
2231 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset);
2232 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset);
2233 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset);
2234 
2235 template<typename T>
operator ==(const Pointer<T> & lhs,const Pointer<T> & rhs)2236 RValue<Bool> operator==(const Pointer<T> &lhs, const Pointer<T> &rhs)
2237 {
2238 	return RValue<Bool>(Nucleus::createICmpEQ(lhs.loadValue(), rhs.loadValue()));
2239 }
2240 
2241 template<typename T>
operator !=(const Pointer<T> & lhs,const Pointer<T> & rhs)2242 RValue<Bool> operator!=(const Pointer<T> &lhs, const Pointer<T> &rhs)
2243 {
2244 	return RValue<Bool>(Nucleus::createICmpNE(lhs.loadValue(), rhs.loadValue()));
2245 }
2246 
2247 template<typename T>
Load(RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2248 RValue<T> Load(RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2249 {
2250 	return RValue<T>(Nucleus::createLoad(pointer.value(), T::type(), false, alignment, atomic, memoryOrder));
2251 }
2252 
2253 template<typename T>
Load(Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2254 RValue<T> Load(Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2255 {
2256 	return Load(RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2257 }
2258 
2259 // TODO: Use SIMD to template these.
2260 // TODO(b/155867273): These can be undeprecated if implemented for Subzero.
2261 [[deprecated]] RValue<Float4> MaskedLoad(RValue<Pointer<Float4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2262 [[deprecated]] RValue<Int4> MaskedLoad(RValue<Pointer<Int4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2263 [[deprecated]] void MaskedStore(RValue<Pointer<Float4>> base, RValue<Float4> val, RValue<Int4> mask, unsigned int alignment);
2264 [[deprecated]] void MaskedStore(RValue<Pointer<Int4>> base, RValue<Int4> val, RValue<Int4> mask, unsigned int alignment);
2265 
2266 template<typename T>
Store(RValue<T> value,RValue<Pointer<T>> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2267 void Store(RValue<T> value, RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2268 {
2269 	Nucleus::createStore(value.value(), pointer.value(), T::type(), false, alignment, atomic, memoryOrder);
2270 }
2271 
2272 template<typename T>
Store(RValue<T> value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2273 void Store(RValue<T> value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2274 {
2275 	Store(value, RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2276 }
2277 
2278 template<typename T>
Store(T value,Pointer<T> pointer,unsigned int alignment,bool atomic,std::memory_order memoryOrder)2279 void Store(T value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2280 {
2281 	Store(RValue<T>(value), RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2282 }
2283 
2284 enum class OutOfBoundsBehavior
2285 {
2286 	Nullify,             // Loads become zero, stores are elided.
2287 	RobustBufferAccess,  // As defined by the Vulkan spec (in short: access anywhere within bounds, or zeroing).
2288 	UndefinedValue,      // Only for load operations. Not secure. No program termination.
2289 	UndefinedBehavior,   // Program may terminate.
2290 };
2291 
2292 RValue<Bool> AnyTrue(const RValue<Int4> &bools);
2293 RValue<Bool> AnyFalse(const RValue<Int4> &bools);
2294 RValue<Bool> AllTrue(const RValue<Int4> &bools);
2295 RValue<Bool> AllFalse(const RValue<Int4> &bools);
2296 
2297 RValue<Bool> Divergent(const RValue<Int4> &ints);
2298 RValue<Bool> Divergent(const RValue<Float4> &floats);
2299 RValue<Bool> Uniform(const RValue<Int4> &ints);
2300 RValue<Bool> Uniform(const RValue<Float4> &floats);
2301 
2302 // Fence adds a memory barrier that enforces ordering constraints on memory
2303 // operations. memoryOrder can only be one of:
2304 // std::memory_order_acquire, std::memory_order_release,
2305 // std::memory_order_acq_rel, or std::memory_order_seq_cst.
2306 void Fence(std::memory_order memoryOrder);
2307 
2308 template<class T, int S = 1>
2309 class Array : public LValue<T>
2310 {
2311 public:
2312 	Array(int size = S);
2313 
2314 	Reference<T> operator[](int index);
2315 	Reference<T> operator[](unsigned int index);
2316 	Reference<T> operator[](RValue<Int> index);
2317 	Reference<T> operator[](RValue<UInt> index);
2318 
2319 	// self() returns the this pointer to this Array object.
2320 	// This function exists because operator&() is overloaded by LValue<T>.
self()2321 	inline Array *self() { return this; }
2322 };
2323 
2324 //	RValue<Array<T>> operator++(Array<T> &val, int);   // Post-increment
2325 //	const Array<T> &operator++(Array<T> &val);   // Pre-increment
2326 //	RValue<Array<T>> operator--(Array<T> &val, int);   // Post-decrement
2327 //	const Array<T> &operator--(Array<T> &val);   // Pre-decrement
2328 
2329 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB);
2330 
2331 // ValueOf returns a rr::Value* for the given C-type, RValue<T>, LValue<T>
2332 // or Reference<T>.
2333 template<typename T>
ValueOf(const T & v)2334 inline Value *ValueOf(const T &v)
2335 {
2336 	return ReactorType<T>::cast(v).loadValue();
2337 }
2338 
2339 void Return();
2340 
2341 template<class T>
Return(const T & ret)2342 void Return(const T &ret)
2343 {
2344 	static_assert(CanBeUsedAsReturn<ReactorTypeT<T>>::value, "Unsupported type for Return()");
2345 	Nucleus::createRet(ValueOf<T>(ret));
2346 	// Place any unreachable instructions in an unreferenced block.
2347 	Nucleus::setInsertBlock(Nucleus::createBasicBlock());
2348 }
2349 
2350 // Generic template, leave undefined!
2351 template<typename FunctionType>
2352 class Function;
2353 
2354 // Specialized for function types
2355 template<typename Return, typename... Arguments>
2356 class Function<Return(Arguments...)>
2357 {
2358 	// Static assert that the function signature is valid.
2359 	static_assert(sizeof(AssertFunctionSignatureIsValid<Return(Arguments...)>) >= 0, "Invalid function signature");
2360 
2361 public:
2362 	Function();
2363 
2364 	template<int index>
Arg() const2365 	Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type> Arg() const
2366 	{
2367 		Value *arg = Nucleus::getArgument(index);
2368 		return Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type>(arg);
2369 	}
2370 
2371 	std::shared_ptr<Routine> operator()(const char *name, ...);
2372 
2373 protected:
2374 	std::unique_ptr<Nucleus> core;
2375 	std::vector<Type *> arguments;
2376 };
2377 
2378 template<typename Return>
2379 class Function<Return()> : public Function<Return(Void)>
2380 {
2381 };
2382 
2383 // FunctionT accepts a C-style function type template argument, allowing it to return a type-safe RoutineT wrapper
2384 template<typename FunctionType>
2385 class FunctionT;
2386 
2387 template<typename Return, typename... Arguments>
2388 class FunctionT<Return(Arguments...)> : public Function<CToReactorT<Return>(CToReactorT<Arguments>...)>
2389 {
2390 public:
2391 	// Type of base class
2392 	using BaseType = Function<CToReactorT<Return>(CToReactorT<Arguments>...)>;
2393 
2394 	// Function type, e.g. void(int,float)
2395 	using CFunctionType = Return(Arguments...);
2396 
2397 	// Reactor function type, e.g. Void(Int, Float)
2398 	using ReactorFunctionType = CToReactorT<Return>(CToReactorT<Arguments>...);
2399 
2400 	// Returned RoutineT type
2401 	using RoutineType = RoutineT<CFunctionType>;
2402 
2403 	// Hide base implementations of operator()
2404 
2405 	template<typename... VarArgs>
operator ()(const char * name,VarArgs...varArgs)2406 	RoutineType operator()(const char *name, VarArgs... varArgs)
2407 	{
2408 		return RoutineType(BaseType::operator()(name, std::forward<VarArgs>(varArgs)...));
2409 	}
2410 };
2411 
2412 RValue<Long> Ticks();
2413 
2414 }  // namespace rr
2415 
2416 /* Inline implementations */
2417 
2418 namespace rr {
2419 
2420 template<class T>
LValue(int arraySize)2421 LValue<T>::LValue(int arraySize)
2422     : Variable(T::type(), arraySize)
2423 {
2424 #ifdef ENABLE_RR_DEBUG_INFO
2425 	materialize();
2426 #endif  // ENABLE_RR_DEBUG_INFO
2427 }
2428 
2429 template<class T>
operator &()2430 RValue<Pointer<T>> LValue<T>::operator&()
2431 {
2432 	return RValue<Pointer<T>>(this->getBaseAddress());
2433 }
2434 
2435 template<class T>
Reference(Value * pointer,int alignment)2436 Reference<T>::Reference(Value *pointer, int alignment)
2437     : address(pointer)
2438     , alignment(alignment)
2439 {
2440 }
2441 
2442 template<class T>
operator =(RValue<T> rhs) const2443 RValue<T> Reference<T>::operator=(RValue<T> rhs) const
2444 {
2445 	Nucleus::createStore(rhs.value(), address, T::type(), false, alignment);
2446 
2447 	return rhs;
2448 }
2449 
2450 template<class T>
operator =(const Reference<T> & ref) const2451 RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
2452 {
2453 	Value *tmp = Nucleus::createLoad(ref.address, T::type(), false, ref.alignment);
2454 	Nucleus::createStore(tmp, address, T::type(), false, alignment);
2455 
2456 	return RValue<T>(tmp);
2457 }
2458 
2459 template<class T>
operator +=(RValue<T> rhs) const2460 RValue<T> Reference<T>::operator+=(RValue<T> rhs) const
2461 {
2462 	return *this = *this + rhs;
2463 }
2464 
2465 template<class T>
loadValue() const2466 Value *Reference<T>::loadValue() const
2467 {
2468 	return Nucleus::createLoad(address, T::type(), false, alignment);
2469 }
2470 
2471 template<class T>
load() const2472 RValue<T> Reference<T>::load() const
2473 {
2474 	return RValue<T>(loadValue());
2475 }
2476 
2477 template<class T>
getAlignment() const2478 int Reference<T>::getAlignment() const
2479 {
2480 	return alignment;
2481 }
2482 
2483 template<class T>
RValue(const RValue<T> & rvalue)2484 RValue<T>::RValue(const RValue<T> &rvalue)
2485     : val(rvalue.val)
2486 {
2487 	RR_DEBUG_INFO_EMIT_VAR(val);
2488 }
2489 
2490 template<class T>
RValue(Value * value)2491 RValue<T>::RValue(Value *value)
2492     : val(value)
2493 {
2494 	assert(Nucleus::createBitCast(value, T::type()) == value);  // Run-time type should match T, so bitcast is no-op.
2495 	RR_DEBUG_INFO_EMIT_VAR(val);
2496 }
2497 
2498 template<class T>
RValue(const T & lvalue)2499 RValue<T>::RValue(const T &lvalue)
2500     : val(lvalue.loadValue())
2501 {
2502 	RR_DEBUG_INFO_EMIT_VAR(val);
2503 }
2504 
2505 template<>
RValue(bool b)2506 inline RValue<Bool>::RValue(bool b)
2507     : val(Nucleus::createConstantBool(b))
2508 {
2509 	RR_DEBUG_INFO_EMIT_VAR(val);
2510 }
2511 
2512 template<class T>
RValue(typename IntLiteral<T>::Type i)2513 RValue<T>::RValue(typename IntLiteral<T>::Type i)
2514     : val(Nucleus::createConstantInt(i))
2515 {
2516 	RR_DEBUG_INFO_EMIT_VAR(val);
2517 }
2518 
2519 template<>
RValue(int64_t i)2520 inline RValue<Long>::RValue(int64_t i)
2521     : val(Nucleus::createConstantLong(i))
2522 {
2523 	RR_DEBUG_INFO_EMIT_VAR(val);
2524 }
2525 
2526 template<>
RValue(float f)2527 inline RValue<Float>::RValue(float f)
2528     : val(Nucleus::createConstantFloat(f))
2529 {
2530 	RR_DEBUG_INFO_EMIT_VAR(val);
2531 }
2532 
broadcast(int i,Type * type)2533 inline Value *broadcast(int i, Type *type)
2534 {
2535 	std::vector<int64_t> constantVector = { i };
2536 	return Nucleus::createConstantVector(constantVector, type);
2537 }
2538 
2539 template<>
RValue(int i)2540 inline RValue<Int4>::RValue(int i)
2541     : val(broadcast(i, Int4::type()))
2542 {
2543 	RR_DEBUG_INFO_EMIT_VAR(val);
2544 }
2545 
2546 template<>
RValue(unsigned int i)2547 inline RValue<UInt4>::RValue(unsigned int i)
2548     : val(broadcast(int(i), UInt4::type()))
2549 {
2550 	RR_DEBUG_INFO_EMIT_VAR(val);
2551 }
2552 
broadcast(float f,Type * type)2553 inline Value *broadcast(float f, Type *type)
2554 {
2555 	// See Float(float) constructor for the rationale behind this assert.
2556 	assert(std::isfinite(f));
2557 
2558 	std::vector<double> constantVector = { f };
2559 	return Nucleus::createConstantVector(constantVector, type);
2560 }
2561 
2562 template<>
RValue(float f)2563 inline RValue<Float4>::RValue(float f)
2564     : val(broadcast(f, Float4::type()))
2565 {
2566 	RR_DEBUG_INFO_EMIT_VAR(val);
2567 }
2568 
2569 template<class T>
RValue(const Reference<T> & ref)2570 RValue<T>::RValue(const Reference<T> &ref)
2571     : val(ref.loadValue())
2572 {
2573 	RR_DEBUG_INFO_EMIT_VAR(val);
2574 }
2575 
2576 template<class Vector4, int T>
operator RValue<Vector4>() const2577 Swizzle2<Vector4, T>::operator RValue<Vector4>() const
2578 {
2579 	RR_DEBUG_INFO_UPDATE_LOC();
2580 	Value *vector = parent->loadValue();
2581 
2582 	return Swizzle(RValue<Vector4>(vector), T);
2583 }
2584 
2585 template<class Vector4, int T>
operator RValue<Vector4>() const2586 Swizzle4<Vector4, T>::operator RValue<Vector4>() const
2587 {
2588 	RR_DEBUG_INFO_UPDATE_LOC();
2589 	Value *vector = parent->loadValue();
2590 
2591 	return Swizzle(RValue<Vector4>(vector), T);
2592 }
2593 
2594 template<class Vector4, int T>
operator RValue<Vector4>() const2595 SwizzleMask4<Vector4, T>::operator RValue<Vector4>() const
2596 {
2597 	RR_DEBUG_INFO_UPDATE_LOC();
2598 	Value *vector = parent->loadValue();
2599 
2600 	return Swizzle(RValue<Vector4>(vector), T);
2601 }
2602 
2603 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2604 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<Vector4> rhs)
2605 {
2606 	RR_DEBUG_INFO_UPDATE_LOC();
2607 	return Mask(*parent, rhs, T);
2608 }
2609 
2610 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2611 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)
2612 {
2613 	RR_DEBUG_INFO_UPDATE_LOC();
2614 	return Mask(*parent, Vector4(rhs), T);
2615 }
2616 
2617 template<class Vector4, int T>
operator RValue<typename Scalar<Vector4>::Type>() const2618 SwizzleMask1<Vector4, T>::operator RValue<typename Scalar<Vector4>::Type>() const  // FIXME: Call a non-template function
2619 {
2620 	RR_DEBUG_INFO_UPDATE_LOC();
2621 	return Extract(*parent, T & 0x3);
2622 }
2623 
2624 template<class Vector4, int T>
operator RValue<Vector4>() const2625 SwizzleMask1<Vector4, T>::operator RValue<Vector4>() const
2626 {
2627 	RR_DEBUG_INFO_UPDATE_LOC();
2628 	Value *vector = parent->loadValue();
2629 
2630 	return Swizzle(RValue<Vector4>(vector), T);
2631 }
2632 
2633 template<class Vector4, int T>
operator =(float x)2634 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(float x)
2635 {
2636 	RR_DEBUG_INFO_UPDATE_LOC();
2637 	return *parent = Insert(*parent, Float(x), T & 0x3);
2638 }
2639 
2640 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2641 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<Vector4> rhs)
2642 {
2643 	RR_DEBUG_INFO_UPDATE_LOC();
2644 	return Mask(*parent, Float4(rhs), T);
2645 }
2646 
2647 template<class Vector4, int T>
operator =(RValue<typename Scalar<Vector4>::Type> rhs)2648 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)  // FIXME: Call a non-template function
2649 {
2650 	RR_DEBUG_INFO_UPDATE_LOC();
2651 	return *parent = Insert(*parent, rhs, T & 0x3);
2652 }
2653 
2654 template<class Vector4, int T>
operator RValue<Vector4>() const2655 SwizzleMask2<Vector4, T>::operator RValue<Vector4>() const
2656 {
2657 	RR_DEBUG_INFO_UPDATE_LOC();
2658 	Value *vector = parent->loadValue();
2659 
2660 	return Swizzle(RValue<Float4>(vector), T);
2661 }
2662 
2663 template<class Vector4, int T>
operator =(RValue<Vector4> rhs)2664 RValue<Vector4> SwizzleMask2<Vector4, T>::operator=(RValue<Vector4> rhs)
2665 {
2666 	RR_DEBUG_INFO_UPDATE_LOC();
2667 	return Mask(*parent, Float4(rhs), T);
2668 }
2669 
2670 template<int T>
Int(const SwizzleMask1<Int4,T> & rhs)2671 Int::Int(const SwizzleMask1<Int4, T> &rhs)
2672 {
2673 	*this = rhs.operator RValue<Int>();
2674 }
2675 
2676 template<int T>
operator =(const SwizzleMask1<Int4,T> & rhs)2677 RValue<Int> Int::operator=(const SwizzleMask1<Int4, T> &rhs)
2678 {
2679 	return *this = rhs.operator RValue<Int>();
2680 }
2681 
2682 template<int T>
Float(const SwizzleMask1<Float4,T> & rhs)2683 Float::Float(const SwizzleMask1<Float4, T> &rhs)
2684 {
2685 	*this = rhs.operator RValue<Float>();
2686 }
2687 
2688 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2689 RValue<Float> Float::operator=(const SwizzleMask1<Float4, T> &rhs)
2690 {
2691 	return *this = rhs.operator RValue<Float>();
2692 }
2693 
2694 template<int T>
Int4(const SwizzleMask1<Int4,T> & rhs)2695 Int4::Int4(const SwizzleMask1<Int4, T> &rhs)
2696     : XYZW(this)
2697 {
2698 	*this = rhs.operator RValue<Int4>();
2699 }
2700 
2701 template<int T>
Float4(const SwizzleMask1<Float4,T> & rhs)2702 Float4::Float4(const SwizzleMask1<Float4, T> &rhs)
2703     : XYZW(this)
2704 {
2705 	*this = rhs.operator RValue<Float4>();
2706 }
2707 
2708 template<int T>
Float4(const Swizzle4<Float4,T> & rhs)2709 Float4::Float4(const Swizzle4<Float4, T> &rhs)
2710     : XYZW(this)
2711 {
2712 	*this = rhs.operator RValue<Float4>();
2713 }
2714 
2715 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2716 Float4::Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2717     : XYZW(this)
2718 {
2719 	RR_DEBUG_INFO_UPDATE_LOC();
2720 	*this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2721 }
2722 
2723 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const Swizzle2<Float4,Y> & y)2724 Float4::Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y)
2725     : XYZW(this)
2726 {
2727 	RR_DEBUG_INFO_UPDATE_LOC();
2728 	*this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2729 }
2730 
2731 template<int X, int Y>
Float4(const Swizzle2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2732 Float4::Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2733     : XYZW(this)
2734 {
2735 	RR_DEBUG_INFO_UPDATE_LOC();
2736 	*this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2737 }
2738 
2739 template<int X, int Y>
Float4(const SwizzleMask2<Float4,X> & x,const SwizzleMask2<Float4,Y> & y)2740 Float4::Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y)
2741     : XYZW(this)
2742 {
2743 	RR_DEBUG_INFO_UPDATE_LOC();
2744 	*this = ShuffleLowHigh(*x.parent, *y.parent, (uint16_t(X) & 0xFF00u) | (uint16_t(Y >> 8) & 0x00FFu));
2745 }
2746 
2747 template<int T>
operator =(const SwizzleMask1<Float4,T> & rhs)2748 RValue<Float4> Float4::operator=(const SwizzleMask1<Float4, T> &rhs)
2749 {
2750 	return *this = rhs.operator RValue<Float4>();
2751 }
2752 
2753 template<int T>
operator =(const Swizzle4<Float4,T> & rhs)2754 RValue<Float4> Float4::operator=(const Swizzle4<Float4, T> &rhs)
2755 {
2756 	return *this = rhs.operator RValue<Float4>();
2757 }
2758 
2759 // Returns a reactor pointer to the fixed-address ptr.
2760 RValue<Pointer<Byte>> ConstantPointer(const void *ptr);
2761 
2762 // Returns a reactor pointer to an immutable copy of the data of size bytes.
2763 RValue<Pointer<Byte>> ConstantData(const void *data, size_t size);
2764 
2765 template<class T>
Pointer(Argument<Pointer<T>> argument)2766 Pointer<T>::Pointer(Argument<Pointer<T>> argument)
2767     : alignment(1)
2768 {
2769 	this->store(argument.rvalue());
2770 }
2771 
2772 template<class T>
Pointer()2773 Pointer<T>::Pointer()
2774     : alignment(1)
2775 {}
2776 
2777 template<class T>
Pointer(RValue<Pointer<T>> rhs)2778 Pointer<T>::Pointer(RValue<Pointer<T>> rhs)
2779     : alignment(1)
2780 {
2781 	this->store(rhs);
2782 }
2783 
2784 template<class T>
Pointer(const Pointer<T> & rhs)2785 Pointer<T>::Pointer(const Pointer<T> &rhs)
2786     : alignment(rhs.alignment)
2787 {
2788 	this->store(rhs.load());
2789 }
2790 
2791 template<class T>
Pointer(const Reference<Pointer<T>> & rhs)2792 Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs)
2793     : alignment(rhs.getAlignment())
2794 {
2795 	this->store(rhs.load());
2796 }
2797 
2798 template<class T>
Pointer(std::nullptr_t)2799 Pointer<T>::Pointer(std::nullptr_t)
2800     : alignment(1)
2801 {
2802 	Value *value = Nucleus::createNullPointer(T::type());
2803 	this->storeValue(value);
2804 }
2805 
2806 template<class T>
operator =(RValue<Pointer<T>> rhs)2807 RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs)
2808 {
2809 	return this->store(rhs);
2810 }
2811 
2812 template<class T>
operator =(const Pointer<T> & rhs)2813 RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs)
2814 {
2815 	return this->store(rhs.load());
2816 }
2817 
2818 template<class T>
operator =(const Reference<Pointer<T>> & rhs)2819 RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs)
2820 {
2821 	return this->store(rhs.load());
2822 }
2823 
2824 template<class T>
operator =(std::nullptr_t)2825 RValue<Pointer<T>> Pointer<T>::operator=(std::nullptr_t)
2826 {
2827 	Value *value = Nucleus::createNullPointer(T::type());
2828 	this->storeValue(value);
2829 
2830 	return RValue<Pointer<T>>(this);
2831 }
2832 
2833 template<class T>
operator *() const2834 Reference<T> Pointer<T>::operator*() const
2835 {
2836 	return Reference<T>(this->loadValue(), alignment);
2837 }
2838 
2839 template<class T>
operator [](int index) const2840 Reference<T> Pointer<T>::operator[](int index) const
2841 {
2842 	RR_DEBUG_INFO_UPDATE_LOC();
2843 	Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), false);
2844 
2845 	return Reference<T>(element, alignment);
2846 }
2847 
2848 template<class T>
operator [](unsigned int index) const2849 Reference<T> Pointer<T>::operator[](unsigned int index) const
2850 {
2851 	RR_DEBUG_INFO_UPDATE_LOC();
2852 	Value *element = Nucleus::createGEP(this->loadValue(), T::type(), Nucleus::createConstantInt(index), true);
2853 
2854 	return Reference<T>(element, alignment);
2855 }
2856 
2857 template<class T>
operator [](RValue<Int> index) const2858 Reference<T> Pointer<T>::operator[](RValue<Int> index) const
2859 {
2860 	RR_DEBUG_INFO_UPDATE_LOC();
2861 	Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), false);
2862 
2863 	return Reference<T>(element, alignment);
2864 }
2865 
2866 template<class T>
operator [](RValue<UInt> index) const2867 Reference<T> Pointer<T>::operator[](RValue<UInt> index) const
2868 {
2869 	RR_DEBUG_INFO_UPDATE_LOC();
2870 	Value *element = Nucleus::createGEP(this->loadValue(), T::type(), index.value(), true);
2871 
2872 	return Reference<T>(element, alignment);
2873 }
2874 
2875 template<class T>
type()2876 Type *Pointer<T>::type()
2877 {
2878 	return Nucleus::getPointerType(T::type());
2879 }
2880 
2881 template<class T, int S>
Array(int size)2882 Array<T, S>::Array(int size)
2883     : LValue<T>(size)
2884 {
2885 }
2886 
2887 template<class T, int S>
operator [](int index)2888 Reference<T> Array<T, S>::operator[](int index)
2889 {
2890 	assert(index < Variable::getArraySize());
2891 	Value *element = this->getElementPointer(Nucleus::createConstantInt(index), false);
2892 
2893 	return Reference<T>(element);
2894 }
2895 
2896 template<class T, int S>
operator [](unsigned int index)2897 Reference<T> Array<T, S>::operator[](unsigned int index)
2898 {
2899 	assert(index < static_cast<unsigned int>(Variable::getArraySize()));
2900 	Value *element = this->getElementPointer(Nucleus::createConstantInt(index), true);
2901 
2902 	return Reference<T>(element);
2903 }
2904 
2905 template<class T, int S>
operator [](RValue<Int> index)2906 Reference<T> Array<T, S>::operator[](RValue<Int> index)
2907 {
2908 	Value *element = this->getElementPointer(index.value(), false);
2909 
2910 	return Reference<T>(element);
2911 }
2912 
2913 template<class T, int S>
operator [](RValue<UInt> index)2914 Reference<T> Array<T, S>::operator[](RValue<UInt> index)
2915 {
2916 	Value *element = this->getElementPointer(index.value(), true);
2917 
2918 	return Reference<T>(element);
2919 }
2920 
2921 //	template<class T>
2922 //	RValue<Array<T>> operator++(Array<T> &val, int)
2923 //	{
2924 //		// FIXME: Requires storing the address of the array
2925 //	}
2926 
2927 //	template<class T>
2928 //	const Array<T> &operator++(Array<T> &val)
2929 //	{
2930 //		// FIXME: Requires storing the address of the array
2931 //	}
2932 
2933 //	template<class T>
2934 //	RValue<Array<T>> operator--(Array<T> &val, int)
2935 //	{
2936 //		// FIXME: Requires storing the address of the array
2937 //	}
2938 
2939 //	template<class T>
2940 //	const Array<T> &operator--(Array<T> &val)
2941 //	{
2942 //		// FIXME: Requires storing the address of the array
2943 //	}
2944 
2945 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,RValue<T> ifFalse)2946 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, RValue<T> ifFalse)
2947 {
2948 	RR_DEBUG_INFO_UPDATE_LOC();
2949 	return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), ifFalse.value()));
2950 }
2951 
2952 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,RValue<T> ifFalse)2953 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, RValue<T> ifFalse)
2954 {
2955 	RR_DEBUG_INFO_UPDATE_LOC();
2956 	Value *trueValue = ifTrue.loadValue();
2957 
2958 	return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, ifFalse.value()));
2959 }
2960 
2961 template<class T>
IfThenElse(RValue<Bool> condition,RValue<T> ifTrue,const T & ifFalse)2962 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, const T &ifFalse)
2963 {
2964 	RR_DEBUG_INFO_UPDATE_LOC();
2965 	Value *falseValue = ifFalse.loadValue();
2966 
2967 	return RValue<T>(Nucleus::createSelect(condition.value(), ifTrue.value(), falseValue));
2968 }
2969 
2970 template<class T>
IfThenElse(RValue<Bool> condition,const T & ifTrue,const T & ifFalse)2971 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, const T &ifFalse)
2972 {
2973 	RR_DEBUG_INFO_UPDATE_LOC();
2974 	Value *trueValue = ifTrue.loadValue();
2975 	Value *falseValue = ifFalse.loadValue();
2976 
2977 	return RValue<T>(Nucleus::createSelect(condition.value(), trueValue, falseValue));
2978 }
2979 
2980 template<typename Return, typename... Arguments>
Function()2981 Function<Return(Arguments...)>::Function()
2982     : core(new Nucleus())
2983 {
2984 	Type *types[] = { Arguments::type()... };
2985 	for(Type *type : types)
2986 	{
2987 		if(type != Void::type())
2988 		{
2989 			arguments.push_back(type);
2990 		}
2991 	}
2992 
2993 	Nucleus::createFunction(Return::type(), arguments);
2994 }
2995 
2996 template<typename Return, typename... Arguments>
operator ()(const char * name,...)2997 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const char *name, ...)
2998 {
2999 	char fullName[1024 + 1];
3000 
3001 	va_list vararg;
3002 	va_start(vararg, name);
3003 	vsnprintf(fullName, 1024, name, vararg);
3004 	va_end(vararg);
3005 
3006 	auto routine = core->acquireRoutine(fullName);
3007 	core.reset(nullptr);
3008 
3009 	return routine;
3010 }
3011 
3012 template<class T, class S>
ReinterpretCast(RValue<S> val)3013 RValue<T> ReinterpretCast(RValue<S> val)
3014 {
3015 	RR_DEBUG_INFO_UPDATE_LOC();
3016 	return RValue<T>(Nucleus::createBitCast(val.value(), T::type()));
3017 }
3018 
3019 template<class T, class S>
ReinterpretCast(const LValue<S> & var)3020 RValue<T> ReinterpretCast(const LValue<S> &var)
3021 {
3022 	RR_DEBUG_INFO_UPDATE_LOC();
3023 	Value *val = var.loadValue();
3024 
3025 	return RValue<T>(Nucleus::createBitCast(val, T::type()));
3026 }
3027 
3028 template<class T, class S>
ReinterpretCast(const Reference<S> & var)3029 RValue<T> ReinterpretCast(const Reference<S> &var)
3030 {
3031 	return ReinterpretCast<T>(RValue<S>(var));
3032 }
3033 
3034 template<class T>
As(Value * val)3035 RValue<T> As(Value *val)
3036 {
3037 	RR_DEBUG_INFO_UPDATE_LOC();
3038 	return RValue<T>(Nucleus::createBitCast(val, T::type()));
3039 }
3040 
3041 template<class T, class S>
As(RValue<S> val)3042 RValue<T> As(RValue<S> val)
3043 {
3044 	return ReinterpretCast<T>(val);
3045 }
3046 
3047 template<class T, class S>
As(const LValue<S> & var)3048 RValue<T> As(const LValue<S> &var)
3049 {
3050 	return ReinterpretCast<T>(var);
3051 }
3052 
3053 template<class T, class S>
As(const Reference<S> & val)3054 RValue<T> As(const Reference<S> &val)
3055 {
3056 	return ReinterpretCast<T>(val);
3057 }
3058 
3059 // Calls the function pointer fptr with the given arguments, return type
3060 // and parameter types. Returns the call's return value if the function has
3061 // a non-void return type.
3062 Value *Call(RValue<Pointer<Byte>> fptr, Type *retTy, std::initializer_list<Value *> args, std::initializer_list<Type *> paramTys);
3063 
3064 template<typename F>
3065 class CallHelper
3066 {};
3067 
3068 template<typename Return, typename... Arguments>
3069 class CallHelper<Return(Arguments...)>
3070 {
3071 public:
3072 	using RReturn = CToReactorT<Return>;
3073 
Call(Return (fptr)(Arguments...),CToReactorT<Arguments>...args)3074 	static inline RReturn Call(Return(fptr)(Arguments...), CToReactorT<Arguments>... args)
3075 	{
3076 		return RValue<RReturn>(rr::Call(
3077 		    ConstantPointer(reinterpret_cast<void *>(fptr)),
3078 		    RReturn::type(),
3079 		    { ValueOf(args)... },
3080 		    { CToReactorT<Arguments>::type()... }));
3081 	}
3082 
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3083 	static inline RReturn Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3084 	{
3085 		return RValue<RReturn>(rr::Call(
3086 		    fptr,
3087 		    RReturn::type(),
3088 		    { ValueOf(args)... },
3089 		    { CToReactorT<Arguments>::type()... }));
3090 	}
3091 };
3092 
3093 template<typename... Arguments>
3094 class CallHelper<void(Arguments...)>
3095 {
3096 public:
Call(void (fptr)(Arguments...),CToReactorT<Arguments>...args)3097 	static inline void Call(void(fptr)(Arguments...), CToReactorT<Arguments>... args)
3098 	{
3099 		rr::Call(ConstantPointer(reinterpret_cast<void *>(fptr)),
3100 		         Void::type(),
3101 		         { ValueOf(args)... },
3102 		         { CToReactorT<Arguments>::type()... });
3103 	}
3104 
Call(Pointer<Byte> fptr,CToReactorT<Arguments>...args)3105 	static inline void Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
3106 	{
3107 		rr::Call(fptr,
3108 		         Void::type(),
3109 		         { ValueOf(args)... },
3110 		         { CToReactorT<Arguments>::type()... });
3111 	}
3112 };
3113 
3114 template<typename T>
CastToReactor(const T & v)3115 inline ReactorTypeT<T> CastToReactor(const T &v)
3116 {
3117 	return ReactorType<T>::cast(v);
3118 }
3119 
3120 // Calls the static function pointer fptr with the given arguments args.
3121 template<typename Return, typename... CArgs, typename... RArgs>
Call(Return (fptr)(CArgs...),RArgs &&...args)3122 inline CToReactorT<Return> Call(Return(fptr)(CArgs...), RArgs &&...args)
3123 {
3124 	return CallHelper<Return(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3125 }
3126 
3127 // Calls the static function pointer fptr with the given arguments args.
3128 // Overload for calling functions with void return type.
3129 template<typename... CArgs, typename... RArgs>
Call(void (fptr)(CArgs...),RArgs &&...args)3130 inline void Call(void(fptr)(CArgs...), RArgs &&...args)
3131 {
3132 	CallHelper<void(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3133 }
3134 
3135 // Calls the member function pointer fptr with the given arguments args.
3136 // object can be a Class*, or a Pointer<Byte>.
3137 template<typename Return, typename Class, typename C, typename... CArgs, typename... RArgs>
Call(Return (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3138 inline CToReactorT<Return> Call(Return (Class::*fptr)(CArgs...), C &&object, RArgs &&...args)
3139 {
3140 	using Helper = CallHelper<Return(Class *, void *, CArgs...)>;
3141 	using fptrTy = decltype(fptr);
3142 
3143 	struct Static
3144 	{
3145 		static inline Return Call(Class *object, void *fptrptr, CArgs... args)
3146 		{
3147 			auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3148 			return (object->*fptr)(std::forward<CArgs>(args)...);
3149 		}
3150 	};
3151 
3152 	return Helper::Call(&Static::Call,
3153 	                    CastToReactor(object),
3154 	                    ConstantData(&fptr, sizeof(fptr)),
3155 	                    CastToReactor(std::forward<RArgs>(args))...);
3156 }
3157 
3158 // Calls the member function pointer fptr with the given arguments args.
3159 // Overload for calling functions with void return type.
3160 // object can be a Class*, or a Pointer<Byte>.
3161 template<typename Class, typename C, typename... CArgs, typename... RArgs>
Call(void (Class::* fptr)(CArgs...),C && object,RArgs &&...args)3162 inline void Call(void (Class::*fptr)(CArgs...), C &&object, RArgs &&...args)
3163 {
3164 	using Helper = CallHelper<void(Class *, void *, CArgs...)>;
3165 	using fptrTy = decltype(fptr);
3166 
3167 	struct Static
3168 	{
3169 		static inline void Call(Class *object, void *fptrptr, CArgs... args)
3170 		{
3171 			auto fptr = *reinterpret_cast<fptrTy *>(fptrptr);
3172 			(object->*fptr)(std::forward<CArgs>(args)...);
3173 		}
3174 	};
3175 
3176 	Helper::Call(&Static::Call,
3177 	             CastToReactor(object),
3178 	             ConstantData(&fptr, sizeof(fptr)),
3179 	             CastToReactor(std::forward<RArgs>(args))...);
3180 }
3181 
3182 // NonVoidFunction<F> and VoidFunction<F> are helper classes which define ReturnType
3183 // when F matches a non-void fuction signature or void function signature, respectively,
3184 // as the function's return type.
3185 template<typename F>
3186 struct NonVoidFunction
3187 {};
3188 
3189 template<typename Return, typename... Arguments>
3190 struct NonVoidFunction<Return(Arguments...)>
3191 {
3192 	using ReturnType = Return;
3193 };
3194 
3195 template<typename... Arguments>
3196 struct NonVoidFunction<void(Arguments...)>
3197 {
3198 };
3199 
3200 template<typename F>
3201 using NonVoidFunctionReturnType = typename NonVoidFunction<F>::ReturnType;
3202 
3203 template<typename F>
3204 struct VoidFunction
3205 {};
3206 
3207 template<typename... Arguments>
3208 struct VoidFunction<void(Arguments...)>
3209 {
3210 	using ReturnType = void;
3211 };
3212 
3213 template<typename F>
3214 using VoidFunctionReturnType = typename VoidFunction<F>::ReturnType;
3215 
3216 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3217 // Overload for calling functions with non-void return type.
3218 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3219 inline CToReactorT<NonVoidFunctionReturnType<FUNCTION_SIGNATURE>> Call(Pointer<Byte> fptr, RArgs &&...args)
3220 {
3221 	return CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3222 }
3223 
3224 // Calls the Reactor function pointer fptr with the signature FUNCTION_SIGNATURE and arguments.
3225 // Overload for calling functions with void return type.
3226 template<typename FUNCTION_SIGNATURE, typename... RArgs>
Call(Pointer<Byte> fptr,RArgs &&...args)3227 inline VoidFunctionReturnType<FUNCTION_SIGNATURE> Call(Pointer<Byte> fptr, RArgs &&...args)
3228 {
3229 	CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
3230 }
3231 
3232 // Breakpoint emits an instruction that will cause the application to trap.
3233 // This can be used to stop an attached debugger at the given call.
3234 void Breakpoint();
3235 
3236 class ForData
3237 {
3238 public:
ForData(bool init)3239 	ForData(bool init)
3240 	    : loopOnce(init)
3241 	{
3242 	}
3243 
operator bool()3244 	operator bool()
3245 	{
3246 		return loopOnce;
3247 	}
3248 
operator =(bool value)3249 	bool operator=(bool value)
3250 	{
3251 		return loopOnce = value;
3252 	}
3253 
setup()3254 	bool setup()
3255 	{
3256 		RR_DEBUG_INFO_FLUSH();
3257 		if(Nucleus::getInsertBlock() != endBB)
3258 		{
3259 			testBB = Nucleus::createBasicBlock();
3260 
3261 			Nucleus::createBr(testBB);
3262 			Nucleus::setInsertBlock(testBB);
3263 
3264 			return true;
3265 		}
3266 
3267 		return false;
3268 	}
3269 
test(RValue<Bool> cmp)3270 	bool test(RValue<Bool> cmp)
3271 	{
3272 		BasicBlock *bodyBB = Nucleus::createBasicBlock();
3273 		endBB = Nucleus::createBasicBlock();
3274 
3275 		Nucleus::createCondBr(cmp.value(), bodyBB, endBB);
3276 		Nucleus::setInsertBlock(bodyBB);
3277 
3278 		return true;
3279 	}
3280 
end()3281 	void end()
3282 	{
3283 		Nucleus::createBr(testBB);
3284 		Nucleus::setInsertBlock(endBB);
3285 	}
3286 
3287 private:
3288 	BasicBlock *testBB = nullptr;
3289 	BasicBlock *endBB = nullptr;
3290 	bool loopOnce = true;
3291 };
3292 
3293 class IfElseData
3294 {
3295 public:
IfElseData(RValue<Bool> cmp)3296 	IfElseData(RValue<Bool> cmp)
3297 	{
3298 		trueBB = Nucleus::createBasicBlock();
3299 		falseBB = Nucleus::createBasicBlock();
3300 		endBB = falseBB;  // Until we encounter an Else statement, these are the same.
3301 
3302 		Nucleus::createCondBr(cmp.value(), trueBB, falseBB);
3303 		Nucleus::setInsertBlock(trueBB);
3304 	}
3305 
~IfElseData()3306 	~IfElseData()
3307 	{
3308 		Nucleus::createBr(endBB);
3309 		Nucleus::setInsertBlock(endBB);
3310 	}
3311 
operator int()3312 	operator int()
3313 	{
3314 		return iteration;
3315 	}
3316 
operator ++()3317 	IfElseData &operator++()
3318 	{
3319 		++iteration;
3320 
3321 		return *this;
3322 	}
3323 
elseClause()3324 	void elseClause()
3325 	{
3326 		endBB = Nucleus::createBasicBlock();
3327 		Nucleus::createBr(endBB);
3328 
3329 		Nucleus::setInsertBlock(falseBB);
3330 	}
3331 
3332 private:
3333 	BasicBlock *trueBB = nullptr;
3334 	BasicBlock *falseBB = nullptr;
3335 	BasicBlock *endBB = nullptr;
3336 	int iteration = 0;
3337 };
3338 
3339 #define For(init, cond, inc)                        \
3340 	for(ForData for__ = true; for__; for__ = false) \
3341 		for(init; for__.setup() && for__.test(cond); inc, for__.end())
3342 
3343 #define While(cond) For((void)0, cond, (void)0)
3344 
3345 #define Do                                                \
3346 	{                                                     \
3347 		BasicBlock *body__ = Nucleus::createBasicBlock(); \
3348 		Nucleus::createBr(body__);                        \
3349 		Nucleus::setInsertBlock(body__);
3350 
3351 #define Until(cond)                                       \
3352 	BasicBlock *end__ = Nucleus::createBasicBlock();      \
3353 	Nucleus::createCondBr((cond).value(), end__, body__); \
3354 	Nucleus::setInsertBlock(end__);                       \
3355 	}                                                     \
3356 	do                                                    \
3357 	{                                                     \
3358 	} while(false)  // Require a semi-colon at the end of the Until()
3359 
3360 enum
3361 {
3362 	IF_BLOCK__,
3363 	ELSE_CLAUSE__,
3364 	ELSE_BLOCK__,
3365 	IFELSE_NUM__
3366 };
3367 
3368 #define If(cond)                                                          \
3369 	for(IfElseData ifElse__{ cond }; ifElse__ < IFELSE_NUM__; ++ifElse__) \
3370 		if(ifElse__ == IF_BLOCK__)
3371 
3372 #define Else                           \
3373 	else if(ifElse__ == ELSE_CLAUSE__) \
3374 	{                                  \
3375 		ifElse__.elseClause();         \
3376 	}                                  \
3377 	else  // ELSE_BLOCK__
3378 
3379 // The OFFSET macro is a generalization of the offsetof() macro defined in <cstddef>.
3380 // It allows e.g. getting the offset of array elements, even when indexed dynamically.
3381 // We cast the address '32' and subtract it again, because null-dereference is undefined behavior.
3382 #define OFFSET(s, m) ((int)(size_t) & reinterpret_cast<const volatile char &>((((s *)32)->m)) - 32)
3383 
3384 }  // namespace rr
3385 
3386 #include "Traits.inl"
3387 
3388 #endif  // rr_Reactor_hpp
3389