blob: b958b2d73c9b27f8b55fe199efee11468c5d774f [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// 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
Nicolas Capens48461502018-08-06 14:20:45 -040015#ifndef rr_Reactor_hpp
16#define rr_Reactor_hpp
Nicolas Capensd022e412016-09-26 13:30:14 -040017
Nicolas Capens0bac2852016-05-07 06:09:58 -040018#include "Nucleus.hpp"
19#include "Routine.hpp"
Ben Clayton351be422019-04-30 12:26:57 +010020#include "Traits.hpp"
Nicolas Capens0bac2852016-05-07 06:09:58 -040021
Nicolas Capens4dd1eff2017-08-04 09:33:04 -040022#include <cassert>
Nicolas Capens3bbc5e12016-09-27 10:49:52 -040023#include <cstddef>
Chris Forbes878d4b02019-01-21 10:48:35 -080024#include <cstdio>
Ben Clayton1bc7ee92019-02-14 18:43:22 +000025
26#include <string>
Ben Clayton169872e2019-02-27 23:58:35 +000027#include <tuple>
Nicolas Capens0192d152019-03-27 14:46:07 -040028#include <unordered_set>
Ben Clayton1bc7ee92019-02-14 18:43:22 +000029
Chris Forbesc2968062019-03-19 16:48:03 -070030#undef Bool // b/127920555
Nicolas Capens3bbc5e12016-09-27 10:49:52 -040031
Ben Clayton5875be52019-04-11 14:57:40 -040032#if !defined(NDEBUG)
Ben Clayton1bc7ee92019-02-14 18:43:22 +000033#define ENABLE_RR_PRINT 1 // Enables RR_PRINT(), RR_WATCH()
Ben Clayton5875be52019-04-11 14:57:40 -040034#endif // !defined(NDEBUG)
Ben Clayton1bc7ee92019-02-14 18:43:22 +000035
Ben Claytonac07ed82019-03-26 14:17:41 +000036#ifdef ENABLE_RR_DEBUG_INFO
37 // Functions used for generating JIT debug info.
38 // See docs/ReactorDebugInfo.md for more information.
39 namespace rr
40 {
41 // Update the current source location for debug.
42 void EmitDebugLocation();
43 // Bind value to its symbolic name taken from the backtrace.
44 void EmitDebugVariable(class Value* value);
45 // Flush any pending variable bindings before the line ends.
46 void FlushDebug();
47 }
48 #define RR_DEBUG_INFO_UPDATE_LOC() rr::EmitDebugLocation()
49 #define RR_DEBUG_INFO_EMIT_VAR(value) rr::EmitDebugVariable(value)
50 #define RR_DEBUG_INFO_FLUSH() rr::FlushDebug()
51#else
52 #define RR_DEBUG_INFO_UPDATE_LOC()
53 #define RR_DEBUG_INFO_EMIT_VAR(value)
54 #define RR_DEBUG_INFO_FLUSH()
55#endif // ENABLE_RR_DEBUG_INFO
56
Nicolas Capens48461502018-08-06 14:20:45 -040057namespace rr
Nicolas Capens0bac2852016-05-07 06:09:58 -040058{
Ben Claytonc7904162019-04-17 17:35:48 -040059 struct Capabilities
60 {
Ben Clayton1c82c7b2019-04-30 12:49:27 +010061 bool CallSupported; // Support for rr::Call()
62 bool CoroutinesSupported; // Support for rr::Coroutine<F>
Ben Claytonc7904162019-04-17 17:35:48 -040063 };
64 extern const Capabilities Caps;
65
Nicolas Capenseb253d02016-11-18 14:40:40 -050066 class Bool;
Nicolas Capensd022e412016-09-26 13:30:14 -040067 class Byte;
68 class SByte;
69 class Byte4;
70 class SByte4;
71 class Byte8;
72 class SByte8;
73 class Byte16;
74 class SByte16;
75 class Short;
76 class UShort;
Nicolas Capens16b5f152016-10-13 13:39:01 -040077 class Short2;
78 class UShort2;
Nicolas Capensd022e412016-09-26 13:30:14 -040079 class Short4;
80 class UShort4;
81 class Short8;
82 class UShort8;
83 class Int;
84 class UInt;
85 class Int2;
86 class UInt2;
87 class Int4;
88 class UInt4;
89 class Long;
Alexis Hetu734e2572018-12-20 14:00:49 -050090 class Half;
Nicolas Capensd022e412016-09-26 13:30:14 -040091 class Float;
92 class Float2;
93 class Float4;
94
95 class Void
96 {
97 public:
98 static Type *getType();
99
100 static bool isVoid()
101 {
102 return true;
103 }
Nicolas Capensd022e412016-09-26 13:30:14 -0400104 };
105
106 template<class T>
107 class RValue;
108
109 template<class T>
110 class Pointer;
111
Nicolas Capens297d26e2016-11-18 12:52:17 -0500112 class Variable
113 {
Nicolas Capens0192d152019-03-27 14:46:07 -0400114 friend class Nucleus;
Ben Clayton1bc7ee92019-02-14 18:43:22 +0000115 friend class PrintValue;
Nicolas Capens5da8d8d2019-03-27 14:45:34 -0400116
Nicolas Capens0192d152019-03-27 14:46:07 -0400117 Variable() = delete;
Nicolas Capens5da8d8d2019-03-27 14:45:34 -0400118 Variable &operator=(const Variable&) = delete;
119
120 public:
Nicolas Capens0192d152019-03-27 14:46:07 -0400121 void materialize() const;
122
123 Value *loadValue() const;
124 Value *storeValue(Value *value) const;
125
126 Value *getBaseAddress() const;
127 Value *getElementPointer(Value *index, bool unsignedIndex) const;
Nicolas Capens5da8d8d2019-03-27 14:45:34 -0400128
129 protected:
Nicolas Capens0192d152019-03-27 14:46:07 -0400130 Variable(Type *type, int arraySize);
131 Variable(const Variable&) = default;
132
133 ~Variable();
134
Ben Clayton83dd4522019-06-27 10:37:00 +0100135 const int arraySize;
136
Nicolas Capens0192d152019-03-27 14:46:07 -0400137 private:
138 static void materializeAll();
139 static void killUnmaterialized();
140
141 static std::unordered_set<Variable*> unmaterializedVariables;
142
143 Type *const type;
Nicolas Capens0192d152019-03-27 14:46:07 -0400144 mutable Value *rvalue = nullptr;
145 mutable Value *address = nullptr;
Nicolas Capens297d26e2016-11-18 12:52:17 -0500146 };
147
Nicolas Capens22479eb2016-09-28 22:34:26 -0400148 template<class T>
Nicolas Capens297d26e2016-11-18 12:52:17 -0500149 class LValue : public Variable
Nicolas Capensd022e412016-09-26 13:30:14 -0400150 {
151 public:
Nicolas Capens22479eb2016-09-28 22:34:26 -0400152 LValue(int arraySize = 0);
Nicolas Capensd022e412016-09-26 13:30:14 -0400153
Nicolas Capens297d26e2016-11-18 12:52:17 -0500154 RValue<Pointer<T>> operator&();
155
Nicolas Capensd022e412016-09-26 13:30:14 -0400156 static bool isVoid()
157 {
158 return false;
159 }
Ben Clayton0953d9b2019-06-25 20:57:06 +0100160
161 // self() returns the this pointer to this LValue<T> object.
162 // This function exists because operator&() is overloaded.
163 inline LValue<T>* self() { return this; }
Nicolas Capensd022e412016-09-26 13:30:14 -0400164 };
165
166 template<class T>
167 class Reference
168 {
169 public:
Ben Clayton208ed402019-05-03 22:30:03 +0100170 using reference_underlying_type = T;
171
Nicolas Capensd022e412016-09-26 13:30:14 -0400172 explicit Reference(Value *pointer, int alignment = 1);
173
174 RValue<T> operator=(RValue<T> rhs) const;
175 RValue<T> operator=(const Reference<T> &ref) const;
176
177 RValue<T> operator+=(RValue<T> rhs) const;
178
Ben Claytonec255732019-02-27 13:51:22 +0000179 RValue<Pointer<T>> operator&() const { return RValue<Pointer<T>>(address); }
180
Nicolas Capensd022e412016-09-26 13:30:14 -0400181 Value *loadValue() const;
182 int getAlignment() const;
183
184 private:
185 Value *address;
186
187 const int alignment;
188 };
189
190 template<class T>
Ben Clayton35e90e22019-03-15 10:06:06 +0000191 struct BoolLiteral
Nicolas Capensd022e412016-09-26 13:30:14 -0400192 {
193 struct type;
194 };
195
Nicolas Capenseb253d02016-11-18 14:40:40 -0500196 template<>
Ben Clayton35e90e22019-03-15 10:06:06 +0000197 struct BoolLiteral<Bool>
Nicolas Capenseb253d02016-11-18 14:40:40 -0500198 {
199 typedef bool type;
200 };
201
Ben Clayton35e90e22019-03-15 10:06:06 +0000202 template<class T>
203 struct IntLiteral
204 {
205 struct type;
206 };
207
Nicolas Capenseb253d02016-11-18 14:40:40 -0500208 template<>
209 struct IntLiteral<Int>
Nicolas Capensd022e412016-09-26 13:30:14 -0400210 {
211 typedef int type;
212 };
213
Nicolas Capenseb253d02016-11-18 14:40:40 -0500214 template<>
215 struct IntLiteral<UInt>
Nicolas Capensd022e412016-09-26 13:30:14 -0400216 {
217 typedef unsigned int type;
218 };
219
Nicolas Capenseb253d02016-11-18 14:40:40 -0500220 template<>
221 struct IntLiteral<Long>
Nicolas Capensd022e412016-09-26 13:30:14 -0400222 {
223 typedef int64_t type;
224 };
225
226 template<class T>
227 struct FloatLiteral
228 {
229 struct type;
230 };
231
Nicolas Capenseb253d02016-11-18 14:40:40 -0500232 template<>
233 struct FloatLiteral<Float>
Nicolas Capensd022e412016-09-26 13:30:14 -0400234 {
235 typedef float type;
236 };
237
238 template<class T>
239 class RValue
240 {
241 public:
Ben Clayton351be422019-04-30 12:26:57 +0100242 using rvalue_underlying_type = T;
243
Nicolas Capensd022e412016-09-26 13:30:14 -0400244 explicit RValue(Value *rvalue);
245
Ben Claytonac07ed82019-03-26 14:17:41 +0000246#ifdef ENABLE_RR_DEBUG_INFO
247 RValue(const RValue<T> &rvalue);
248#endif // ENABLE_RR_DEBUG_INFO
249
Nicolas Capensd022e412016-09-26 13:30:14 -0400250 RValue(const T &lvalue);
Ben Clayton35e90e22019-03-15 10:06:06 +0000251 RValue(typename BoolLiteral<T>::type i);
Nicolas Capensd022e412016-09-26 13:30:14 -0400252 RValue(typename IntLiteral<T>::type i);
253 RValue(typename FloatLiteral<T>::type f);
254 RValue(const Reference<T> &rhs);
255
256 RValue<T> &operator=(const RValue<T>&) = delete;
257
258 Value *value; // FIXME: Make private
259 };
260
261 template<typename T>
262 struct Argument
263 {
264 explicit Argument(Value *value) : value(value) {}
265
266 Value *value;
267 };
268
Nicolas Capens297d26e2016-11-18 12:52:17 -0500269 class Bool : public LValue<Bool>
Nicolas Capensd022e412016-09-26 13:30:14 -0400270 {
271 public:
272 Bool(Argument<Bool> argument);
273
Nicolas Capensa25311a2017-01-16 17:19:00 -0500274 Bool() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400275 Bool(bool x);
276 Bool(RValue<Bool> rhs);
277 Bool(const Bool &rhs);
278 Bool(const Reference<Bool> &rhs);
279
Nicolas Capens96d4e092016-11-18 14:22:38 -0500280 // RValue<Bool> operator=(bool rhs); // FIXME: Implement
281 RValue<Bool> operator=(RValue<Bool> rhs);
282 RValue<Bool> operator=(const Bool &rhs);
283 RValue<Bool> operator=(const Reference<Bool> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400284
285 static Type *getType();
286 };
287
288 RValue<Bool> operator!(RValue<Bool> val);
289 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs);
290 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs);
Ben Claytonf3b57972019-03-15 09:56:47 +0000291 RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs);
292 RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400293
Nicolas Capens297d26e2016-11-18 12:52:17 -0500294 class Byte : public LValue<Byte>
Nicolas Capensd022e412016-09-26 13:30:14 -0400295 {
296 public:
297 Byte(Argument<Byte> argument);
298
299 explicit Byte(RValue<Int> cast);
300 explicit Byte(RValue<UInt> cast);
301 explicit Byte(RValue<UShort> cast);
302
Nicolas Capensa25311a2017-01-16 17:19:00 -0500303 Byte() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400304 Byte(int x);
305 Byte(unsigned char x);
306 Byte(RValue<Byte> rhs);
307 Byte(const Byte &rhs);
308 Byte(const Reference<Byte> &rhs);
309
Nicolas Capens96d4e092016-11-18 14:22:38 -0500310 // RValue<Byte> operator=(unsigned char rhs); // FIXME: Implement
311 RValue<Byte> operator=(RValue<Byte> rhs);
312 RValue<Byte> operator=(const Byte &rhs);
313 RValue<Byte> operator=(const Reference<Byte> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400314
315 static Type *getType();
316 };
317
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%(RValue<Byte> lhs, RValue<Byte> rhs);
323 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs);
324 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs);
325 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs);
326 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs);
327 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500328 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%=(Byte &lhs, RValue<Byte> rhs);
333 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs);
334 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs);
335 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs);
336 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs);
337 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400338 RValue<Byte> operator+(RValue<Byte> val);
339 RValue<Byte> operator-(RValue<Byte> val);
340 RValue<Byte> operator~(RValue<Byte> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500341 RValue<Byte> operator++(Byte &val, int); // Post-increment
342 const Byte &operator++(Byte &val); // Pre-increment
343 RValue<Byte> operator--(Byte &val, int); // Post-decrement
344 const Byte &operator--(Byte &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400345 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs);
346 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs);
347 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs);
348 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs);
349 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs);
350 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs);
351
Nicolas Capens297d26e2016-11-18 12:52:17 -0500352 class SByte : public LValue<SByte>
Nicolas Capensd022e412016-09-26 13:30:14 -0400353 {
354 public:
355 SByte(Argument<SByte> argument);
356
357 explicit SByte(RValue<Int> cast);
358 explicit SByte(RValue<Short> cast);
359
Nicolas Capensa25311a2017-01-16 17:19:00 -0500360 SByte() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400361 SByte(signed char x);
362 SByte(RValue<SByte> rhs);
363 SByte(const SByte &rhs);
364 SByte(const Reference<SByte> &rhs);
365
Nicolas Capens96d4e092016-11-18 14:22:38 -0500366 // RValue<SByte> operator=(signed char rhs); // FIXME: Implement
367 RValue<SByte> operator=(RValue<SByte> rhs);
368 RValue<SByte> operator=(const SByte &rhs);
369 RValue<SByte> operator=(const Reference<SByte> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400370
371 static Type *getType();
372 };
373
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%(RValue<SByte> lhs, RValue<SByte> rhs);
379 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs);
380 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs);
381 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs);
382 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs);
383 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500384 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%=(SByte &lhs, RValue<SByte> rhs);
389 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs);
390 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs);
391 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs);
392 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs);
393 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400394 RValue<SByte> operator+(RValue<SByte> val);
395 RValue<SByte> operator-(RValue<SByte> val);
396 RValue<SByte> operator~(RValue<SByte> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500397 RValue<SByte> operator++(SByte &val, int); // Post-increment
398 const SByte &operator++(SByte &val); // Pre-increment
399 RValue<SByte> operator--(SByte &val, int); // Post-decrement
400 const SByte &operator--(SByte &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400401 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs);
402 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs);
403 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs);
404 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs);
405 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs);
406 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs);
407
Nicolas Capens297d26e2016-11-18 12:52:17 -0500408 class Short : public LValue<Short>
Nicolas Capensd022e412016-09-26 13:30:14 -0400409 {
410 public:
411 Short(Argument<Short> argument);
412
413 explicit Short(RValue<Int> cast);
414
Nicolas Capensa25311a2017-01-16 17:19:00 -0500415 Short() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400416 Short(short x);
417 Short(RValue<Short> rhs);
418 Short(const Short &rhs);
419 Short(const Reference<Short> &rhs);
420
Nicolas Capens96d4e092016-11-18 14:22:38 -0500421 // RValue<Short> operator=(short rhs); // FIXME: Implement
422 RValue<Short> operator=(RValue<Short> rhs);
423 RValue<Short> operator=(const Short &rhs);
424 RValue<Short> operator=(const Reference<Short> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400425
426 static Type *getType();
427 };
428
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%(RValue<Short> lhs, RValue<Short> rhs);
434 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs);
435 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs);
436 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs);
437 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs);
438 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500439 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%=(Short &lhs, RValue<Short> rhs);
444 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs);
445 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs);
446 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs);
447 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs);
448 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400449 RValue<Short> operator+(RValue<Short> val);
450 RValue<Short> operator-(RValue<Short> val);
451 RValue<Short> operator~(RValue<Short> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500452 RValue<Short> operator++(Short &val, int); // Post-increment
453 const Short &operator++(Short &val); // Pre-increment
454 RValue<Short> operator--(Short &val, int); // Post-decrement
455 const Short &operator--(Short &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400456 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs);
457 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs);
458 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs);
459 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs);
460 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs);
461 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs);
462
Nicolas Capens297d26e2016-11-18 12:52:17 -0500463 class UShort : public LValue<UShort>
Nicolas Capensd022e412016-09-26 13:30:14 -0400464 {
465 public:
466 UShort(Argument<UShort> argument);
467
468 explicit UShort(RValue<UInt> cast);
469 explicit UShort(RValue<Int> cast);
470
Nicolas Capensa25311a2017-01-16 17:19:00 -0500471 UShort() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400472 UShort(unsigned short x);
473 UShort(RValue<UShort> rhs);
474 UShort(const UShort &rhs);
475 UShort(const Reference<UShort> &rhs);
476
Nicolas Capens96d4e092016-11-18 14:22:38 -0500477 // RValue<UShort> operator=(unsigned short rhs); // FIXME: Implement
478 RValue<UShort> operator=(RValue<UShort> rhs);
479 RValue<UShort> operator=(const UShort &rhs);
480 RValue<UShort> operator=(const Reference<UShort> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400481
482 static Type *getType();
483 };
484
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%(RValue<UShort> lhs, RValue<UShort> rhs);
490 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs);
491 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs);
492 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs);
493 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs);
494 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500495 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%=(UShort &lhs, RValue<UShort> rhs);
500 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs);
501 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs);
502 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs);
503 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs);
504 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400505 RValue<UShort> operator+(RValue<UShort> val);
506 RValue<UShort> operator-(RValue<UShort> val);
507 RValue<UShort> operator~(RValue<UShort> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500508 RValue<UShort> operator++(UShort &val, int); // Post-increment
509 const UShort &operator++(UShort &val); // Pre-increment
510 RValue<UShort> operator--(UShort &val, int); // Post-decrement
511 const UShort &operator--(UShort &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400512 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs);
513 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs);
514 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs);
515 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs);
516 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs);
517 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs);
518
Nicolas Capens297d26e2016-11-18 12:52:17 -0500519 class Byte4 : public LValue<Byte4>
Nicolas Capensd022e412016-09-26 13:30:14 -0400520 {
521 public:
Nicolas Capens16b5f152016-10-13 13:39:01 -0400522 explicit Byte4(RValue<Byte8> cast);
523
Nicolas Capensa25311a2017-01-16 17:19:00 -0500524 Byte4() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400525 // Byte4(int x, int y, int z, int w);
526 // Byte4(RValue<Byte4> rhs);
527 // Byte4(const Byte4 &rhs);
Nicolas Capens16b5f152016-10-13 13:39:01 -0400528 Byte4(const Reference<Byte4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400529
Nicolas Capens96d4e092016-11-18 14:22:38 -0500530 // RValue<Byte4> operator=(RValue<Byte4> rhs);
531 // RValue<Byte4> operator=(const Byte4 &rhs);
532 // RValue<Byte4> operator=(const Reference<Byte4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400533
534 static Type *getType();
535 };
536
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%(RValue<Byte4> lhs, RValue<Byte4> rhs);
542// RValue<Byte4> operator&(RValue<Byte4> lhs, RValue<Byte4> rhs);
543// RValue<Byte4> operator|(RValue<Byte4> lhs, RValue<Byte4> rhs);
544// RValue<Byte4> operator^(RValue<Byte4> lhs, RValue<Byte4> rhs);
545// RValue<Byte4> operator<<(RValue<Byte4> lhs, RValue<Byte4> rhs);
546// RValue<Byte4> operator>>(RValue<Byte4> lhs, RValue<Byte4> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500547// 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%=(Byte4 &lhs, RValue<Byte4> rhs);
552// RValue<Byte4> operator&=(Byte4 &lhs, RValue<Byte4> rhs);
553// RValue<Byte4> operator|=(Byte4 &lhs, RValue<Byte4> rhs);
554// RValue<Byte4> operator^=(Byte4 &lhs, RValue<Byte4> rhs);
555// RValue<Byte4> operator<<=(Byte4 &lhs, RValue<Byte4> rhs);
556// RValue<Byte4> operator>>=(Byte4 &lhs, RValue<Byte4> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400557// RValue<Byte4> operator+(RValue<Byte4> val);
558// RValue<Byte4> operator-(RValue<Byte4> val);
559// RValue<Byte4> operator~(RValue<Byte4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500560// RValue<Byte4> operator++(Byte4 &val, int); // Post-increment
561// const Byte4 &operator++(Byte4 &val); // Pre-increment
562// RValue<Byte4> operator--(Byte4 &val, int); // Post-decrement
563// const Byte4 &operator--(Byte4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400564
Nicolas Capens297d26e2016-11-18 12:52:17 -0500565 class SByte4 : public LValue<SByte4>
Nicolas Capensd022e412016-09-26 13:30:14 -0400566 {
567 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500568 SByte4() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400569 // SByte4(int x, int y, int z, int w);
570 // SByte4(RValue<SByte4> rhs);
571 // SByte4(const SByte4 &rhs);
572 // SByte4(const Reference<SByte4> &rhs);
573
Nicolas Capens96d4e092016-11-18 14:22:38 -0500574 // RValue<SByte4> operator=(RValue<SByte4> rhs);
575 // RValue<SByte4> operator=(const SByte4 &rhs);
576 // RValue<SByte4> operator=(const Reference<SByte4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400577
578 static Type *getType();
579 };
580
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%(RValue<SByte4> lhs, RValue<SByte4> rhs);
586// RValue<SByte4> operator&(RValue<SByte4> lhs, RValue<SByte4> rhs);
587// RValue<SByte4> operator|(RValue<SByte4> lhs, RValue<SByte4> rhs);
588// RValue<SByte4> operator^(RValue<SByte4> lhs, RValue<SByte4> rhs);
589// RValue<SByte4> operator<<(RValue<SByte4> lhs, RValue<SByte4> rhs);
590// RValue<SByte4> operator>>(RValue<SByte4> lhs, RValue<SByte4> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500591// 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%=(SByte4 &lhs, RValue<SByte4> rhs);
596// RValue<SByte4> operator&=(SByte4 &lhs, RValue<SByte4> rhs);
597// RValue<SByte4> operator|=(SByte4 &lhs, RValue<SByte4> rhs);
598// RValue<SByte4> operator^=(SByte4 &lhs, RValue<SByte4> rhs);
599// RValue<SByte4> operator<<=(SByte4 &lhs, RValue<SByte4> rhs);
600// RValue<SByte4> operator>>=(SByte4 &lhs, RValue<SByte4> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400601// RValue<SByte4> operator+(RValue<SByte4> val);
602// RValue<SByte4> operator-(RValue<SByte4> val);
603// RValue<SByte4> operator~(RValue<SByte4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500604// RValue<SByte4> operator++(SByte4 &val, int); // Post-increment
605// const SByte4 &operator++(SByte4 &val); // Pre-increment
606// RValue<SByte4> operator--(SByte4 &val, int); // Post-decrement
607// const SByte4 &operator--(SByte4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400608
Nicolas Capens297d26e2016-11-18 12:52:17 -0500609 class Byte8 : public LValue<Byte8>
Nicolas Capensd022e412016-09-26 13:30:14 -0400610 {
611 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500612 Byte8() = default;
Nicolas Capens3bbc5e12016-09-27 10:49:52 -0400613 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);
Nicolas Capensd022e412016-09-26 13:30:14 -0400614 Byte8(RValue<Byte8> rhs);
615 Byte8(const Byte8 &rhs);
616 Byte8(const Reference<Byte8> &rhs);
617
Nicolas Capens96d4e092016-11-18 14:22:38 -0500618 RValue<Byte8> operator=(RValue<Byte8> rhs);
619 RValue<Byte8> operator=(const Byte8 &rhs);
620 RValue<Byte8> operator=(const Reference<Byte8> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400621
622 static Type *getType();
623 };
624
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%(RValue<Byte8> lhs, RValue<Byte8> rhs);
630 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs);
631 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs);
632 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs);
633// RValue<Byte8> operator<<(RValue<Byte8> lhs, RValue<Byte8> rhs);
634// RValue<Byte8> operator>>(RValue<Byte8> lhs, RValue<Byte8> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500635 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%=(Byte8 &lhs, RValue<Byte8> rhs);
640 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs);
641 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs);
642 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs);
643// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs);
644// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400645// RValue<Byte8> operator+(RValue<Byte8> val);
646// RValue<Byte8> operator-(RValue<Byte8> val);
647 RValue<Byte8> operator~(RValue<Byte8> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500648// RValue<Byte8> operator++(Byte8 &val, int); // Post-increment
649// const Byte8 &operator++(Byte8 &val); // Pre-increment
650// RValue<Byte8> operator--(Byte8 &val, int); // Post-decrement
651// const Byte8 &operator--(Byte8 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400652
653 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y);
654 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y);
655 RValue<Short4> Unpack(RValue<Byte4> x);
Nicolas Capens411273e2017-01-26 15:13:36 -0800656 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y);
Nicolas Capensd022e412016-09-26 13:30:14 -0400657 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y);
658 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y);
659 RValue<Int> SignMask(RValue<Byte8> x);
660// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y);
661 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y);
662
Nicolas Capens297d26e2016-11-18 12:52:17 -0500663 class SByte8 : public LValue<SByte8>
Nicolas Capensd022e412016-09-26 13:30:14 -0400664 {
665 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500666 SByte8() = default;
Nicolas Capens3bbc5e12016-09-27 10:49:52 -0400667 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);
Nicolas Capensd022e412016-09-26 13:30:14 -0400668 SByte8(RValue<SByte8> rhs);
669 SByte8(const SByte8 &rhs);
670 SByte8(const Reference<SByte8> &rhs);
671
Nicolas Capens96d4e092016-11-18 14:22:38 -0500672 RValue<SByte8> operator=(RValue<SByte8> rhs);
673 RValue<SByte8> operator=(const SByte8 &rhs);
674 RValue<SByte8> operator=(const Reference<SByte8> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400675
676 static Type *getType();
677 };
678
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%(RValue<SByte8> lhs, RValue<SByte8> rhs);
684 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs);
685 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs);
686 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs);
687// RValue<SByte8> operator<<(RValue<SByte8> lhs, RValue<SByte8> rhs);
688// RValue<SByte8> operator>>(RValue<SByte8> lhs, RValue<SByte8> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500689 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%=(SByte8 &lhs, RValue<SByte8> rhs);
694 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs);
695 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs);
696 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs);
697// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs);
698// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400699// RValue<SByte8> operator+(RValue<SByte8> val);
700// RValue<SByte8> operator-(RValue<SByte8> val);
701 RValue<SByte8> operator~(RValue<SByte8> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500702// RValue<SByte8> operator++(SByte8 &val, int); // Post-increment
703// const SByte8 &operator++(SByte8 &val); // Pre-increment
704// RValue<SByte8> operator--(SByte8 &val, int); // Post-decrement
705// const SByte8 &operator--(SByte8 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400706
707 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y);
708 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y);
709 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y);
710 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y);
711 RValue<Int> SignMask(RValue<SByte8> x);
712 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y);
713 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y);
714
Nicolas Capens297d26e2016-11-18 12:52:17 -0500715 class Byte16 : public LValue<Byte16>
Nicolas Capensd022e412016-09-26 13:30:14 -0400716 {
717 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500718 Byte16() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400719 // Byte16(int x, int y, int z, int w);
720 Byte16(RValue<Byte16> rhs);
721 Byte16(const Byte16 &rhs);
722 Byte16(const Reference<Byte16> &rhs);
723
Nicolas Capens96d4e092016-11-18 14:22:38 -0500724 RValue<Byte16> operator=(RValue<Byte16> rhs);
725 RValue<Byte16> operator=(const Byte16 &rhs);
726 RValue<Byte16> operator=(const Reference<Byte16> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400727
728 static Type *getType();
729 };
730
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%(RValue<Byte16> lhs, RValue<Byte16> rhs);
736// RValue<Byte16> operator&(RValue<Byte16> lhs, RValue<Byte16> rhs);
737// RValue<Byte16> operator|(RValue<Byte16> lhs, RValue<Byte16> rhs);
738// RValue<Byte16> operator^(RValue<Byte16> lhs, RValue<Byte16> rhs);
739// RValue<Byte16> operator<<(RValue<Byte16> lhs, RValue<Byte16> rhs);
740// RValue<Byte16> operator>>(RValue<Byte16> lhs, RValue<Byte16> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500741// 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%=(Byte16 &lhs, RValue<Byte16> rhs);
746// RValue<Byte16> operator&=(Byte16 &lhs, RValue<Byte16> rhs);
747// RValue<Byte16> operator|=(Byte16 &lhs, RValue<Byte16> rhs);
748// RValue<Byte16> operator^=(Byte16 &lhs, RValue<Byte16> rhs);
749// RValue<Byte16> operator<<=(Byte16 &lhs, RValue<Byte16> rhs);
750// RValue<Byte16> operator>>=(Byte16 &lhs, RValue<Byte16> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400751// RValue<Byte16> operator+(RValue<Byte16> val);
752// RValue<Byte16> operator-(RValue<Byte16> val);
753// RValue<Byte16> operator~(RValue<Byte16> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500754// RValue<Byte16> operator++(Byte16 &val, int); // Post-increment
755// const Byte16 &operator++(Byte16 &val); // Pre-increment
756// RValue<Byte16> operator--(Byte16 &val, int); // Post-decrement
757// const Byte16 &operator--(Byte16 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400758
Nicolas Capens297d26e2016-11-18 12:52:17 -0500759 class SByte16 : public LValue<SByte16>
Nicolas Capensd022e412016-09-26 13:30:14 -0400760 {
761 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500762 SByte16() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400763 // SByte16(int x, int y, int z, int w);
764 // SByte16(RValue<SByte16> rhs);
765 // SByte16(const SByte16 &rhs);
766 // SByte16(const Reference<SByte16> &rhs);
767
Nicolas Capens96d4e092016-11-18 14:22:38 -0500768 // RValue<SByte16> operator=(RValue<SByte16> rhs);
769 // RValue<SByte16> operator=(const SByte16 &rhs);
770 // RValue<SByte16> operator=(const Reference<SByte16> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400771
772 static Type *getType();
773 };
774
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%(RValue<SByte16> lhs, RValue<SByte16> rhs);
780// RValue<SByte16> operator&(RValue<SByte16> lhs, RValue<SByte16> rhs);
781// RValue<SByte16> operator|(RValue<SByte16> lhs, RValue<SByte16> rhs);
782// RValue<SByte16> operator^(RValue<SByte16> lhs, RValue<SByte16> rhs);
783// RValue<SByte16> operator<<(RValue<SByte16> lhs, RValue<SByte16> rhs);
784// RValue<SByte16> operator>>(RValue<SByte16> lhs, RValue<SByte16> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500785// 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%=(SByte16 &lhs, RValue<SByte16> rhs);
790// RValue<SByte16> operator&=(SByte16 &lhs, RValue<SByte16> rhs);
791// RValue<SByte16> operator|=(SByte16 &lhs, RValue<SByte16> rhs);
792// RValue<SByte16> operator^=(SByte16 &lhs, RValue<SByte16> rhs);
793// RValue<SByte16> operator<<=(SByte16 &lhs, RValue<SByte16> rhs);
794// RValue<SByte16> operator>>=(SByte16 &lhs, RValue<SByte16> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400795// RValue<SByte16> operator+(RValue<SByte16> val);
796// RValue<SByte16> operator-(RValue<SByte16> val);
797// RValue<SByte16> operator~(RValue<SByte16> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500798// RValue<SByte16> operator++(SByte16 &val, int); // Post-increment
799// const SByte16 &operator++(SByte16 &val); // Pre-increment
800// RValue<SByte16> operator--(SByte16 &val, int); // Post-decrement
801// const SByte16 &operator--(SByte16 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400802
Nicolas Capens297d26e2016-11-18 12:52:17 -0500803 class Short2 : public LValue<Short2>
Nicolas Capens16b5f152016-10-13 13:39:01 -0400804 {
805 public:
806 explicit Short2(RValue<Short4> cast);
807
808 static Type *getType();
809 };
810
Nicolas Capens297d26e2016-11-18 12:52:17 -0500811 class UShort2 : public LValue<UShort2>
Nicolas Capens16b5f152016-10-13 13:39:01 -0400812 {
813 public:
814 explicit UShort2(RValue<UShort4> cast);
815
816 static Type *getType();
817 };
818
Nicolas Capens297d26e2016-11-18 12:52:17 -0500819 class Short4 : public LValue<Short4>
Nicolas Capensd022e412016-09-26 13:30:14 -0400820 {
821 public:
822 explicit Short4(RValue<Int> cast);
823 explicit Short4(RValue<Int4> cast);
824 // explicit Short4(RValue<Float> cast);
825 explicit Short4(RValue<Float4> cast);
826
Nicolas Capensa25311a2017-01-16 17:19:00 -0500827 Short4() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400828 Short4(short xyzw);
829 Short4(short x, short y, short z, short w);
830 Short4(RValue<Short4> rhs);
831 Short4(const Short4 &rhs);
832 Short4(const Reference<Short4> &rhs);
833 Short4(RValue<UShort4> rhs);
834 Short4(const UShort4 &rhs);
835 Short4(const Reference<UShort4> &rhs);
836
Nicolas Capens96d4e092016-11-18 14:22:38 -0500837 RValue<Short4> operator=(RValue<Short4> rhs);
838 RValue<Short4> operator=(const Short4 &rhs);
839 RValue<Short4> operator=(const Reference<Short4> &rhs);
840 RValue<Short4> operator=(RValue<UShort4> rhs);
841 RValue<Short4> operator=(const UShort4 &rhs);
842 RValue<Short4> operator=(const Reference<UShort4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400843
844 static Type *getType();
845 };
846
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, RValue<Short4> rhs);
850// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs);
851// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs);
852 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs);
853 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs);
854 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs);
855 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs);
856 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500857 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs);
858 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs);
859 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs);
860// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs);
861// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs);
862 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs);
863 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs);
864 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs);
865 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs);
866 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400867// RValue<Short4> operator+(RValue<Short4> val);
868 RValue<Short4> operator-(RValue<Short4> val);
869 RValue<Short4> operator~(RValue<Short4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500870// RValue<Short4> operator++(Short4 &val, int); // Post-increment
871// const Short4 &operator++(Short4 &val); // Pre-increment
872// RValue<Short4> operator--(Short4 &val, int); // Post-decrement
873// const Short4 &operator--(Short4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400874// RValue<Bool> operator<(RValue<Short4> lhs, RValue<Short4> rhs);
875// RValue<Bool> operator<=(RValue<Short4> lhs, RValue<Short4> rhs);
876// RValue<Bool> operator>(RValue<Short4> lhs, RValue<Short4> rhs);
877// RValue<Bool> operator>=(RValue<Short4> lhs, RValue<Short4> rhs);
878// RValue<Bool> operator!=(RValue<Short4> lhs, RValue<Short4> rhs);
879// RValue<Bool> operator==(RValue<Short4> lhs, RValue<Short4> rhs);
880
881 RValue<Short4> RoundShort4(RValue<Float4> cast);
882 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y);
883 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y);
884 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y);
885 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y);
886 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y);
887 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y);
Nicolas Capens33438a62017-09-27 11:47:35 -0400888 RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y);
889 RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y);
Nicolas Capensd022e412016-09-26 13:30:14 -0400890 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y);
891 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y);
892 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select);
893 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i);
894 RValue<Short> Extract(RValue<Short4> val, int i);
895 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y);
896 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y);
897
Nicolas Capens297d26e2016-11-18 12:52:17 -0500898 class UShort4 : public LValue<UShort4>
Nicolas Capensd022e412016-09-26 13:30:14 -0400899 {
900 public:
901 explicit UShort4(RValue<Int4> cast);
902 explicit UShort4(RValue<Float4> cast, bool saturate = false);
903
Nicolas Capensa25311a2017-01-16 17:19:00 -0500904 UShort4() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -0400905 UShort4(unsigned short xyzw);
906 UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
907 UShort4(RValue<UShort4> rhs);
908 UShort4(const UShort4 &rhs);
909 UShort4(const Reference<UShort4> &rhs);
910 UShort4(RValue<Short4> rhs);
911 UShort4(const Short4 &rhs);
912 UShort4(const Reference<Short4> &rhs);
913
Nicolas Capens96d4e092016-11-18 14:22:38 -0500914 RValue<UShort4> operator=(RValue<UShort4> rhs);
915 RValue<UShort4> operator=(const UShort4 &rhs);
916 RValue<UShort4> operator=(const Reference<UShort4> &rhs);
917 RValue<UShort4> operator=(RValue<Short4> rhs);
918 RValue<UShort4> operator=(const Short4 &rhs);
919 RValue<UShort4> operator=(const Reference<Short4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400920
921 static Type *getType();
922 };
923
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, RValue<UShort4> rhs);
927// RValue<UShort4> operator/(RValue<UShort4> lhs, RValue<UShort4> rhs);
928// RValue<UShort4> operator%(RValue<UShort4> lhs, RValue<UShort4> rhs);
Nicolas Capens16b5f152016-10-13 13:39:01 -0400929 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs);
930 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs);
931 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400932 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs);
933 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500934// RValue<UShort4> operator+=(UShort4 &lhs, RValue<UShort4> rhs);
935// RValue<UShort4> operator-=(UShort4 &lhs, RValue<UShort4> rhs);
936// RValue<UShort4> operator*=(UShort4 &lhs, RValue<UShort4> rhs);
937// RValue<UShort4> operator/=(UShort4 &lhs, RValue<UShort4> rhs);
938// RValue<UShort4> operator%=(UShort4 &lhs, RValue<UShort4> rhs);
939// RValue<UShort4> operator&=(UShort4 &lhs, RValue<UShort4> rhs);
940// RValue<UShort4> operator|=(UShort4 &lhs, RValue<UShort4> rhs);
941// RValue<UShort4> operator^=(UShort4 &lhs, RValue<UShort4> rhs);
942 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs);
943 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400944// RValue<UShort4> operator+(RValue<UShort4> val);
945// RValue<UShort4> operator-(RValue<UShort4> val);
946 RValue<UShort4> operator~(RValue<UShort4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500947// RValue<UShort4> operator++(UShort4 &val, int); // Post-increment
948// const UShort4 &operator++(UShort4 &val); // Pre-increment
949// RValue<UShort4> operator--(UShort4 &val, int); // Post-decrement
950// const UShort4 &operator--(UShort4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -0400951
952 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y);
953 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y);
954 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y);
955 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y);
956 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y);
957 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y);
Nicolas Capensd022e412016-09-26 13:30:14 -0400958
Nicolas Capens297d26e2016-11-18 12:52:17 -0500959 class Short8 : public LValue<Short8>
Nicolas Capensd022e412016-09-26 13:30:14 -0400960 {
961 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -0500962 Short8() = default;
Nicolas Capens3e7062b2017-01-17 14:01:33 -0500963 Short8(short c);
Nicolas Capensd022e412016-09-26 13:30:14 -0400964 Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7);
965 Short8(RValue<Short8> rhs);
966 // Short8(const Short8 &rhs);
967 Short8(const Reference<Short8> &rhs);
968 Short8(RValue<Short4> lo, RValue<Short4> hi);
969
Nicolas Capensf1beca42019-03-26 17:18:57 -0400970 RValue<Short8> operator=(RValue<Short8> rhs);
971 RValue<Short8> operator=(const Short8 &rhs);
972 RValue<Short8> operator=(const Reference<Short8> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400973
974 static Type *getType();
975 };
976
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, RValue<Short8> rhs);
980// RValue<Short8> operator/(RValue<Short8> lhs, RValue<Short8> 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|(RValue<Short8> lhs, RValue<Short8> rhs);
984// RValue<Short8> operator^(RValue<Short8> lhs, RValue<Short8> rhs);
985 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs);
986 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs);
987// RValue<Short8> operator<<(RValue<Short8> lhs, RValue<Short8> rhs);
988// RValue<Short8> operator>>(RValue<Short8> lhs, RValue<Short8> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -0500989// 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%=(Short8 &lhs, RValue<Short8> rhs);
994// RValue<Short8> operator&=(Short8 &lhs, RValue<Short8> rhs);
995// RValue<Short8> operator|=(Short8 &lhs, RValue<Short8> rhs);
996// RValue<Short8> operator^=(Short8 &lhs, RValue<Short8> rhs);
997// RValue<Short8> operator<<=(Short8 &lhs, RValue<Short8> rhs);
998// RValue<Short8> operator>>=(Short8 &lhs, RValue<Short8> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -0400999// RValue<Short8> operator+(RValue<Short8> val);
1000// RValue<Short8> operator-(RValue<Short8> val);
1001// RValue<Short8> operator~(RValue<Short8> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001002// RValue<Short8> operator++(Short8 &val, int); // Post-increment
1003// const Short8 &operator++(Short8 &val); // Pre-increment
1004// RValue<Short8> operator--(Short8 &val, int); // Post-decrement
1005// const Short8 &operator--(Short8 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001006// RValue<Bool> operator<(RValue<Short8> lhs, RValue<Short8> rhs);
1007// RValue<Bool> operator<=(RValue<Short8> lhs, RValue<Short8> rhs);
1008// RValue<Bool> operator>(RValue<Short8> lhs, RValue<Short8> rhs);
1009// RValue<Bool> operator>=(RValue<Short8> lhs, RValue<Short8> rhs);
1010// RValue<Bool> operator!=(RValue<Short8> lhs, RValue<Short8> rhs);
1011// RValue<Bool> operator==(RValue<Short8> lhs, RValue<Short8> rhs);
1012
1013 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y);
1014 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y);
1015 RValue<Int4> Abs(RValue<Int4> x);
1016
Nicolas Capens297d26e2016-11-18 12:52:17 -05001017 class UShort8 : public LValue<UShort8>
Nicolas Capensd022e412016-09-26 13:30:14 -04001018 {
1019 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -05001020 UShort8() = default;
Nicolas Capens3e7062b2017-01-17 14:01:33 -05001021 UShort8(unsigned short c);
Nicolas Capensd022e412016-09-26 13:30:14 -04001022 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);
1023 UShort8(RValue<UShort8> rhs);
1024 // UShort8(const UShort8 &rhs);
1025 UShort8(const Reference<UShort8> &rhs);
1026 UShort8(RValue<UShort4> lo, RValue<UShort4> hi);
1027
Nicolas Capens96d4e092016-11-18 14:22:38 -05001028 RValue<UShort8> operator=(RValue<UShort8> rhs);
1029 RValue<UShort8> operator=(const UShort8 &rhs);
1030 RValue<UShort8> operator=(const Reference<UShort8> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001031
1032 static Type *getType();
1033 };
1034
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, RValue<UShort8> rhs);
1038// RValue<UShort8> operator/(RValue<UShort8> lhs, RValue<UShort8> 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|(RValue<UShort8> lhs, RValue<UShort8> rhs);
1042// RValue<UShort8> operator^(RValue<UShort8> lhs, RValue<UShort8> rhs);
1043 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs);
1044 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs);
1045// RValue<UShort8> operator<<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1046// RValue<UShort8> operator>>(RValue<UShort8> lhs, RValue<UShort8> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001047 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%=(UShort8 &lhs, RValue<UShort8> rhs);
1052// RValue<UShort8> operator&=(UShort8 &lhs, RValue<UShort8> rhs);
1053// RValue<UShort8> operator|=(UShort8 &lhs, RValue<UShort8> rhs);
1054// RValue<UShort8> operator^=(UShort8 &lhs, RValue<UShort8> rhs);
1055// RValue<UShort8> operator<<=(UShort8 &lhs, RValue<UShort8> rhs);
1056// RValue<UShort8> operator>>=(UShort8 &lhs, RValue<UShort8> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001057// RValue<UShort8> operator+(RValue<UShort8> val);
1058// RValue<UShort8> operator-(RValue<UShort8> val);
1059 RValue<UShort8> operator~(RValue<UShort8> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001060// RValue<UShort8> operator++(UShort8 &val, int); // Post-increment
1061// const UShort8 &operator++(UShort8 &val); // Pre-increment
1062// RValue<UShort8> operator--(UShort8 &val, int); // Post-decrement
1063// const UShort8 &operator--(UShort8 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001064// RValue<Bool> operator<(RValue<UShort8> lhs, RValue<UShort8> rhs);
1065// RValue<Bool> operator<=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1066// RValue<Bool> operator>(RValue<UShort8> lhs, RValue<UShort8> rhs);
1067// RValue<Bool> operator>=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1068// RValue<Bool> operator!=(RValue<UShort8> lhs, RValue<UShort8> rhs);
1069// RValue<Bool> operator==(RValue<UShort8> lhs, RValue<UShort8> rhs);
1070
1071 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7);
1072 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y);
1073
Nicolas Capens297d26e2016-11-18 12:52:17 -05001074 class Int : public LValue<Int>
Nicolas Capensd022e412016-09-26 13:30:14 -04001075 {
1076 public:
1077 Int(Argument<Int> argument);
1078
1079 explicit Int(RValue<Byte> cast);
1080 explicit Int(RValue<SByte> cast);
1081 explicit Int(RValue<Short> cast);
1082 explicit Int(RValue<UShort> cast);
1083 explicit Int(RValue<Int2> cast);
1084 explicit Int(RValue<Long> cast);
1085 explicit Int(RValue<Float> cast);
1086
Nicolas Capensa25311a2017-01-16 17:19:00 -05001087 Int() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04001088 Int(int x);
1089 Int(RValue<Int> rhs);
1090 Int(RValue<UInt> rhs);
1091 Int(const Int &rhs);
1092 Int(const UInt &rhs);
1093 Int(const Reference<Int> &rhs);
1094 Int(const Reference<UInt> &rhs);
1095
Nicolas Capens96d4e092016-11-18 14:22:38 -05001096 RValue<Int> operator=(int rhs);
1097 RValue<Int> operator=(RValue<Int> rhs);
1098 RValue<Int> operator=(RValue<UInt> rhs);
1099 RValue<Int> operator=(const Int &rhs);
1100 RValue<Int> operator=(const UInt &rhs);
1101 RValue<Int> operator=(const Reference<Int> &rhs);
1102 RValue<Int> operator=(const Reference<UInt> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001103
1104 static Type *getType();
1105 };
1106
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%(RValue<Int> lhs, RValue<Int> rhs);
1112 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs);
1113 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs);
1114 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs);
1115 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs);
1116 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001117 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%=(Int &lhs, RValue<Int> rhs);
1122 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs);
1123 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs);
1124 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs);
1125 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs);
1126 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001127 RValue<Int> operator+(RValue<Int> val);
1128 RValue<Int> operator-(RValue<Int> val);
1129 RValue<Int> operator~(RValue<Int> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001130 RValue<Int> operator++(Int &val, int); // Post-increment
1131 const Int &operator++(Int &val); // Pre-increment
1132 RValue<Int> operator--(Int &val, int); // Post-decrement
1133 const Int &operator--(Int &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001134 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs);
1135 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs);
1136 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs);
1137 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs);
1138 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs);
1139 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs);
1140
1141 RValue<Int> Max(RValue<Int> x, RValue<Int> y);
1142 RValue<Int> Min(RValue<Int> x, RValue<Int> y);
1143 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max);
1144 RValue<Int> RoundInt(RValue<Float> cast);
1145
Nicolas Capens297d26e2016-11-18 12:52:17 -05001146 class Long : public LValue<Long>
Nicolas Capensd022e412016-09-26 13:30:14 -04001147 {
1148 public:
1149 // Long(Argument<Long> argument);
1150
1151 // explicit Long(RValue<Short> cast);
1152 // explicit Long(RValue<UShort> cast);
1153 explicit Long(RValue<Int> cast);
1154 explicit Long(RValue<UInt> cast);
1155 // explicit Long(RValue<Float> cast);
1156
Nicolas Capensa25311a2017-01-16 17:19:00 -05001157 Long() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04001158 // Long(qword x);
1159 Long(RValue<Long> rhs);
1160 // Long(RValue<ULong> rhs);
1161 // Long(const Long &rhs);
1162 // Long(const Reference<Long> &rhs);
1163 // Long(const ULong &rhs);
1164 // Long(const Reference<ULong> &rhs);
1165
Nicolas Capens96d4e092016-11-18 14:22:38 -05001166 RValue<Long> operator=(int64_t rhs);
1167 RValue<Long> operator=(RValue<Long> rhs);
1168 // RValue<Long> operator=(RValue<ULong> rhs);
1169 RValue<Long> operator=(const Long &rhs);
1170 RValue<Long> operator=(const Reference<Long> &rhs);
1171 // RValue<Long> operator=(const ULong &rhs);
1172 // RValue<Long> operator=(const Reference<ULong> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001173
1174 static Type *getType();
1175 };
1176
1177 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs);
1178 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs);
Chris Forbesaa8f6992019-03-01 14:18:30 -08001179 RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001180// RValue<Long> operator/(RValue<Long> lhs, RValue<Long> rhs);
1181// RValue<Long> operator%(RValue<Long> lhs, RValue<Long> rhs);
1182// RValue<Long> operator&(RValue<Long> lhs, RValue<Long> rhs);
1183// RValue<Long> operator|(RValue<Long> lhs, RValue<Long> rhs);
1184// RValue<Long> operator^(RValue<Long> lhs, RValue<Long> rhs);
1185// RValue<Long> operator<<(RValue<Long> lhs, RValue<Long> rhs);
Chris Forbesaa8f6992019-03-01 14:18:30 -08001186 RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001187 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%=(Long &lhs, RValue<Long> rhs);
1192// RValue<Long> operator&=(Long &lhs, RValue<Long> rhs);
1193// RValue<Long> operator|=(Long &lhs, RValue<Long> rhs);
1194// RValue<Long> operator^=(Long &lhs, RValue<Long> rhs);
1195// RValue<Long> operator<<=(Long &lhs, RValue<Long> rhs);
1196// RValue<Long> operator>>=(Long &lhs, RValue<Long> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001197// RValue<Long> operator+(RValue<Long> val);
1198// RValue<Long> operator-(RValue<Long> val);
1199// RValue<Long> operator~(RValue<Long> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001200// RValue<Long> operator++(Long &val, int); // Post-increment
1201// const Long &operator++(Long &val); // Pre-increment
1202// RValue<Long> operator--(Long &val, int); // Post-decrement
1203// const Long &operator--(Long &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001204// RValue<Bool> operator<(RValue<Long> lhs, RValue<Long> rhs);
1205// RValue<Bool> operator<=(RValue<Long> lhs, RValue<Long> rhs);
1206// RValue<Bool> operator>(RValue<Long> lhs, RValue<Long> rhs);
1207// RValue<Bool> operator>=(RValue<Long> lhs, RValue<Long> rhs);
1208// RValue<Bool> operator!=(RValue<Long> lhs, RValue<Long> rhs);
1209// RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs);
1210
1211// RValue<Long> RoundLong(RValue<Float> cast);
1212 RValue<Long> AddAtomic( RValue<Pointer<Long>> x, RValue<Long> y);
1213
Nicolas Capens297d26e2016-11-18 12:52:17 -05001214 class UInt : public LValue<UInt>
Nicolas Capensd022e412016-09-26 13:30:14 -04001215 {
1216 public:
1217 UInt(Argument<UInt> argument);
1218
1219 explicit UInt(RValue<UShort> cast);
1220 explicit UInt(RValue<Long> cast);
1221 explicit UInt(RValue<Float> cast);
1222
Nicolas Capensa25311a2017-01-16 17:19:00 -05001223 UInt() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04001224 UInt(int x);
1225 UInt(unsigned int x);
1226 UInt(RValue<UInt> rhs);
1227 UInt(RValue<Int> rhs);
1228 UInt(const UInt &rhs);
1229 UInt(const Int &rhs);
1230 UInt(const Reference<UInt> &rhs);
1231 UInt(const Reference<Int> &rhs);
1232
Nicolas Capens96d4e092016-11-18 14:22:38 -05001233 RValue<UInt> operator=(unsigned int rhs);
1234 RValue<UInt> operator=(RValue<UInt> rhs);
1235 RValue<UInt> operator=(RValue<Int> rhs);
1236 RValue<UInt> operator=(const UInt &rhs);
1237 RValue<UInt> operator=(const Int &rhs);
1238 RValue<UInt> operator=(const Reference<UInt> &rhs);
1239 RValue<UInt> operator=(const Reference<Int> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001240
1241 static Type *getType();
1242 };
1243
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%(RValue<UInt> lhs, RValue<UInt> rhs);
1249 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs);
1250 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs);
1251 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs);
1252 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs);
1253 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001254 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%=(UInt &lhs, RValue<UInt> rhs);
1259 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs);
1260 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs);
1261 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs);
1262 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs);
1263 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001264 RValue<UInt> operator+(RValue<UInt> val);
1265 RValue<UInt> operator-(RValue<UInt> val);
1266 RValue<UInt> operator~(RValue<UInt> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001267 RValue<UInt> operator++(UInt &val, int); // Post-increment
1268 const UInt &operator++(UInt &val); // Pre-increment
1269 RValue<UInt> operator--(UInt &val, int); // Post-decrement
1270 const UInt &operator--(UInt &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001271 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs);
1272 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs);
1273 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs);
1274 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs);
1275 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs);
1276 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs);
1277
1278 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y);
1279 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y);
1280 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max);
Chris Forbes17813932019-04-18 11:45:54 -07001281
1282 RValue<UInt> AddAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
Chris Forbes707ed992019-04-18 18:17:35 -07001283 RValue<UInt> SubAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
Chris Forbes17813932019-04-18 11:45:54 -07001284 RValue<UInt> AndAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1285 RValue<UInt> OrAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1286 RValue<UInt> XorAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1287 RValue<Int> MinAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1288 RValue<Int> MaxAtomic(RValue<Pointer<Int>> x, RValue<Int> y, std::memory_order memoryOrder);
1289 RValue<UInt> MinAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1290 RValue<UInt> MaxAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
1291 RValue<UInt> ExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder);
Chris Forbesa16238d2019-04-18 16:31:54 -07001292 RValue<UInt> CompareExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, RValue<UInt> compare, std::memory_order memoryOrderEqual, std::memory_order memoryOrderUnequal);
Chris Forbes17813932019-04-18 11:45:54 -07001293
Nicolas Capensd022e412016-09-26 13:30:14 -04001294// RValue<UInt> RoundUInt(RValue<Float> cast);
1295
Nicolas Capens297d26e2016-11-18 12:52:17 -05001296 class Int2 : public LValue<Int2>
Nicolas Capensd022e412016-09-26 13:30:14 -04001297 {
1298 public:
1299 // explicit Int2(RValue<Int> cast);
1300 explicit Int2(RValue<Int4> cast);
1301
Nicolas Capensa25311a2017-01-16 17:19:00 -05001302 Int2() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04001303 Int2(int x, int y);
1304 Int2(RValue<Int2> rhs);
1305 Int2(const Int2 &rhs);
1306 Int2(const Reference<Int2> &rhs);
1307 Int2(RValue<Int> lo, RValue<Int> hi);
1308
Nicolas Capens96d4e092016-11-18 14:22:38 -05001309 RValue<Int2> operator=(RValue<Int2> rhs);
1310 RValue<Int2> operator=(const Int2 &rhs);
1311 RValue<Int2> operator=(const Reference<Int2> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001312
1313 static Type *getType();
1314 };
1315
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, RValue<Int2> rhs);
1319// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs);
1320// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs);
1321 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs);
1322 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs);
1323 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs);
1324 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs);
1325 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001326 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs);
1327 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs);
1328// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs);
1329// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs);
1330// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs);
1331 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs);
1332 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs);
1333 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs);
1334 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs);
1335 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001336// RValue<Int2> operator+(RValue<Int2> val);
1337// RValue<Int2> operator-(RValue<Int2> val);
1338 RValue<Int2> operator~(RValue<Int2> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001339// RValue<Int2> operator++(Int2 &val, int); // Post-increment
1340// const Int2 &operator++(Int2 &val); // Pre-increment
1341// RValue<Int2> operator--(Int2 &val, int); // Post-decrement
1342// const Int2 &operator--(Int2 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001343// RValue<Bool> operator<(RValue<Int2> lhs, RValue<Int2> rhs);
1344// RValue<Bool> operator<=(RValue<Int2> lhs, RValue<Int2> rhs);
1345// RValue<Bool> operator>(RValue<Int2> lhs, RValue<Int2> rhs);
1346// RValue<Bool> operator>=(RValue<Int2> lhs, RValue<Int2> rhs);
1347// RValue<Bool> operator!=(RValue<Int2> lhs, RValue<Int2> rhs);
1348// RValue<Bool> operator==(RValue<Int2> lhs, RValue<Int2> rhs);
1349
1350// RValue<Int2> RoundInt(RValue<Float4> cast);
Nicolas Capens45f187a2016-12-02 15:30:56 -05001351 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y);
1352 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y);
Nicolas Capensd022e412016-09-26 13:30:14 -04001353 RValue<Int> Extract(RValue<Int2> val, int i);
1354 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i);
1355
Nicolas Capens297d26e2016-11-18 12:52:17 -05001356 class UInt2 : public LValue<UInt2>
Nicolas Capensd022e412016-09-26 13:30:14 -04001357 {
1358 public:
Nicolas Capensa25311a2017-01-16 17:19:00 -05001359 UInt2() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04001360 UInt2(unsigned int x, unsigned int y);
1361 UInt2(RValue<UInt2> rhs);
1362 UInt2(const UInt2 &rhs);
1363 UInt2(const Reference<UInt2> &rhs);
1364
Nicolas Capens96d4e092016-11-18 14:22:38 -05001365 RValue<UInt2> operator=(RValue<UInt2> rhs);
1366 RValue<UInt2> operator=(const UInt2 &rhs);
1367 RValue<UInt2> operator=(const Reference<UInt2> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001368
1369 static Type *getType();
1370 };
1371
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, RValue<UInt2> rhs);
1375// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs);
1376// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs);
1377 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs);
1378 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs);
1379 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs);
1380 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs);
1381 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001382 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs);
1383 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs);
1384// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs);
1385// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs);
1386// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs);
1387 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs);
1388 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs);
1389 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs);
1390 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs);
1391 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001392// RValue<UInt2> operator+(RValue<UInt2> val);
1393// RValue<UInt2> operator-(RValue<UInt2> val);
1394 RValue<UInt2> operator~(RValue<UInt2> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001395// RValue<UInt2> operator++(UInt2 &val, int); // Post-increment
1396// const UInt2 &operator++(UInt2 &val); // Pre-increment
1397// RValue<UInt2> operator--(UInt2 &val, int); // Post-decrement
1398// const UInt2 &operator--(UInt2 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001399// RValue<Bool> operator<(RValue<UInt2> lhs, RValue<UInt2> rhs);
1400// RValue<Bool> operator<=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1401// RValue<Bool> operator>(RValue<UInt2> lhs, RValue<UInt2> rhs);
1402// RValue<Bool> operator>=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1403// RValue<Bool> operator!=(RValue<UInt2> lhs, RValue<UInt2> rhs);
1404// RValue<Bool> operator==(RValue<UInt2> lhs, RValue<UInt2> rhs);
1405
1406// RValue<UInt2> RoundInt(RValue<Float4> cast);
Ben Clayton8ab40532019-05-10 16:23:13 +01001407 RValue<UInt> Extract(RValue<UInt2> val, int i);
1408 RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i);
Nicolas Capensd022e412016-09-26 13:30:14 -04001409
Nicolas Capenscb986762017-01-20 11:34:37 -05001410 template<class T>
1411 struct Scalar;
1412
1413 template<class Vector4>
1414 struct XYZW;
1415
1416 template<class Vector4, int T>
1417 class Swizzle2
1418 {
1419 friend Vector4;
1420
1421 public:
1422 operator RValue<Vector4>() const;
1423
1424 private:
1425 Vector4 *parent;
1426 };
1427
1428 template<class Vector4, int T>
1429 class Swizzle4
1430 {
1431 public:
1432 operator RValue<Vector4>() const;
1433
1434 private:
1435 Vector4 *parent;
1436 };
1437
1438 template<class Vector4, int T>
1439 class SwizzleMask4
1440 {
1441 friend XYZW<Vector4>;
1442
1443 public:
1444 operator RValue<Vector4>() const;
1445
1446 RValue<Vector4> operator=(RValue<Vector4> rhs);
1447 RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
1448
1449 private:
1450 Vector4 *parent;
1451 };
1452
1453 template<>
1454 struct Scalar<Float4>
1455 {
1456 using Type = Float;
1457 };
1458
1459 template<>
1460 struct Scalar<Int4>
1461 {
1462 using Type = Int;
1463 };
1464
1465 template<>
1466 struct Scalar<UInt4>
1467 {
1468 using Type = UInt;
1469 };
1470
1471 template<class Vector4, int T>
1472 class SwizzleMask1
1473 {
1474 public:
1475 operator RValue<typename Scalar<Vector4>::Type>() const;
1476 operator RValue<Vector4>() const;
1477
1478 RValue<Vector4> operator=(float x);
1479 RValue<Vector4> operator=(RValue<Vector4> rhs);
1480 RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
1481
1482 private:
Nicolas Capensbb575d42019-05-31 15:36:59 -04001483 Vector4 *parent;
Nicolas Capenscb986762017-01-20 11:34:37 -05001484 };
1485
1486 template<class Vector4, int T>
1487 class SwizzleMask2
1488 {
1489 friend class Float4;
1490
1491 public:
1492 operator RValue<Vector4>() const;
1493
1494 RValue<Vector4> operator=(RValue<Vector4> rhs);
1495
1496 private:
1497 Float4 *parent;
1498 };
1499
1500 template<class Vector4>
1501 struct XYZW
1502 {
1503 friend Vector4;
1504
1505 private:
1506 XYZW(Vector4 *parent)
1507 {
1508 xyzw.parent = parent;
1509 }
1510
1511 public:
1512 union
1513 {
1514 SwizzleMask1<Vector4, 0x00> x;
1515 SwizzleMask1<Vector4, 0x55> y;
1516 SwizzleMask1<Vector4, 0xAA> z;
1517 SwizzleMask1<Vector4, 0xFF> w;
1518 Swizzle2<Vector4, 0x00> xx;
1519 Swizzle2<Vector4, 0x01> yx;
1520 Swizzle2<Vector4, 0x02> zx;
1521 Swizzle2<Vector4, 0x03> wx;
1522 SwizzleMask2<Vector4, 0x54> xy;
1523 Swizzle2<Vector4, 0x55> yy;
1524 Swizzle2<Vector4, 0x56> zy;
1525 Swizzle2<Vector4, 0x57> wy;
1526 SwizzleMask2<Vector4, 0xA8> xz;
1527 SwizzleMask2<Vector4, 0xA9> yz;
1528 Swizzle2<Vector4, 0xAA> zz;
1529 Swizzle2<Vector4, 0xAB> wz;
1530 SwizzleMask2<Vector4, 0xFC> xw;
1531 SwizzleMask2<Vector4, 0xFD> yw;
1532 SwizzleMask2<Vector4, 0xFE> zw;
1533 Swizzle2<Vector4, 0xFF> ww;
1534 Swizzle4<Vector4, 0x00> xxx;
1535 Swizzle4<Vector4, 0x01> yxx;
1536 Swizzle4<Vector4, 0x02> zxx;
1537 Swizzle4<Vector4, 0x03> wxx;
1538 Swizzle4<Vector4, 0x04> xyx;
1539 Swizzle4<Vector4, 0x05> yyx;
1540 Swizzle4<Vector4, 0x06> zyx;
1541 Swizzle4<Vector4, 0x07> wyx;
1542 Swizzle4<Vector4, 0x08> xzx;
1543 Swizzle4<Vector4, 0x09> yzx;
1544 Swizzle4<Vector4, 0x0A> zzx;
1545 Swizzle4<Vector4, 0x0B> wzx;
1546 Swizzle4<Vector4, 0x0C> xwx;
1547 Swizzle4<Vector4, 0x0D> ywx;
1548 Swizzle4<Vector4, 0x0E> zwx;
1549 Swizzle4<Vector4, 0x0F> wwx;
1550 Swizzle4<Vector4, 0x50> xxy;
1551 Swizzle4<Vector4, 0x51> yxy;
1552 Swizzle4<Vector4, 0x52> zxy;
1553 Swizzle4<Vector4, 0x53> wxy;
1554 Swizzle4<Vector4, 0x54> xyy;
1555 Swizzle4<Vector4, 0x55> yyy;
1556 Swizzle4<Vector4, 0x56> zyy;
1557 Swizzle4<Vector4, 0x57> wyy;
1558 Swizzle4<Vector4, 0x58> xzy;
1559 Swizzle4<Vector4, 0x59> yzy;
1560 Swizzle4<Vector4, 0x5A> zzy;
1561 Swizzle4<Vector4, 0x5B> wzy;
1562 Swizzle4<Vector4, 0x5C> xwy;
1563 Swizzle4<Vector4, 0x5D> ywy;
1564 Swizzle4<Vector4, 0x5E> zwy;
1565 Swizzle4<Vector4, 0x5F> wwy;
1566 Swizzle4<Vector4, 0xA0> xxz;
1567 Swizzle4<Vector4, 0xA1> yxz;
1568 Swizzle4<Vector4, 0xA2> zxz;
1569 Swizzle4<Vector4, 0xA3> wxz;
1570 SwizzleMask4<Vector4, 0xA4> xyz;
1571 Swizzle4<Vector4, 0xA5> yyz;
1572 Swizzle4<Vector4, 0xA6> zyz;
1573 Swizzle4<Vector4, 0xA7> wyz;
1574 Swizzle4<Vector4, 0xA8> xzz;
1575 Swizzle4<Vector4, 0xA9> yzz;
1576 Swizzle4<Vector4, 0xAA> zzz;
1577 Swizzle4<Vector4, 0xAB> wzz;
1578 Swizzle4<Vector4, 0xAC> xwz;
1579 Swizzle4<Vector4, 0xAD> ywz;
1580 Swizzle4<Vector4, 0xAE> zwz;
1581 Swizzle4<Vector4, 0xAF> wwz;
1582 Swizzle4<Vector4, 0xF0> xxw;
1583 Swizzle4<Vector4, 0xF1> yxw;
1584 Swizzle4<Vector4, 0xF2> zxw;
1585 Swizzle4<Vector4, 0xF3> wxw;
1586 SwizzleMask4<Vector4, 0xF4> xyw;
1587 Swizzle4<Vector4, 0xF5> yyw;
1588 Swizzle4<Vector4, 0xF6> zyw;
1589 Swizzle4<Vector4, 0xF7> wyw;
1590 SwizzleMask4<Vector4, 0xF8> xzw;
1591 SwizzleMask4<Vector4, 0xF9> yzw;
1592 Swizzle4<Vector4, 0xFA> zzw;
1593 Swizzle4<Vector4, 0xFB> wzw;
1594 Swizzle4<Vector4, 0xFC> xww;
1595 Swizzle4<Vector4, 0xFD> yww;
1596 Swizzle4<Vector4, 0xFE> zww;
1597 Swizzle4<Vector4, 0xFF> www;
1598 Swizzle4<Vector4, 0x00> xxxx;
1599 Swizzle4<Vector4, 0x01> yxxx;
1600 Swizzle4<Vector4, 0x02> zxxx;
1601 Swizzle4<Vector4, 0x03> wxxx;
1602 Swizzle4<Vector4, 0x04> xyxx;
1603 Swizzle4<Vector4, 0x05> yyxx;
1604 Swizzle4<Vector4, 0x06> zyxx;
1605 Swizzle4<Vector4, 0x07> wyxx;
1606 Swizzle4<Vector4, 0x08> xzxx;
1607 Swizzle4<Vector4, 0x09> yzxx;
1608 Swizzle4<Vector4, 0x0A> zzxx;
1609 Swizzle4<Vector4, 0x0B> wzxx;
1610 Swizzle4<Vector4, 0x0C> xwxx;
1611 Swizzle4<Vector4, 0x0D> ywxx;
1612 Swizzle4<Vector4, 0x0E> zwxx;
1613 Swizzle4<Vector4, 0x0F> wwxx;
1614 Swizzle4<Vector4, 0x10> xxyx;
1615 Swizzle4<Vector4, 0x11> yxyx;
1616 Swizzle4<Vector4, 0x12> zxyx;
1617 Swizzle4<Vector4, 0x13> wxyx;
1618 Swizzle4<Vector4, 0x14> xyyx;
1619 Swizzle4<Vector4, 0x15> yyyx;
1620 Swizzle4<Vector4, 0x16> zyyx;
1621 Swizzle4<Vector4, 0x17> wyyx;
1622 Swizzle4<Vector4, 0x18> xzyx;
1623 Swizzle4<Vector4, 0x19> yzyx;
1624 Swizzle4<Vector4, 0x1A> zzyx;
1625 Swizzle4<Vector4, 0x1B> wzyx;
1626 Swizzle4<Vector4, 0x1C> xwyx;
1627 Swizzle4<Vector4, 0x1D> ywyx;
1628 Swizzle4<Vector4, 0x1E> zwyx;
1629 Swizzle4<Vector4, 0x1F> wwyx;
1630 Swizzle4<Vector4, 0x20> xxzx;
1631 Swizzle4<Vector4, 0x21> yxzx;
1632 Swizzle4<Vector4, 0x22> zxzx;
1633 Swizzle4<Vector4, 0x23> wxzx;
1634 Swizzle4<Vector4, 0x24> xyzx;
1635 Swizzle4<Vector4, 0x25> yyzx;
1636 Swizzle4<Vector4, 0x26> zyzx;
1637 Swizzle4<Vector4, 0x27> wyzx;
1638 Swizzle4<Vector4, 0x28> xzzx;
1639 Swizzle4<Vector4, 0x29> yzzx;
1640 Swizzle4<Vector4, 0x2A> zzzx;
1641 Swizzle4<Vector4, 0x2B> wzzx;
1642 Swizzle4<Vector4, 0x2C> xwzx;
1643 Swizzle4<Vector4, 0x2D> ywzx;
1644 Swizzle4<Vector4, 0x2E> zwzx;
1645 Swizzle4<Vector4, 0x2F> wwzx;
1646 Swizzle4<Vector4, 0x30> xxwx;
1647 Swizzle4<Vector4, 0x31> yxwx;
1648 Swizzle4<Vector4, 0x32> zxwx;
1649 Swizzle4<Vector4, 0x33> wxwx;
1650 Swizzle4<Vector4, 0x34> xywx;
1651 Swizzle4<Vector4, 0x35> yywx;
1652 Swizzle4<Vector4, 0x36> zywx;
1653 Swizzle4<Vector4, 0x37> wywx;
1654 Swizzle4<Vector4, 0x38> xzwx;
1655 Swizzle4<Vector4, 0x39> yzwx;
1656 Swizzle4<Vector4, 0x3A> zzwx;
1657 Swizzle4<Vector4, 0x3B> wzwx;
1658 Swizzle4<Vector4, 0x3C> xwwx;
1659 Swizzle4<Vector4, 0x3D> ywwx;
1660 Swizzle4<Vector4, 0x3E> zwwx;
1661 Swizzle4<Vector4, 0x3F> wwwx;
1662 Swizzle4<Vector4, 0x40> xxxy;
1663 Swizzle4<Vector4, 0x41> yxxy;
1664 Swizzle4<Vector4, 0x42> zxxy;
1665 Swizzle4<Vector4, 0x43> wxxy;
1666 Swizzle4<Vector4, 0x44> xyxy;
1667 Swizzle4<Vector4, 0x45> yyxy;
1668 Swizzle4<Vector4, 0x46> zyxy;
1669 Swizzle4<Vector4, 0x47> wyxy;
1670 Swizzle4<Vector4, 0x48> xzxy;
1671 Swizzle4<Vector4, 0x49> yzxy;
1672 Swizzle4<Vector4, 0x4A> zzxy;
1673 Swizzle4<Vector4, 0x4B> wzxy;
1674 Swizzle4<Vector4, 0x4C> xwxy;
1675 Swizzle4<Vector4, 0x4D> ywxy;
1676 Swizzle4<Vector4, 0x4E> zwxy;
1677 Swizzle4<Vector4, 0x4F> wwxy;
1678 Swizzle4<Vector4, 0x50> xxyy;
1679 Swizzle4<Vector4, 0x51> yxyy;
1680 Swizzle4<Vector4, 0x52> zxyy;
1681 Swizzle4<Vector4, 0x53> wxyy;
1682 Swizzle4<Vector4, 0x54> xyyy;
1683 Swizzle4<Vector4, 0x55> yyyy;
1684 Swizzle4<Vector4, 0x56> zyyy;
1685 Swizzle4<Vector4, 0x57> wyyy;
1686 Swizzle4<Vector4, 0x58> xzyy;
1687 Swizzle4<Vector4, 0x59> yzyy;
1688 Swizzle4<Vector4, 0x5A> zzyy;
1689 Swizzle4<Vector4, 0x5B> wzyy;
1690 Swizzle4<Vector4, 0x5C> xwyy;
1691 Swizzle4<Vector4, 0x5D> ywyy;
1692 Swizzle4<Vector4, 0x5E> zwyy;
1693 Swizzle4<Vector4, 0x5F> wwyy;
1694 Swizzle4<Vector4, 0x60> xxzy;
1695 Swizzle4<Vector4, 0x61> yxzy;
1696 Swizzle4<Vector4, 0x62> zxzy;
1697 Swizzle4<Vector4, 0x63> wxzy;
1698 Swizzle4<Vector4, 0x64> xyzy;
1699 Swizzle4<Vector4, 0x65> yyzy;
1700 Swizzle4<Vector4, 0x66> zyzy;
1701 Swizzle4<Vector4, 0x67> wyzy;
1702 Swizzle4<Vector4, 0x68> xzzy;
1703 Swizzle4<Vector4, 0x69> yzzy;
1704 Swizzle4<Vector4, 0x6A> zzzy;
1705 Swizzle4<Vector4, 0x6B> wzzy;
1706 Swizzle4<Vector4, 0x6C> xwzy;
1707 Swizzle4<Vector4, 0x6D> ywzy;
1708 Swizzle4<Vector4, 0x6E> zwzy;
1709 Swizzle4<Vector4, 0x6F> wwzy;
1710 Swizzle4<Vector4, 0x70> xxwy;
1711 Swizzle4<Vector4, 0x71> yxwy;
1712 Swizzle4<Vector4, 0x72> zxwy;
1713 Swizzle4<Vector4, 0x73> wxwy;
1714 Swizzle4<Vector4, 0x74> xywy;
1715 Swizzle4<Vector4, 0x75> yywy;
1716 Swizzle4<Vector4, 0x76> zywy;
1717 Swizzle4<Vector4, 0x77> wywy;
1718 Swizzle4<Vector4, 0x78> xzwy;
1719 Swizzle4<Vector4, 0x79> yzwy;
1720 Swizzle4<Vector4, 0x7A> zzwy;
1721 Swizzle4<Vector4, 0x7B> wzwy;
1722 Swizzle4<Vector4, 0x7C> xwwy;
1723 Swizzle4<Vector4, 0x7D> ywwy;
1724 Swizzle4<Vector4, 0x7E> zwwy;
1725 Swizzle4<Vector4, 0x7F> wwwy;
1726 Swizzle4<Vector4, 0x80> xxxz;
1727 Swizzle4<Vector4, 0x81> yxxz;
1728 Swizzle4<Vector4, 0x82> zxxz;
1729 Swizzle4<Vector4, 0x83> wxxz;
1730 Swizzle4<Vector4, 0x84> xyxz;
1731 Swizzle4<Vector4, 0x85> yyxz;
1732 Swizzle4<Vector4, 0x86> zyxz;
1733 Swizzle4<Vector4, 0x87> wyxz;
1734 Swizzle4<Vector4, 0x88> xzxz;
1735 Swizzle4<Vector4, 0x89> yzxz;
1736 Swizzle4<Vector4, 0x8A> zzxz;
1737 Swizzle4<Vector4, 0x8B> wzxz;
1738 Swizzle4<Vector4, 0x8C> xwxz;
1739 Swizzle4<Vector4, 0x8D> ywxz;
1740 Swizzle4<Vector4, 0x8E> zwxz;
1741 Swizzle4<Vector4, 0x8F> wwxz;
1742 Swizzle4<Vector4, 0x90> xxyz;
1743 Swizzle4<Vector4, 0x91> yxyz;
1744 Swizzle4<Vector4, 0x92> zxyz;
1745 Swizzle4<Vector4, 0x93> wxyz;
1746 Swizzle4<Vector4, 0x94> xyyz;
1747 Swizzle4<Vector4, 0x95> yyyz;
1748 Swizzle4<Vector4, 0x96> zyyz;
1749 Swizzle4<Vector4, 0x97> wyyz;
1750 Swizzle4<Vector4, 0x98> xzyz;
1751 Swizzle4<Vector4, 0x99> yzyz;
1752 Swizzle4<Vector4, 0x9A> zzyz;
1753 Swizzle4<Vector4, 0x9B> wzyz;
1754 Swizzle4<Vector4, 0x9C> xwyz;
1755 Swizzle4<Vector4, 0x9D> ywyz;
1756 Swizzle4<Vector4, 0x9E> zwyz;
1757 Swizzle4<Vector4, 0x9F> wwyz;
1758 Swizzle4<Vector4, 0xA0> xxzz;
1759 Swizzle4<Vector4, 0xA1> yxzz;
1760 Swizzle4<Vector4, 0xA2> zxzz;
1761 Swizzle4<Vector4, 0xA3> wxzz;
1762 Swizzle4<Vector4, 0xA4> xyzz;
1763 Swizzle4<Vector4, 0xA5> yyzz;
1764 Swizzle4<Vector4, 0xA6> zyzz;
1765 Swizzle4<Vector4, 0xA7> wyzz;
1766 Swizzle4<Vector4, 0xA8> xzzz;
1767 Swizzle4<Vector4, 0xA9> yzzz;
1768 Swizzle4<Vector4, 0xAA> zzzz;
1769 Swizzle4<Vector4, 0xAB> wzzz;
1770 Swizzle4<Vector4, 0xAC> xwzz;
1771 Swizzle4<Vector4, 0xAD> ywzz;
1772 Swizzle4<Vector4, 0xAE> zwzz;
1773 Swizzle4<Vector4, 0xAF> wwzz;
1774 Swizzle4<Vector4, 0xB0> xxwz;
1775 Swizzle4<Vector4, 0xB1> yxwz;
1776 Swizzle4<Vector4, 0xB2> zxwz;
1777 Swizzle4<Vector4, 0xB3> wxwz;
1778 Swizzle4<Vector4, 0xB4> xywz;
1779 Swizzle4<Vector4, 0xB5> yywz;
1780 Swizzle4<Vector4, 0xB6> zywz;
1781 Swizzle4<Vector4, 0xB7> wywz;
1782 Swizzle4<Vector4, 0xB8> xzwz;
1783 Swizzle4<Vector4, 0xB9> yzwz;
1784 Swizzle4<Vector4, 0xBA> zzwz;
1785 Swizzle4<Vector4, 0xBB> wzwz;
1786 Swizzle4<Vector4, 0xBC> xwwz;
1787 Swizzle4<Vector4, 0xBD> ywwz;
1788 Swizzle4<Vector4, 0xBE> zwwz;
1789 Swizzle4<Vector4, 0xBF> wwwz;
1790 Swizzle4<Vector4, 0xC0> xxxw;
1791 Swizzle4<Vector4, 0xC1> yxxw;
1792 Swizzle4<Vector4, 0xC2> zxxw;
1793 Swizzle4<Vector4, 0xC3> wxxw;
1794 Swizzle4<Vector4, 0xC4> xyxw;
1795 Swizzle4<Vector4, 0xC5> yyxw;
1796 Swizzle4<Vector4, 0xC6> zyxw;
1797 Swizzle4<Vector4, 0xC7> wyxw;
1798 Swizzle4<Vector4, 0xC8> xzxw;
1799 Swizzle4<Vector4, 0xC9> yzxw;
1800 Swizzle4<Vector4, 0xCA> zzxw;
1801 Swizzle4<Vector4, 0xCB> wzxw;
1802 Swizzle4<Vector4, 0xCC> xwxw;
1803 Swizzle4<Vector4, 0xCD> ywxw;
1804 Swizzle4<Vector4, 0xCE> zwxw;
1805 Swizzle4<Vector4, 0xCF> wwxw;
1806 Swizzle4<Vector4, 0xD0> xxyw;
1807 Swizzle4<Vector4, 0xD1> yxyw;
1808 Swizzle4<Vector4, 0xD2> zxyw;
1809 Swizzle4<Vector4, 0xD3> wxyw;
1810 Swizzle4<Vector4, 0xD4> xyyw;
1811 Swizzle4<Vector4, 0xD5> yyyw;
1812 Swizzle4<Vector4, 0xD6> zyyw;
1813 Swizzle4<Vector4, 0xD7> wyyw;
1814 Swizzle4<Vector4, 0xD8> xzyw;
1815 Swizzle4<Vector4, 0xD9> yzyw;
1816 Swizzle4<Vector4, 0xDA> zzyw;
1817 Swizzle4<Vector4, 0xDB> wzyw;
1818 Swizzle4<Vector4, 0xDC> xwyw;
1819 Swizzle4<Vector4, 0xDD> ywyw;
1820 Swizzle4<Vector4, 0xDE> zwyw;
1821 Swizzle4<Vector4, 0xDF> wwyw;
1822 Swizzle4<Vector4, 0xE0> xxzw;
1823 Swizzle4<Vector4, 0xE1> yxzw;
1824 Swizzle4<Vector4, 0xE2> zxzw;
1825 Swizzle4<Vector4, 0xE3> wxzw;
1826 SwizzleMask4<Vector4, 0xE4> xyzw;
1827 Swizzle4<Vector4, 0xE5> yyzw;
1828 Swizzle4<Vector4, 0xE6> zyzw;
1829 Swizzle4<Vector4, 0xE7> wyzw;
1830 Swizzle4<Vector4, 0xE8> xzzw;
1831 Swizzle4<Vector4, 0xE9> yzzw;
1832 Swizzle4<Vector4, 0xEA> zzzw;
1833 Swizzle4<Vector4, 0xEB> wzzw;
1834 Swizzle4<Vector4, 0xEC> xwzw;
1835 Swizzle4<Vector4, 0xED> ywzw;
1836 Swizzle4<Vector4, 0xEE> zwzw;
1837 Swizzle4<Vector4, 0xEF> wwzw;
1838 Swizzle4<Vector4, 0xF0> xxww;
1839 Swizzle4<Vector4, 0xF1> yxww;
1840 Swizzle4<Vector4, 0xF2> zxww;
1841 Swizzle4<Vector4, 0xF3> wxww;
1842 Swizzle4<Vector4, 0xF4> xyww;
1843 Swizzle4<Vector4, 0xF5> yyww;
1844 Swizzle4<Vector4, 0xF6> zyww;
1845 Swizzle4<Vector4, 0xF7> wyww;
1846 Swizzle4<Vector4, 0xF8> xzww;
1847 Swizzle4<Vector4, 0xF9> yzww;
1848 Swizzle4<Vector4, 0xFA> zzww;
1849 Swizzle4<Vector4, 0xFB> wzww;
1850 Swizzle4<Vector4, 0xFC> xwww;
1851 Swizzle4<Vector4, 0xFD> ywww;
1852 Swizzle4<Vector4, 0xFE> zwww;
1853 Swizzle4<Vector4, 0xFF> wwww;
1854 };
1855 };
1856
1857 class Int4 : public LValue<Int4>, public XYZW<Int4>
Nicolas Capensd022e412016-09-26 13:30:14 -04001858 {
1859 public:
1860 explicit Int4(RValue<Byte4> cast);
1861 explicit Int4(RValue<SByte4> cast);
1862 explicit Int4(RValue<Float4> cast);
1863 explicit Int4(RValue<Short4> cast);
1864 explicit Int4(RValue<UShort4> cast);
1865
Nicolas Capenscb986762017-01-20 11:34:37 -05001866 Int4();
Nicolas Capensd022e412016-09-26 13:30:14 -04001867 Int4(int xyzw);
1868 Int4(int x, int yzw);
1869 Int4(int x, int y, int zw);
1870 Int4(int x, int y, int z, int w);
1871 Int4(RValue<Int4> rhs);
1872 Int4(const Int4 &rhs);
1873 Int4(const Reference<Int4> &rhs);
1874 Int4(RValue<UInt4> rhs);
1875 Int4(const UInt4 &rhs);
1876 Int4(const Reference<UInt4> &rhs);
1877 Int4(RValue<Int2> lo, RValue<Int2> hi);
1878 Int4(RValue<Int> rhs);
1879 Int4(const Int &rhs);
1880 Int4(const Reference<Int> &rhs);
1881
Nicolas Capens96d4e092016-11-18 14:22:38 -05001882 RValue<Int4> operator=(RValue<Int4> rhs);
1883 RValue<Int4> operator=(const Int4 &rhs);
1884 RValue<Int4> operator=(const Reference<Int4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001885
1886 static Type *getType();
1887
1888 private:
1889 void constant(int x, int y, int z, int w);
1890 };
1891
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, RValue<Int4> rhs);
1895 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> 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|(RValue<Int4> lhs, RValue<Int4> rhs);
1899 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs);
1900 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs);
1901 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs);
1902 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs);
1903 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001904 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs);
1905 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs);
1906 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs);
1907// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs);
1908// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs);
1909 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs);
1910 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs);
1911 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs);
1912 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs);
1913 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001914 RValue<Int4> operator+(RValue<Int4> val);
1915 RValue<Int4> operator-(RValue<Int4> val);
1916 RValue<Int4> operator~(RValue<Int4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05001917// RValue<Int4> operator++(Int4 &val, int); // Post-increment
1918// const Int4 &operator++(Int4 &val); // Pre-increment
1919// RValue<Int4> operator--(Int4 &val, int); // Post-decrement
1920// const Int4 &operator--(Int4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04001921// RValue<Bool> operator<(RValue<Int4> lhs, RValue<Int4> rhs);
1922// RValue<Bool> operator<=(RValue<Int4> lhs, RValue<Int4> rhs);
1923// RValue<Bool> operator>(RValue<Int4> lhs, RValue<Int4> rhs);
1924// RValue<Bool> operator>=(RValue<Int4> lhs, RValue<Int4> rhs);
1925// RValue<Bool> operator!=(RValue<Int4> lhs, RValue<Int4> rhs);
1926// RValue<Bool> operator==(RValue<Int4> lhs, RValue<Int4> rhs);
1927
Nicolas Capens4b743732018-05-28 13:22:07 -04001928 inline RValue<Int4> operator+(RValue<Int> lhs, RValue<Int4> rhs)
1929 {
1930 return Int4(lhs) + rhs;
1931 }
1932
1933 inline RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int> rhs)
1934 {
1935 return lhs + Int4(rhs);
1936 }
1937
Nicolas Capensd022e412016-09-26 13:30:14 -04001938 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y);
1939 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y);
1940 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y);
1941 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y);
1942 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y);
1943 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y);
Ben Claytone95eeb12019-03-04 16:32:09 +00001944 inline RValue<Int4> CmpGT(RValue<Int4> x, RValue<Int4> y) { return CmpNLE(x, y); }
1945 inline RValue<Int4> CmpGE(RValue<Int4> x, RValue<Int4> y) { return CmpNLT(x, y); }
Nicolas Capensd022e412016-09-26 13:30:14 -04001946 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y);
1947 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y);
1948 RValue<Int4> RoundInt(RValue<Float4> cast);
Nicolas Capens33438a62017-09-27 11:47:35 -04001949 RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y);
1950 RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y);
Nicolas Capensc94ab742016-11-08 15:15:31 -05001951 RValue<Int> Extract(RValue<Int4> val, int i);
Nicolas Capensd022e412016-09-26 13:30:14 -04001952 RValue<Int4> Insert(RValue<Int4> val, RValue<Int> element, int i);
1953 RValue<Int> SignMask(RValue<Int4> x);
1954 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select);
Chris Forbese86b6dc2019-03-01 09:08:47 -08001955 RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y);
Nicolas Capensd022e412016-09-26 13:30:14 -04001956
Nicolas Capenscb986762017-01-20 11:34:37 -05001957 class UInt4 : public LValue<UInt4>, public XYZW<UInt4>
Nicolas Capensd022e412016-09-26 13:30:14 -04001958 {
1959 public:
1960 explicit UInt4(RValue<Float4> cast);
1961
Nicolas Capenscb986762017-01-20 11:34:37 -05001962 UInt4();
Nicolas Capensd022e412016-09-26 13:30:14 -04001963 UInt4(int xyzw);
1964 UInt4(int x, int yzw);
1965 UInt4(int x, int y, int zw);
1966 UInt4(int x, int y, int z, int w);
Nicolas Capensd022e412016-09-26 13:30:14 -04001967 UInt4(RValue<UInt4> rhs);
1968 UInt4(const UInt4 &rhs);
1969 UInt4(const Reference<UInt4> &rhs);
1970 UInt4(RValue<Int4> rhs);
1971 UInt4(const Int4 &rhs);
1972 UInt4(const Reference<Int4> &rhs);
1973 UInt4(RValue<UInt2> lo, RValue<UInt2> hi);
Ben Clayton88816fa2019-05-15 17:08:14 +01001974 UInt4(RValue<UInt> rhs);
1975 UInt4(const UInt &rhs);
1976 UInt4(const Reference<UInt> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001977
Nicolas Capens96d4e092016-11-18 14:22:38 -05001978 RValue<UInt4> operator=(RValue<UInt4> rhs);
1979 RValue<UInt4> operator=(const UInt4 &rhs);
1980 RValue<UInt4> operator=(const Reference<UInt4> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04001981
1982 static Type *getType();
1983
1984 private:
1985 void constant(int x, int y, int z, int w);
1986 };
1987
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, RValue<UInt4> rhs);
1991 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> 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|(RValue<UInt4> lhs, RValue<UInt4> rhs);
1995 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs);
1996 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs);
1997 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs);
1998 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs);
1999 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002000 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs);
2001 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs);
2002 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs);
2003// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs);
2004// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs);
2005 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs);
2006 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs);
2007 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs);
2008 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs);
2009 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002010 RValue<UInt4> operator+(RValue<UInt4> val);
2011 RValue<UInt4> operator-(RValue<UInt4> val);
2012 RValue<UInt4> operator~(RValue<UInt4> val);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002013// RValue<UInt4> operator++(UInt4 &val, int); // Post-increment
2014// const UInt4 &operator++(UInt4 &val); // Pre-increment
2015// RValue<UInt4> operator--(UInt4 &val, int); // Post-decrement
2016// const UInt4 &operator--(UInt4 &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04002017// RValue<Bool> operator<(RValue<UInt4> lhs, RValue<UInt4> rhs);
2018// RValue<Bool> operator<=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2019// RValue<Bool> operator>(RValue<UInt4> lhs, RValue<UInt4> rhs);
2020// RValue<Bool> operator>=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2021// RValue<Bool> operator!=(RValue<UInt4> lhs, RValue<UInt4> rhs);
2022// RValue<Bool> operator==(RValue<UInt4> lhs, RValue<UInt4> rhs);
2023
2024 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y);
2025 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y);
2026 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y);
2027 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y);
2028 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y);
2029 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y);
Ben Claytone95eeb12019-03-04 16:32:09 +00002030 inline RValue<UInt4> CmpGT(RValue<UInt4> x, RValue<UInt4> y) { return CmpNLE(x, y); }
2031 inline RValue<UInt4> CmpGE(RValue<UInt4> x, RValue<UInt4> y) { return CmpNLT(x, y); }
Nicolas Capensd022e412016-09-26 13:30:14 -04002032 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y);
2033 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y);
Chris Forbese86b6dc2019-03-01 09:08:47 -08002034 RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y);
Ben Claytonfc77af12019-04-09 10:48:00 -04002035 RValue<UInt> Extract(RValue<UInt4> val, int i);
2036 RValue<UInt4> Insert(RValue<UInt4> val, RValue<UInt> element, int i);
Nicolas Capensd022e412016-09-26 13:30:14 -04002037// RValue<UInt4> RoundInt(RValue<Float4> cast);
Ben Clayton74591722019-05-14 16:51:52 +01002038 RValue<UInt4> Swizzle(RValue<UInt4> x, unsigned char select);
Nicolas Capensd022e412016-09-26 13:30:14 -04002039
Alexis Hetu734e2572018-12-20 14:00:49 -05002040 class Half : public LValue<Half>
2041 {
2042 public:
2043 explicit Half(RValue<Float> cast);
2044
2045 static Type *getType();
2046 };
2047
Nicolas Capens297d26e2016-11-18 12:52:17 -05002048 class Float : public LValue<Float>
Nicolas Capensd022e412016-09-26 13:30:14 -04002049 {
2050 public:
2051 explicit Float(RValue<Int> cast);
Alexis Hetucfd96322017-07-24 14:44:33 -04002052 explicit Float(RValue<UInt> cast);
Alexis Hetu734e2572018-12-20 14:00:49 -05002053 explicit Float(RValue<Half> cast);
Nicolas Capensd022e412016-09-26 13:30:14 -04002054
Nicolas Capensa25311a2017-01-16 17:19:00 -05002055 Float() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04002056 Float(float x);
2057 Float(RValue<Float> rhs);
2058 Float(const Float &rhs);
2059 Float(const Reference<Float> &rhs);
Ben Claytonf3b57972019-03-15 09:56:47 +00002060 Float(Argument<Float> argument);
Nicolas Capensd022e412016-09-26 13:30:14 -04002061
2062 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002063 Float(const SwizzleMask1<Float4, T> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002064
Nicolas Capens96d4e092016-11-18 14:22:38 -05002065 // RValue<Float> operator=(float rhs); // FIXME: Implement
2066 RValue<Float> operator=(RValue<Float> rhs);
2067 RValue<Float> operator=(const Float &rhs);
2068 RValue<Float> operator=(const Reference<Float> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002069
2070 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002071 RValue<Float> operator=(const SwizzleMask1<Float4, T> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002072
2073 static Type *getType();
2074 };
2075
2076 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs);
2077 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs);
2078 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs);
2079 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002080 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs);
2081 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs);
2082 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs);
2083 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002084 RValue<Float> operator+(RValue<Float> val);
2085 RValue<Float> operator-(RValue<Float> val);
2086 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs);
2087 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs);
2088 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs);
2089 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs);
2090 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs);
2091 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs);
2092
2093 RValue<Float> Abs(RValue<Float> x);
2094 RValue<Float> Max(RValue<Float> x, RValue<Float> y);
2095 RValue<Float> Min(RValue<Float> x, RValue<Float> y);
2096 RValue<Float> Rcp_pp(RValue<Float> val, bool exactAtPow2 = false);
2097 RValue<Float> RcpSqrt_pp(RValue<Float> val);
2098 RValue<Float> Sqrt(RValue<Float> x);
Nicolas Capens88ac3672019-08-01 13:22:34 -04002099
2100// RValue<Int4> IsInf(RValue<Float> x);
2101// RValue<Int4> IsNan(RValue<Float> x);
2102 RValue<Float> Round(RValue<Float> x);
2103 RValue<Float> Trunc(RValue<Float> x);
2104 RValue<Float> Frac(RValue<Float> x);
2105 RValue<Float> Floor(RValue<Float> x);
2106 RValue<Float> Ceil(RValue<Float> x);
2107
2108 // Trigonometric functions
2109 // TODO: Currently unimplemented for Subzero.
2110// RValue<Float> Sin(RValue<Float> x);
2111// RValue<Float> Cos(RValue<Float> x);
2112// RValue<Float> Tan(RValue<Float> x);
2113// RValue<Float> Asin(RValue<Float> x);
2114// RValue<Float> Acos(RValue<Float> x);
2115// RValue<Float> Atan(RValue<Float> x);
2116// RValue<Float> Sinh(RValue<Float> x);
2117// RValue<Float> Cosh(RValue<Float> x);
2118// RValue<Float> Tanh(RValue<Float> x);
2119// RValue<Float> Asinh(RValue<Float> x);
2120// RValue<Float> Acosh(RValue<Float> x);
2121// RValue<Float> Atanh(RValue<Float> x);
2122// RValue<Float> Atan2(RValue<Float> x, RValue<Float> y);
2123
2124 // Exponential functions
2125 // TODO: Currently unimplemented for Subzero.
2126// RValue<Float> Pow(RValue<Float> x, RValue<Float> y);
2127// RValue<Float> Exp(RValue<Float> x);
2128// RValue<Float> Log(RValue<Float> x);
2129 RValue<Float> Exp2(RValue<Float> x);
2130 RValue<Float> Log2(RValue<Float> x);
Nicolas Capensd022e412016-09-26 13:30:14 -04002131
Nicolas Capens297d26e2016-11-18 12:52:17 -05002132 class Float2 : public LValue<Float2>
Nicolas Capensd022e412016-09-26 13:30:14 -04002133 {
2134 public:
2135 // explicit Float2(RValue<Byte2> cast);
2136 // explicit Float2(RValue<Short2> cast);
2137 // explicit Float2(RValue<UShort2> cast);
2138 // explicit Float2(RValue<Int2> cast);
2139 // explicit Float2(RValue<UInt2> cast);
2140 explicit Float2(RValue<Float4> cast);
2141
Nicolas Capensa25311a2017-01-16 17:19:00 -05002142 Float2() = default;
Nicolas Capensd022e412016-09-26 13:30:14 -04002143 // Float2(float x, float y);
2144 // Float2(RValue<Float2> rhs);
2145 // Float2(const Float2 &rhs);
2146 // Float2(const Reference<Float2> &rhs);
2147 // Float2(RValue<Float> rhs);
2148 // Float2(const Float &rhs);
2149 // Float2(const Reference<Float> &rhs);
2150
2151 // template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002152 // Float2(const SwizzleMask1<T> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002153
Nicolas Capens96d4e092016-11-18 14:22:38 -05002154 // RValue<Float2> operator=(float replicate);
2155 // RValue<Float2> operator=(RValue<Float2> rhs);
2156 // RValue<Float2> operator=(const Float2 &rhs);
2157 // RValue<Float2> operator=(const Reference<Float2> &rhs);
2158 // RValue<Float2> operator=(RValue<Float> rhs);
2159 // RValue<Float2> operator=(const Float &rhs);
2160 // RValue<Float2> operator=(const Reference<Float> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002161
2162 // template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002163 // RValue<Float2> operator=(const SwizzleMask1<T> &rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002164
2165 static Type *getType();
2166 };
2167
2168// RValue<Float2> operator+(RValue<Float2> lhs, RValue<Float2> rhs);
2169// RValue<Float2> operator-(RValue<Float2> lhs, RValue<Float2> rhs);
2170// RValue<Float2> operator*(RValue<Float2> lhs, RValue<Float2> rhs);
2171// RValue<Float2> operator/(RValue<Float2> lhs, RValue<Float2> rhs);
2172// RValue<Float2> operator%(RValue<Float2> lhs, RValue<Float2> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002173// RValue<Float2> operator+=(Float2 &lhs, RValue<Float2> rhs);
2174// RValue<Float2> operator-=(Float2 &lhs, RValue<Float2> rhs);
2175// RValue<Float2> operator*=(Float2 &lhs, RValue<Float2> rhs);
2176// RValue<Float2> operator/=(Float2 &lhs, RValue<Float2> rhs);
2177// RValue<Float2> operator%=(Float2 &lhs, RValue<Float2> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002178// RValue<Float2> operator+(RValue<Float2> val);
2179// RValue<Float2> operator-(RValue<Float2> val);
2180
2181// RValue<Float2> Abs(RValue<Float2> x);
2182// RValue<Float2> Max(RValue<Float2> x, RValue<Float2> y);
2183// RValue<Float2> Min(RValue<Float2> x, RValue<Float2> y);
2184// RValue<Float2> Swizzle(RValue<Float2> x, unsigned char select);
2185// RValue<Float2> Mask(Float2 &lhs, RValue<Float2> rhs, unsigned char select);
2186
Nicolas Capenscb986762017-01-20 11:34:37 -05002187 class Float4 : public LValue<Float4>, public XYZW<Float4>
Nicolas Capensa25311a2017-01-16 17:19:00 -05002188 {
2189 public:
2190 explicit Float4(RValue<Byte4> cast);
2191 explicit Float4(RValue<SByte4> cast);
2192 explicit Float4(RValue<Short4> cast);
2193 explicit Float4(RValue<UShort4> cast);
2194 explicit Float4(RValue<Int4> cast);
2195 explicit Float4(RValue<UInt4> cast);
2196
2197 Float4();
2198 Float4(float xyzw);
2199 Float4(float x, float yzw);
2200 Float4(float x, float y, float zw);
2201 Float4(float x, float y, float z, float w);
2202 Float4(RValue<Float4> rhs);
2203 Float4(const Float4 &rhs);
2204 Float4(const Reference<Float4> &rhs);
2205 Float4(RValue<Float> rhs);
2206 Float4(const Float &rhs);
2207 Float4(const Reference<Float> &rhs);
2208
2209 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002210 Float4(const SwizzleMask1<Float4, T> &rhs);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002211 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002212 Float4(const Swizzle4<Float4, T> &rhs);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002213 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002214 Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002215 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002216 Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002217 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002218 Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002219 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002220 Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002221
2222 RValue<Float4> operator=(float replicate);
2223 RValue<Float4> operator=(RValue<Float4> rhs);
2224 RValue<Float4> operator=(const Float4 &rhs);
2225 RValue<Float4> operator=(const Reference<Float4> &rhs);
2226 RValue<Float4> operator=(RValue<Float> rhs);
2227 RValue<Float4> operator=(const Float &rhs);
2228 RValue<Float4> operator=(const Reference<Float> &rhs);
2229
2230 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002231 RValue<Float4> operator=(const SwizzleMask1<Float4, T> &rhs);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002232 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002233 RValue<Float4> operator=(const Swizzle4<Float4, T> &rhs);
Nicolas Capensa25311a2017-01-16 17:19:00 -05002234
2235 static Type *getType();
Nicolas Capensd022e412016-09-26 13:30:14 -04002236
2237 private:
2238 void constant(float x, float y, float z, float w);
2239 };
2240
2241 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs);
2242 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs);
2243 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs);
2244 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs);
2245 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002246 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs);
2247 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs);
2248 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs);
2249 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs);
2250 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs);
Nicolas Capensd022e412016-09-26 13:30:14 -04002251 RValue<Float4> operator+(RValue<Float4> val);
2252 RValue<Float4> operator-(RValue<Float4> val);
2253
2254 RValue<Float4> Abs(RValue<Float4> x);
2255 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y);
2256 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y);
2257 RValue<Float4> Rcp_pp(RValue<Float4> val, bool exactAtPow2 = false);
2258 RValue<Float4> RcpSqrt_pp(RValue<Float4> val);
2259 RValue<Float4> Sqrt(RValue<Float4> x);
Nicolas Capensc94ab742016-11-08 15:15:31 -05002260 RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i);
Nicolas Capensd022e412016-09-26 13:30:14 -04002261 RValue<Float> Extract(RValue<Float4> x, int i);
2262 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select);
2263 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm);
2264 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y);
2265 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y);
2266 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select);
2267 RValue<Int> SignMask(RValue<Float4> x);
Ben Claytonec1aeb82019-03-04 19:33:27 +00002268
2269 // Ordered comparison functions
Nicolas Capensd022e412016-09-26 13:30:14 -04002270 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y);
2271 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y);
2272 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y);
2273 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y);
2274 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y);
2275 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y);
Ben Claytonec1aeb82019-03-04 19:33:27 +00002276 inline RValue<Int4> CmpGT(RValue<Float4> x, RValue<Float4> y) { return CmpNLE(x, y); }
2277 inline RValue<Int4> CmpGE(RValue<Float4> x, RValue<Float4> y) { return CmpNLT(x, y); }
2278
2279 // Unordered comparison functions
2280 RValue<Int4> CmpUEQ(RValue<Float4> x, RValue<Float4> y);
2281 RValue<Int4> CmpULT(RValue<Float4> x, RValue<Float4> y);
2282 RValue<Int4> CmpULE(RValue<Float4> x, RValue<Float4> y);
2283 RValue<Int4> CmpUNEQ(RValue<Float4> x, RValue<Float4> y);
2284 RValue<Int4> CmpUNLT(RValue<Float4> x, RValue<Float4> y);
2285 RValue<Int4> CmpUNLE(RValue<Float4> x, RValue<Float4> y);
2286 inline RValue<Int4> CmpUGT(RValue<Float4> x, RValue<Float4> y) { return CmpUNLE(x, y); }
2287 inline RValue<Int4> CmpUGE(RValue<Float4> x, RValue<Float4> y) { return CmpUNLT(x, y); }
2288
Alexis Hetu8ef6d102017-11-09 15:49:09 -05002289 RValue<Int4> IsInf(RValue<Float4> x);
2290 RValue<Int4> IsNan(RValue<Float4> x);
Nicolas Capensd022e412016-09-26 13:30:14 -04002291 RValue<Float4> Round(RValue<Float4> x);
2292 RValue<Float4> Trunc(RValue<Float4> x);
2293 RValue<Float4> Frac(RValue<Float4> x);
2294 RValue<Float4> Floor(RValue<Float4> x);
2295 RValue<Float4> Ceil(RValue<Float4> x);
2296
Ben Claytona2c8b772019-04-09 13:42:36 -04002297 // Trigonometric functions
Nicolas Capens88ac3672019-08-01 13:22:34 -04002298 // TODO: Currently unimplemented for Subzero.
Ben Claytona2c8b772019-04-09 13:42:36 -04002299 RValue<Float4> Sin(RValue<Float4> x);
Ben Clayton1b6f8c72019-04-09 13:47:43 -04002300 RValue<Float4> Cos(RValue<Float4> x);
Ben Clayton14740062019-04-09 13:48:41 -04002301 RValue<Float4> Tan(RValue<Float4> x);
Ben Claytonf9350d72019-04-09 14:19:02 -04002302 RValue<Float4> Asin(RValue<Float4> x);
Ben Claytoneafae472019-04-09 14:22:38 -04002303 RValue<Float4> Acos(RValue<Float4> x);
Ben Clayton749b4e02019-04-09 14:27:43 -04002304 RValue<Float4> Atan(RValue<Float4> x);
Ben Claytond9636972019-04-09 15:09:54 -04002305 RValue<Float4> Sinh(RValue<Float4> x);
Ben Clayton900ea2c2019-04-09 15:25:36 -04002306 RValue<Float4> Cosh(RValue<Float4> x);
Ben Clayton3928bd92019-04-09 15:27:41 -04002307 RValue<Float4> Tanh(RValue<Float4> x);
Ben Claytonf6d77ab2019-04-09 15:30:04 -04002308 RValue<Float4> Asinh(RValue<Float4> x);
Ben Clayton28ebcb02019-04-09 15:33:38 -04002309 RValue<Float4> Acosh(RValue<Float4> x);
Ben Claytonfa6a5392019-04-09 15:35:24 -04002310 RValue<Float4> Atanh(RValue<Float4> x);
Ben Claytona520c3e2019-04-09 15:43:45 -04002311 RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y);
Ben Claytona2c8b772019-04-09 13:42:36 -04002312
Ben Claytonbfe94f02019-04-09 15:52:12 -04002313 // Exponential functions
Nicolas Capens88ac3672019-08-01 13:22:34 -04002314 // TODO: Currently unimplemented for Subzero.
Ben Claytonbfe94f02019-04-09 15:52:12 -04002315 RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y);
Ben Clayton242f0022019-04-09 16:00:53 -04002316 RValue<Float4> Exp(RValue<Float4> x);
Ben Clayton2c1da722019-04-09 16:03:03 -04002317 RValue<Float4> Log(RValue<Float4> x);
Ben Claytonf40b56c2019-04-09 16:06:55 -04002318 RValue<Float4> Exp2(RValue<Float4> x);
Ben Claytone17acfe2019-04-09 16:09:13 -04002319 RValue<Float4> Log2(RValue<Float4> x);
Ben Claytonbfe94f02019-04-09 15:52:12 -04002320
Ben Clayton60958262019-04-10 14:53:30 -04002321 // Bit Manipulation functions.
Nicolas Capens88ac3672019-08-01 13:22:34 -04002322 // TODO: Currently unimplemented for Subzero.
Ben Clayton60958262019-04-10 14:53:30 -04002323
2324 // Count leading zeros.
2325 // Returns 32 when: isZeroUndef && x == 0.
2326 // Returns an undefined value when: !isZeroUndef && x == 0.
Ben Claytonff6e8c02019-08-06 21:23:44 +01002327 RValue<UInt> Ctlz(RValue<UInt> x, bool isZeroUndef);
Ben Clayton60958262019-04-10 14:53:30 -04002328 RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
2329
Ben Clayton3f007c42019-04-10 14:54:23 -04002330 // Count trailing zeros.
2331 // Returns 32 when: isZeroUndef && x == 0.
2332 // Returns an undefined value when: !isZeroUndef && x == 0.
Ben Claytonff6e8c02019-08-06 21:23:44 +01002333 RValue<UInt> Cttz(RValue<UInt> x, bool isZeroUndef);
Ben Clayton3f007c42019-04-10 14:54:23 -04002334 RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
2335
Nicolas Capensd022e412016-09-26 13:30:14 -04002336 template<class T>
Nicolas Capens297d26e2016-11-18 12:52:17 -05002337 class Pointer : public LValue<Pointer<T>>
Nicolas Capensd022e412016-09-26 13:30:14 -04002338 {
2339 public:
2340 template<class S>
2341 Pointer(RValue<Pointer<S>> pointerS, int alignment = 1) : alignment(alignment)
2342 {
2343 Value *pointerT = Nucleus::createBitCast(pointerS.value, Nucleus::getPointerType(T::getType()));
Nicolas Capens22479eb2016-09-28 22:34:26 -04002344 LValue<Pointer<T>>::storeValue(pointerT);
Nicolas Capensd022e412016-09-26 13:30:14 -04002345 }
2346
2347 template<class S>
2348 Pointer(const Pointer<S> &pointer, int alignment = 1) : alignment(alignment)
2349 {
Nicolas Capens4126b8e2017-07-26 13:34:36 -04002350 Value *pointerS = pointer.loadValue();
Nicolas Capensd022e412016-09-26 13:30:14 -04002351 Value *pointerT = Nucleus::createBitCast(pointerS, Nucleus::getPointerType(T::getType()));
Nicolas Capens22479eb2016-09-28 22:34:26 -04002352 LValue<Pointer<T>>::storeValue(pointerT);
Nicolas Capensd022e412016-09-26 13:30:14 -04002353 }
2354
2355 Pointer(Argument<Pointer<T>> argument);
Nicolas Capensd022e412016-09-26 13:30:14 -04002356
2357 Pointer();
2358 Pointer(RValue<Pointer<T>> rhs);
2359 Pointer(const Pointer<T> &rhs);
2360 Pointer(const Reference<Pointer<T>> &rhs);
Ben Clayton0697da02019-08-01 13:35:48 +01002361 Pointer(std::nullptr_t);
Nicolas Capensd022e412016-09-26 13:30:14 -04002362
Nicolas Capens96d4e092016-11-18 14:22:38 -05002363 RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs);
2364 RValue<Pointer<T>> operator=(const Pointer<T> &rhs);
2365 RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs);
Ben Clayton0697da02019-08-01 13:35:48 +01002366 RValue<Pointer<T>> operator=(std::nullptr_t);
Nicolas Capensd022e412016-09-26 13:30:14 -04002367
2368 Reference<T> operator*();
2369 Reference<T> operator[](int index);
Nicolas Capensd294def2017-01-26 17:44:37 -08002370 Reference<T> operator[](unsigned int index);
Nicolas Capensd022e412016-09-26 13:30:14 -04002371 Reference<T> operator[](RValue<Int> index);
Nicolas Capensd294def2017-01-26 17:44:37 -08002372 Reference<T> operator[](RValue<UInt> index);
Nicolas Capensd022e412016-09-26 13:30:14 -04002373
2374 static Type *getType();
2375
2376 private:
2377 const int alignment;
2378 };
2379
2380 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);
2381 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2382 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002383 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset);
2384 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset);
2385 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset);
Nicolas Capensd022e412016-09-26 13:30:14 -04002386
2387 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);
2388 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
2389 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
Nicolas Capens96d4e092016-11-18 14:22:38 -05002390 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset);
2391 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset);
2392 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset);
Nicolas Capensd022e412016-09-26 13:30:14 -04002393
Ben Clayton204a4102019-07-31 13:17:47 +01002394 template <typename T>
2395 RValue<Bool> operator==(const Pointer<T> &lhs, const Pointer<T> &rhs)
2396 {
2397 return RValue<Bool>(Nucleus::createPtrEQ(lhs.loadValue(), rhs.loadValue()));
2398 }
2399
Nicolas Capens86509d92019-03-21 13:23:50 -04002400 template<typename T>
2401 RValue<T> Load(RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2402 {
2403 return RValue<T>(Nucleus::createLoad(pointer.value, T::getType(), false, alignment, atomic, memoryOrder));
2404 }
2405
2406 template<typename T>
Ben Clayton97035bd2019-04-16 11:35:38 -04002407 RValue<T> Load(Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2408 {
2409 return Load(RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2410 }
2411
Ben Clayton0fc611f2019-04-18 11:23:27 -04002412 // TODO: Use SIMD to template these.
Ben Clayton0b00b952019-07-03 15:51:19 +01002413 RValue<Float4> MaskedLoad(RValue<Pointer<Float4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2414 RValue<Int4> MaskedLoad(RValue<Pointer<Int4>> base, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
Ben Claytoncb2ebc92019-06-20 00:18:03 +01002415 void MaskedStore(RValue<Pointer<Float4>> base, RValue<Float4> val, RValue<Int4> mask, unsigned int alignment);
2416 void MaskedStore(RValue<Pointer<Int4>> base, RValue<Int4> val, RValue<Int4> mask, unsigned int alignment);
2417
Ben Clayton0b00b952019-07-03 15:51:19 +01002418 RValue<Float4> Gather(RValue<Pointer<Float>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
2419 RValue<Int4> Gather(RValue<Pointer<Int>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes = false);
Ben Clayton0fc611f2019-04-18 11:23:27 -04002420 void Scatter(RValue<Pointer<Float>> base, RValue<Float4> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment);
2421 void Scatter(RValue<Pointer<Int>> base, RValue<Int4> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment);
2422
Ben Clayton97035bd2019-04-16 11:35:38 -04002423 template<typename T>
Nicolas Capens86509d92019-03-21 13:23:50 -04002424 void Store(RValue<T> value, RValue<Pointer<T>> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2425 {
2426 Nucleus::createStore(value.value, pointer.value, T::getType(), false, alignment, atomic, memoryOrder);
2427 }
2428
Ben Clayton97035bd2019-04-16 11:35:38 -04002429 template<typename T>
2430 void Store(RValue<T> value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2431 {
2432 Store(value, RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2433 }
2434
2435 template<typename T>
2436 void Store(T value, Pointer<T> pointer, unsigned int alignment, bool atomic, std::memory_order memoryOrder)
2437 {
2438 Store(RValue<T>(value), RValue<Pointer<T>>(pointer), alignment, atomic, memoryOrder);
2439 }
2440
Ben Claytonb16c5862019-05-08 14:01:38 +01002441 // Fence adds a memory barrier that enforces ordering constraints on memory
2442 // operations. memoryOrder can only be one of:
2443 // std::memory_order_acquire, std::memory_order_release,
2444 // std::memory_order_acq_rel, or std::memory_order_seq_cst.
2445 void Fence(std::memory_order memoryOrder);
Ben Clayton97035bd2019-04-16 11:35:38 -04002446
Nicolas Capensd022e412016-09-26 13:30:14 -04002447 template<class T, int S = 1>
Nicolas Capens297d26e2016-11-18 12:52:17 -05002448 class Array : public LValue<T>
Nicolas Capensd022e412016-09-26 13:30:14 -04002449 {
2450 public:
2451 Array(int size = S);
2452
2453 Reference<T> operator[](int index);
Nicolas Capensd294def2017-01-26 17:44:37 -08002454 Reference<T> operator[](unsigned int index);
Nicolas Capensd022e412016-09-26 13:30:14 -04002455 Reference<T> operator[](RValue<Int> index);
Nicolas Capensd294def2017-01-26 17:44:37 -08002456 Reference<T> operator[](RValue<UInt> index);
Ben Clayton0953d9b2019-06-25 20:57:06 +01002457
2458 // self() returns the this pointer to this Array object.
2459 // This function exists because operator&() is overloaded by LValue<T>.
2460 inline Array* self() { return this; }
Nicolas Capensd022e412016-09-26 13:30:14 -04002461 };
2462
Nicolas Capens96d4e092016-11-18 14:22:38 -05002463// RValue<Array<T>> operator++(Array<T> &val, int); // Post-increment
2464// const Array<T> &operator++(Array<T> &val); // Pre-increment
2465// RValue<Array<T>> operator--(Array<T> &val, int); // Post-decrement
2466// const Array<T> &operator--(Array<T> &val); // Pre-decrement
Nicolas Capensd022e412016-09-26 13:30:14 -04002467
Nicolas Capensf4eec2f2017-05-24 15:46:48 -04002468 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB);
Nicolas Capensd022e412016-09-26 13:30:14 -04002469
Ben Clayton208ed402019-05-03 22:30:03 +01002470 // ValueOf returns a rr::Value* for the given C-type, RValue<T>, LValue<T>
2471 // or Reference<T>.
Ben Clayton351be422019-04-30 12:26:57 +01002472 template <typename T>
2473 inline Value* ValueOf(const T &v)
2474 {
Ben Clayton51f08312019-11-08 14:39:26 +00002475 return ReactorType<T>::cast(v).loadValue();
Ben Clayton351be422019-04-30 12:26:57 +01002476 }
2477
Nicolas Capensd022e412016-09-26 13:30:14 -04002478 void Return();
Nicolas Capensd022e412016-09-26 13:30:14 -04002479
2480 template<class T>
Ben Clayton351be422019-04-30 12:26:57 +01002481 void Return(const T &ret)
2482 {
Ben Clayton51f08312019-11-08 14:39:26 +00002483 static_assert(CanBeUsedAsReturn< ReactorTypeT<T> >::value, "Unsupported type for Return()");
Ben Clayton351be422019-04-30 12:26:57 +01002484 Nucleus::createRet(ValueOf<T>(ret));
2485 // Place any unreachable instructions in an unreferenced block.
2486 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
2487 }
Nicolas Capensd022e412016-09-26 13:30:14 -04002488
Nicolas Capensd022e412016-09-26 13:30:14 -04002489 // Generic template, leave undefined!
2490 template<typename FunctionType>
2491 class Function;
2492
2493 // Specialized for function types
2494 template<typename Return, typename... Arguments>
2495 class Function<Return(Arguments...)>
2496 {
Ben Clayton351be422019-04-30 12:26:57 +01002497 // Static assert that the function signature is valid.
2498 static_assert(sizeof(AssertFunctionSignatureIsValid<Return(Arguments...)>) >= 0, "Invalid function signature");
2499
Nicolas Capensd022e412016-09-26 13:30:14 -04002500 public:
2501 Function();
2502
2503 virtual ~Function();
2504
2505 template<int index>
Ben Clayton169872e2019-02-27 23:58:35 +00002506 Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type> Arg() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002507 {
2508 Value *arg = Nucleus::getArgument(index);
Ben Clayton169872e2019-02-27 23:58:35 +00002509 return Argument<typename std::tuple_element<index, std::tuple<Arguments...>>::type>(arg);
Nicolas Capensd022e412016-09-26 13:30:14 -04002510 }
2511
Ben Clayton6897e9b2019-07-16 17:27:27 +01002512 std::shared_ptr<Routine> operator()(const char *name, ...);
2513 std::shared_ptr<Routine> operator()(const Config::Edit &cfg, const char *name, ...);
Nicolas Capensd022e412016-09-26 13:30:14 -04002514
2515 protected:
2516 Nucleus *core;
2517 std::vector<Type*> arguments;
2518 };
2519
2520 template<typename Return>
2521 class Function<Return()> : public Function<Return(Void)>
2522 {
2523 };
2524
Antonio Maiorano62f49b22019-10-29 09:27:58 -04002525 // FunctionT accepts a C-style function type template argument, allowing it to return a type-safe RoutineT wrapper
2526 template<typename FunctionType>
2527 class FunctionT;
2528
2529 template<typename Return, typename... Arguments>
Ben Clayton51f08312019-11-08 14:39:26 +00002530 class FunctionT<Return(Arguments...)> : public Function<CToReactorT<Return>(CToReactorT<Arguments>...)>
Antonio Maiorano62f49b22019-10-29 09:27:58 -04002531 {
2532 public:
2533 // Type of base class
Ben Clayton51f08312019-11-08 14:39:26 +00002534 using BaseType = Function<CToReactorT<Return>(CToReactorT<Arguments>...)>;
Antonio Maiorano62f49b22019-10-29 09:27:58 -04002535
2536 // Function type, e.g. void(int,float)
2537 using CFunctionType = Return(Arguments...);
2538
2539 // Reactor function type, e.g. Void(Int, Float)
Ben Clayton51f08312019-11-08 14:39:26 +00002540 using ReactorFunctionType = CToReactorT<Return>(CToReactorT<Arguments>...);
Antonio Maiorano62f49b22019-10-29 09:27:58 -04002541
2542 // Returned RoutineT type
2543 using RoutineType = RoutineT<CFunctionType>;
2544
2545 // Hide base implementations of operator()
2546
2547 RoutineType operator()(const char* name, ...)
2548 {
2549 return RoutineType(BaseType::operator()(name));
2550 }
2551
2552 RoutineType operator()(const Config::Edit& cfg, const char* name, ...)
2553 {
2554 return RoutineType(BaseType::operator()(cfg, name));
2555 }
2556 };
2557
Nicolas Capensd022e412016-09-26 13:30:14 -04002558 RValue<Long> Ticks();
2559}
2560
Nicolas Capens48461502018-08-06 14:20:45 -04002561namespace rr
Nicolas Capensd022e412016-09-26 13:30:14 -04002562{
2563 template<class T>
Nicolas Capens0192d152019-03-27 14:46:07 -04002564 LValue<T>::LValue(int arraySize) : Variable(T::getType(), arraySize)
Nicolas Capens22479eb2016-09-28 22:34:26 -04002565 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002566#ifdef ENABLE_RR_DEBUG_INFO
2567 materialize();
2568#endif // ENABLE_RR_DEBUG_INFO
Nicolas Capens22479eb2016-09-28 22:34:26 -04002569 }
2570
Nicolas Capens0192d152019-03-27 14:46:07 -04002571 inline void Variable::materialize() const
Nicolas Capens22479eb2016-09-28 22:34:26 -04002572 {
Nicolas Capens0192d152019-03-27 14:46:07 -04002573 if(!address)
2574 {
2575 address = Nucleus::allocateStackVariable(type, arraySize);
Ben Claytonac07ed82019-03-26 14:17:41 +00002576 RR_DEBUG_INFO_EMIT_VAR(address);
Nicolas Capens0192d152019-03-27 14:46:07 -04002577
2578 if(rvalue)
2579 {
2580 storeValue(rvalue);
2581 rvalue = nullptr;
2582 }
2583 }
Nicolas Capens22479eb2016-09-28 22:34:26 -04002584 }
2585
Nicolas Capens0192d152019-03-27 14:46:07 -04002586 inline Value *Variable::loadValue() const
Nicolas Capens22479eb2016-09-28 22:34:26 -04002587 {
Nicolas Capens0192d152019-03-27 14:46:07 -04002588 if(rvalue)
2589 {
2590 return rvalue;
2591 }
2592
2593 if(!address)
2594 {
2595 // TODO: Return undef instead.
2596 materialize();
2597 }
2598
2599 return Nucleus::createLoad(address, type, false, 0);
Nicolas Capens22479eb2016-09-28 22:34:26 -04002600 }
2601
Nicolas Capens0192d152019-03-27 14:46:07 -04002602 inline Value *Variable::storeValue(Value *value) const
Nicolas Capens22479eb2016-09-28 22:34:26 -04002603 {
Nicolas Capens0192d152019-03-27 14:46:07 -04002604 if(address)
2605 {
2606 return Nucleus::createStore(value, address, type, false, 0);
2607 }
2608
2609 rvalue = value;
2610
2611 return value;
2612 }
2613
2614 inline Value *Variable::getBaseAddress() const
2615 {
2616 materialize();
2617
2618 return address;
2619 }
2620
2621 inline Value *Variable::getElementPointer(Value *index, bool unsignedIndex) const
2622 {
2623 return Nucleus::createGEP(getBaseAddress(), type, index, unsignedIndex);
Nicolas Capens22479eb2016-09-28 22:34:26 -04002624 }
2625
2626 template<class T>
Nicolas Capens297d26e2016-11-18 12:52:17 -05002627 RValue<Pointer<T>> LValue<T>::operator&()
Nicolas Capensd022e412016-09-26 13:30:14 -04002628 {
Nicolas Capens0192d152019-03-27 14:46:07 -04002629 return RValue<Pointer<T>>(getBaseAddress());
Nicolas Capensd022e412016-09-26 13:30:14 -04002630 }
2631
2632 template<class T>
2633 Reference<T>::Reference(Value *pointer, int alignment) : alignment(alignment)
2634 {
2635 address = pointer;
2636 }
2637
2638 template<class T>
2639 RValue<T> Reference<T>::operator=(RValue<T> rhs) const
2640 {
Nicolas Capens6d738712016-09-30 04:15:22 -04002641 Nucleus::createStore(rhs.value, address, T::getType(), false, alignment);
Nicolas Capensd022e412016-09-26 13:30:14 -04002642
2643 return rhs;
2644 }
2645
2646 template<class T>
2647 RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
2648 {
Nicolas Capense12780d2016-09-27 14:18:07 -04002649 Value *tmp = Nucleus::createLoad(ref.address, T::getType(), false, ref.alignment);
Nicolas Capens6d738712016-09-30 04:15:22 -04002650 Nucleus::createStore(tmp, address, T::getType(), false, alignment);
Nicolas Capensd022e412016-09-26 13:30:14 -04002651
2652 return RValue<T>(tmp);
2653 }
2654
2655 template<class T>
2656 RValue<T> Reference<T>::operator+=(RValue<T> rhs) const
2657 {
2658 return *this = *this + rhs;
2659 }
2660
2661 template<class T>
2662 Value *Reference<T>::loadValue() const
2663 {
Nicolas Capense12780d2016-09-27 14:18:07 -04002664 return Nucleus::createLoad(address, T::getType(), false, alignment);
Nicolas Capensd022e412016-09-26 13:30:14 -04002665 }
2666
2667 template<class T>
2668 int Reference<T>::getAlignment() const
2669 {
2670 return alignment;
2671 }
2672
Ben Claytonac07ed82019-03-26 14:17:41 +00002673#ifdef ENABLE_RR_DEBUG_INFO
2674 template<class T>
2675 RValue<T>::RValue(const RValue<T> &rvalue) : value(rvalue.value)
2676 {
2677 RR_DEBUG_INFO_EMIT_VAR(value);
2678 }
2679#endif // ENABLE_RR_DEBUG_INFO
2680
Nicolas Capensd022e412016-09-26 13:30:14 -04002681 template<class T>
2682 RValue<T>::RValue(Value *rvalue)
2683 {
Nicolas Capensbea4dce2017-07-24 16:54:44 -04002684 assert(Nucleus::createBitCast(rvalue, T::getType()) == rvalue); // Run-time type should match T, so bitcast is no-op.
2685
Nicolas Capensd022e412016-09-26 13:30:14 -04002686 value = rvalue;
Ben Claytonac07ed82019-03-26 14:17:41 +00002687 RR_DEBUG_INFO_EMIT_VAR(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002688 }
2689
2690 template<class T>
2691 RValue<T>::RValue(const T &lvalue)
2692 {
2693 value = lvalue.loadValue();
Ben Claytonac07ed82019-03-26 14:17:41 +00002694 RR_DEBUG_INFO_EMIT_VAR(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002695 }
2696
2697 template<class T>
Ben Clayton35e90e22019-03-15 10:06:06 +00002698 RValue<T>::RValue(typename BoolLiteral<T>::type i)
2699 {
2700 value = Nucleus::createConstantBool(i);
Ben Claytonac07ed82019-03-26 14:17:41 +00002701 RR_DEBUG_INFO_EMIT_VAR(value);
Ben Clayton35e90e22019-03-15 10:06:06 +00002702 }
2703
2704 template<class T>
Nicolas Capensd022e412016-09-26 13:30:14 -04002705 RValue<T>::RValue(typename IntLiteral<T>::type i)
2706 {
Nicolas Capensa16473e2016-11-07 15:32:52 -05002707 value = Nucleus::createConstantInt(i);
Ben Claytonac07ed82019-03-26 14:17:41 +00002708 RR_DEBUG_INFO_EMIT_VAR(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002709 }
2710
2711 template<class T>
2712 RValue<T>::RValue(typename FloatLiteral<T>::type f)
2713 {
Nicolas Capensa16473e2016-11-07 15:32:52 -05002714 value = Nucleus::createConstantFloat(f);
Ben Claytonac07ed82019-03-26 14:17:41 +00002715 RR_DEBUG_INFO_EMIT_VAR(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002716 }
2717
2718 template<class T>
2719 RValue<T>::RValue(const Reference<T> &ref)
2720 {
2721 value = ref.loadValue();
Ben Claytonac07ed82019-03-26 14:17:41 +00002722 RR_DEBUG_INFO_EMIT_VAR(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002723 }
2724
Nicolas Capenscb986762017-01-20 11:34:37 -05002725 template<class Vector4, int T>
2726 Swizzle2<Vector4, T>::operator RValue<Vector4>() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002727 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002728 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002729 Value *vector = parent->loadValue();
2730
Nicolas Capenscb986762017-01-20 11:34:37 -05002731 return Swizzle(RValue<Vector4>(vector), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002732 }
2733
Nicolas Capenscb986762017-01-20 11:34:37 -05002734 template<class Vector4, int T>
2735 Swizzle4<Vector4, T>::operator RValue<Vector4>() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002736 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002737 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002738 Value *vector = parent->loadValue();
2739
Nicolas Capenscb986762017-01-20 11:34:37 -05002740 return Swizzle(RValue<Vector4>(vector), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002741 }
2742
Nicolas Capenscb986762017-01-20 11:34:37 -05002743 template<class Vector4, int T>
2744 SwizzleMask4<Vector4, T>::operator RValue<Vector4>() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002745 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002746 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002747 Value *vector = parent->loadValue();
2748
Nicolas Capenscb986762017-01-20 11:34:37 -05002749 return Swizzle(RValue<Vector4>(vector), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002750 }
2751
Nicolas Capenscb986762017-01-20 11:34:37 -05002752 template<class Vector4, int T>
2753 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<Vector4> rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002754 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002755 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002756 return Mask(*parent, rhs, T);
2757 }
2758
Nicolas Capenscb986762017-01-20 11:34:37 -05002759 template<class Vector4, int T>
2760 RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002761 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002762 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capenscb986762017-01-20 11:34:37 -05002763 return Mask(*parent, Vector4(rhs), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002764 }
2765
Nicolas Capenscb986762017-01-20 11:34:37 -05002766 template<class Vector4, int T>
2767 SwizzleMask1<Vector4, T>::operator RValue<typename Scalar<Vector4>::Type>() const // FIXME: Call a non-template function
Nicolas Capensd022e412016-09-26 13:30:14 -04002768 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002769 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002770 return Extract(*parent, T & 0x3);
2771 }
2772
Nicolas Capenscb986762017-01-20 11:34:37 -05002773 template<class Vector4, int T>
2774 SwizzleMask1<Vector4, T>::operator RValue<Vector4>() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002775 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002776 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002777 Value *vector = parent->loadValue();
2778
Nicolas Capenscb986762017-01-20 11:34:37 -05002779 return Swizzle(RValue<Vector4>(vector), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002780 }
2781
Nicolas Capenscb986762017-01-20 11:34:37 -05002782 template<class Vector4, int T>
2783 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(float x)
Nicolas Capensd022e412016-09-26 13:30:14 -04002784 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002785 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensc94ab742016-11-08 15:15:31 -05002786 return *parent = Insert(*parent, Float(x), T & 0x3);
Nicolas Capensd022e412016-09-26 13:30:14 -04002787 }
2788
Nicolas Capenscb986762017-01-20 11:34:37 -05002789 template<class Vector4, int T>
2790 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<Vector4> rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002791 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002792 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002793 return Mask(*parent, Float4(rhs), T);
2794 }
2795
Nicolas Capenscb986762017-01-20 11:34:37 -05002796 template<class Vector4, int T>
2797 RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs) // FIXME: Call a non-template function
Nicolas Capensd022e412016-09-26 13:30:14 -04002798 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002799 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensc94ab742016-11-08 15:15:31 -05002800 return *parent = Insert(*parent, rhs, T & 0x3);
Nicolas Capensd022e412016-09-26 13:30:14 -04002801 }
2802
Nicolas Capenscb986762017-01-20 11:34:37 -05002803 template<class Vector4, int T>
2804 SwizzleMask2<Vector4, T>::operator RValue<Vector4>() const
Nicolas Capensd022e412016-09-26 13:30:14 -04002805 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002806 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002807 Value *vector = parent->loadValue();
2808
Nicolas Capense95d5342016-09-30 11:37:28 -04002809 return Swizzle(RValue<Float4>(vector), T);
Nicolas Capensd022e412016-09-26 13:30:14 -04002810 }
2811
Nicolas Capenscb986762017-01-20 11:34:37 -05002812 template<class Vector4, int T>
2813 RValue<Vector4> SwizzleMask2<Vector4, T>::operator=(RValue<Vector4> rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002814 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002815 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002816 return Mask(*parent, Float4(rhs), T);
2817 }
2818
2819 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002820 Float::Float(const SwizzleMask1<Float4, T> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002821 {
2822 *this = rhs.operator RValue<Float>();
2823 }
2824
2825 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002826 RValue<Float> Float::operator=(const SwizzleMask1<Float4, T> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002827 {
2828 return *this = rhs.operator RValue<Float>();
2829 }
2830
2831 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002832 Float4::Float4(const SwizzleMask1<Float4, T> &rhs) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002833 {
Nicolas Capensd022e412016-09-26 13:30:14 -04002834 *this = rhs.operator RValue<Float4>();
2835 }
2836
2837 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002838 Float4::Float4(const Swizzle4<Float4, T> &rhs) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002839 {
Nicolas Capensd022e412016-09-26 13:30:14 -04002840 *this = rhs.operator RValue<Float4>();
2841 }
2842
2843 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002844 Float4::Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002845 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002846 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002847 *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
2848 }
2849
2850 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002851 Float4::Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002852 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002853 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002854 *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
2855 }
2856
2857 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002858 Float4::Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002859 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002860 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002861 *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
2862 }
2863
2864 template<int X, int Y>
Nicolas Capenscb986762017-01-20 11:34:37 -05002865 Float4::Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y) : XYZW(this)
Nicolas Capensd022e412016-09-26 13:30:14 -04002866 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002867 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04002868 *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
2869 }
2870
2871 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002872 RValue<Float4> Float4::operator=(const SwizzleMask1<Float4, T> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002873 {
2874 return *this = rhs.operator RValue<Float4>();
2875 }
2876
2877 template<int T>
Nicolas Capenscb986762017-01-20 11:34:37 -05002878 RValue<Float4> Float4::operator=(const Swizzle4<Float4, T> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002879 {
2880 return *this = rhs.operator RValue<Float4>();
2881 }
2882
Ben Claytonb7eb3a82019-11-19 00:43:50 +00002883 // Returns a reactor pointer to the fixed-address ptr.
2884 RValue<Pointer<Byte>> ConstantPointer(void const * ptr);
2885
2886 // Returns a reactor pointer to an immutable copy of the data of size bytes.
2887 RValue<Pointer<Byte>> ConstantData(void const * data, size_t size);
2888
Nicolas Capensd022e412016-09-26 13:30:14 -04002889 template<class T>
2890 Pointer<T>::Pointer(Argument<Pointer<T>> argument) : alignment(1)
2891 {
Nicolas Capens51d98672019-04-02 12:05:40 -04002892 LValue<Pointer<T>>::materialize(); // FIXME(b/129757459)
Nicolas Capens22479eb2016-09-28 22:34:26 -04002893 LValue<Pointer<T>>::storeValue(argument.value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002894 }
2895
2896 template<class T>
Ben Claytonf63c4e52019-08-01 13:40:43 +01002897 Pointer<T>::Pointer() : alignment(1) {}
Nicolas Capensd022e412016-09-26 13:30:14 -04002898
2899 template<class T>
2900 Pointer<T>::Pointer(RValue<Pointer<T>> rhs) : alignment(1)
2901 {
Nicolas Capens22479eb2016-09-28 22:34:26 -04002902 LValue<Pointer<T>>::storeValue(rhs.value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002903 }
2904
2905 template<class T>
2906 Pointer<T>::Pointer(const Pointer<T> &rhs) : alignment(rhs.alignment)
2907 {
2908 Value *value = rhs.loadValue();
Nicolas Capens22479eb2016-09-28 22:34:26 -04002909 LValue<Pointer<T>>::storeValue(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002910 }
2911
2912 template<class T>
2913 Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs) : alignment(rhs.getAlignment())
2914 {
2915 Value *value = rhs.loadValue();
Nicolas Capens22479eb2016-09-28 22:34:26 -04002916 LValue<Pointer<T>>::storeValue(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002917 }
2918
2919 template<class T>
Ben Clayton0697da02019-08-01 13:35:48 +01002920 Pointer<T>::Pointer(std::nullptr_t) : alignment(1)
2921 {
2922 Value *value = Nucleus::createNullPointer(T::getType());
2923 LValue<Pointer<T>>::storeValue(value);
2924 }
2925
2926 template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05002927 RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002928 {
Nicolas Capens22479eb2016-09-28 22:34:26 -04002929 LValue<Pointer<T>>::storeValue(rhs.value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002930
2931 return rhs;
2932 }
2933
2934 template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05002935 RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002936 {
2937 Value *value = rhs.loadValue();
Nicolas Capens22479eb2016-09-28 22:34:26 -04002938 LValue<Pointer<T>>::storeValue(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002939
2940 return RValue<Pointer<T>>(value);
2941 }
2942
2943 template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05002944 RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs)
Nicolas Capensd022e412016-09-26 13:30:14 -04002945 {
2946 Value *value = rhs.loadValue();
Nicolas Capens22479eb2016-09-28 22:34:26 -04002947 LValue<Pointer<T>>::storeValue(value);
Nicolas Capensd022e412016-09-26 13:30:14 -04002948
2949 return RValue<Pointer<T>>(value);
2950 }
2951
2952 template<class T>
Ben Clayton0697da02019-08-01 13:35:48 +01002953 RValue<Pointer<T>> Pointer<T>::operator=(std::nullptr_t)
2954 {
2955 Value *value = Nucleus::createNullPointer(T::getType());
2956 LValue<Pointer<T>>::storeValue(value);
2957
2958 return RValue<Pointer<T>>(this);
2959 }
2960
2961 template<class T>
Nicolas Capensd022e412016-09-26 13:30:14 -04002962 Reference<T> Pointer<T>::operator*()
2963 {
Nicolas Capens22479eb2016-09-28 22:34:26 -04002964 return Reference<T>(LValue<Pointer<T>>::loadValue(), alignment);
Nicolas Capensd022e412016-09-26 13:30:14 -04002965 }
2966
2967 template<class T>
2968 Reference<T> Pointer<T>::operator[](int index)
2969 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002970 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd294def2017-01-26 17:44:37 -08002971 Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), Nucleus::createConstantInt(index), false);
2972
2973 return Reference<T>(element, alignment);
2974 }
2975
2976 template<class T>
2977 Reference<T> Pointer<T>::operator[](unsigned int index)
2978 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002979 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd294def2017-01-26 17:44:37 -08002980 Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), Nucleus::createConstantInt(index), true);
Nicolas Capensd022e412016-09-26 13:30:14 -04002981
2982 return Reference<T>(element, alignment);
2983 }
2984
2985 template<class T>
2986 Reference<T> Pointer<T>::operator[](RValue<Int> index)
2987 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002988 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd294def2017-01-26 17:44:37 -08002989 Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), index.value, false);
2990
2991 return Reference<T>(element, alignment);
2992 }
2993
2994 template<class T>
2995 Reference<T> Pointer<T>::operator[](RValue<UInt> index)
2996 {
Ben Claytonac07ed82019-03-26 14:17:41 +00002997 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd294def2017-01-26 17:44:37 -08002998 Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), index.value, true);
Nicolas Capensd022e412016-09-26 13:30:14 -04002999
3000 return Reference<T>(element, alignment);
3001 }
3002
3003 template<class T>
3004 Type *Pointer<T>::getType()
3005 {
3006 return Nucleus::getPointerType(T::getType());
3007 }
3008
3009 template<class T, int S>
Nicolas Capens297d26e2016-11-18 12:52:17 -05003010 Array<T, S>::Array(int size) : LValue<T>(size)
Nicolas Capensd022e412016-09-26 13:30:14 -04003011 {
3012 }
3013
3014 template<class T, int S>
3015 Reference<T> Array<T, S>::operator[](int index)
3016 {
Ben Clayton83dd4522019-06-27 10:37:00 +01003017 assert(index < this->arraySize);
Nicolas Capens0192d152019-03-27 14:46:07 -04003018 Value *element = LValue<T>::getElementPointer(Nucleus::createConstantInt(index), false);
Nicolas Capensd294def2017-01-26 17:44:37 -08003019
3020 return Reference<T>(element);
3021 }
3022
3023 template<class T, int S>
3024 Reference<T> Array<T, S>::operator[](unsigned int index)
3025 {
Ben Clayton83dd4522019-06-27 10:37:00 +01003026 assert(index < static_cast<unsigned int>(this->arraySize));
Nicolas Capens0192d152019-03-27 14:46:07 -04003027 Value *element = LValue<T>::getElementPointer(Nucleus::createConstantInt(index), true);
Nicolas Capensd022e412016-09-26 13:30:14 -04003028
3029 return Reference<T>(element);
3030 }
3031
3032 template<class T, int S>
3033 Reference<T> Array<T, S>::operator[](RValue<Int> index)
3034 {
Nicolas Capens0192d152019-03-27 14:46:07 -04003035 Value *element = LValue<T>::getElementPointer(index.value, false);
Nicolas Capensd294def2017-01-26 17:44:37 -08003036
3037 return Reference<T>(element);
3038 }
3039
3040 template<class T, int S>
3041 Reference<T> Array<T, S>::operator[](RValue<UInt> index)
3042 {
Nicolas Capens0192d152019-03-27 14:46:07 -04003043 Value *element = LValue<T>::getElementPointer(index.value, true);
Nicolas Capensd022e412016-09-26 13:30:14 -04003044
3045 return Reference<T>(element);
3046 }
3047
3048// template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05003049// RValue<Array<T>> operator++(Array<T> &val, int)
Nicolas Capensd022e412016-09-26 13:30:14 -04003050// {
3051// // FIXME: Requires storing the address of the array
3052// }
3053
3054// template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05003055// const Array<T> &operator++(Array<T> &val)
Nicolas Capensd022e412016-09-26 13:30:14 -04003056// {
3057// // FIXME: Requires storing the address of the array
3058// }
3059
3060// template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05003061// RValue<Array<T>> operator--(Array<T> &val, int)
Nicolas Capensd022e412016-09-26 13:30:14 -04003062// {
3063// // FIXME: Requires storing the address of the array
3064// }
3065
3066// template<class T>
Nicolas Capens96d4e092016-11-18 14:22:38 -05003067// const Array<T> &operator--(Array<T> &val)
Nicolas Capensd022e412016-09-26 13:30:14 -04003068// {
3069// // FIXME: Requires storing the address of the array
3070// }
3071
3072 template<class T>
3073 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, RValue<T> ifFalse)
3074 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003075 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003076 return RValue<T>(Nucleus::createSelect(condition.value, ifTrue.value, ifFalse.value));
3077 }
3078
3079 template<class T>
3080 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, RValue<T> ifFalse)
3081 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003082 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003083 Value *trueValue = ifTrue.loadValue();
3084
3085 return RValue<T>(Nucleus::createSelect(condition.value, trueValue, ifFalse.value));
3086 }
3087
3088 template<class T>
3089 RValue<T> IfThenElse(RValue<Bool> condition, RValue<T> ifTrue, const T &ifFalse)
3090 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003091 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003092 Value *falseValue = ifFalse.loadValue();
3093
3094 return RValue<T>(Nucleus::createSelect(condition.value, ifTrue.value, falseValue));
3095 }
3096
3097 template<class T>
3098 RValue<T> IfThenElse(RValue<Bool> condition, const T &ifTrue, const T &ifFalse)
3099 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003100 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003101 Value *trueValue = ifTrue.loadValue();
3102 Value *falseValue = ifFalse.loadValue();
3103
3104 return RValue<T>(Nucleus::createSelect(condition.value, trueValue, falseValue));
3105 }
3106
Nicolas Capensd022e412016-09-26 13:30:14 -04003107 template<typename Return, typename... Arguments>
3108 Function<Return(Arguments...)>::Function()
3109 {
3110 core = new Nucleus();
3111
3112 Type *types[] = {Arguments::getType()...};
3113 for(Type *type : types)
3114 {
3115 if(type != Void::getType())
3116 {
3117 arguments.push_back(type);
3118 }
3119 }
3120
3121 Nucleus::createFunction(Return::getType(), arguments);
3122 }
3123
3124 template<typename Return, typename... Arguments>
3125 Function<Return(Arguments...)>::~Function()
3126 {
3127 delete core;
3128 }
3129
3130 template<typename Return, typename... Arguments>
Ben Clayton6897e9b2019-07-16 17:27:27 +01003131 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const char *name, ...)
Nicolas Capensd022e412016-09-26 13:30:14 -04003132 {
Chris Forbes878d4b02019-01-21 10:48:35 -08003133 char fullName[1024 + 1];
Nicolas Capensd022e412016-09-26 13:30:14 -04003134
3135 va_list vararg;
3136 va_start(vararg, name);
Chris Forbes878d4b02019-01-21 10:48:35 -08003137 vsnprintf(fullName, 1024, name, vararg);
Nicolas Capensd022e412016-09-26 13:30:14 -04003138 va_end(vararg);
3139
Ben Clayton55bc37a2019-07-04 12:17:12 +01003140 return core->acquireRoutine(fullName, Config::Edit::None);
Ben Clayton68cfc782019-06-29 12:31:08 +01003141 }
3142
3143 template<typename Return, typename... Arguments>
Ben Clayton6897e9b2019-07-16 17:27:27 +01003144 std::shared_ptr<Routine> Function<Return(Arguments...)>::operator()(const Config::Edit &cfg, const char *name, ...)
Ben Clayton68cfc782019-06-29 12:31:08 +01003145 {
3146 char fullName[1024 + 1];
3147
3148 va_list vararg;
3149 va_start(vararg, name);
3150 vsnprintf(fullName, 1024, name, vararg);
3151 va_end(vararg);
3152
Ben Clayton55bc37a2019-07-04 12:17:12 +01003153 return core->acquireRoutine(fullName, cfg);
Nicolas Capensd022e412016-09-26 13:30:14 -04003154 }
3155
3156 template<class T, class S>
3157 RValue<T> ReinterpretCast(RValue<S> val)
3158 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003159 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003160 return RValue<T>(Nucleus::createBitCast(val.value, T::getType()));
3161 }
3162
Nicolas Capens22479eb2016-09-28 22:34:26 -04003163 template<class T, class S>
3164 RValue<T> ReinterpretCast(const LValue<S> &var)
Nicolas Capensd022e412016-09-26 13:30:14 -04003165 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003166 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capensd022e412016-09-26 13:30:14 -04003167 Value *val = var.loadValue();
3168
3169 return RValue<T>(Nucleus::createBitCast(val, T::getType()));
3170 }
3171
3172 template<class T, class S>
3173 RValue<T> ReinterpretCast(const Reference<S> &var)
3174 {
3175 return ReinterpretCast<T>(RValue<S>(var));
3176 }
3177
Nicolas Capens70dfff42016-10-27 10:20:28 -04003178 template<class T>
3179 RValue<T> As(Value *val)
3180 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003181 RR_DEBUG_INFO_UPDATE_LOC();
Nicolas Capens70dfff42016-10-27 10:20:28 -04003182 return RValue<T>(Nucleus::createBitCast(val, T::getType()));
3183 }
3184
Nicolas Capensd022e412016-09-26 13:30:14 -04003185 template<class T, class S>
3186 RValue<T> As(RValue<S> val)
3187 {
3188 return ReinterpretCast<T>(val);
3189 }
3190
Nicolas Capens22479eb2016-09-28 22:34:26 -04003191 template<class T, class S>
3192 RValue<T> As(const LValue<S> &var)
Nicolas Capensd022e412016-09-26 13:30:14 -04003193 {
3194 return ReinterpretCast<T>(var);
3195 }
3196
3197 template<class T, class S>
3198 RValue<T> As(const Reference<S> &val)
3199 {
3200 return ReinterpretCast<T>(val);
3201 }
3202
Ben Claytond853c122019-04-16 17:51:49 -04003203 // Calls the function pointer fptr with the given arguments, return type
3204 // and parameter types. Returns the call's return value if the function has
3205 // a non-void return type.
3206 Value* Call(RValue<Pointer<Byte>> fptr, Type* retTy, std::initializer_list<Value*> args, std::initializer_list<Type*> paramTys);
3207
3208 template <typename F>
3209 class CallHelper {};
3210
3211 template<typename Return, typename ... Arguments>
3212 class CallHelper<Return(Arguments...)>
3213 {
3214 public:
Ben Clayton51f08312019-11-08 14:39:26 +00003215 using RReturn = CToReactorT<Return>;
Ben Claytond853c122019-04-16 17:51:49 -04003216
Ben Clayton51f08312019-11-08 14:39:26 +00003217 static inline RReturn Call(Return(fptr)(Arguments...), CToReactorT<Arguments>... args)
Ben Claytond853c122019-04-16 17:51:49 -04003218 {
3219 return RValue<RReturn>(rr::Call(
3220 ConstantPointer(reinterpret_cast<void*>(fptr)),
3221 RReturn::getType(),
Ben Clayton351be422019-04-30 12:26:57 +01003222 { ValueOf(args) ... },
Ben Clayton51f08312019-11-08 14:39:26 +00003223 { CToReactorT<Arguments>::getType() ... }));
Ben Claytond853c122019-04-16 17:51:49 -04003224 }
3225
Ben Clayton51f08312019-11-08 14:39:26 +00003226 static inline RReturn Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
Ben Claytond853c122019-04-16 17:51:49 -04003227 {
3228 return RValue<RReturn>(rr::Call(
3229 fptr,
3230 RReturn::getType(),
Ben Clayton351be422019-04-30 12:26:57 +01003231 { ValueOf(args) ... },
Ben Clayton51f08312019-11-08 14:39:26 +00003232 { CToReactorT<Arguments>::getType() ... }));
Ben Claytond853c122019-04-16 17:51:49 -04003233 }
3234 };
3235
3236 template<typename ... Arguments>
3237 class CallHelper<void(Arguments...)>
3238 {
3239 public:
Ben Clayton51f08312019-11-08 14:39:26 +00003240 static inline void Call(void(fptr)(Arguments...), CToReactorT<Arguments>... args)
Ben Claytond853c122019-04-16 17:51:49 -04003241 {
3242 rr::Call(ConstantPointer(reinterpret_cast<void*>(fptr)),
3243 Void::getType(),
Ben Clayton351be422019-04-30 12:26:57 +01003244 { ValueOf(args) ... },
Ben Clayton51f08312019-11-08 14:39:26 +00003245 { CToReactorT<Arguments>::getType() ... });
Ben Claytond853c122019-04-16 17:51:49 -04003246 }
3247
Ben Clayton51f08312019-11-08 14:39:26 +00003248 static inline void Call(Pointer<Byte> fptr, CToReactorT<Arguments>... args)
Ben Claytond853c122019-04-16 17:51:49 -04003249 {
3250 rr::Call(fptr,
3251 Void::getType(),
Ben Clayton351be422019-04-30 12:26:57 +01003252 { ValueOf(args) ... },
Ben Clayton51f08312019-11-08 14:39:26 +00003253 { CToReactorT<Arguments>::getType() ... });
Ben Claytond853c122019-04-16 17:51:49 -04003254 }
3255 };
3256
Ben Clayton51f08312019-11-08 14:39:26 +00003257 template <typename T>
3258 inline ReactorTypeT<T> CastToReactor(const T& v) { return ReactorType<T>::cast(v); }
3259
Ben Claytonb7eb3a82019-11-19 00:43:50 +00003260 // Calls the static function pointer fptr with the given arguments args.
Ben Clayton51f08312019-11-08 14:39:26 +00003261 template<typename Return, typename ... CArgs, typename ... RArgs>
3262 inline CToReactorT<Return> Call(Return(fptr)(CArgs...), RArgs&&... args)
Ben Claytond853c122019-04-16 17:51:49 -04003263 {
Ben Clayton51f08312019-11-08 14:39:26 +00003264 return CallHelper<Return(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
Ben Claytond853c122019-04-16 17:51:49 -04003265 }
3266
Ben Claytonb7eb3a82019-11-19 00:43:50 +00003267 // Calls the static function pointer fptr with the given arguments args.
Antonio Maiorano7363cd22019-10-11 15:23:22 -04003268 // Overload for calling functions with void return type.
Ben Clayton51f08312019-11-08 14:39:26 +00003269 template<typename ... CArgs, typename ... RArgs>
3270 inline void Call(void(fptr)(CArgs...), RArgs&&... args)
Antonio Maiorano7363cd22019-10-11 15:23:22 -04003271 {
Ben Clayton51f08312019-11-08 14:39:26 +00003272 CallHelper<void(CArgs...)>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
Antonio Maiorano7363cd22019-10-11 15:23:22 -04003273 }
3274
Ben Claytonb7eb3a82019-11-19 00:43:50 +00003275 // Calls the member function pointer fptr with the given arguments args.
3276 // object can be a Class*, or a Pointer<Byte>.
3277 template<typename Return, typename Class, typename C, typename ... CArgs, typename ... RArgs>
3278 inline CToReactorT<Return> Call(Return(Class::* fptr)(CArgs...), C&& object, RArgs&&... args)
3279 {
3280 using Helper = CallHelper<Return(Class*, void*, CArgs...)>;
3281 using fptrTy = decltype(fptr);
3282 struct Static {
3283 static inline Return Call(Class* object, void* fptrptr, CArgs... args)
3284 {
3285 auto fptr = *reinterpret_cast<fptrTy*>(fptrptr);
3286 return (object->*fptr)(std::forward<CArgs>(args)...);
3287 }
3288 };
3289 return Helper::Call(&Static::Call,
3290 CastToReactor(object),
3291 ConstantData(&fptr, sizeof(fptr)),
3292 CastToReactor(std::forward<RArgs>(args))...);
3293 }
3294
3295 // Calls the member function pointer fptr with the given arguments args.
3296 // Overload for calling functions with void return type.
3297 // object can be a Class*, or a Pointer<Byte>.
3298 template<typename Class, typename C, typename ... CArgs, typename ... RArgs>
3299 inline void Call(void(Class::* fptr)(CArgs...), C&& object, RArgs&&... args)
3300 {
3301 using Helper = CallHelper<void(Class*, void*, CArgs...)>;
3302 using fptrTy = decltype(fptr);
3303 struct Static {
3304 static inline void Call(Class* object, void* fptrptr, CArgs... args)
3305 {
3306 auto fptr = *reinterpret_cast<fptrTy*>(fptrptr);
3307 (object->*fptr)(std::forward<CArgs>(args)...);
3308 }
3309 };
3310 Helper::Call(&Static::Call,
3311 CastToReactor(object),
3312 ConstantData(&fptr, sizeof(fptr)),
3313 CastToReactor(std::forward<RArgs>(args))...);
3314 }
3315
3316 // Calls the Reactor function pointer fptr with the signature
3317 // FUNCTION_SIGNATURE and arguments.
Ben Clayton51f08312019-11-08 14:39:26 +00003318 template<typename FUNCTION_SIGNATURE, typename ... RArgs>
3319 inline void Call(Pointer<Byte> fptr, RArgs&& ... args)
Ben Claytond853c122019-04-16 17:51:49 -04003320 {
Ben Clayton51f08312019-11-08 14:39:26 +00003321 CallHelper<FUNCTION_SIGNATURE>::Call(fptr, CastToReactor(std::forward<RArgs>(args))...);
Ben Claytond853c122019-04-16 17:51:49 -04003322 }
3323
Ben Claytonac07ed82019-03-26 14:17:41 +00003324 // Breakpoint emits an instruction that will cause the application to trap.
3325 // This can be used to stop an attached debugger at the given call.
3326 void Breakpoint();
3327
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003328#ifdef ENABLE_RR_PRINT
3329 // PrintValue holds the printf format and value(s) for a single argument
3330 // to Print(). A single argument can be expanded into multiple printf
3331 // values - for example a Float4 will expand to "%f %f %f %f" and four
3332 // scalar values.
3333 // The PrintValue constructor accepts the following:
3334 // * Reactor LValues, RValues, Pointers.
3335 // * Standard Plain-Old-Value types (int, float, bool, etc)
3336 // * Custom types that specialize the PrintValue::Ty template struct.
3337 // * Static arrays in the form T[N] where T can be any of the above.
3338 class PrintValue
3339 {
3340 // Ty is a template that can be specialized for printing type T.
3341 // Each specialization must expose:
Ben Claytona6833282019-05-28 17:15:02 +01003342 // * A 'static std::string fmt(const T& v)' method that provides the
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003343 // printf format specifier.
3344 // * A 'static std::vector<rr::Value*> val(const T& v)' method that
3345 // returns all the printf format values.
3346 template <typename T> struct Ty
3347 {
Ben Claytona6833282019-05-28 17:15:02 +01003348 // static std::string fmt(const T& v);
3349 // static std::vector<rr::Value*> val(const T& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003350 };
3351
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003352 // returns the printf values for all the values in the given array.
3353 template <typename T>
3354 static std::vector<Value*> val(const T* list, int count) {
3355 std::vector<Value*> values;
3356 values.reserve(count);
3357 for (int i = 0; i < count; i++)
3358 {
3359 auto v = val(list[i]);
3360 values.insert(values.end(), v.begin(), v.end());
3361 }
3362 return values;
Ben Claytonbcc71a32019-04-21 07:35:37 -04003363 }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003364
Ben Claytona6833282019-05-28 17:15:02 +01003365 // fmt returns the comma-delimited list of printf format strings for
3366 // every element in the provided list, all enclosed in square brackets.
3367 template <typename T>
3368 static std::string fmt(const T* list, int count)
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003369 {
3370 std::string out = "[";
3371 for (int i = 0; i < count; i++)
3372 {
3373 if (i > 0) { out += ", "; }
Ben Claytona6833282019-05-28 17:15:02 +01003374 out += fmt(list[i]);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003375 }
3376 return out + "]";
3377 }
3378
Ben Clayton3ed8ba02019-04-04 22:01:51 +01003379 static std::string addr(const void* ptr)
3380 {
3381 char buf[32];
3382 snprintf(buf, sizeof(buf), "%p", ptr);
3383 return buf;
3384 }
3385
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003386 public:
3387 const std::string format;
3388 const std::vector<Value*> values;
3389
3390 // Constructs a PrintValue for the given value.
3391 template <typename T>
Ben Claytona6833282019-05-28 17:15:02 +01003392 PrintValue(const T& v) : format(fmt(v)), values(val(v)) {}
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003393
3394 // Constructs a PrintValue for the given static array.
3395 template <typename T, int N>
Ben Claytona6833282019-05-28 17:15:02 +01003396 PrintValue(const T (&v)[N]) : format(fmt(&v[0], N)), values(val(&v[0], N)) {}
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003397
3398 // Constructs a PrintValue for the given array starting at arr of length
3399 // len.
3400 template <typename T>
Ben Claytona6833282019-05-28 17:15:02 +01003401 PrintValue(const T* arr, int len) : format(fmt(arr, len)), values(val(arr, len)) {}
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003402
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003403 // PrintValue constructors for plain-old-data values.
3404 PrintValue(bool v) : format(v ? "true" : "false") {}
3405 PrintValue(int8_t v) : format(std::to_string(v)) {}
3406 PrintValue(uint8_t v) : format(std::to_string(v)) {}
3407 PrintValue(int16_t v) : format(std::to_string(v)) {}
3408 PrintValue(uint16_t v) : format(std::to_string(v)) {}
3409 PrintValue(int32_t v) : format(std::to_string(v)) {}
3410 PrintValue(uint32_t v) : format(std::to_string(v)) {}
3411 PrintValue(int64_t v) : format(std::to_string(v)) {}
3412 PrintValue(uint64_t v) : format(std::to_string(v)) {}
3413 PrintValue(float v) : format(std::to_string(v)) {}
3414 PrintValue(double v) : format(std::to_string(v)) {}
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003415
Ben Clayton3ed8ba02019-04-04 22:01:51 +01003416 template <typename T>
3417 PrintValue(const T* v) : format(addr(v)) {}
3418
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003419 // vals is a helper to build composite value lists.
3420 // vals returns the full, sequential list of printf argument values used
3421 // to print all the provided variadic values.
3422 // vals() is intended to be used by implementations of
3423 // PrintValue::Ty<>::vals() to help declare aggregate types.
3424 // For example, if you were declaring a PrintValue::Ty<> specialization
3425 // for a custom Mat4x4 matrix formed from four Vector4 values, you'd
3426 // write:
3427 //
3428 // namespace rr
3429 // {
3430 // template <> struct PrintValue::Ty<Mat4x4>
3431 // {
Ben Claytona6833282019-05-28 17:15:02 +01003432 // static std::string fmt(const Mat4x4& v)
3433 // {
3434 // return "[a: <%f, %f, %f, %f>,"
3435 // " b: <%f, %f, %f, %f>,"
3436 // " c: <%f, %f, %f, %f>,"
3437 // " d: <%f, %f, %f, %f>]";
3438 // }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003439 // static std::vector<rr::Value*> val(const Mat4x4& v)
3440 // {
3441 // return PrintValue::vals(v.a, v.b, v.c, v.d);
3442 // }
3443 // };
3444 // }
3445 template<typename ... ARGS>
3446 static std::vector<Value*> vals(ARGS... v)
3447 {
3448 std::vector< std::vector<Value*> > lists = {val(v)...};
3449 std::vector<Value*> joined;
3450 for (const auto& list : lists)
3451 {
3452 joined.insert(joined.end(), list.begin(), list.end());
3453 }
3454 return joined;
3455 }
Ben Claytona6833282019-05-28 17:15:02 +01003456
3457 // returns the printf format specifier for the given type via the
3458 // PrintValue::Ty<T> specialization.
3459 template <typename T>
3460 static std::string fmt(const T& v) { return Ty<T>::fmt(v); }
3461
3462 // returns the printf value for the given type with a
3463 // PrintValue::Ty<T> specialization.
3464 template <typename T>
3465 static std::vector<Value*> val(const T& v) { return Ty<T>::val(v); }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003466 };
3467
Ben Claytonbc0cbb92019-05-15 17:12:57 +01003468 // PrintValue::Ty<T> specializations for basic types.
3469 template <> struct PrintValue::Ty<const char*>
3470 {
Ben Claytona6833282019-05-28 17:15:02 +01003471 static std::string fmt(const char* v) { return "%s"; }
Ben Claytonbc0cbb92019-05-15 17:12:57 +01003472 static std::vector<Value*> val(const char* v);
3473 };
3474 template <> struct PrintValue::Ty<std::string>
3475 {
Ben Claytona6833282019-05-28 17:15:02 +01003476 static std::string fmt(const std::string& v) { return PrintValue::Ty<const char*>::fmt(v.c_str()); }
Ben Claytonbc0cbb92019-05-15 17:12:57 +01003477 static std::vector<Value*> val(const std::string& v) { return PrintValue::Ty<const char*>::val(v.c_str()); }
3478 };
3479
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003480 // PrintValue::Ty<T> specializations for standard Reactor types.
Ben Claytonca56e8b2019-03-12 20:05:43 +00003481 template <> struct PrintValue::Ty<Bool>
3482 {
Ben Claytona6833282019-05-28 17:15:02 +01003483 static std::string fmt(const RValue<Bool>& v) { return "%d"; }
Ben Claytonca56e8b2019-03-12 20:05:43 +00003484 static std::vector<Value*> val(const RValue<Bool>& v) { return {v.value}; }
3485 };
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003486 template <> struct PrintValue::Ty<Byte>
3487 {
Ben Claytona6833282019-05-28 17:15:02 +01003488 static std::string fmt(const RValue<Byte>& v) { return "%d"; }
3489 static std::vector<Value*> val(const RValue<Byte>& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003490 };
3491 template <> struct PrintValue::Ty<Byte4>
3492 {
Ben Claytona6833282019-05-28 17:15:02 +01003493 static std::string fmt(const RValue<Byte4>& v) { return "[%d, %d, %d, %d]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003494 static std::vector<Value*> val(const RValue<Byte4>& v);
3495 };
3496 template <> struct PrintValue::Ty<Int>
3497 {
Ben Claytona6833282019-05-28 17:15:02 +01003498 static std::string fmt(const RValue<Int>& v) { return "%d"; }
Ben Claytonca8e3d72019-05-14 16:51:05 +01003499 static std::vector<Value*> val(const RValue<Int>& v);
3500 };
3501 template <> struct PrintValue::Ty<Int2>
3502 {
Ben Claytona6833282019-05-28 17:15:02 +01003503 static std::string fmt(const RValue<Int>& v) { return "[%d, %d]"; }
Ben Claytonca8e3d72019-05-14 16:51:05 +01003504 static std::vector<Value*> val(const RValue<Int2>& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003505 };
3506 template <> struct PrintValue::Ty<Int4>
3507 {
Ben Claytona6833282019-05-28 17:15:02 +01003508 static std::string fmt(const RValue<Int4>& v) { return "[%d, %d, %d, %d]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003509 static std::vector<Value*> val(const RValue<Int4>& v);
3510 };
3511 template <> struct PrintValue::Ty<UInt>
3512 {
Ben Claytona6833282019-05-28 17:15:02 +01003513 static std::string fmt(const RValue<UInt>& v) { return "%u"; }
Ben Claytonca8e3d72019-05-14 16:51:05 +01003514 static std::vector<Value*> val(const RValue<UInt>& v);
3515 };
3516 template <> struct PrintValue::Ty<UInt2>
3517 {
Ben Claytona6833282019-05-28 17:15:02 +01003518 static std::string fmt(const RValue<UInt>& v) { return "[%u, %u]"; }
Ben Claytonca8e3d72019-05-14 16:51:05 +01003519 static std::vector<Value*> val(const RValue<UInt2>& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003520 };
3521 template <> struct PrintValue::Ty<UInt4>
3522 {
Ben Claytona6833282019-05-28 17:15:02 +01003523 static std::string fmt(const RValue<UInt4>& v) { return "[%u, %u, %u, %u]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003524 static std::vector<Value*> val(const RValue<UInt4>& v);
3525 };
3526 template <> struct PrintValue::Ty<Short>
3527 {
Ben Claytona6833282019-05-28 17:15:02 +01003528 static std::string fmt(const RValue<Short>& v) { return "%d"; }
3529 static std::vector<Value*> val(const RValue<Short>& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003530 };
3531 template <> struct PrintValue::Ty<Short4>
3532 {
Ben Claytona6833282019-05-28 17:15:02 +01003533 static std::string fmt(const RValue<Short4>& v) { return "[%d, %d, %d, %d]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003534 static std::vector<Value*> val(const RValue<Short4>& v);
3535 };
3536 template <> struct PrintValue::Ty<UShort>
3537 {
Ben Claytona6833282019-05-28 17:15:02 +01003538 static std::string fmt(const RValue<UShort>& v) { return "%u"; }
3539 static std::vector<Value*> val(const RValue<UShort>& v);
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003540 };
3541 template <> struct PrintValue::Ty<UShort4>
3542 {
Ben Claytona6833282019-05-28 17:15:02 +01003543 static std::string fmt(const RValue<UShort4>& v) { return "[%u, %u, %u, %u]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003544 static std::vector<Value*> val(const RValue<UShort4>& v);
3545 };
3546 template <> struct PrintValue::Ty<Float>
3547 {
Ben Claytona6833282019-05-28 17:15:02 +01003548 static std::string fmt(const RValue<Float>& v) { return "[%f]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003549 static std::vector<Value*> val(const RValue<Float>& v);
3550 };
3551 template <> struct PrintValue::Ty<Float4>
3552 {
Ben Claytona6833282019-05-28 17:15:02 +01003553 static std::string fmt(const RValue<Float4>& v) { return "[%f, %f, %f, %f]"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003554 static std::vector<Value*> val(const RValue<Float4>& v);
3555 };
Ben Clayton7945a512019-04-15 23:00:43 -04003556 template <> struct PrintValue::Ty<Long>
3557 {
Ben Claytona6833282019-05-28 17:15:02 +01003558 static std::string fmt(const RValue<Long>& v) { return "%lld"; }
Ben Clayton7945a512019-04-15 23:00:43 -04003559 static std::vector<Value*> val(const RValue<Long>& v) { return {v.value}; }
3560 };
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003561 template <typename T> struct PrintValue::Ty< Pointer<T> >
3562 {
Ben Claytona6833282019-05-28 17:15:02 +01003563 static std::string fmt(const RValue<Pointer<T>>& v) { return "%p"; }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003564 static std::vector<Value*> val(const RValue<Pointer<T>>& v) { return {v.value}; }
3565 };
3566 template <typename T> struct PrintValue::Ty< Reference<T> >
3567 {
Ben Claytona6833282019-05-28 17:15:02 +01003568 static std::string fmt(const Reference<T>& v) { return PrintValue::Ty<T>::fmt(v); }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003569 static std::vector<Value*> val(const Reference<T>& v) { return PrintValue::Ty<T>::val(v); }
3570 };
3571 template <typename T> struct PrintValue::Ty< RValue<T> >
3572 {
Ben Claytona6833282019-05-28 17:15:02 +01003573 static std::string fmt(const RValue<T>& v) { return PrintValue::Ty<T>::fmt(v); }
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003574 static std::vector<Value*> val(const RValue<T>& v) { return PrintValue::Ty<T>::val(v); }
3575 };
3576
3577 // Printv emits a call to printf() using the function, file and line,
3578 // message and optional values.
3579 // See Printv below.
3580 void Printv(const char* function, const char* file, int line, const char* msg, std::initializer_list<PrintValue> vals);
3581
3582 // Printv emits a call to printf() using the provided message and optional
3583 // values.
3584 // Printf replaces any bracketed indices in the message with string
3585 // representations of the corresponding value in vals.
3586 // For example:
3587 // Printv("{0} and {1}", "red", "green");
3588 // Would print the string:
3589 // "red and green"
3590 // Arguments can be indexed in any order.
3591 // Invalid indices are not substituted.
3592 inline void Printv(const char* msg, std::initializer_list<PrintValue> vals)
3593 {
3594 Printv(nullptr, nullptr, 0, msg, vals);
3595 }
3596
3597 // Print is a wrapper over Printv that wraps the variadic arguments into an
3598 // initializer_list before calling Printv.
3599 template <typename ... ARGS>
3600 void Print(const char* msg, const ARGS& ... vals) { Printv(msg, {vals...}); }
3601
3602 // Print is a wrapper over Printv that wraps the variadic arguments into an
3603 // initializer_list before calling Printv.
3604 template <typename ... ARGS>
3605 void Print(const char* function, const char* file, int line, const char* msg, const ARGS& ... vals)
3606 {
3607 Printv(function, file, line, msg, {vals...});
3608 }
3609
3610 // RR_LOG is a macro that calls Print(), automatically populating the
3611 // function, file and line parameters and appending a newline to the string.
3612 //
3613 // RR_LOG() is intended to be used for debugging JIT compiled code, and is
3614 // not intended for production use.
Antonio Maioranof448d8e2019-04-26 16:19:16 -04003615 #if defined(_WIN32)
Ben Clayton68a29012019-06-23 19:15:45 +01003616 #define RR_LOG(msg, ...) Print(__FUNCSIG__, __FILE__, static_cast<int>(__LINE__), msg "\n", ##__VA_ARGS__)
Antonio Maioranof448d8e2019-04-26 16:19:16 -04003617 #else
Ben Clayton68a29012019-06-23 19:15:45 +01003618 #define RR_LOG(msg, ...) Print(__PRETTY_FUNCTION__, __FILE__, static_cast<int>(__LINE__), msg "\n", ##__VA_ARGS__)
Antonio Maioranof448d8e2019-04-26 16:19:16 -04003619 #endif
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003620
3621 // Macro magic to perform variadic dispatch.
3622 // See: https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/preprocessor/macros/__VA_ARGS__/count-arguments
3623 // Note, this doesn't attempt to use the ##__VA_ARGS__ trick to handle 0
Ben Clayton68a29012019-06-23 19:15:45 +01003624 #define RR_MSVC_EXPAND_BUG(X) X // Helper macro to force expanding __VA_ARGS__ to satisfy MSVC compiler.
3625 #define RR_GET_NTH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N
3626 #define RR_COUNT_ARGUMENTS(...) RR_MSVC_EXPAND_BUG(RR_GET_NTH_ARG(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
Ben Clayton60a3d6f2019-02-26 17:24:46 +00003627 static_assert(1 == RR_COUNT_ARGUMENTS(a), "RR_COUNT_ARGUMENTS broken"); // Sanity checks.
3628 static_assert(2 == RR_COUNT_ARGUMENTS(a, b), "RR_COUNT_ARGUMENTS broken");
3629 static_assert(3 == RR_COUNT_ARGUMENTS(a, b, c), "RR_COUNT_ARGUMENTS broken");
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003630
3631 // RR_WATCH_FMT(...) resolves to a string literal that lists all the
3632 // arguments by name. This string can be passed to LOG() to print each of
3633 // the arguments with their name and value.
3634 //
3635 // RR_WATCH_FMT(...) uses the RR_COUNT_ARGUMENTS helper macro to delegate to a
3636 // corresponding RR_WATCH_FMT_n specialization macro below.
3637 #define RR_WATCH_CONCAT(a, b) a ## b
3638 #define RR_WATCH_CONCAT2(a, b) RR_WATCH_CONCAT(a, b)
Ben Clayton68a29012019-06-23 19:15:45 +01003639 #define RR_WATCH_FMT(...) RR_MSVC_EXPAND_BUG(RR_WATCH_CONCAT2(RR_WATCH_FMT_, RR_COUNT_ARGUMENTS(__VA_ARGS__))(__VA_ARGS__))
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003640 #define RR_WATCH_FMT_1(_1) "\n " #_1 ": {0}"
Ben Clayton644a3502019-03-13 11:24:46 +00003641 #define RR_WATCH_FMT_2(_1, _2) RR_WATCH_FMT_1(_1) "\n " #_2 ": {1}"
3642 #define RR_WATCH_FMT_3(_1, _2, _3) RR_WATCH_FMT_2(_1, _2) "\n " #_3 ": {2}"
3643 #define RR_WATCH_FMT_4(_1, _2, _3, _4) RR_WATCH_FMT_3(_1, _2, _3) "\n " #_4 ": {3}"
3644 #define RR_WATCH_FMT_5(_1, _2, _3, _4, _5) RR_WATCH_FMT_4(_1, _2, _3, _4) "\n " #_5 ": {4}"
3645 #define RR_WATCH_FMT_6(_1, _2, _3, _4, _5, _6) RR_WATCH_FMT_5(_1, _2, _3, _4, _5) "\n " #_6 ": {5}"
3646 #define RR_WATCH_FMT_7(_1, _2, _3, _4, _5, _6, _7) RR_WATCH_FMT_6(_1, _2, _3, _4, _5, _6) "\n " #_7 ": {6}"
3647 #define RR_WATCH_FMT_8(_1, _2, _3, _4, _5, _6, _7, _8) RR_WATCH_FMT_7(_1, _2, _3, _4, _5, _6, _7) "\n " #_8 ": {7}"
3648 #define RR_WATCH_FMT_9(_1, _2, _3, _4, _5, _6, _7, _8, _9) RR_WATCH_FMT_8(_1, _2, _3, _4, _5, _6, _7, _8) "\n " #_9 ": {8}"
3649 #define RR_WATCH_FMT_10(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) RR_WATCH_FMT_9(_1, _2, _3, _4, _5, _6, _7, _8, _9) "\n " #_10 ": {9}"
3650 #define RR_WATCH_FMT_11(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) RR_WATCH_FMT_10(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) "\n " #_11 ": {10}"
3651 #define RR_WATCH_FMT_12(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) RR_WATCH_FMT_11(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) "\n " #_12 ": {11}"
Ben Clayton1bc7ee92019-02-14 18:43:22 +00003652
3653 // RR_WATCH() is a helper that prints the name and value of all the supplied
3654 // arguments.
3655 // For example, if you had the Int and bool variables 'foo' and 'bar' that
3656 // you want to print, you can simply write:
3657 // RR_WATCH(foo, bar)
3658 // When this JIT compiled code is executed, it will print the string
3659 // "foo: 1, bar: true" to stdout.
3660 //
3661 // RR_WATCH() is intended to be used for debugging JIT compiled code, and
3662 // is not intended for production use.
3663 #define RR_WATCH(...) RR_LOG(RR_WATCH_FMT(__VA_ARGS__), __VA_ARGS__)
3664#endif // ENABLE_RR_PRINT
3665
Nicolas Capens37ed9082016-11-16 17:40:48 -05003666 class ForData
3667 {
3668 public:
3669 ForData(bool init) : loopOnce(init)
3670 {
3671 }
3672
3673 operator bool()
3674 {
3675 return loopOnce;
3676 }
3677
3678 bool operator=(bool value)
3679 {
3680 return loopOnce = value;
3681 }
3682
3683 bool setup()
3684 {
Ben Claytonac07ed82019-03-26 14:17:41 +00003685 RR_DEBUG_INFO_FLUSH();
Nicolas Capens37ed9082016-11-16 17:40:48 -05003686 if(Nucleus::getInsertBlock() != endBB)
3687 {
3688 testBB = Nucleus::createBasicBlock();
3689
3690 Nucleus::createBr(testBB);
3691 Nucleus::setInsertBlock(testBB);
3692
3693 return true;
3694 }
3695
3696 return false;
3697 }
3698
3699 bool test(RValue<Bool> cmp)
3700 {
3701 BasicBlock *bodyBB = Nucleus::createBasicBlock();
3702 endBB = Nucleus::createBasicBlock();
3703
3704 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
3705 Nucleus::setInsertBlock(bodyBB);
3706
3707 return true;
3708 }
3709
3710 void end()
3711 {
3712 Nucleus::createBr(testBB);
3713 Nucleus::setInsertBlock(endBB);
3714 }
3715
3716 private:
3717 BasicBlock *testBB = nullptr;
3718 BasicBlock *endBB = nullptr;
3719 bool loopOnce = true;
3720 };
3721
3722 class IfElseData
3723 {
3724 public:
3725 IfElseData(RValue<Bool> cmp) : iteration(0)
3726 {
3727 condition = cmp.value;
3728
3729 beginBB = Nucleus::getInsertBlock();
3730 trueBB = Nucleus::createBasicBlock();
3731 falseBB = nullptr;
3732 endBB = Nucleus::createBasicBlock();
3733
3734 Nucleus::setInsertBlock(trueBB);
3735 }
3736
3737 ~IfElseData()
3738 {
3739 Nucleus::createBr(endBB);
3740
3741 Nucleus::setInsertBlock(beginBB);
3742 Nucleus::createCondBr(condition, trueBB, falseBB ? falseBB : endBB);
3743
3744 Nucleus::setInsertBlock(endBB);
3745 }
3746
3747 operator int()
3748 {
3749 return iteration;
3750 }
3751
3752 IfElseData &operator++()
3753 {
3754 ++iteration;
3755
3756 return *this;
3757 }
3758
3759 void elseClause()
3760 {
3761 Nucleus::createBr(endBB);
3762
3763 falseBB = Nucleus::createBasicBlock();
3764 Nucleus::setInsertBlock(falseBB);
3765 }
3766
3767 private:
3768 Value *condition;
3769 BasicBlock *beginBB;
3770 BasicBlock *trueBB;
3771 BasicBlock *falseBB;
3772 BasicBlock *endBB;
3773 int iteration;
3774 };
3775
Nicolas Capensb0eb3772016-10-24 17:49:13 -04003776 #define For(init, cond, inc) \
Nicolas Capens8884a232016-11-16 15:03:18 -05003777 for(ForData for__ = true; for__; for__ = false) \
3778 for(init; for__.setup() && for__.test(cond); inc, for__.end())
Nicolas Capens0bac2852016-05-07 06:09:58 -04003779
Nicolas Capensb0eb3772016-10-24 17:49:13 -04003780 #define While(cond) For((void)0, cond, (void)0)
Nicolas Capens0bac2852016-05-07 06:09:58 -04003781
Nicolas Capensb0eb3772016-10-24 17:49:13 -04003782 #define Do \
3783 { \
3784 BasicBlock *body__ = Nucleus::createBasicBlock(); \
3785 Nucleus::createBr(body__); \
3786 Nucleus::setInsertBlock(body__);
3787
3788 #define Until(cond) \
3789 BasicBlock *end__ = Nucleus::createBasicBlock(); \
3790 Nucleus::createCondBr((cond).value, end__, body__); \
3791 Nucleus::setInsertBlock(end__); \
Nicolas Capens0bac2852016-05-07 06:09:58 -04003792 }
3793
Nicolas Capens37ed9082016-11-16 17:40:48 -05003794 enum {IF_BLOCK__, ELSE_CLAUSE__, ELSE_BLOCK__, IFELSE_NUM__};
Nicolas Capens0bac2852016-05-07 06:09:58 -04003795
Nicolas Capens37ed9082016-11-16 17:40:48 -05003796 #define If(cond) \
3797 for(IfElseData ifElse__(cond); ifElse__ < IFELSE_NUM__; ++ifElse__) \
3798 if(ifElse__ == IF_BLOCK__)
3799
3800 #define Else \
3801 else if(ifElse__ == ELSE_CLAUSE__) \
3802 { \
3803 ifElse__.elseClause(); \
3804 } \
3805 else // ELSE_BLOCK__
Nicolas Capensd022e412016-09-26 13:30:14 -04003806}
3807
Ben Clayton7e11f462019-11-18 16:00:31 +00003808#include "Traits.inl"
3809
Nicolas Capens48461502018-08-06 14:20:45 -04003810#endif // rr_Reactor_hpp