Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "Reactor.hpp" |
Ben Clayton | 1c82c7b | 2019-04-30 12:49:27 +0100 | [diff] [blame] | 16 | #include "Coroutine.hpp" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 17 | |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 18 | #include "gtest/gtest.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 19 | |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 20 | #include <tuple> |
| 21 | |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 22 | using namespace rr; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 23 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 24 | int reference(int *p, int y) |
| 25 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 26 | int x = p[-1]; |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 27 | int z = 4; |
| 28 | |
| 29 | for(int i = 0; i < 10; i++) |
| 30 | { |
| 31 | z += (2 << i) - (i / 3); |
| 32 | } |
| 33 | |
| 34 | int sum = x + y + z; |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 35 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 36 | return sum; |
| 37 | } |
| 38 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 39 | TEST(ReactorUnitTests, Sample) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 40 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 41 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 42 | FunctionT<int(int*, int)> function; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 43 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 44 | Pointer<Int> p = function.Arg<0>(); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 45 | Int x = p[-1]; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 46 | Int y = function.Arg<1>(); |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 47 | Int z = 4; |
| 48 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 49 | For(Int i = 0, i < 10, i++) |
| 50 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 51 | z += (2 << i) - (i / 3); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 54 | Float4 v; |
| 55 | v.z = As<Float>(z); |
| 56 | z = As<Int>(Float(Float4(v.xzxx).y)); |
| 57 | |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 58 | Int sum = x + y + z; |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 59 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 60 | Return(sum); |
| 61 | } |
| 62 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 63 | auto routine = function("one"); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 64 | |
| 65 | if(routine) |
| 66 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 67 | int one[2] = {1, 0}; |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 68 | int result = routine(&one[1], 2); |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 69 | EXPECT_EQ(result, reference(&one[1], 2)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 73 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 74 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 75 | TEST(ReactorUnitTests, Uninitialized) |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 76 | { |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 77 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 78 | FunctionT<int()> function; |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 79 | { |
| 80 | Int a; |
| 81 | Int z = 4; |
| 82 | Int q; |
| 83 | Int c; |
| 84 | Int p; |
| 85 | Bool b; |
| 86 | |
| 87 | q += q; |
| 88 | |
| 89 | If(b) |
| 90 | { |
| 91 | c = p; |
| 92 | } |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 93 | |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 94 | Return(a + z + q + c); |
| 95 | } |
| 96 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 97 | auto routine = function("one"); |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 98 | |
| 99 | if(routine) |
| 100 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 101 | int result = routine(); |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 102 | EXPECT_EQ(result, result); // Anything is fine, just don't crash |
| 103 | } |
| 104 | } |
| 105 | |
Nicolas Capens | f4452fc | 2016-12-12 13:08:06 -0500 | [diff] [blame] | 106 | } |
| 107 | |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 108 | TEST(ReactorUnitTests, Unreachable) |
| 109 | { |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 110 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 111 | FunctionT<int(int)> function; |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 112 | { |
| 113 | Int a = function.Arg<0>(); |
| 114 | Int z = 4; |
| 115 | |
| 116 | Return(a + z); |
| 117 | |
| 118 | // Code beyond this point is unreachable but should not cause any |
| 119 | // compilation issues. |
| 120 | |
| 121 | z += a; |
| 122 | } |
| 123 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 124 | auto routine = function("one"); |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 125 | |
| 126 | if(routine) |
| 127 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 128 | int result = routine(16); |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 129 | EXPECT_EQ(result, 20); |
| 130 | } |
| 131 | } |
| 132 | |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | TEST(ReactorUnitTests, VariableAddress) |
| 136 | { |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 137 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 138 | FunctionT<int(int)> function; |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 139 | { |
| 140 | Int a = function.Arg<0>(); |
| 141 | Int z = 0; |
| 142 | Pointer<Int> p = &z; |
| 143 | *p = 4; |
| 144 | |
| 145 | Return(a + z); |
| 146 | } |
| 147 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 148 | auto routine = function("one"); |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 149 | |
| 150 | if(routine) |
| 151 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 152 | int result = routine(16); |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 153 | EXPECT_EQ(result, 20); |
| 154 | } |
| 155 | } |
| 156 | |
Nicolas Capens | 0192d15 | 2019-03-27 14:46:07 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 159 | TEST(ReactorUnitTests, SubVectorLoadStore) |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 160 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 161 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 162 | FunctionT<int(void*, void*)> function; |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 163 | { |
| 164 | Pointer<Byte> in = function.Arg<0>(); |
| 165 | Pointer<Byte> out = function.Arg<1>(); |
| 166 | |
| 167 | *Pointer<Int4>(out + 16 * 0) = *Pointer<Int4>(in + 16 * 0); |
| 168 | *Pointer<Short4>(out + 16 * 1) = *Pointer<Short4>(in + 16 * 1); |
| 169 | *Pointer<Byte8>(out + 16 * 2) = *Pointer<Byte8>(in + 16 * 2); |
| 170 | *Pointer<Byte4>(out + 16 * 3) = *Pointer<Byte4>(in + 16 * 3); |
| 171 | *Pointer<Short2>(out + 16 * 4) = *Pointer<Short2>(in + 16 * 4); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 172 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 173 | Return(0); |
| 174 | } |
| 175 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 176 | auto routine = function("one"); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 177 | |
| 178 | if(routine) |
| 179 | { |
| 180 | int8_t in[16 * 5] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
| 181 | 17, 18, 19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 0, 0, 0, 0, |
| 182 | 25, 26, 27, 28, 29, 30, 31, 32, 0, 0, 0, 0, 0, 0, 0, 0, |
| 183 | 33, 34, 35, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 184 | 37, 38, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 185 | |
| 186 | int8_t out[16 * 5] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 187 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 188 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 189 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 190 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 191 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 192 | routine(in, out); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 193 | |
| 194 | for(int row = 0; row < 5; row++) |
| 195 | { |
| 196 | for(int col = 0; col < 16; col++) |
| 197 | { |
| 198 | int i = row * 16 + col; |
| 199 | |
| 200 | if(in[i] == 0) |
| 201 | { |
| 202 | EXPECT_EQ(out[i], -1) << "Row " << row << " column " << col << " not left untouched."; |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | EXPECT_EQ(out[i], in[i]) << "Row " << row << " column " << col << " not equal to input."; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 215 | TEST(ReactorUnitTests, VectorConstant) |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 216 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 217 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 218 | FunctionT<int(void*)> function; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 219 | { |
| 220 | Pointer<Byte> out = function.Arg<0>(); |
| 221 | |
| 222 | *Pointer<Int4>(out + 16 * 0) = Int4(0x04030201, 0x08070605, 0x0C0B0A09, 0x100F0E0D); |
| 223 | *Pointer<Short4>(out + 16 * 1) = Short4(0x1211, 0x1413, 0x1615, 0x1817); |
| 224 | *Pointer<Byte8>(out + 16 * 2) = Byte8(0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20); |
| 225 | *Pointer<Int2>(out + 16 * 3) = Int2(0x24232221, 0x28272625); |
| 226 | |
| 227 | Return(0); |
| 228 | } |
| 229 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 230 | auto routine = function("one"); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 231 | |
| 232 | if(routine) |
| 233 | { |
| 234 | int8_t out[16 * 4] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 235 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 236 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 237 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
| 238 | |
| 239 | int8_t exp[16 * 4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
| 240 | 17, 18, 19, 20, 21, 22, 23, 24, -1, -1, -1, -1, -1, -1, -1, -1, |
| 241 | 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1, -1, -1, -1, |
| 242 | 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, -1, -1, -1, -1}; |
| 243 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 244 | routine(out); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 245 | |
| 246 | for(int row = 0; row < 4; row++) |
| 247 | { |
| 248 | for(int col = 0; col < 16; col++) |
| 249 | { |
| 250 | int i = row * 16 + col; |
| 251 | |
| 252 | EXPECT_EQ(out[i], exp[i]); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 258 | } |
| 259 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 260 | TEST(ReactorUnitTests, Concatenate) |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 261 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 262 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 263 | FunctionT<int(void*)> function; |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 264 | { |
| 265 | Pointer<Byte> out = function.Arg<0>(); |
| 266 | |
| 267 | *Pointer<Int4>(out + 16 * 0) = Int4(Int2(0x04030201, 0x08070605), Int2(0x0C0B0A09, 0x100F0E0D)); |
| 268 | *Pointer<Short8>(out + 16 * 1) = Short8(Short4(0x0201, 0x0403, 0x0605, 0x0807), Short4(0x0A09, 0x0C0B, 0x0E0D, 0x100F)); |
| 269 | |
| 270 | Return(0); |
| 271 | } |
| 272 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 273 | auto routine = function("one"); |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 274 | |
| 275 | if(routine) |
| 276 | { |
| 277 | int8_t ref[16 * 5] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
| 278 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; |
| 279 | |
| 280 | int8_t out[16 * 5] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 281 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 282 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 283 | routine(out); |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 284 | |
| 285 | for(int row = 0; row < 2; row++) |
| 286 | { |
| 287 | for(int col = 0; col < 16; col++) |
| 288 | { |
| 289 | int i = row * 16 + col; |
| 290 | |
| 291 | EXPECT_EQ(out[i], ref[i]) << "Row " << row << " column " << col << " not equal to reference."; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 299 | TEST(ReactorUnitTests, Swizzle) |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 300 | { |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 301 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 302 | FunctionT<int(void*)> function; |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 303 | { |
| 304 | Pointer<Byte> out = function.Arg<0>(); |
| 305 | |
| 306 | for(int i = 0; i < 256; i++) |
| 307 | { |
| 308 | *Pointer<Float4>(out + 16 * i) = Swizzle(Float4(1.0f, 2.0f, 3.0f, 4.0f), i); |
| 309 | } |
| 310 | |
| 311 | for(int i = 0; i < 256; i++) |
| 312 | { |
| 313 | *Pointer<Float4>(out + 16 * (256 + i)) = ShuffleLowHigh(Float4(1.0f, 2.0f, 3.0f, 4.0f), Float4(5.0f, 6.0f, 7.0f, 8.0f), i); |
| 314 | } |
| 315 | |
| 316 | *Pointer<Float4>(out + 16 * (512 + 0)) = UnpackLow(Float4(1.0f, 2.0f, 3.0f, 4.0f), Float4(5.0f, 6.0f, 7.0f, 8.0f)); |
| 317 | *Pointer<Float4>(out + 16 * (512 + 1)) = UnpackHigh(Float4(1.0f, 2.0f, 3.0f, 4.0f), Float4(5.0f, 6.0f, 7.0f, 8.0f)); |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 318 | *Pointer<Int2>(out + 16 * (512 + 2)) = UnpackLow(Short4(1, 2, 3, 4), Short4(5, 6, 7, 8)); |
| 319 | *Pointer<Int2>(out + 16 * (512 + 3)) = UnpackHigh(Short4(1, 2, 3, 4), Short4(5, 6, 7, 8)); |
| 320 | *Pointer<Short4>(out + 16 * (512 + 4)) = UnpackLow(Byte8(1, 2, 3, 4, 5, 6, 7, 8), Byte8(9, 10, 11, 12, 13, 14, 15, 16)); |
| 321 | *Pointer<Short4>(out + 16 * (512 + 5)) = UnpackHigh(Byte8(1, 2, 3, 4, 5, 6, 7, 8), Byte8(9, 10, 11, 12, 13, 14, 15, 16)); |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 322 | |
Casey Dahlin | 9d56da2 | 2017-10-03 13:23:11 -0700 | [diff] [blame] | 323 | for(int i = 0; i < 256; i++) |
| 324 | { |
| 325 | *Pointer<Short4>(out + 16 * (512 + 6) + (8 * i)) = |
| 326 | Swizzle(Short4(1, 2, 3, 4), i); |
| 327 | } |
| 328 | |
| 329 | for(int i = 0; i < 256; i++) |
| 330 | { |
| 331 | *Pointer<Int4>(out + 16 * (512 + 6 + i) + (8 * 256)) = |
| 332 | Swizzle(Int4(1, 2, 3, 4), i); |
| 333 | } |
| 334 | |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 335 | Return(0); |
| 336 | } |
| 337 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 338 | auto routine = function("one"); |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 339 | |
| 340 | if(routine) |
| 341 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 342 | struct |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 343 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 344 | float f[256 + 256 + 2][4]; |
Casey Dahlin | 9d56da2 | 2017-10-03 13:23:11 -0700 | [diff] [blame] | 345 | int i[388][4]; |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 346 | } out; |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 347 | |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 348 | memset(&out, 0, sizeof(out)); |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 349 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 350 | routine(&out); |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 351 | |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 352 | for(int i = 0; i < 256; i++) |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 353 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 354 | EXPECT_EQ(out.f[i][0], float((i >> 0) & 0x03) + 1.0f); |
| 355 | EXPECT_EQ(out.f[i][1], float((i >> 2) & 0x03) + 1.0f); |
| 356 | EXPECT_EQ(out.f[i][2], float((i >> 4) & 0x03) + 1.0f); |
| 357 | EXPECT_EQ(out.f[i][3], float((i >> 6) & 0x03) + 1.0f); |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 358 | } |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 359 | |
| 360 | for(int i = 0; i < 256; i++) |
| 361 | { |
| 362 | EXPECT_EQ(out.f[256 + i][0], float((i >> 0) & 0x03) + 1.0f); |
| 363 | EXPECT_EQ(out.f[256 + i][1], float((i >> 2) & 0x03) + 1.0f); |
| 364 | EXPECT_EQ(out.f[256 + i][2], float((i >> 4) & 0x03) + 5.0f); |
| 365 | EXPECT_EQ(out.f[256 + i][3], float((i >> 6) & 0x03) + 5.0f); |
| 366 | } |
| 367 | |
| 368 | EXPECT_EQ(out.f[512 + 0][0], 1.0f); |
| 369 | EXPECT_EQ(out.f[512 + 0][1], 5.0f); |
| 370 | EXPECT_EQ(out.f[512 + 0][2], 2.0f); |
| 371 | EXPECT_EQ(out.f[512 + 0][3], 6.0f); |
| 372 | |
| 373 | EXPECT_EQ(out.f[512 + 1][0], 3.0f); |
| 374 | EXPECT_EQ(out.f[512 + 1][1], 7.0f); |
| 375 | EXPECT_EQ(out.f[512 + 1][2], 4.0f); |
| 376 | EXPECT_EQ(out.f[512 + 1][3], 8.0f); |
| 377 | |
| 378 | EXPECT_EQ(out.i[0][0], 0x00050001); |
| 379 | EXPECT_EQ(out.i[0][1], 0x00060002); |
| 380 | EXPECT_EQ(out.i[0][2], 0x00000000); |
| 381 | EXPECT_EQ(out.i[0][3], 0x00000000); |
| 382 | |
| 383 | EXPECT_EQ(out.i[1][0], 0x00070003); |
| 384 | EXPECT_EQ(out.i[1][1], 0x00080004); |
| 385 | EXPECT_EQ(out.i[1][2], 0x00000000); |
| 386 | EXPECT_EQ(out.i[1][3], 0x00000000); |
| 387 | |
| 388 | EXPECT_EQ(out.i[2][0], 0x0A020901); |
| 389 | EXPECT_EQ(out.i[2][1], 0x0C040B03); |
| 390 | EXPECT_EQ(out.i[2][2], 0x00000000); |
| 391 | EXPECT_EQ(out.i[2][3], 0x00000000); |
| 392 | |
| 393 | EXPECT_EQ(out.i[3][0], 0x0E060D05); |
| 394 | EXPECT_EQ(out.i[3][1], 0x10080F07); |
| 395 | EXPECT_EQ(out.i[3][2], 0x00000000); |
| 396 | EXPECT_EQ(out.i[3][3], 0x00000000); |
Casey Dahlin | 9d56da2 | 2017-10-03 13:23:11 -0700 | [diff] [blame] | 397 | |
| 398 | for(int i = 0; i < 256; i++) |
| 399 | { |
| 400 | EXPECT_EQ(out.i[4 + i/2][0 + (i%2) * 2] & 0xFFFF, |
| 401 | ((i >> 0) & 0x03) + 1); |
| 402 | EXPECT_EQ(out.i[4 + i/2][0 + (i%2) * 2] >> 16, |
| 403 | ((i >> 2) & 0x03) + 1); |
| 404 | EXPECT_EQ(out.i[4 + i/2][1 + (i%2) * 2] & 0xFFFF, |
| 405 | ((i >> 4) & 0x03) + 1); |
| 406 | EXPECT_EQ(out.i[4 + i/2][1 + (i%2) * 2] >> 16, |
| 407 | ((i >> 6) & 0x03) + 1); |
| 408 | } |
| 409 | |
| 410 | for(int i = 0; i < 256; i++) |
| 411 | { |
| 412 | EXPECT_EQ(out.i[132 + i][0], ((i >> 0) & 0x03) + 1); |
| 413 | EXPECT_EQ(out.i[132 + i][1], ((i >> 2) & 0x03) + 1); |
| 414 | EXPECT_EQ(out.i[132 + i][2], ((i >> 4) & 0x03) + 1); |
| 415 | EXPECT_EQ(out.i[132 + i][3], ((i >> 6) & 0x03) + 1); |
| 416 | } |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Nicolas Capens | 363b61e | 2016-10-21 13:19:34 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 422 | TEST(ReactorUnitTests, Branching) |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 423 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 424 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 425 | FunctionT<int()> function; |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 426 | { |
| 427 | Int x = 0; |
| 428 | |
| 429 | For(Int i = 0, i < 8, i++) |
| 430 | { |
| 431 | If(i < 2) |
| 432 | { |
| 433 | x += 1; |
| 434 | } |
| 435 | Else If(i < 4) |
| 436 | { |
| 437 | x += 10; |
| 438 | } |
| 439 | Else If(i < 6) |
| 440 | { |
| 441 | x += 100; |
| 442 | } |
| 443 | Else |
| 444 | { |
| 445 | x += 1000; |
| 446 | } |
| 447 | |
| 448 | For(Int i = 0, i < 5, i++) |
| 449 | x += 10000; |
| 450 | } |
| 451 | |
Nicolas Capens | b0eb377 | 2016-10-24 17:49:13 -0400 | [diff] [blame] | 452 | For(Int i = 0, i < 10, i++) |
| 453 | for(int i = 0; i < 10; i++) |
| 454 | For(Int i = 0, i < 10, i++) |
| 455 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 456 | x += 1000000; |
Nicolas Capens | b0eb377 | 2016-10-24 17:49:13 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | For(Int i = 0, i < 2, i++) |
| 460 | If(x == 1000402222) |
| 461 | { |
| 462 | If(x != 1000402222) |
| 463 | x += 1000000000; |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 464 | } |
| 465 | Else |
| 466 | x = -5; |
| 467 | |
| 468 | Return(x); |
| 469 | } |
| 470 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 471 | auto routine = function("one"); |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 472 | |
| 473 | if(routine) |
| 474 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 475 | int result = routine(); |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 476 | |
Nicolas Capens | b0eb377 | 2016-10-24 17:49:13 -0400 | [diff] [blame] | 477 | EXPECT_EQ(result, 1000402222); |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 483 | TEST(ReactorUnitTests, MinMax) |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 484 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 485 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 486 | FunctionT<int(void*)> function; |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 487 | { |
| 488 | Pointer<Byte> out = function.Arg<0>(); |
| 489 | |
| 490 | *Pointer<Float4>(out + 16 * 0) = Min(Float4(1.0f, 0.0f, -0.0f, +0.0f), Float4(0.0f, 1.0f, +0.0f, -0.0f)); |
| 491 | *Pointer<Float4>(out + 16 * 1) = Max(Float4(1.0f, 0.0f, -0.0f, +0.0f), Float4(0.0f, 1.0f, +0.0f, -0.0f)); |
| 492 | |
| 493 | *Pointer<Int4>(out + 16 * 2) = Min(Int4(1, 0, -1, -0), Int4(0, 1, 0, +0)); |
| 494 | *Pointer<Int4>(out + 16 * 3) = Max(Int4(1, 0, -1, -0), Int4(0, 1, 0, +0)); |
| 495 | *Pointer<UInt4>(out + 16 * 4) = Min(UInt4(1, 0, -1, -0), UInt4(0, 1, 0, +0)); |
| 496 | *Pointer<UInt4>(out + 16 * 5) = Max(UInt4(1, 0, -1, -0), UInt4(0, 1, 0, +0)); |
| 497 | |
| 498 | *Pointer<Short4>(out + 16 * 6) = Min(Short4(1, 0, -1, -0), Short4(0, 1, 0, +0)); |
| 499 | *Pointer<Short4>(out + 16 * 7) = Max(Short4(1, 0, -1, -0), Short4(0, 1, 0, +0)); |
| 500 | *Pointer<UShort4>(out + 16 * 8) = Min(UShort4(1, 0, -1, -0), UShort4(0, 1, 0, +0)); |
| 501 | *Pointer<UShort4>(out + 16 * 9) = Max(UShort4(1, 0, -1, -0), UShort4(0, 1, 0, +0)); |
| 502 | |
| 503 | Return(0); |
| 504 | } |
| 505 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 506 | auto routine = function("one"); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 507 | |
| 508 | if(routine) |
| 509 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 510 | unsigned int out[10][4]; |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 511 | |
| 512 | memset(&out, 0, sizeof(out)); |
| 513 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 514 | routine(&out); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 515 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 516 | EXPECT_EQ(out[0][0], 0x00000000u); |
| 517 | EXPECT_EQ(out[0][1], 0x00000000u); |
| 518 | EXPECT_EQ(out[0][2], 0x00000000u); |
| 519 | EXPECT_EQ(out[0][3], 0x80000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 520 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 521 | EXPECT_EQ(out[1][0], 0x3F800000u); |
| 522 | EXPECT_EQ(out[1][1], 0x3F800000u); |
| 523 | EXPECT_EQ(out[1][2], 0x00000000u); |
| 524 | EXPECT_EQ(out[1][3], 0x80000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 525 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 526 | EXPECT_EQ(out[2][0], 0x00000000u); |
| 527 | EXPECT_EQ(out[2][1], 0x00000000u); |
| 528 | EXPECT_EQ(out[2][2], 0xFFFFFFFFu); |
| 529 | EXPECT_EQ(out[2][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 530 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 531 | EXPECT_EQ(out[3][0], 0x00000001u); |
| 532 | EXPECT_EQ(out[3][1], 0x00000001u); |
| 533 | EXPECT_EQ(out[3][2], 0x00000000u); |
| 534 | EXPECT_EQ(out[3][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 535 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 536 | EXPECT_EQ(out[4][0], 0x00000000u); |
| 537 | EXPECT_EQ(out[4][1], 0x00000000u); |
| 538 | EXPECT_EQ(out[4][2], 0x00000000u); |
| 539 | EXPECT_EQ(out[4][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 540 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 541 | EXPECT_EQ(out[5][0], 0x00000001u); |
| 542 | EXPECT_EQ(out[5][1], 0x00000001u); |
| 543 | EXPECT_EQ(out[5][2], 0xFFFFFFFFu); |
| 544 | EXPECT_EQ(out[5][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 545 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 546 | EXPECT_EQ(out[6][0], 0x00000000u); |
| 547 | EXPECT_EQ(out[6][1], 0x0000FFFFu); |
| 548 | EXPECT_EQ(out[6][2], 0x00000000u); |
| 549 | EXPECT_EQ(out[6][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 550 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 551 | EXPECT_EQ(out[7][0], 0x00010001u); |
| 552 | EXPECT_EQ(out[7][1], 0x00000000u); |
| 553 | EXPECT_EQ(out[7][2], 0x00000000u); |
| 554 | EXPECT_EQ(out[7][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 555 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 556 | EXPECT_EQ(out[8][0], 0x00000000u); |
| 557 | EXPECT_EQ(out[8][1], 0x00000000u); |
| 558 | EXPECT_EQ(out[8][2], 0x00000000u); |
| 559 | EXPECT_EQ(out[8][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 560 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 561 | EXPECT_EQ(out[9][0], 0x00010001u); |
| 562 | EXPECT_EQ(out[9][1], 0x0000FFFFu); |
| 563 | EXPECT_EQ(out[9][2], 0x00000000u); |
| 564 | EXPECT_EQ(out[9][3], 0x00000000u); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 568 | } |
| 569 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 570 | TEST(ReactorUnitTests, NotNeg) |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 571 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 572 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 573 | FunctionT<int(void*)> function; |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 574 | { |
| 575 | Pointer<Byte> out = function.Arg<0>(); |
| 576 | |
| 577 | *Pointer<Int>(out + 16 * 0) = ~Int(0x55555555); |
| 578 | *Pointer<Short>(out + 16 * 1) = ~Short(0x5555); |
| 579 | *Pointer<Int4>(out + 16 * 2) = ~Int4(0x55555555, 0xAAAAAAAA, 0x00000000, 0xFFFFFFFF); |
| 580 | *Pointer<Short4>(out + 16 * 3) = ~Short4(0x5555, 0xAAAA, 0x0000, 0xFFFF); |
| 581 | |
| 582 | *Pointer<Int>(out + 16 * 4) = -Int(0x55555555); |
| 583 | *Pointer<Short>(out + 16 * 5) = -Short(0x5555); |
| 584 | *Pointer<Int4>(out + 16 * 6) = -Int4(0x55555555, 0xAAAAAAAA, 0x00000000, 0xFFFFFFFF); |
| 585 | *Pointer<Short4>(out + 16 * 7) = -Short4(0x5555, 0xAAAA, 0x0000, 0xFFFF); |
| 586 | |
| 587 | *Pointer<Float4>(out + 16 * 8) = -Float4(1.0f, -1.0f, 0.0f, -0.0f); |
| 588 | |
| 589 | Return(0); |
| 590 | } |
| 591 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 592 | auto routine = function("one"); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 593 | |
| 594 | if(routine) |
| 595 | { |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 596 | unsigned int out[10][4]; |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 597 | |
| 598 | memset(&out, 0, sizeof(out)); |
| 599 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 600 | routine(&out); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 601 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 602 | EXPECT_EQ(out[0][0], 0xAAAAAAAAu); |
| 603 | EXPECT_EQ(out[0][1], 0x00000000u); |
| 604 | EXPECT_EQ(out[0][2], 0x00000000u); |
| 605 | EXPECT_EQ(out[0][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 606 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 607 | EXPECT_EQ(out[1][0], 0x0000AAAAu); |
| 608 | EXPECT_EQ(out[1][1], 0x00000000u); |
| 609 | EXPECT_EQ(out[1][2], 0x00000000u); |
| 610 | EXPECT_EQ(out[1][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 611 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 612 | EXPECT_EQ(out[2][0], 0xAAAAAAAAu); |
| 613 | EXPECT_EQ(out[2][1], 0x55555555u); |
| 614 | EXPECT_EQ(out[2][2], 0xFFFFFFFFu); |
| 615 | EXPECT_EQ(out[2][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 616 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 617 | EXPECT_EQ(out[3][0], 0x5555AAAAu); |
| 618 | EXPECT_EQ(out[3][1], 0x0000FFFFu); |
| 619 | EXPECT_EQ(out[3][2], 0x00000000u); |
| 620 | EXPECT_EQ(out[3][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 621 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 622 | EXPECT_EQ(out[4][0], 0xAAAAAAABu); |
| 623 | EXPECT_EQ(out[4][1], 0x00000000u); |
| 624 | EXPECT_EQ(out[4][2], 0x00000000u); |
| 625 | EXPECT_EQ(out[4][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 626 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 627 | EXPECT_EQ(out[5][0], 0x0000AAABu); |
| 628 | EXPECT_EQ(out[5][1], 0x00000000u); |
| 629 | EXPECT_EQ(out[5][2], 0x00000000u); |
| 630 | EXPECT_EQ(out[5][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 631 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 632 | EXPECT_EQ(out[6][0], 0xAAAAAAABu); |
| 633 | EXPECT_EQ(out[6][1], 0x55555556u); |
| 634 | EXPECT_EQ(out[6][2], 0x00000000u); |
| 635 | EXPECT_EQ(out[6][3], 0x00000001u); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 636 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 637 | EXPECT_EQ(out[7][0], 0x5556AAABu); |
| 638 | EXPECT_EQ(out[7][1], 0x00010000u); |
| 639 | EXPECT_EQ(out[7][2], 0x00000000u); |
| 640 | EXPECT_EQ(out[7][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 641 | |
Nicolas Capens | da5320a | 2018-02-08 10:26:10 -0500 | [diff] [blame] | 642 | EXPECT_EQ(out[8][0], 0xBF800000u); |
| 643 | EXPECT_EQ(out[8][1], 0x3F800000u); |
| 644 | EXPECT_EQ(out[8][2], 0x80000000u); |
| 645 | EXPECT_EQ(out[8][3], 0x00000000u); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 651 | TEST(ReactorUnitTests, VectorCompare) |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 652 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 653 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 654 | FunctionT<int(void*)> function; |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 655 | { |
| 656 | Pointer<Byte> out = function.Arg<0>(); |
| 657 | |
| 658 | *Pointer<Int4>(out + 16 * 0) = CmpEQ(Float4(1.0f, 1.0f, -0.0f, +0.0f), Float4(0.0f, 1.0f, +0.0f, -0.0f)); |
| 659 | *Pointer<Int4>(out + 16 * 1) = CmpEQ(Int4(1, 0, -1, -0), Int4(0, 1, 0, +0)); |
| 660 | *Pointer<Byte8>(out + 16 * 2) = CmpEQ(SByte8(1, 2, 3, 4, 5, 6, 7, 8), SByte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 661 | |
| 662 | *Pointer<Int4>(out + 16 * 3) = CmpNLT(Float4(1.0f, 1.0f, -0.0f, +0.0f), Float4(0.0f, 1.0f, +0.0f, -0.0f)); |
| 663 | *Pointer<Int4>(out + 16 * 4) = CmpNLT(Int4(1, 0, -1, -0), Int4(0, 1, 0, +0)); |
| 664 | *Pointer<Byte8>(out + 16 * 5) = CmpGT(SByte8(1, 2, 3, 4, 5, 6, 7, 8), SByte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 665 | |
| 666 | Return(0); |
| 667 | } |
| 668 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 669 | auto routine = function("one"); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 670 | |
| 671 | if(routine) |
| 672 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 673 | unsigned int out[6][4]; |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 674 | |
| 675 | memset(&out, 0, sizeof(out)); |
| 676 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 677 | routine(&out); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 678 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 679 | EXPECT_EQ(out[0][0], 0x00000000u); |
| 680 | EXPECT_EQ(out[0][1], 0xFFFFFFFFu); |
| 681 | EXPECT_EQ(out[0][2], 0xFFFFFFFFu); |
| 682 | EXPECT_EQ(out[0][3], 0xFFFFFFFFu); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 683 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 684 | EXPECT_EQ(out[1][0], 0x00000000u); |
| 685 | EXPECT_EQ(out[1][1], 0x00000000u); |
| 686 | EXPECT_EQ(out[1][2], 0x00000000u); |
| 687 | EXPECT_EQ(out[1][3], 0xFFFFFFFFu); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 688 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 689 | EXPECT_EQ(out[2][0], 0xFF000000u); |
| 690 | EXPECT_EQ(out[2][1], 0x00000000u); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 691 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 692 | EXPECT_EQ(out[3][0], 0xFFFFFFFFu); |
| 693 | EXPECT_EQ(out[3][1], 0xFFFFFFFFu); |
| 694 | EXPECT_EQ(out[3][2], 0xFFFFFFFFu); |
| 695 | EXPECT_EQ(out[3][3], 0xFFFFFFFFu); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 696 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 697 | EXPECT_EQ(out[4][0], 0xFFFFFFFFu); |
| 698 | EXPECT_EQ(out[4][1], 0x00000000u); |
| 699 | EXPECT_EQ(out[4][2], 0x00000000u); |
| 700 | EXPECT_EQ(out[4][3], 0xFFFFFFFFu); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 701 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 702 | EXPECT_EQ(out[5][0], 0x00000000u); |
| 703 | EXPECT_EQ(out[5][1], 0xFFFFFFFFu); |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 707 | } |
| 708 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 709 | TEST(ReactorUnitTests, SaturatedAddAndSubtract) |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 710 | { |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 711 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 712 | FunctionT<int(void*)> function; |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 713 | { |
| 714 | Pointer<Byte> out = function.Arg<0>(); |
| 715 | |
| 716 | *Pointer<Byte8>(out + 8 * 0) = |
| 717 | AddSat(Byte8(1, 2, 3, 4, 5, 6, 7, 8), |
| 718 | Byte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 719 | *Pointer<Byte8>(out + 8 * 1) = |
| 720 | AddSat(Byte8(0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE), |
| 721 | Byte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 722 | *Pointer<Byte8>(out + 8 * 2) = |
| 723 | SubSat(Byte8(1, 2, 3, 4, 5, 6, 7, 8), |
| 724 | Byte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 725 | |
| 726 | *Pointer<SByte8>(out + 8 * 3) = |
| 727 | AddSat(SByte8(1, 2, 3, 4, 5, 6, 7, 8), |
| 728 | SByte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 729 | *Pointer<SByte8>(out + 8 * 4) = |
| 730 | AddSat(SByte8(0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E), |
| 731 | SByte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 732 | *Pointer<SByte8>(out + 8 * 5) = |
| 733 | AddSat(SByte8(0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88), |
| 734 | SByte8(-7, -6, -5, -4, -3, -2, -1, -0)); |
| 735 | *Pointer<SByte8>(out + 8 * 6) = |
| 736 | SubSat(SByte8(0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88), |
| 737 | SByte8(7, 6, 5, 4, 3, 2, 1, 0)); |
| 738 | |
| 739 | *Pointer<Short4>(out + 8 * 7) = |
| 740 | AddSat(Short4(1, 2, 3, 4), Short4(3, 2, 1, 0)); |
| 741 | *Pointer<Short4>(out + 8 * 8) = |
| 742 | AddSat(Short4(0x7FFE, 0x7FFE, 0x7FFE, 0x7FFE), |
| 743 | Short4(3, 2, 1, 0)); |
| 744 | *Pointer<Short4>(out + 8 * 9) = |
| 745 | AddSat(Short4(0x8001, 0x8002, 0x8003, 0x8004), |
| 746 | Short4(-3, -2, -1, -0)); |
| 747 | *Pointer<Short4>(out + 8 * 10) = |
| 748 | SubSat(Short4(0x8001, 0x8002, 0x8003, 0x8004), |
| 749 | Short4(3, 2, 1, 0)); |
| 750 | |
| 751 | *Pointer<UShort4>(out + 8 * 11) = |
| 752 | AddSat(UShort4(1, 2, 3, 4), UShort4(3, 2, 1, 0)); |
| 753 | *Pointer<UShort4>(out + 8 * 12) = |
| 754 | AddSat(UShort4(0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE), |
| 755 | UShort4(3, 2, 1, 0)); |
| 756 | *Pointer<UShort4>(out + 8 * 13) = |
| 757 | SubSat(UShort4(1, 2, 3, 4), UShort4(3, 2, 1, 0)); |
| 758 | |
| 759 | Return(0); |
| 760 | } |
| 761 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 762 | auto routine = function("one"); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 763 | |
| 764 | if(routine) |
| 765 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 766 | unsigned int out[14][2]; |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 767 | |
| 768 | memset(&out, 0, sizeof(out)); |
| 769 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 770 | routine(&out); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 771 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 772 | EXPECT_EQ(out[0][0], 0x08080808u); |
| 773 | EXPECT_EQ(out[0][1], 0x08080808u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 774 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 775 | EXPECT_EQ(out[1][0], 0xFFFFFFFFu); |
| 776 | EXPECT_EQ(out[1][1], 0xFEFFFFFFu); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 777 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 778 | EXPECT_EQ(out[2][0], 0x00000000u); |
| 779 | EXPECT_EQ(out[2][1], 0x08060402u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 780 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 781 | EXPECT_EQ(out[3][0], 0x08080808u); |
| 782 | EXPECT_EQ(out[3][1], 0x08080808u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 783 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 784 | EXPECT_EQ(out[4][0], 0x7F7F7F7Fu); |
| 785 | EXPECT_EQ(out[4][1], 0x7E7F7F7Fu); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 786 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 787 | EXPECT_EQ(out[5][0], 0x80808080u); |
| 788 | EXPECT_EQ(out[5][1], 0x88868482u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 789 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 790 | EXPECT_EQ(out[6][0], 0x80808080u); |
| 791 | EXPECT_EQ(out[6][1], 0x88868482u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 792 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 793 | EXPECT_EQ(out[7][0], 0x00040004u); |
| 794 | EXPECT_EQ(out[7][1], 0x00040004u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 795 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 796 | EXPECT_EQ(out[8][0], 0x7FFF7FFFu); |
| 797 | EXPECT_EQ(out[8][1], 0x7FFE7FFFu); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 798 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 799 | EXPECT_EQ(out[9][0], 0x80008000u); |
| 800 | EXPECT_EQ(out[9][1], 0x80048002u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 801 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 802 | EXPECT_EQ(out[10][0], 0x80008000u); |
| 803 | EXPECT_EQ(out[10][1], 0x80048002u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 804 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 805 | EXPECT_EQ(out[11][0], 0x00040004u); |
| 806 | EXPECT_EQ(out[11][1], 0x00040004u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 807 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 808 | EXPECT_EQ(out[12][0], 0xFFFFFFFFu); |
| 809 | EXPECT_EQ(out[12][1], 0xFFFEFFFFu); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 810 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 811 | EXPECT_EQ(out[13][0], 0x00000000u); |
| 812 | EXPECT_EQ(out[13][1], 0x00040002u); |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | |
Casey Dahlin | 642fc92 | 2017-09-28 17:18:41 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 818 | TEST(ReactorUnitTests, Unpack) |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 819 | { |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 820 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 821 | FunctionT<int(void*, void*)> function; |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 822 | { |
| 823 | Pointer<Byte> in = function.Arg<0>(); |
| 824 | Pointer<Byte> out = function.Arg<1>(); |
| 825 | |
| 826 | Byte4 test_byte_a = *Pointer<Byte4>(in + 4 * 0); |
| 827 | Byte4 test_byte_b = *Pointer<Byte4>(in + 4 * 1); |
| 828 | |
| 829 | *Pointer<Short4>(out + 8 * 0) = |
| 830 | Unpack(test_byte_a, test_byte_b); |
| 831 | |
| 832 | *Pointer<Short4>(out + 8 * 1) = Unpack(test_byte_a); |
| 833 | |
| 834 | Return(0); |
| 835 | } |
| 836 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 837 | auto routine = function("one"); |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 838 | |
| 839 | if(routine) |
| 840 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 841 | unsigned int in[1][2]; |
| 842 | unsigned int out[2][2]; |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 843 | |
| 844 | memset(&out, 0, sizeof(out)); |
| 845 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 846 | in[0][0] = 0xABCDEF12u; |
| 847 | in[0][1] = 0x34567890u; |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 848 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 849 | routine(&in, &out); |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 850 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 851 | EXPECT_EQ(out[0][0], 0x78EF9012u); |
| 852 | EXPECT_EQ(out[0][1], 0x34AB56CDu); |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 853 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 854 | EXPECT_EQ(out[1][0], 0xEFEF1212u); |
| 855 | EXPECT_EQ(out[1][1], 0xABABCDCDu); |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
Casey Dahlin | 4e759e4 | 2017-09-29 13:43:18 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 861 | TEST(ReactorUnitTests, Pack) |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 862 | { |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 863 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 864 | FunctionT<int(void*)> function; |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 865 | { |
| 866 | Pointer<Byte> out = function.Arg<0>(); |
| 867 | |
| 868 | *Pointer<SByte8>(out + 8 * 0) = |
| 869 | PackSigned(Short4(-1, -2, 1, 2), |
| 870 | Short4(3, 4, -3, -4)); |
| 871 | |
| 872 | *Pointer<Byte8>(out + 8 * 1) = |
| 873 | PackUnsigned(Short4(-1, -2, 1, 2), |
| 874 | Short4(3, 4, -3, -4)); |
| 875 | |
| 876 | *Pointer<Short8>(out + 8 * 2) = |
| 877 | PackSigned(Int4(-1, -2, 1, 2), |
| 878 | Int4(3, 4, -3, -4)); |
| 879 | |
| 880 | *Pointer<UShort8>(out + 8 * 4) = |
| 881 | PackUnsigned(Int4(-1, -2, 1, 2), |
| 882 | Int4(3, 4, -3, -4)); |
| 883 | |
| 884 | Return(0); |
| 885 | } |
| 886 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 887 | auto routine = function("one"); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 888 | |
| 889 | if(routine) |
| 890 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 891 | unsigned int out[6][2]; |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 892 | |
| 893 | memset(&out, 0, sizeof(out)); |
| 894 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 895 | routine(&out); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 896 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 897 | EXPECT_EQ(out[0][0], 0x0201FEFFu); |
| 898 | EXPECT_EQ(out[0][1], 0xFCFD0403u); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 899 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 900 | EXPECT_EQ(out[1][0], 0x02010000u); |
| 901 | EXPECT_EQ(out[1][1], 0x00000403u); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 902 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 903 | EXPECT_EQ(out[2][0], 0xFFFEFFFFu); |
| 904 | EXPECT_EQ(out[2][1], 0x00020001u); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 905 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 906 | EXPECT_EQ(out[3][0], 0x00040003u); |
| 907 | EXPECT_EQ(out[3][1], 0xFFFCFFFDu); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 908 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 909 | EXPECT_EQ(out[4][0], 0x00000000u); |
| 910 | EXPECT_EQ(out[4][1], 0x00020001u); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 911 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 912 | EXPECT_EQ(out[5][0], 0x00040003u); |
| 913 | EXPECT_EQ(out[5][1], 0x00000000u); |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
Casey Dahlin | 1165812 | 2017-09-29 16:32:32 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 919 | TEST(ReactorUnitTests, MulHigh) |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 920 | { |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 921 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 922 | FunctionT<int(void*)> function; |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 923 | { |
| 924 | Pointer<Byte> out = function.Arg<0>(); |
| 925 | |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame] | 926 | *Pointer<Short4>(out + 16 * 0) = |
| 927 | MulHigh(Short4(0x01AA, 0x02DD, 0x03EE, 0xF422), |
| 928 | Short4(0x01BB, 0x02CC, 0x03FF, 0xF411)); |
| 929 | *Pointer<UShort4>(out + 16 * 1) = |
| 930 | MulHigh(UShort4(0x01AA, 0x02DD, 0x03EE, 0xF422), |
| 931 | UShort4(0x01BB, 0x02CC, 0x03FF, 0xF411)); |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 932 | |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame] | 933 | *Pointer<Int4>(out + 16 * 2) = |
| 934 | MulHigh(Int4(0x000001AA, 0x000002DD, 0xC8000000, 0xF8000000), |
| 935 | Int4(0x000001BB, 0x84000000, 0x000003EE, 0xD7000000)); |
| 936 | *Pointer<UInt4>(out + 16 * 3) = |
| 937 | MulHigh(UInt4(0x000001AAu, 0x000002DDu, 0xC8000000u, 0xD8000000u), |
| 938 | UInt4(0x000001BBu, 0x84000000u, 0x000003EEu, 0xD7000000u)); |
| 939 | |
| 940 | *Pointer<Int4>(out + 16 * 4) = |
| 941 | MulHigh(Int4(0x7FFFFFFF, 0x7FFFFFFF, 0x80008000, 0xFFFFFFFF), |
| 942 | Int4(0x7FFFFFFF, 0x80000000, 0x80008000, 0xFFFFFFFF)); |
| 943 | *Pointer<UInt4>(out + 16 * 5) = |
| 944 | MulHigh(UInt4(0x7FFFFFFFu, 0x7FFFFFFFu, 0x80008000u, 0xFFFFFFFFu), |
| 945 | UInt4(0x7FFFFFFFu, 0x80000000u, 0x80008000u, 0xFFFFFFFFu)); |
| 946 | |
| 947 | // (U)Short8 variants currently unimplemented. |
| 948 | |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 949 | Return(0); |
| 950 | } |
| 951 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 952 | auto routine = function("one"); |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 953 | |
| 954 | if(routine) |
| 955 | { |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame] | 956 | unsigned int out[6][4]; |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 957 | |
| 958 | memset(&out, 0, sizeof(out)); |
| 959 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 960 | routine(&out); |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 961 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 962 | EXPECT_EQ(out[0][0], 0x00080002u); |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame] | 963 | EXPECT_EQ(out[0][1], 0x008D000Fu); |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 964 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 965 | EXPECT_EQ(out[1][0], 0x00080002u); |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame] | 966 | EXPECT_EQ(out[1][1], 0xE8C0000Fu); |
| 967 | |
| 968 | EXPECT_EQ(out[2][0], 0x00000000u); |
| 969 | EXPECT_EQ(out[2][1], 0xFFFFFE9Cu); |
| 970 | EXPECT_EQ(out[2][2], 0xFFFFFF23u); |
| 971 | EXPECT_EQ(out[2][3], 0x01480000u); |
| 972 | |
| 973 | EXPECT_EQ(out[3][0], 0x00000000u); |
| 974 | EXPECT_EQ(out[3][1], 0x00000179u); |
| 975 | EXPECT_EQ(out[3][2], 0x00000311u); |
| 976 | EXPECT_EQ(out[3][3], 0xB5680000u); |
| 977 | |
| 978 | EXPECT_EQ(out[4][0], 0x3FFFFFFFu); |
| 979 | EXPECT_EQ(out[4][1], 0xC0000000u); |
| 980 | EXPECT_EQ(out[4][2], 0x3FFF8000u); |
| 981 | EXPECT_EQ(out[4][3], 0x00000000u); |
| 982 | |
| 983 | EXPECT_EQ(out[5][0], 0x3FFFFFFFu); |
| 984 | EXPECT_EQ(out[5][1], 0x3FFFFFFFu); |
| 985 | EXPECT_EQ(out[5][2], 0x40008000u); |
| 986 | EXPECT_EQ(out[5][3], 0xFFFFFFFEu); |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
Casey Dahlin | 36fad3c | 2017-10-02 15:02:02 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 992 | TEST(ReactorUnitTests, MulAdd) |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 993 | { |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 994 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 995 | FunctionT<int(void*)> function; |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 996 | { |
| 997 | Pointer<Byte> out = function.Arg<0>(); |
| 998 | |
| 999 | *Pointer<Int2>(out + 8 * 0) = |
| 1000 | MulAdd(Short4(0x1aa, 0x2dd, 0x3ee, 0xF422), |
| 1001 | Short4(0x1bb, 0x2cc, 0x3ff, 0xF411)); |
| 1002 | |
| 1003 | // (U)Short8 variant is mentioned but unimplemented |
| 1004 | Return(0); |
| 1005 | } |
| 1006 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1007 | auto routine = function("one"); |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 1008 | |
| 1009 | if(routine) |
| 1010 | { |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 1011 | unsigned int out[1][2]; |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 1012 | |
| 1013 | memset(&out, 0, sizeof(out)); |
| 1014 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1015 | routine(&out); |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 1016 | |
Nicolas Capens | 92593eb | 2018-02-14 14:52:49 -0500 | [diff] [blame] | 1017 | EXPECT_EQ(out[0][0], 0x000AE34Au); |
| 1018 | EXPECT_EQ(out[0][1], 0x009D5254u); |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
Casey Dahlin | b098c54 | 2017-10-03 11:24:01 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Ben Clayton | 204a410 | 2019-07-31 13:17:47 +0100 | [diff] [blame] | 1024 | TEST(ReactorUnitTests, PointersEqual) |
| 1025 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1026 | FunctionT<int(void*, void*)> function; |
Ben Clayton | 204a410 | 2019-07-31 13:17:47 +0100 | [diff] [blame] | 1027 | { |
| 1028 | Pointer<Byte> ptrA = function.Arg<0>(); |
| 1029 | Pointer<Byte> ptrB = function.Arg<1>(); |
| 1030 | If (ptrA == ptrB) |
| 1031 | { |
| 1032 | Return(1); |
| 1033 | } |
| 1034 | Else |
| 1035 | { |
| 1036 | Return(0); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | auto routine = function("one"); |
Ben Clayton | 204a410 | 2019-07-31 13:17:47 +0100 | [diff] [blame] | 1041 | int* a = reinterpret_cast<int*>(uintptr_t(0x0000000000000000)); |
| 1042 | int* b = reinterpret_cast<int*>(uintptr_t(0x00000000F0000000)); |
| 1043 | int* c = reinterpret_cast<int*>(uintptr_t(0xF000000000000000)); |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1044 | EXPECT_EQ(routine(&a, &a), 1); |
| 1045 | EXPECT_EQ(routine(&b, &b), 1); |
| 1046 | EXPECT_EQ(routine(&c, &c), 1); |
Ben Clayton | 204a410 | 2019-07-31 13:17:47 +0100 | [diff] [blame] | 1047 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1048 | EXPECT_EQ(routine(&a, &b), 0); |
| 1049 | EXPECT_EQ(routine(&b, &a), 0); |
| 1050 | EXPECT_EQ(routine(&b, &c), 0); |
| 1051 | EXPECT_EQ(routine(&c, &b), 0); |
| 1052 | EXPECT_EQ(routine(&c, &a), 0); |
| 1053 | EXPECT_EQ(routine(&a, &c), 0); |
Ben Clayton | 204a410 | 2019-07-31 13:17:47 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1056 | TEST(ReactorUnitTests, Args_2Mixed) |
| 1057 | { |
| 1058 | // 2 mixed type args |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1059 | FunctionT<float(int, float)> function; |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1060 | { |
| 1061 | Int a = function.Arg<0>(); |
| 1062 | Float b = function.Arg<1>(); |
| 1063 | Return(Float(a) + b); |
| 1064 | } |
| 1065 | |
| 1066 | if (auto routine = function("one")) |
| 1067 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1068 | float result = routine(1, 2.f); |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1069 | EXPECT_EQ(result, 3.f); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | TEST(ReactorUnitTests, Args_4Mixed) |
| 1074 | { |
| 1075 | // 4 mixed type args (max register allocation on Windows) |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1076 | FunctionT<float(int, float, int, float)> function; |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1077 | { |
| 1078 | Int a = function.Arg<0>(); |
| 1079 | Float b = function.Arg<1>(); |
| 1080 | Int c = function.Arg<2>(); |
| 1081 | Float d = function.Arg<3>(); |
| 1082 | Return(Float(a) + b + Float(c) + d); |
| 1083 | } |
| 1084 | |
| 1085 | if (auto routine = function("one")) |
| 1086 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1087 | float result = routine(1, 2.f, 3, 4.f); |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1088 | EXPECT_EQ(result, 10.f); |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | TEST(ReactorUnitTests, Args_5Mixed) |
| 1093 | { |
| 1094 | // 5 mixed type args (5th spills over to stack on Windows) |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1095 | FunctionT<float(int, float, int, float, int)> function; |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1096 | { |
| 1097 | Int a = function.Arg<0>(); |
| 1098 | Float b = function.Arg<1>(); |
| 1099 | Int c = function.Arg<2>(); |
| 1100 | Float d = function.Arg<3>(); |
| 1101 | Int e = function.Arg<4>(); |
| 1102 | Return(Float(a) + b + Float(c) + d + Float(e)); |
| 1103 | } |
| 1104 | |
| 1105 | if (auto routine = function("one")) |
| 1106 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1107 | float result = routine(1, 2.f, 3, 4.f, 5); |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1108 | EXPECT_EQ(result, 15.f); |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | TEST(ReactorUnitTests, Args_GreaterThan5Mixed) |
| 1113 | { |
| 1114 | // >5 mixed type args |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1115 | FunctionT<float(int, float, int, float, int, float, int, float, int, float)> function; |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1116 | { |
| 1117 | Int a = function.Arg<0>(); |
| 1118 | Float b = function.Arg<1>(); |
| 1119 | Int c = function.Arg<2>(); |
| 1120 | Float d = function.Arg<3>(); |
| 1121 | Int e = function.Arg<4>(); |
| 1122 | Float f = function.Arg<5>(); |
| 1123 | Int g = function.Arg<6>(); |
| 1124 | Float h = function.Arg<7>(); |
| 1125 | Int i = function.Arg<8>(); |
| 1126 | Float j = function.Arg<9>(); |
| 1127 | Return(Float(a) + b + Float(c) + d + Float(e) + f + Float(g) + h + Float(i) + j); |
| 1128 | } |
| 1129 | |
| 1130 | if (auto routine = function("one")) |
| 1131 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1132 | float result = routine(1, 2.f, 3, 4.f, 5, 6.f, 7, 8.f, 9, 10.f); |
Antonio Maiorano | 29ba7a0 | 2019-10-11 15:23:56 -0400 | [diff] [blame] | 1133 | EXPECT_EQ(result, 55.f); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1137 | TEST(ReactorUnitTests, Call) |
| 1138 | { |
| 1139 | if (!rr::Caps.CallSupported) |
| 1140 | { |
| 1141 | SUCCEED() << "rr::Call() not supported"; |
| 1142 | return; |
| 1143 | } |
| 1144 | |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1145 | struct Class |
| 1146 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1147 | static int Callback(Class *p, int i, float f) |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1148 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1149 | p->i = i; |
| 1150 | p->f = f; |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1151 | return i + int(f); |
| 1152 | } |
| 1153 | |
| 1154 | int i = 0; |
| 1155 | float f = 0.0f; |
| 1156 | }; |
| 1157 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1158 | FunctionT<int(void*)> function; |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1159 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1160 | Pointer<Byte> c = function.Arg<0>(); |
| 1161 | auto res = Call(Class::Callback, c, 10, 20.0f); |
| 1162 | Return(res); |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1163 | } |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1164 | |
| 1165 | auto routine = function("one"); |
| 1166 | |
| 1167 | Class c; |
| 1168 | int res = routine(&c); |
| 1169 | EXPECT_EQ(res, 30); |
| 1170 | EXPECT_EQ(c.i, 10); |
| 1171 | EXPECT_EQ(c.f, 20.0f); |
| 1172 | } |
| 1173 | |
| 1174 | TEST(ReactorUnitTests, CallImplicitCast) |
| 1175 | { |
| 1176 | if (!rr::Caps.CallSupported) |
| 1177 | { |
| 1178 | SUCCEED() << "rr::Call() not supported"; |
| 1179 | return; |
| 1180 | } |
| 1181 | |
| 1182 | struct Class |
| 1183 | { |
| 1184 | static void Callback(Class *c, const char* s) |
| 1185 | { |
| 1186 | c->str = s; |
| 1187 | } |
| 1188 | std::string str; |
| 1189 | }; |
| 1190 | |
| 1191 | FunctionT<void(Class *c, const char *s)> function; |
| 1192 | { |
| 1193 | Pointer<Byte> c = function.Arg<0>(); |
| 1194 | Pointer<Byte> s = function.Arg<1>(); |
| 1195 | Call(Class::Callback, c, s); |
| 1196 | } |
| 1197 | |
| 1198 | auto routine = function("one"); |
| 1199 | |
| 1200 | Class c; |
| 1201 | routine(&c, "hello world"); |
| 1202 | EXPECT_EQ(c.str, "hello world"); |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1203 | } |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1204 | |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1205 | TEST(ReactorUnitTests, CallExternalCallRoutine) |
| 1206 | { |
| 1207 | if (!rr::Caps.CallSupported) |
| 1208 | { |
| 1209 | SUCCEED() << "rr::Call() not supported"; |
| 1210 | return; |
| 1211 | } |
| 1212 | |
| 1213 | // routine1 calls Class::Func, passing it a pointer to routine2, and Class::Func calls routine2 |
| 1214 | |
| 1215 | auto routine2 = [] { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1216 | FunctionT<float(float, int)> function; |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1217 | { |
| 1218 | Float a = function.Arg<0>(); |
| 1219 | Int b = function.Arg<1>(); |
| 1220 | Return(a + Float(b)); |
| 1221 | } |
| 1222 | return function("two"); |
| 1223 | }(); |
| 1224 | |
| 1225 | struct Class |
| 1226 | { |
| 1227 | static float Func(void* p, float a, int b) |
| 1228 | { |
| 1229 | auto funcToCall = reinterpret_cast<float(*)(float, int)>(p); |
| 1230 | return funcToCall(a, b); |
| 1231 | } |
| 1232 | }; |
| 1233 | |
| 1234 | auto routine1 = [] { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1235 | FunctionT<float(void*, float, int)> function; |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1236 | { |
| 1237 | Pointer<Byte> funcToCall = function.Arg<0>(); |
| 1238 | Float a = function.Arg<1>(); |
| 1239 | Int b = function.Arg<2>(); |
| 1240 | Float result = Call(Class::Func, funcToCall, a, b); |
| 1241 | Return(result); |
| 1242 | } |
| 1243 | return function("one"); |
| 1244 | }(); |
| 1245 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1246 | float result = routine1((void*)routine2.getEntry(), 12.f, 13); |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1247 | EXPECT_EQ(result, 25.f); |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1250 | // Check that a complex generated function which utilizes all 8 or 16 XMM |
| 1251 | // registers computes the correct result. |
| 1252 | // (Note that due to MSC's lack of support for inline assembly in x64, |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1253 | // this test does not actually check that the register contents are |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1254 | // preserved, just that the generated function computes the correct value. |
| 1255 | // It's necessary to inspect the registers in a debugger to actually verify.) |
| 1256 | TEST(ReactorUnitTests, PreserveXMMRegisters) |
| 1257 | { |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1258 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1259 | FunctionT<void(void*, void*)> function; |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1260 | { |
| 1261 | Pointer<Byte> in = function.Arg<0>(); |
| 1262 | Pointer<Byte> out = function.Arg<1>(); |
| 1263 | |
| 1264 | Float4 a = *Pointer<Float4>(in + 16 * 0); |
| 1265 | Float4 b = *Pointer<Float4>(in + 16 * 1); |
| 1266 | Float4 c = *Pointer<Float4>(in + 16 * 2); |
| 1267 | Float4 d = *Pointer<Float4>(in + 16 * 3); |
| 1268 | Float4 e = *Pointer<Float4>(in + 16 * 4); |
| 1269 | Float4 f = *Pointer<Float4>(in + 16 * 5); |
| 1270 | Float4 g = *Pointer<Float4>(in + 16 * 6); |
| 1271 | Float4 h = *Pointer<Float4>(in + 16 * 7); |
| 1272 | Float4 i = *Pointer<Float4>(in + 16 * 8); |
| 1273 | Float4 j = *Pointer<Float4>(in + 16 * 9); |
| 1274 | Float4 k = *Pointer<Float4>(in + 16 * 10); |
| 1275 | Float4 l = *Pointer<Float4>(in + 16 * 11); |
| 1276 | Float4 m = *Pointer<Float4>(in + 16 * 12); |
| 1277 | Float4 n = *Pointer<Float4>(in + 16 * 13); |
| 1278 | Float4 o = *Pointer<Float4>(in + 16 * 14); |
| 1279 | Float4 p = *Pointer<Float4>(in + 16 * 15); |
| 1280 | |
| 1281 | Float4 ab = a + b; |
| 1282 | Float4 cd = c + d; |
| 1283 | Float4 ef = e + f; |
| 1284 | Float4 gh = g + h; |
| 1285 | Float4 ij = i + j; |
| 1286 | Float4 kl = k + l; |
| 1287 | Float4 mn = m + n; |
| 1288 | Float4 op = o + p; |
| 1289 | |
| 1290 | Float4 abcd = ab + cd; |
| 1291 | Float4 efgh = ef + gh; |
| 1292 | Float4 ijkl = ij + kl; |
| 1293 | Float4 mnop = mn + op; |
| 1294 | |
| 1295 | Float4 abcdefgh = abcd + efgh; |
| 1296 | Float4 ijklmnop = ijkl + mnop; |
| 1297 | Float4 sum = abcdefgh + ijklmnop; |
| 1298 | *Pointer<Float4>(out) = sum; |
| 1299 | Return(); |
| 1300 | } |
| 1301 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1302 | auto routine = function("one"); |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1303 | assert(routine); |
| 1304 | |
| 1305 | float input[64] = { 1.0f, 0.0f, 0.0f, 0.0f, |
| 1306 | -1.0f, 1.0f, -1.0f, 0.0f, |
| 1307 | 1.0f, 2.0f, -2.0f, 0.0f, |
| 1308 | -1.0f, 3.0f, -3.0f, 0.0f, |
| 1309 | 1.0f, 4.0f, -4.0f, 0.0f, |
| 1310 | -1.0f, 5.0f, -5.0f, 0.0f, |
| 1311 | 1.0f, 6.0f, -6.0f, 0.0f, |
| 1312 | -1.0f, 7.0f, -7.0f, 0.0f, |
| 1313 | 1.0f, 8.0f, -8.0f, 0.0f, |
| 1314 | -1.0f, 9.0f, -9.0f, 0.0f, |
| 1315 | 1.0f, 10.0f, -10.0f, 0.0f, |
| 1316 | -1.0f, 11.0f, -11.0f, 0.0f, |
| 1317 | 1.0f, 12.0f, -12.0f, 0.0f, |
| 1318 | -1.0f, 13.0f, -13.0f, 0.0f, |
| 1319 | 1.0f, 14.0f, -14.0f, 0.0f, |
| 1320 | -1.0f, 15.0f, -15.0f, 0.0f }; |
| 1321 | |
| 1322 | float result[4]; |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1323 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1324 | routine(input, result); |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1325 | |
| 1326 | EXPECT_EQ(result[0], 0.0f); |
| 1327 | EXPECT_EQ(result[1], 120.0f); |
| 1328 | EXPECT_EQ(result[2], -120.0f); |
| 1329 | EXPECT_EQ(result[3], 0.0f); |
| 1330 | } |
| 1331 | |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1334 | template <typename T> |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1335 | class CToReactorTCastTest : public ::testing::Test |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1336 | { |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1337 | public: |
| 1338 | using CType = typename std::tuple_element<0, T>::type; |
| 1339 | using ReactorType = typename std::tuple_element<1, T>::type; |
| 1340 | }; |
| 1341 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1342 | using CToReactorTCastTestTypes = ::testing::Types |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1343 | < // Subset of types that can be used as arguments. |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1344 | // std::pair<bool, Bool>, FIXME(capn): Not supported as argument type by Subzero. |
| 1345 | // std::pair<uint8_t, Byte>, FIXME(capn): Not supported as argument type by Subzero. |
| 1346 | // std::pair<int8_t, SByte>, FIXME(capn): Not supported as argument type by Subzero. |
| 1347 | // std::pair<int16_t, Short>, FIXME(capn): Not supported as argument type by Subzero. |
| 1348 | // std::pair<uint16_t, UShort>, FIXME(capn): Not supported as argument type by Subzero. |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1349 | std::pair<int, Int>, |
| 1350 | std::pair<unsigned int, UInt>, |
| 1351 | std::pair<float, Float> |
| 1352 | >; |
| 1353 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1354 | TYPED_TEST_SUITE(CToReactorTCastTest, CToReactorTCastTestTypes); |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1355 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1356 | TYPED_TEST(CToReactorTCastTest, Casts) |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1357 | { |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1358 | using CType = typename TestFixture::CType; |
| 1359 | using ReactorType = typename TestFixture::ReactorType; |
| 1360 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 1361 | std::shared_ptr<Routine> routine; |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1362 | |
| 1363 | { |
| 1364 | Function< Int(ReactorType) > function; |
| 1365 | { |
| 1366 | ReactorType a = function.template Arg<0>(); |
| 1367 | ReactorType b = CType{}; |
| 1368 | RValue<ReactorType> c = RValue<ReactorType>(CType{}); |
| 1369 | Bool same = (a == b) && (a == c); |
| 1370 | Return(IfThenElse(same, Int(1), Int(0))); // TODO: Ability to use Bools as return values. |
| 1371 | } |
| 1372 | |
| 1373 | routine = function("one"); |
| 1374 | |
| 1375 | if(routine) |
| 1376 | { |
| 1377 | auto callable = (int(*)(CType))routine->getEntry(); |
| 1378 | CType in = {}; |
| 1379 | EXPECT_EQ(callable(in), 1); |
| 1380 | } |
| 1381 | } |
| 1382 | |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | template <typename T> |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1386 | class GEPTest : public ::testing::Test |
| 1387 | { |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1388 | public: |
| 1389 | using CType = typename std::tuple_element<0, T>::type; |
| 1390 | using ReactorType = typename std::tuple_element<1, T>::type; |
| 1391 | }; |
| 1392 | |
| 1393 | using GEPTestTypes = ::testing::Types |
| 1394 | < |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1395 | std::pair<bool, Bool>, |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1396 | std::pair<int8_t, Byte>, |
| 1397 | std::pair<int8_t, SByte>, |
| 1398 | std::pair<int8_t[4], Byte4>, |
| 1399 | std::pair<int8_t[4], SByte4>, |
| 1400 | std::pair<int8_t[8], Byte8>, |
| 1401 | std::pair<int8_t[8], SByte8>, |
| 1402 | std::pair<int8_t[16], Byte16>, |
| 1403 | std::pair<int8_t[16], SByte16>, |
| 1404 | std::pair<int16_t, Short>, |
| 1405 | std::pair<int16_t, UShort>, |
| 1406 | std::pair<int16_t[2], Short2>, |
| 1407 | std::pair<int16_t[2], UShort2>, |
| 1408 | std::pair<int16_t[4], Short4>, |
| 1409 | std::pair<int16_t[4], UShort4>, |
| 1410 | std::pair<int16_t[8], Short8>, |
| 1411 | std::pair<int16_t[8], UShort8>, |
| 1412 | std::pair<int, Int>, |
| 1413 | std::pair<int, UInt>, |
| 1414 | std::pair<int[2], Int2>, |
| 1415 | std::pair<int[2], UInt2>, |
| 1416 | std::pair<int[4], Int4>, |
| 1417 | std::pair<int[4], UInt4>, |
| 1418 | std::pair<int64_t, Long>, |
| 1419 | std::pair<int16_t, Half>, |
| 1420 | std::pair<float, Float>, |
| 1421 | std::pair<float[2], Float2>, |
| 1422 | std::pair<float[4], Float4> |
| 1423 | >; |
| 1424 | |
Alexis Hetu | 79d4ac9 | 2019-06-03 11:31:46 -0400 | [diff] [blame] | 1425 | TYPED_TEST_SUITE(GEPTest, GEPTestTypes); |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1426 | |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1427 | TYPED_TEST(GEPTest, PtrOffsets) |
| 1428 | { |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1429 | using CType = typename TestFixture::CType; |
| 1430 | using ReactorType = typename TestFixture::ReactorType; |
| 1431 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 1432 | std::shared_ptr<Routine> routine; |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1433 | |
| 1434 | { |
| 1435 | Function< Pointer<ReactorType>(Pointer<ReactorType>, Int) > function; |
| 1436 | { |
| 1437 | Pointer<ReactorType> pointer = function.template Arg<0>(); |
| 1438 | Int index = function.template Arg<1>(); |
| 1439 | Return(&pointer[index]); |
| 1440 | } |
| 1441 | |
| 1442 | routine = function("one"); |
| 1443 | |
| 1444 | if(routine) |
| 1445 | { |
| 1446 | auto callable = (CType*(*)(CType*, unsigned int))routine->getEntry(); |
| 1447 | |
| 1448 | union PtrInt { |
| 1449 | CType* p; |
| 1450 | size_t i; |
| 1451 | }; |
| 1452 | |
| 1453 | PtrInt base; |
| 1454 | base.i = 0x10000; |
| 1455 | |
| 1456 | for (int i = 0; i < 5; i++) |
| 1457 | { |
| 1458 | PtrInt reference; |
| 1459 | reference.p = &base.p[i]; |
| 1460 | |
| 1461 | PtrInt result; |
| 1462 | result.p = callable(base.p, i); |
| 1463 | |
| 1464 | auto expect = reference.i - base.i; |
| 1465 | auto got = result.i - base.i; |
| 1466 | |
| 1467 | EXPECT_EQ(got, expect) << "i:" << i; |
| 1468 | } |
| 1469 | } |
| 1470 | } |
| 1471 | |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Ben Clayton | 1c82c7b | 2019-04-30 12:49:27 +0100 | [diff] [blame] | 1474 | TEST(ReactorUnitTests, Coroutines_Fibonacci) |
| 1475 | { |
| 1476 | if (!rr::Caps.CoroutinesSupported) |
| 1477 | { |
| 1478 | SUCCEED() << "Coroutines not supported"; |
| 1479 | return; |
| 1480 | } |
| 1481 | |
| 1482 | Coroutine<int()> function; |
| 1483 | { |
| 1484 | Yield(Int(0)); |
| 1485 | Yield(Int(1)); |
| 1486 | Int current = 1; |
| 1487 | Int next = 1; |
| 1488 | While (true) { |
| 1489 | Yield(next); |
| 1490 | auto tmp = current + next; |
| 1491 | current = next; |
| 1492 | next = tmp; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | auto coroutine = function(); |
| 1497 | |
| 1498 | int32_t expected[] = |
| 1499 | { |
| 1500 | 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, |
| 1501 | 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, |
| 1502 | 317811, |
| 1503 | }; |
| 1504 | |
| 1505 | auto count = sizeof(expected) / sizeof(expected[0]); |
| 1506 | |
| 1507 | for (size_t i = 0; i < count; i++) |
| 1508 | { |
| 1509 | int out = 0; |
| 1510 | EXPECT_EQ(coroutine->await(out), true); |
| 1511 | EXPECT_EQ(out, expected[i]); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | TEST(ReactorUnitTests, Coroutines_Parameters) |
| 1516 | { |
| 1517 | if (!rr::Caps.CoroutinesSupported) |
| 1518 | { |
| 1519 | SUCCEED() << "Coroutines not supported"; |
| 1520 | return; |
| 1521 | } |
| 1522 | |
| 1523 | Coroutine<uint8_t(uint8_t* data, int count)> function; |
| 1524 | { |
| 1525 | Pointer<Byte> data = function.Arg<0>(); |
| 1526 | Int count = function.Arg<1>(); |
| 1527 | |
| 1528 | For(Int i = 0, i < count, i++) |
| 1529 | { |
| 1530 | Yield(data[i]); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | uint8_t data[] = {10, 20, 30}; |
| 1535 | auto coroutine = function(&data[0], 3); |
| 1536 | |
| 1537 | uint8_t out = 0; |
| 1538 | EXPECT_EQ(coroutine->await(out), true); |
| 1539 | EXPECT_EQ(out, 10); out = 0; |
| 1540 | EXPECT_EQ(coroutine->await(out), true); |
| 1541 | EXPECT_EQ(out, 20); out = 0; |
| 1542 | EXPECT_EQ(coroutine->await(out), true); |
| 1543 | EXPECT_EQ(out, 30); out = 99; |
| 1544 | EXPECT_EQ(coroutine->await(out), false); |
| 1545 | EXPECT_EQ(out, 99); |
| 1546 | EXPECT_EQ(coroutine->await(out), false); |
| 1547 | EXPECT_EQ(out, 99); |
| 1548 | } |
| 1549 | |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 1550 | int main(int argc, char **argv) |
| 1551 | { |
| 1552 | ::testing::InitGoogleTest(&argc, argv); |
| 1553 | return RUN_ALL_TESTS(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1554 | } |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1555 | |
| 1556 | //////////////////////////////// |
| 1557 | // Trait compile time checks. // |
| 1558 | //////////////////////////////// |
| 1559 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1560 | // Assert CToReactorT resolves to expected types. |
| 1561 | static_assert(std::is_same<CToReactorT<void>, Void>::value, ""); |
| 1562 | static_assert(std::is_same<CToReactorT<bool>, Bool>::value, ""); |
| 1563 | static_assert(std::is_same<CToReactorT<uint8_t>, Byte>::value, ""); |
| 1564 | static_assert(std::is_same<CToReactorT<int8_t>, SByte>::value, ""); |
| 1565 | static_assert(std::is_same<CToReactorT<int16_t>, Short>::value, ""); |
| 1566 | static_assert(std::is_same<CToReactorT<uint16_t>, UShort>::value, ""); |
| 1567 | static_assert(std::is_same<CToReactorT<int32_t>, Int>::value, ""); |
| 1568 | static_assert(std::is_same<CToReactorT<uint64_t>, Long>::value, ""); |
| 1569 | static_assert(std::is_same<CToReactorT<uint32_t>, UInt>::value, ""); |
| 1570 | static_assert(std::is_same<CToReactorT<float>, Float>::value, ""); |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1571 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1572 | // Assert CToReactorT for known pointer types resolves to expected types. |
| 1573 | static_assert(std::is_same<CToReactorT<void*>, Pointer<Byte>>::value, ""); |
| 1574 | static_assert(std::is_same<CToReactorT<bool*>, Pointer<Bool>>::value, ""); |
| 1575 | static_assert(std::is_same<CToReactorT<uint8_t*>, Pointer<Byte>>::value, ""); |
| 1576 | static_assert(std::is_same<CToReactorT<int8_t*>, Pointer<SByte>>::value, ""); |
| 1577 | static_assert(std::is_same<CToReactorT<int16_t*>, Pointer<Short>>::value, ""); |
| 1578 | static_assert(std::is_same<CToReactorT<uint16_t*>, Pointer<UShort>>::value, ""); |
| 1579 | static_assert(std::is_same<CToReactorT<int32_t*>, Pointer<Int>>::value, ""); |
| 1580 | static_assert(std::is_same<CToReactorT<uint64_t*>, Pointer<Long>>::value, ""); |
| 1581 | static_assert(std::is_same<CToReactorT<uint32_t*>, Pointer<UInt>>::value, ""); |
| 1582 | static_assert(std::is_same<CToReactorT<float*>, Pointer<Float>>::value, ""); |
| 1583 | static_assert(std::is_same<CToReactorT<uint16_t**>, Pointer<Pointer<UShort>>>::value, ""); |
| 1584 | static_assert(std::is_same<CToReactorT<uint16_t***>, Pointer<Pointer<Pointer<UShort>>>>::value, ""); |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1585 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1586 | // Assert CToReactorT for unknown pointer types resolves to Pointer<Byte>. |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1587 | struct S{}; |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame^] | 1588 | static_assert(std::is_same<CToReactorT<S*>, Pointer<Byte>>::value, ""); |
| 1589 | static_assert(std::is_same<CToReactorT<S**>, Pointer<Pointer<Byte>>>::value, ""); |
| 1590 | static_assert(std::is_same<CToReactorT<S***>, Pointer<Pointer<Pointer<Byte>>>>::value, ""); |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1591 | |
| 1592 | // Assert IsRValue<> resolves true for RValue<> types. |
| 1593 | static_assert(IsRValue<RValue<Void>>::value, ""); |
| 1594 | static_assert(IsRValue<RValue<Bool>>::value, ""); |
| 1595 | static_assert(IsRValue<RValue<Byte>>::value, ""); |
| 1596 | static_assert(IsRValue<RValue<SByte>>::value, ""); |
| 1597 | static_assert(IsRValue<RValue<Short>>::value, ""); |
| 1598 | static_assert(IsRValue<RValue<UShort>>::value, ""); |
| 1599 | static_assert(IsRValue<RValue<Int>>::value, ""); |
| 1600 | static_assert(IsRValue<RValue<Long>>::value, ""); |
| 1601 | static_assert(IsRValue<RValue<UInt>>::value, ""); |
| 1602 | static_assert(IsRValue<RValue<Float>>::value, ""); |
| 1603 | |
| 1604 | // Assert IsLValue<> resolves true for LValue types. |
| 1605 | static_assert(IsLValue<Bool>::value, ""); |
| 1606 | static_assert(IsLValue<Byte>::value, ""); |
| 1607 | static_assert(IsLValue<SByte>::value, ""); |
| 1608 | static_assert(IsLValue<Short>::value, ""); |
| 1609 | static_assert(IsLValue<UShort>::value, ""); |
| 1610 | static_assert(IsLValue<Int>::value, ""); |
| 1611 | static_assert(IsLValue<Long>::value, ""); |
| 1612 | static_assert(IsLValue<UInt>::value, ""); |
| 1613 | static_assert(IsLValue<Float>::value, ""); |
| 1614 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1615 | // Assert IsReference<> resolves true for Reference types. |
| 1616 | static_assert(IsReference<Reference<Bool>>::value, ""); |
| 1617 | static_assert(IsReference<Reference<Byte>>::value, ""); |
| 1618 | static_assert(IsReference<Reference<SByte>>::value, ""); |
| 1619 | static_assert(IsReference<Reference<Short>>::value, ""); |
| 1620 | static_assert(IsReference<Reference<UShort>>::value, ""); |
| 1621 | static_assert(IsReference<Reference<Int>>::value, ""); |
| 1622 | static_assert(IsReference<Reference<Long>>::value, ""); |
| 1623 | static_assert(IsReference<Reference<UInt>>::value, ""); |
| 1624 | static_assert(IsReference<Reference<Float>>::value, ""); |
| 1625 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1626 | // Assert IsRValue<> resolves false for LValue types. |
| 1627 | static_assert(!IsRValue<Void>::value, ""); |
| 1628 | static_assert(!IsRValue<Bool>::value, ""); |
| 1629 | static_assert(!IsRValue<Byte>::value, ""); |
| 1630 | static_assert(!IsRValue<SByte>::value, ""); |
| 1631 | static_assert(!IsRValue<Short>::value, ""); |
| 1632 | static_assert(!IsRValue<UShort>::value, ""); |
| 1633 | static_assert(!IsRValue<Int>::value, ""); |
| 1634 | static_assert(!IsRValue<Long>::value, ""); |
| 1635 | static_assert(!IsRValue<UInt>::value, ""); |
| 1636 | static_assert(!IsRValue<Float>::value, ""); |
| 1637 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1638 | // Assert IsRValue<> resolves false for Reference types. |
| 1639 | static_assert(!IsRValue<Reference<Void>>::value, ""); |
| 1640 | static_assert(!IsRValue<Reference<Bool>>::value, ""); |
| 1641 | static_assert(!IsRValue<Reference<Byte>>::value, ""); |
| 1642 | static_assert(!IsRValue<Reference<SByte>>::value, ""); |
| 1643 | static_assert(!IsRValue<Reference<Short>>::value, ""); |
| 1644 | static_assert(!IsRValue<Reference<UShort>>::value, ""); |
| 1645 | static_assert(!IsRValue<Reference<Int>>::value, ""); |
| 1646 | static_assert(!IsRValue<Reference<Long>>::value, ""); |
| 1647 | static_assert(!IsRValue<Reference<UInt>>::value, ""); |
| 1648 | static_assert(!IsRValue<Reference<Float>>::value, ""); |
| 1649 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1650 | // Assert IsRValue<> resolves false for C types. |
| 1651 | static_assert(!IsRValue<void>::value, ""); |
| 1652 | static_assert(!IsRValue<bool>::value, ""); |
| 1653 | static_assert(!IsRValue<uint8_t>::value, ""); |
| 1654 | static_assert(!IsRValue<int8_t>::value, ""); |
| 1655 | static_assert(!IsRValue<int16_t>::value, ""); |
| 1656 | static_assert(!IsRValue<uint16_t>::value, ""); |
| 1657 | static_assert(!IsRValue<int32_t>::value, ""); |
| 1658 | static_assert(!IsRValue<uint64_t>::value, ""); |
| 1659 | static_assert(!IsRValue<uint32_t>::value, ""); |
| 1660 | static_assert(!IsRValue<float>::value, ""); |
| 1661 | |
| 1662 | // Assert IsLValue<> resolves false for RValue<> types. |
| 1663 | static_assert(!IsLValue<RValue<Void>>::value, ""); |
| 1664 | static_assert(!IsLValue<RValue<Bool>>::value, ""); |
| 1665 | static_assert(!IsLValue<RValue<Byte>>::value, ""); |
| 1666 | static_assert(!IsLValue<RValue<SByte>>::value, ""); |
| 1667 | static_assert(!IsLValue<RValue<Short>>::value, ""); |
| 1668 | static_assert(!IsLValue<RValue<UShort>>::value, ""); |
| 1669 | static_assert(!IsLValue<RValue<Int>>::value, ""); |
| 1670 | static_assert(!IsLValue<RValue<Long>>::value, ""); |
| 1671 | static_assert(!IsLValue<RValue<UInt>>::value, ""); |
| 1672 | static_assert(!IsLValue<RValue<Float>>::value, ""); |
| 1673 | |
| 1674 | // Assert IsLValue<> resolves false for Void type. |
| 1675 | static_assert(!IsLValue<Void>::value, ""); |
| 1676 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1677 | // Assert IsLValue<> resolves false for Reference<> types. |
| 1678 | static_assert(!IsLValue<Reference<Void>>::value, ""); |
| 1679 | static_assert(!IsLValue<Reference<Bool>>::value, ""); |
| 1680 | static_assert(!IsLValue<Reference<Byte>>::value, ""); |
| 1681 | static_assert(!IsLValue<Reference<SByte>>::value, ""); |
| 1682 | static_assert(!IsLValue<Reference<Short>>::value, ""); |
| 1683 | static_assert(!IsLValue<Reference<UShort>>::value, ""); |
| 1684 | static_assert(!IsLValue<Reference<Int>>::value, ""); |
| 1685 | static_assert(!IsLValue<Reference<Long>>::value, ""); |
| 1686 | static_assert(!IsLValue<Reference<UInt>>::value, ""); |
| 1687 | static_assert(!IsLValue<Reference<Float>>::value, ""); |
| 1688 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1689 | // Assert IsLValue<> resolves false for C types. |
| 1690 | static_assert(!IsLValue<void>::value, ""); |
| 1691 | static_assert(!IsLValue<bool>::value, ""); |
| 1692 | static_assert(!IsLValue<uint8_t>::value, ""); |
| 1693 | static_assert(!IsLValue<int8_t>::value, ""); |
| 1694 | static_assert(!IsLValue<int16_t>::value, ""); |
| 1695 | static_assert(!IsLValue<uint16_t>::value, ""); |
| 1696 | static_assert(!IsLValue<int32_t>::value, ""); |
| 1697 | static_assert(!IsLValue<uint64_t>::value, ""); |
| 1698 | static_assert(!IsLValue<uint32_t>::value, ""); |
| 1699 | static_assert(!IsLValue<float>::value, ""); |
| 1700 | |
| 1701 | // Assert IsDefined<> resolves true for RValue<> types. |
| 1702 | static_assert(IsDefined<RValue<Void>>::value, ""); |
| 1703 | static_assert(IsDefined<RValue<Bool>>::value, ""); |
| 1704 | static_assert(IsDefined<RValue<Byte>>::value, ""); |
| 1705 | static_assert(IsDefined<RValue<SByte>>::value, ""); |
| 1706 | static_assert(IsDefined<RValue<Short>>::value, ""); |
| 1707 | static_assert(IsDefined<RValue<UShort>>::value, ""); |
| 1708 | static_assert(IsDefined<RValue<Int>>::value, ""); |
| 1709 | static_assert(IsDefined<RValue<Long>>::value, ""); |
| 1710 | static_assert(IsDefined<RValue<UInt>>::value, ""); |
| 1711 | static_assert(IsDefined<RValue<Float>>::value, ""); |
| 1712 | |
| 1713 | // Assert IsDefined<> resolves true for LValue types. |
| 1714 | static_assert(IsDefined<Void>::value, ""); |
| 1715 | static_assert(IsDefined<Bool>::value, ""); |
| 1716 | static_assert(IsDefined<Byte>::value, ""); |
| 1717 | static_assert(IsDefined<SByte>::value, ""); |
| 1718 | static_assert(IsDefined<Short>::value, ""); |
| 1719 | static_assert(IsDefined<UShort>::value, ""); |
| 1720 | static_assert(IsDefined<Int>::value, ""); |
| 1721 | static_assert(IsDefined<Long>::value, ""); |
| 1722 | static_assert(IsDefined<UInt>::value, ""); |
| 1723 | static_assert(IsDefined<Float>::value, ""); |
| 1724 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1725 | // Assert IsDefined<> resolves true for Reference<> types. |
| 1726 | static_assert(IsDefined<Reference<Bool>>::value, ""); |
| 1727 | static_assert(IsDefined<Reference<Byte>>::value, ""); |
| 1728 | static_assert(IsDefined<Reference<SByte>>::value, ""); |
| 1729 | static_assert(IsDefined<Reference<Short>>::value, ""); |
| 1730 | static_assert(IsDefined<Reference<UShort>>::value, ""); |
| 1731 | static_assert(IsDefined<Reference<Int>>::value, ""); |
| 1732 | static_assert(IsDefined<Reference<Long>>::value, ""); |
| 1733 | static_assert(IsDefined<Reference<UInt>>::value, ""); |
| 1734 | static_assert(IsDefined<Reference<Float>>::value, ""); |
| 1735 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1736 | // Assert IsDefined<> resolves true for C types. |
| 1737 | static_assert(IsDefined<void>::value, ""); |
| 1738 | static_assert(IsDefined<bool>::value, ""); |
| 1739 | static_assert(IsDefined<uint8_t>::value, ""); |
| 1740 | static_assert(IsDefined<int8_t>::value, ""); |
| 1741 | static_assert(IsDefined<int16_t>::value, ""); |
| 1742 | static_assert(IsDefined<uint16_t>::value, ""); |
| 1743 | static_assert(IsDefined<int32_t>::value, ""); |
| 1744 | static_assert(IsDefined<uint64_t>::value, ""); |
| 1745 | static_assert(IsDefined<uint32_t>::value, ""); |
| 1746 | static_assert(IsDefined<float>::value, ""); |