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