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