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 | { |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1139 | struct Class |
| 1140 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1141 | static int Callback(Class *p, int i, float f) |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1142 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1143 | p->i = i; |
| 1144 | p->f = f; |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1145 | return i + int(f); |
| 1146 | } |
| 1147 | |
| 1148 | int i = 0; |
| 1149 | float f = 0.0f; |
| 1150 | }; |
| 1151 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1152 | FunctionT<int(void*)> function; |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1153 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1154 | Pointer<Byte> c = function.Arg<0>(); |
| 1155 | auto res = Call(Class::Callback, c, 10, 20.0f); |
| 1156 | Return(res); |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1157 | } |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1158 | |
| 1159 | auto routine = function("one"); |
| 1160 | |
| 1161 | Class c; |
| 1162 | int res = routine(&c); |
| 1163 | EXPECT_EQ(res, 30); |
| 1164 | EXPECT_EQ(c.i, 10); |
| 1165 | EXPECT_EQ(c.f, 20.0f); |
| 1166 | } |
| 1167 | |
Ben Clayton | b7eb3a8 | 2019-11-19 00:43:50 +0000 | [diff] [blame] | 1168 | TEST(ReactorUnitTests, CallMemberFunction) |
| 1169 | { |
Ben Clayton | b7eb3a8 | 2019-11-19 00:43:50 +0000 | [diff] [blame] | 1170 | struct Class |
| 1171 | { |
| 1172 | int Callback(int argI, float argF) |
| 1173 | { |
| 1174 | i = argI; |
| 1175 | f = argF; |
| 1176 | return i + int(f); |
| 1177 | } |
| 1178 | |
| 1179 | int i = 0; |
| 1180 | float f = 0.0f; |
| 1181 | }; |
| 1182 | |
| 1183 | Class c; |
| 1184 | |
| 1185 | FunctionT<int()> function; |
| 1186 | { |
| 1187 | auto res = Call(&Class::Callback, &c, 10, 20.0f); |
| 1188 | Return(res); |
| 1189 | } |
| 1190 | |
| 1191 | auto routine = function("one"); |
| 1192 | |
| 1193 | int res = routine(); |
| 1194 | EXPECT_EQ(res, 30); |
| 1195 | EXPECT_EQ(c.i, 10); |
| 1196 | EXPECT_EQ(c.f, 20.0f); |
| 1197 | } |
| 1198 | |
| 1199 | TEST(ReactorUnitTests, CallMemberFunctionIndirect) |
| 1200 | { |
Ben Clayton | b7eb3a8 | 2019-11-19 00:43:50 +0000 | [diff] [blame] | 1201 | struct Class |
| 1202 | { |
| 1203 | int Callback(int argI, float argF) |
| 1204 | { |
| 1205 | i = argI; |
| 1206 | f = argF; |
| 1207 | return i + int(f); |
| 1208 | } |
| 1209 | |
| 1210 | int i = 0; |
| 1211 | float f = 0.0f; |
| 1212 | }; |
| 1213 | |
| 1214 | FunctionT<int(void*)> function; |
| 1215 | { |
| 1216 | Pointer<Byte> c = function.Arg<0>(); |
| 1217 | auto res = Call(&Class::Callback, c, 10, 20.0f); |
| 1218 | Return(res); |
| 1219 | } |
| 1220 | |
| 1221 | auto routine = function("one"); |
| 1222 | |
| 1223 | Class c; |
| 1224 | int res = routine(&c); |
| 1225 | EXPECT_EQ(res, 30); |
| 1226 | EXPECT_EQ(c.i, 10); |
| 1227 | EXPECT_EQ(c.f, 20.0f); |
| 1228 | } |
| 1229 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1230 | TEST(ReactorUnitTests, CallImplicitCast) |
| 1231 | { |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1232 | struct Class |
| 1233 | { |
| 1234 | static void Callback(Class *c, const char* s) |
| 1235 | { |
| 1236 | c->str = s; |
| 1237 | } |
| 1238 | std::string str; |
| 1239 | }; |
| 1240 | |
| 1241 | FunctionT<void(Class *c, const char *s)> function; |
| 1242 | { |
| 1243 | Pointer<Byte> c = function.Arg<0>(); |
| 1244 | Pointer<Byte> s = function.Arg<1>(); |
| 1245 | Call(Class::Callback, c, s); |
| 1246 | } |
| 1247 | |
| 1248 | auto routine = function("one"); |
| 1249 | |
| 1250 | Class c; |
| 1251 | routine(&c, "hello world"); |
| 1252 | EXPECT_EQ(c.str, "hello world"); |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1253 | } |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1254 | |
Antonio Maiorano | 01386d1 | 2019-11-20 14:43:48 -0500 | [diff] [blame] | 1255 | TEST(ReactorUnitTests, Call_Args4) |
| 1256 | { |
| 1257 | struct Class |
| 1258 | { |
| 1259 | static int Func(int a, int b, int c, int d) |
| 1260 | { |
| 1261 | return a + b + c + d; |
| 1262 | } |
| 1263 | }; |
| 1264 | |
| 1265 | { |
| 1266 | FunctionT<int()> function; |
| 1267 | { |
| 1268 | auto res = Call(Class::Func, 1, 2, 3, 4); |
| 1269 | Return(res); |
| 1270 | } |
| 1271 | |
| 1272 | auto routine = function("one"); |
| 1273 | |
| 1274 | if(routine) |
| 1275 | { |
| 1276 | int res = routine(); |
| 1277 | EXPECT_EQ(res, 1 + 2 + 3 + 4); |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | TEST(ReactorUnitTests, Call_Args5) |
| 1283 | { |
| 1284 | struct Class |
| 1285 | { |
| 1286 | static int Func(int a, int b, int c, int d, int e) |
| 1287 | { |
| 1288 | return a + b + c + d + e; |
| 1289 | } |
| 1290 | }; |
| 1291 | |
| 1292 | { |
| 1293 | FunctionT<int()> function; |
| 1294 | { |
| 1295 | auto res = Call(Class::Func, 1, 2, 3, 4, 5); |
| 1296 | Return(res); |
| 1297 | } |
| 1298 | |
| 1299 | auto routine = function("one"); |
| 1300 | |
| 1301 | if(routine) |
| 1302 | { |
| 1303 | int res = routine(); |
| 1304 | EXPECT_EQ(res, 1 + 2 + 3 + 4 + 5); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | TEST(ReactorUnitTests, Call_ArgsMany) |
| 1310 | { |
| 1311 | struct Class |
| 1312 | { |
| 1313 | static int Func(int a, int b, int c, int d, int e, int f, int g, int h) |
| 1314 | { |
| 1315 | return a + b + c + d + e + f + g + h; |
| 1316 | } |
| 1317 | }; |
| 1318 | |
| 1319 | { |
| 1320 | FunctionT<int()> function; |
| 1321 | { |
| 1322 | auto res = Call(Class::Func, 1, 2, 3, 4, 5, 6, 7, 8); |
| 1323 | Return(res); |
| 1324 | } |
| 1325 | |
| 1326 | auto routine = function("one"); |
| 1327 | |
| 1328 | if(routine) |
| 1329 | { |
| 1330 | int res = routine(); |
| 1331 | EXPECT_EQ(res, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | TEST(ReactorUnitTests, Call_ArgsMixed) |
| 1337 | { |
| 1338 | struct Class |
| 1339 | { |
| 1340 | static int Func(int a, float b, int* c, float* d, int e, float f, int* g, float* h) |
| 1341 | { |
| 1342 | return a + b + *c + *d + e + f + *g + *h; |
| 1343 | } |
| 1344 | }; |
| 1345 | |
| 1346 | { |
| 1347 | FunctionT<int()> function; |
| 1348 | { |
| 1349 | Int c(3); |
| 1350 | Float d(4); |
| 1351 | Int g(7); |
| 1352 | Float h(8); |
| 1353 | auto res = Call(Class::Func, 1, 2.f, &c, &d, 5, 6.f, &g, &h); |
| 1354 | Return(res); |
| 1355 | } |
| 1356 | |
| 1357 | auto routine = function("one"); |
| 1358 | |
| 1359 | if(routine) |
| 1360 | { |
| 1361 | int res = routine(); |
| 1362 | EXPECT_EQ(res, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); |
| 1363 | } |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | TEST(ReactorUnitTests, Call_ArgsPointer) |
| 1368 | { |
| 1369 | struct Class |
| 1370 | { |
| 1371 | static int Func(int *a) |
| 1372 | { |
| 1373 | return *a; |
| 1374 | } |
| 1375 | }; |
| 1376 | |
| 1377 | { |
| 1378 | FunctionT<int()> function; |
| 1379 | { |
| 1380 | Int a(12345); |
| 1381 | auto res = Call(Class::Func, &a); |
| 1382 | Return(res); |
| 1383 | } |
| 1384 | |
| 1385 | auto routine = function("one"); |
| 1386 | |
| 1387 | if(routine) |
| 1388 | { |
| 1389 | int res = routine(); |
| 1390 | EXPECT_EQ(res, 12345); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1396 | TEST(ReactorUnitTests, CallExternalCallRoutine) |
| 1397 | { |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1398 | // routine1 calls Class::Func, passing it a pointer to routine2, and Class::Func calls routine2 |
| 1399 | |
| 1400 | auto routine2 = [] { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1401 | FunctionT<float(float, int)> function; |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1402 | { |
| 1403 | Float a = function.Arg<0>(); |
| 1404 | Int b = function.Arg<1>(); |
| 1405 | Return(a + Float(b)); |
| 1406 | } |
| 1407 | return function("two"); |
| 1408 | }(); |
| 1409 | |
| 1410 | struct Class |
| 1411 | { |
| 1412 | static float Func(void* p, float a, int b) |
| 1413 | { |
| 1414 | auto funcToCall = reinterpret_cast<float(*)(float, int)>(p); |
| 1415 | return funcToCall(a, b); |
| 1416 | } |
| 1417 | }; |
| 1418 | |
| 1419 | auto routine1 = [] { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1420 | FunctionT<float(void*, float, int)> function; |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1421 | { |
| 1422 | Pointer<Byte> funcToCall = function.Arg<0>(); |
| 1423 | Float a = function.Arg<1>(); |
| 1424 | Int b = function.Arg<2>(); |
| 1425 | Float result = Call(Class::Func, funcToCall, a, b); |
| 1426 | Return(result); |
| 1427 | } |
| 1428 | return function("one"); |
| 1429 | }(); |
| 1430 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1431 | float result = routine1((void*)routine2.getEntry(), 12.f, 13); |
Antonio Maiorano | b7dad7d | 2019-10-11 15:26:58 -0400 | [diff] [blame] | 1432 | EXPECT_EQ(result, 25.f); |
Ben Clayton | d853c12 | 2019-04-16 17:51:49 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1435 | // Check that a complex generated function which utilizes all 8 or 16 XMM |
| 1436 | // registers computes the correct result. |
| 1437 | // (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] | 1438 | // this test does not actually check that the register contents are |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1439 | // preserved, just that the generated function computes the correct value. |
| 1440 | // It's necessary to inspect the registers in a debugger to actually verify.) |
| 1441 | TEST(ReactorUnitTests, PreserveXMMRegisters) |
| 1442 | { |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1443 | { |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1444 | FunctionT<void(void*, void*)> function; |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1445 | { |
| 1446 | Pointer<Byte> in = function.Arg<0>(); |
| 1447 | Pointer<Byte> out = function.Arg<1>(); |
| 1448 | |
| 1449 | Float4 a = *Pointer<Float4>(in + 16 * 0); |
| 1450 | Float4 b = *Pointer<Float4>(in + 16 * 1); |
| 1451 | Float4 c = *Pointer<Float4>(in + 16 * 2); |
| 1452 | Float4 d = *Pointer<Float4>(in + 16 * 3); |
| 1453 | Float4 e = *Pointer<Float4>(in + 16 * 4); |
| 1454 | Float4 f = *Pointer<Float4>(in + 16 * 5); |
| 1455 | Float4 g = *Pointer<Float4>(in + 16 * 6); |
| 1456 | Float4 h = *Pointer<Float4>(in + 16 * 7); |
| 1457 | Float4 i = *Pointer<Float4>(in + 16 * 8); |
| 1458 | Float4 j = *Pointer<Float4>(in + 16 * 9); |
| 1459 | Float4 k = *Pointer<Float4>(in + 16 * 10); |
| 1460 | Float4 l = *Pointer<Float4>(in + 16 * 11); |
| 1461 | Float4 m = *Pointer<Float4>(in + 16 * 12); |
| 1462 | Float4 n = *Pointer<Float4>(in + 16 * 13); |
| 1463 | Float4 o = *Pointer<Float4>(in + 16 * 14); |
| 1464 | Float4 p = *Pointer<Float4>(in + 16 * 15); |
| 1465 | |
| 1466 | Float4 ab = a + b; |
| 1467 | Float4 cd = c + d; |
| 1468 | Float4 ef = e + f; |
| 1469 | Float4 gh = g + h; |
| 1470 | Float4 ij = i + j; |
| 1471 | Float4 kl = k + l; |
| 1472 | Float4 mn = m + n; |
| 1473 | Float4 op = o + p; |
| 1474 | |
| 1475 | Float4 abcd = ab + cd; |
| 1476 | Float4 efgh = ef + gh; |
| 1477 | Float4 ijkl = ij + kl; |
| 1478 | Float4 mnop = mn + op; |
| 1479 | |
| 1480 | Float4 abcdefgh = abcd + efgh; |
| 1481 | Float4 ijklmnop = ijkl + mnop; |
| 1482 | Float4 sum = abcdefgh + ijklmnop; |
| 1483 | *Pointer<Float4>(out) = sum; |
| 1484 | Return(); |
| 1485 | } |
| 1486 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1487 | auto routine = function("one"); |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1488 | assert(routine); |
| 1489 | |
| 1490 | float input[64] = { 1.0f, 0.0f, 0.0f, 0.0f, |
| 1491 | -1.0f, 1.0f, -1.0f, 0.0f, |
| 1492 | 1.0f, 2.0f, -2.0f, 0.0f, |
| 1493 | -1.0f, 3.0f, -3.0f, 0.0f, |
| 1494 | 1.0f, 4.0f, -4.0f, 0.0f, |
| 1495 | -1.0f, 5.0f, -5.0f, 0.0f, |
| 1496 | 1.0f, 6.0f, -6.0f, 0.0f, |
| 1497 | -1.0f, 7.0f, -7.0f, 0.0f, |
| 1498 | 1.0f, 8.0f, -8.0f, 0.0f, |
| 1499 | -1.0f, 9.0f, -9.0f, 0.0f, |
| 1500 | 1.0f, 10.0f, -10.0f, 0.0f, |
| 1501 | -1.0f, 11.0f, -11.0f, 0.0f, |
| 1502 | 1.0f, 12.0f, -12.0f, 0.0f, |
| 1503 | -1.0f, 13.0f, -13.0f, 0.0f, |
| 1504 | 1.0f, 14.0f, -14.0f, 0.0f, |
| 1505 | -1.0f, 15.0f, -15.0f, 0.0f }; |
| 1506 | |
| 1507 | float result[4]; |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1508 | |
Antonio Maiorano | 03935ae | 2019-10-29 16:20:27 -0400 | [diff] [blame] | 1509 | routine(input, result); |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1510 | |
| 1511 | EXPECT_EQ(result[0], 0.0f); |
| 1512 | EXPECT_EQ(result[1], 120.0f); |
| 1513 | EXPECT_EQ(result[2], -120.0f); |
| 1514 | EXPECT_EQ(result[3], 0.0f); |
| 1515 | } |
| 1516 | |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 1517 | } |
| 1518 | |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1519 | template <typename T> |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1520 | class CToReactorTCastTest : public ::testing::Test |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1521 | { |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1522 | public: |
| 1523 | using CType = typename std::tuple_element<0, T>::type; |
| 1524 | using ReactorType = typename std::tuple_element<1, T>::type; |
| 1525 | }; |
| 1526 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1527 | using CToReactorTCastTestTypes = ::testing::Types |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1528 | < // Subset of types that can be used as arguments. |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1529 | // std::pair<bool, Bool>, FIXME(capn): Not supported as argument type by Subzero. |
| 1530 | // std::pair<uint8_t, Byte>, FIXME(capn): Not supported as argument type by Subzero. |
| 1531 | // std::pair<int8_t, SByte>, FIXME(capn): Not supported as argument type by Subzero. |
| 1532 | // std::pair<int16_t, Short>, FIXME(capn): Not supported as argument type by Subzero. |
| 1533 | // 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] | 1534 | std::pair<int, Int>, |
| 1535 | std::pair<unsigned int, UInt>, |
| 1536 | std::pair<float, Float> |
| 1537 | >; |
| 1538 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1539 | TYPED_TEST_SUITE(CToReactorTCastTest, CToReactorTCastTestTypes); |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1540 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1541 | TYPED_TEST(CToReactorTCastTest, Casts) |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1542 | { |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1543 | using CType = typename TestFixture::CType; |
| 1544 | using ReactorType = typename TestFixture::ReactorType; |
| 1545 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 1546 | std::shared_ptr<Routine> routine; |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1547 | |
| 1548 | { |
| 1549 | Function< Int(ReactorType) > function; |
| 1550 | { |
| 1551 | ReactorType a = function.template Arg<0>(); |
| 1552 | ReactorType b = CType{}; |
| 1553 | RValue<ReactorType> c = RValue<ReactorType>(CType{}); |
| 1554 | Bool same = (a == b) && (a == c); |
| 1555 | Return(IfThenElse(same, Int(1), Int(0))); // TODO: Ability to use Bools as return values. |
| 1556 | } |
| 1557 | |
| 1558 | routine = function("one"); |
| 1559 | |
| 1560 | if(routine) |
| 1561 | { |
| 1562 | auto callable = (int(*)(CType))routine->getEntry(); |
| 1563 | CType in = {}; |
| 1564 | EXPECT_EQ(callable(in), 1); |
| 1565 | } |
| 1566 | } |
| 1567 | |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | template <typename T> |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1571 | class GEPTest : public ::testing::Test |
| 1572 | { |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1573 | public: |
| 1574 | using CType = typename std::tuple_element<0, T>::type; |
| 1575 | using ReactorType = typename std::tuple_element<1, T>::type; |
| 1576 | }; |
| 1577 | |
| 1578 | using GEPTestTypes = ::testing::Types |
| 1579 | < |
Ben Clayton | f3b5797 | 2019-03-15 09:56:47 +0000 | [diff] [blame] | 1580 | std::pair<bool, Bool>, |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1581 | std::pair<int8_t, Byte>, |
| 1582 | std::pair<int8_t, SByte>, |
| 1583 | std::pair<int8_t[4], Byte4>, |
| 1584 | std::pair<int8_t[4], SByte4>, |
| 1585 | std::pair<int8_t[8], Byte8>, |
| 1586 | std::pair<int8_t[8], SByte8>, |
| 1587 | std::pair<int8_t[16], Byte16>, |
| 1588 | std::pair<int8_t[16], SByte16>, |
| 1589 | std::pair<int16_t, Short>, |
| 1590 | std::pair<int16_t, UShort>, |
| 1591 | std::pair<int16_t[2], Short2>, |
| 1592 | std::pair<int16_t[2], UShort2>, |
| 1593 | std::pair<int16_t[4], Short4>, |
| 1594 | std::pair<int16_t[4], UShort4>, |
| 1595 | std::pair<int16_t[8], Short8>, |
| 1596 | std::pair<int16_t[8], UShort8>, |
| 1597 | std::pair<int, Int>, |
| 1598 | std::pair<int, UInt>, |
| 1599 | std::pair<int[2], Int2>, |
| 1600 | std::pair<int[2], UInt2>, |
| 1601 | std::pair<int[4], Int4>, |
| 1602 | std::pair<int[4], UInt4>, |
| 1603 | std::pair<int64_t, Long>, |
| 1604 | std::pair<int16_t, Half>, |
| 1605 | std::pair<float, Float>, |
| 1606 | std::pair<float[2], Float2>, |
| 1607 | std::pair<float[4], Float4> |
| 1608 | >; |
| 1609 | |
Alexis Hetu | 79d4ac9 | 2019-06-03 11:31:46 -0400 | [diff] [blame] | 1610 | TYPED_TEST_SUITE(GEPTest, GEPTestTypes); |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1611 | |
Nicolas Capens | f0d22ad | 2019-03-15 17:22:42 -0400 | [diff] [blame] | 1612 | TYPED_TEST(GEPTest, PtrOffsets) |
| 1613 | { |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1614 | using CType = typename TestFixture::CType; |
| 1615 | using ReactorType = typename TestFixture::ReactorType; |
| 1616 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 1617 | std::shared_ptr<Routine> routine; |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1618 | |
| 1619 | { |
| 1620 | Function< Pointer<ReactorType>(Pointer<ReactorType>, Int) > function; |
| 1621 | { |
| 1622 | Pointer<ReactorType> pointer = function.template Arg<0>(); |
| 1623 | Int index = function.template Arg<1>(); |
| 1624 | Return(&pointer[index]); |
| 1625 | } |
| 1626 | |
| 1627 | routine = function("one"); |
| 1628 | |
| 1629 | if(routine) |
| 1630 | { |
| 1631 | auto callable = (CType*(*)(CType*, unsigned int))routine->getEntry(); |
| 1632 | |
| 1633 | union PtrInt { |
| 1634 | CType* p; |
| 1635 | size_t i; |
| 1636 | }; |
| 1637 | |
| 1638 | PtrInt base; |
| 1639 | base.i = 0x10000; |
| 1640 | |
| 1641 | for (int i = 0; i < 5; i++) |
| 1642 | { |
| 1643 | PtrInt reference; |
| 1644 | reference.p = &base.p[i]; |
| 1645 | |
| 1646 | PtrInt result; |
| 1647 | result.p = callable(base.p, i); |
| 1648 | |
| 1649 | auto expect = reference.i - base.i; |
| 1650 | auto got = result.i - base.i; |
| 1651 | |
| 1652 | EXPECT_EQ(got, expect) << "i:" << i; |
| 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
Ben Clayton | b124373 | 2019-02-27 23:56:18 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Ben Clayton | 1c82c7b | 2019-04-30 12:49:27 +0100 | [diff] [blame] | 1659 | TEST(ReactorUnitTests, Coroutines_Fibonacci) |
| 1660 | { |
| 1661 | if (!rr::Caps.CoroutinesSupported) |
| 1662 | { |
| 1663 | SUCCEED() << "Coroutines not supported"; |
| 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | Coroutine<int()> function; |
| 1668 | { |
| 1669 | Yield(Int(0)); |
| 1670 | Yield(Int(1)); |
| 1671 | Int current = 1; |
| 1672 | Int next = 1; |
| 1673 | While (true) { |
| 1674 | Yield(next); |
| 1675 | auto tmp = current + next; |
| 1676 | current = next; |
| 1677 | next = tmp; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | auto coroutine = function(); |
| 1682 | |
| 1683 | int32_t expected[] = |
| 1684 | { |
| 1685 | 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, |
| 1686 | 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, |
| 1687 | 317811, |
| 1688 | }; |
| 1689 | |
| 1690 | auto count = sizeof(expected) / sizeof(expected[0]); |
| 1691 | |
| 1692 | for (size_t i = 0; i < count; i++) |
| 1693 | { |
| 1694 | int out = 0; |
| 1695 | EXPECT_EQ(coroutine->await(out), true); |
| 1696 | EXPECT_EQ(out, expected[i]); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | TEST(ReactorUnitTests, Coroutines_Parameters) |
| 1701 | { |
| 1702 | if (!rr::Caps.CoroutinesSupported) |
| 1703 | { |
| 1704 | SUCCEED() << "Coroutines not supported"; |
| 1705 | return; |
| 1706 | } |
| 1707 | |
| 1708 | Coroutine<uint8_t(uint8_t* data, int count)> function; |
| 1709 | { |
| 1710 | Pointer<Byte> data = function.Arg<0>(); |
| 1711 | Int count = function.Arg<1>(); |
| 1712 | |
| 1713 | For(Int i = 0, i < count, i++) |
| 1714 | { |
| 1715 | Yield(data[i]); |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | uint8_t data[] = {10, 20, 30}; |
| 1720 | auto coroutine = function(&data[0], 3); |
| 1721 | |
| 1722 | uint8_t out = 0; |
| 1723 | EXPECT_EQ(coroutine->await(out), true); |
| 1724 | EXPECT_EQ(out, 10); out = 0; |
| 1725 | EXPECT_EQ(coroutine->await(out), true); |
| 1726 | EXPECT_EQ(out, 20); out = 0; |
| 1727 | EXPECT_EQ(coroutine->await(out), true); |
| 1728 | EXPECT_EQ(out, 30); out = 99; |
| 1729 | EXPECT_EQ(coroutine->await(out), false); |
| 1730 | EXPECT_EQ(out, 99); |
| 1731 | EXPECT_EQ(coroutine->await(out), false); |
| 1732 | EXPECT_EQ(out, 99); |
| 1733 | } |
| 1734 | |
Antonio Maiorano | 7ffda5b | 2019-11-20 15:31:51 -0500 | [diff] [blame^] | 1735 | TEST(ReactorUnitTests, ExtractFromRValue) |
| 1736 | { |
| 1737 | Function<Void(Pointer<Int4> values, Pointer<Int4> result)> function; |
| 1738 | { |
| 1739 | Pointer<Int4> vIn = function.Arg<0>(); |
| 1740 | Pointer<Int4> resultIn = function.Arg<1>(); |
| 1741 | |
| 1742 | RValue<Int4> v = *vIn; |
| 1743 | |
| 1744 | Int4 result(678); |
| 1745 | |
| 1746 | If(Extract(v, 0) == 42) |
| 1747 | { |
| 1748 | result = Insert(result, 1, 0); |
| 1749 | } |
| 1750 | |
| 1751 | If(Extract(v, 1) == 42) |
| 1752 | { |
| 1753 | result = Insert(result, 1, 1); |
| 1754 | } |
| 1755 | |
| 1756 | *resultIn = result; |
| 1757 | |
| 1758 | Return(); |
| 1759 | } |
| 1760 | |
| 1761 | auto routine = function("one"); |
| 1762 | auto entry = (void(*)(int*, int*))routine->getEntry(); |
| 1763 | |
| 1764 | int v[4] = { 42, 42, 42, 42 }; |
| 1765 | int result[4] = { 99, 99, 99, 99 }; |
| 1766 | entry(v, result); |
| 1767 | EXPECT_EQ(result[0], 1); |
| 1768 | EXPECT_EQ(result[1], 1); |
| 1769 | EXPECT_EQ(result[2], 678); |
| 1770 | EXPECT_EQ(result[3], 678); |
| 1771 | } |
| 1772 | |
Nicolas Capens | 228b05d | 2016-10-12 15:27:04 -0400 | [diff] [blame] | 1773 | int main(int argc, char **argv) |
| 1774 | { |
| 1775 | ::testing::InitGoogleTest(&argc, argv); |
| 1776 | return RUN_ALL_TESTS(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1777 | } |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1778 | |
| 1779 | //////////////////////////////// |
| 1780 | // Trait compile time checks. // |
| 1781 | //////////////////////////////// |
| 1782 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1783 | // Assert CToReactorT resolves to expected types. |
| 1784 | static_assert(std::is_same<CToReactorT<void>, Void>::value, ""); |
| 1785 | static_assert(std::is_same<CToReactorT<bool>, Bool>::value, ""); |
| 1786 | static_assert(std::is_same<CToReactorT<uint8_t>, Byte>::value, ""); |
| 1787 | static_assert(std::is_same<CToReactorT<int8_t>, SByte>::value, ""); |
| 1788 | static_assert(std::is_same<CToReactorT<int16_t>, Short>::value, ""); |
| 1789 | static_assert(std::is_same<CToReactorT<uint16_t>, UShort>::value, ""); |
| 1790 | static_assert(std::is_same<CToReactorT<int32_t>, Int>::value, ""); |
| 1791 | static_assert(std::is_same<CToReactorT<uint64_t>, Long>::value, ""); |
| 1792 | static_assert(std::is_same<CToReactorT<uint32_t>, UInt>::value, ""); |
| 1793 | static_assert(std::is_same<CToReactorT<float>, Float>::value, ""); |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1794 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1795 | // Assert CToReactorT for known pointer types resolves to expected types. |
| 1796 | static_assert(std::is_same<CToReactorT<void*>, Pointer<Byte>>::value, ""); |
| 1797 | static_assert(std::is_same<CToReactorT<bool*>, Pointer<Bool>>::value, ""); |
| 1798 | static_assert(std::is_same<CToReactorT<uint8_t*>, Pointer<Byte>>::value, ""); |
| 1799 | static_assert(std::is_same<CToReactorT<int8_t*>, Pointer<SByte>>::value, ""); |
| 1800 | static_assert(std::is_same<CToReactorT<int16_t*>, Pointer<Short>>::value, ""); |
| 1801 | static_assert(std::is_same<CToReactorT<uint16_t*>, Pointer<UShort>>::value, ""); |
| 1802 | static_assert(std::is_same<CToReactorT<int32_t*>, Pointer<Int>>::value, ""); |
| 1803 | static_assert(std::is_same<CToReactorT<uint64_t*>, Pointer<Long>>::value, ""); |
| 1804 | static_assert(std::is_same<CToReactorT<uint32_t*>, Pointer<UInt>>::value, ""); |
| 1805 | static_assert(std::is_same<CToReactorT<float*>, Pointer<Float>>::value, ""); |
| 1806 | static_assert(std::is_same<CToReactorT<uint16_t**>, Pointer<Pointer<UShort>>>::value, ""); |
| 1807 | 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] | 1808 | |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1809 | // Assert CToReactorT for unknown pointer types resolves to Pointer<Byte>. |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1810 | struct S{}; |
Ben Clayton | 51f0831 | 2019-11-08 14:39:26 +0000 | [diff] [blame] | 1811 | static_assert(std::is_same<CToReactorT<S*>, Pointer<Byte>>::value, ""); |
| 1812 | static_assert(std::is_same<CToReactorT<S**>, Pointer<Pointer<Byte>>>::value, ""); |
| 1813 | static_assert(std::is_same<CToReactorT<S***>, Pointer<Pointer<Pointer<Byte>>>>::value, ""); |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1814 | |
| 1815 | // Assert IsRValue<> resolves true for RValue<> types. |
| 1816 | static_assert(IsRValue<RValue<Void>>::value, ""); |
| 1817 | static_assert(IsRValue<RValue<Bool>>::value, ""); |
| 1818 | static_assert(IsRValue<RValue<Byte>>::value, ""); |
| 1819 | static_assert(IsRValue<RValue<SByte>>::value, ""); |
| 1820 | static_assert(IsRValue<RValue<Short>>::value, ""); |
| 1821 | static_assert(IsRValue<RValue<UShort>>::value, ""); |
| 1822 | static_assert(IsRValue<RValue<Int>>::value, ""); |
| 1823 | static_assert(IsRValue<RValue<Long>>::value, ""); |
| 1824 | static_assert(IsRValue<RValue<UInt>>::value, ""); |
| 1825 | static_assert(IsRValue<RValue<Float>>::value, ""); |
| 1826 | |
| 1827 | // Assert IsLValue<> resolves true for LValue types. |
| 1828 | static_assert(IsLValue<Bool>::value, ""); |
| 1829 | static_assert(IsLValue<Byte>::value, ""); |
| 1830 | static_assert(IsLValue<SByte>::value, ""); |
| 1831 | static_assert(IsLValue<Short>::value, ""); |
| 1832 | static_assert(IsLValue<UShort>::value, ""); |
| 1833 | static_assert(IsLValue<Int>::value, ""); |
| 1834 | static_assert(IsLValue<Long>::value, ""); |
| 1835 | static_assert(IsLValue<UInt>::value, ""); |
| 1836 | static_assert(IsLValue<Float>::value, ""); |
| 1837 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1838 | // Assert IsReference<> resolves true for Reference types. |
| 1839 | static_assert(IsReference<Reference<Bool>>::value, ""); |
| 1840 | static_assert(IsReference<Reference<Byte>>::value, ""); |
| 1841 | static_assert(IsReference<Reference<SByte>>::value, ""); |
| 1842 | static_assert(IsReference<Reference<Short>>::value, ""); |
| 1843 | static_assert(IsReference<Reference<UShort>>::value, ""); |
| 1844 | static_assert(IsReference<Reference<Int>>::value, ""); |
| 1845 | static_assert(IsReference<Reference<Long>>::value, ""); |
| 1846 | static_assert(IsReference<Reference<UInt>>::value, ""); |
| 1847 | static_assert(IsReference<Reference<Float>>::value, ""); |
| 1848 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1849 | // Assert IsRValue<> resolves false for LValue types. |
| 1850 | static_assert(!IsRValue<Void>::value, ""); |
| 1851 | static_assert(!IsRValue<Bool>::value, ""); |
| 1852 | static_assert(!IsRValue<Byte>::value, ""); |
| 1853 | static_assert(!IsRValue<SByte>::value, ""); |
| 1854 | static_assert(!IsRValue<Short>::value, ""); |
| 1855 | static_assert(!IsRValue<UShort>::value, ""); |
| 1856 | static_assert(!IsRValue<Int>::value, ""); |
| 1857 | static_assert(!IsRValue<Long>::value, ""); |
| 1858 | static_assert(!IsRValue<UInt>::value, ""); |
| 1859 | static_assert(!IsRValue<Float>::value, ""); |
| 1860 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1861 | // Assert IsRValue<> resolves false for Reference types. |
| 1862 | static_assert(!IsRValue<Reference<Void>>::value, ""); |
| 1863 | static_assert(!IsRValue<Reference<Bool>>::value, ""); |
| 1864 | static_assert(!IsRValue<Reference<Byte>>::value, ""); |
| 1865 | static_assert(!IsRValue<Reference<SByte>>::value, ""); |
| 1866 | static_assert(!IsRValue<Reference<Short>>::value, ""); |
| 1867 | static_assert(!IsRValue<Reference<UShort>>::value, ""); |
| 1868 | static_assert(!IsRValue<Reference<Int>>::value, ""); |
| 1869 | static_assert(!IsRValue<Reference<Long>>::value, ""); |
| 1870 | static_assert(!IsRValue<Reference<UInt>>::value, ""); |
| 1871 | static_assert(!IsRValue<Reference<Float>>::value, ""); |
| 1872 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1873 | // Assert IsRValue<> resolves false for C types. |
| 1874 | static_assert(!IsRValue<void>::value, ""); |
| 1875 | static_assert(!IsRValue<bool>::value, ""); |
| 1876 | static_assert(!IsRValue<uint8_t>::value, ""); |
| 1877 | static_assert(!IsRValue<int8_t>::value, ""); |
| 1878 | static_assert(!IsRValue<int16_t>::value, ""); |
| 1879 | static_assert(!IsRValue<uint16_t>::value, ""); |
| 1880 | static_assert(!IsRValue<int32_t>::value, ""); |
| 1881 | static_assert(!IsRValue<uint64_t>::value, ""); |
| 1882 | static_assert(!IsRValue<uint32_t>::value, ""); |
| 1883 | static_assert(!IsRValue<float>::value, ""); |
| 1884 | |
| 1885 | // Assert IsLValue<> resolves false for RValue<> types. |
| 1886 | static_assert(!IsLValue<RValue<Void>>::value, ""); |
| 1887 | static_assert(!IsLValue<RValue<Bool>>::value, ""); |
| 1888 | static_assert(!IsLValue<RValue<Byte>>::value, ""); |
| 1889 | static_assert(!IsLValue<RValue<SByte>>::value, ""); |
| 1890 | static_assert(!IsLValue<RValue<Short>>::value, ""); |
| 1891 | static_assert(!IsLValue<RValue<UShort>>::value, ""); |
| 1892 | static_assert(!IsLValue<RValue<Int>>::value, ""); |
| 1893 | static_assert(!IsLValue<RValue<Long>>::value, ""); |
| 1894 | static_assert(!IsLValue<RValue<UInt>>::value, ""); |
| 1895 | static_assert(!IsLValue<RValue<Float>>::value, ""); |
| 1896 | |
| 1897 | // Assert IsLValue<> resolves false for Void type. |
| 1898 | static_assert(!IsLValue<Void>::value, ""); |
| 1899 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1900 | // Assert IsLValue<> resolves false for Reference<> types. |
| 1901 | static_assert(!IsLValue<Reference<Void>>::value, ""); |
| 1902 | static_assert(!IsLValue<Reference<Bool>>::value, ""); |
| 1903 | static_assert(!IsLValue<Reference<Byte>>::value, ""); |
| 1904 | static_assert(!IsLValue<Reference<SByte>>::value, ""); |
| 1905 | static_assert(!IsLValue<Reference<Short>>::value, ""); |
| 1906 | static_assert(!IsLValue<Reference<UShort>>::value, ""); |
| 1907 | static_assert(!IsLValue<Reference<Int>>::value, ""); |
| 1908 | static_assert(!IsLValue<Reference<Long>>::value, ""); |
| 1909 | static_assert(!IsLValue<Reference<UInt>>::value, ""); |
| 1910 | static_assert(!IsLValue<Reference<Float>>::value, ""); |
| 1911 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1912 | // Assert IsLValue<> resolves false for C types. |
| 1913 | static_assert(!IsLValue<void>::value, ""); |
| 1914 | static_assert(!IsLValue<bool>::value, ""); |
| 1915 | static_assert(!IsLValue<uint8_t>::value, ""); |
| 1916 | static_assert(!IsLValue<int8_t>::value, ""); |
| 1917 | static_assert(!IsLValue<int16_t>::value, ""); |
| 1918 | static_assert(!IsLValue<uint16_t>::value, ""); |
| 1919 | static_assert(!IsLValue<int32_t>::value, ""); |
| 1920 | static_assert(!IsLValue<uint64_t>::value, ""); |
| 1921 | static_assert(!IsLValue<uint32_t>::value, ""); |
| 1922 | static_assert(!IsLValue<float>::value, ""); |
| 1923 | |
| 1924 | // Assert IsDefined<> resolves true for RValue<> types. |
| 1925 | static_assert(IsDefined<RValue<Void>>::value, ""); |
| 1926 | static_assert(IsDefined<RValue<Bool>>::value, ""); |
| 1927 | static_assert(IsDefined<RValue<Byte>>::value, ""); |
| 1928 | static_assert(IsDefined<RValue<SByte>>::value, ""); |
| 1929 | static_assert(IsDefined<RValue<Short>>::value, ""); |
| 1930 | static_assert(IsDefined<RValue<UShort>>::value, ""); |
| 1931 | static_assert(IsDefined<RValue<Int>>::value, ""); |
| 1932 | static_assert(IsDefined<RValue<Long>>::value, ""); |
| 1933 | static_assert(IsDefined<RValue<UInt>>::value, ""); |
| 1934 | static_assert(IsDefined<RValue<Float>>::value, ""); |
| 1935 | |
| 1936 | // Assert IsDefined<> resolves true for LValue types. |
| 1937 | static_assert(IsDefined<Void>::value, ""); |
| 1938 | static_assert(IsDefined<Bool>::value, ""); |
| 1939 | static_assert(IsDefined<Byte>::value, ""); |
| 1940 | static_assert(IsDefined<SByte>::value, ""); |
| 1941 | static_assert(IsDefined<Short>::value, ""); |
| 1942 | static_assert(IsDefined<UShort>::value, ""); |
| 1943 | static_assert(IsDefined<Int>::value, ""); |
| 1944 | static_assert(IsDefined<Long>::value, ""); |
| 1945 | static_assert(IsDefined<UInt>::value, ""); |
| 1946 | static_assert(IsDefined<Float>::value, ""); |
| 1947 | |
Ben Clayton | 208ed40 | 2019-05-03 22:30:03 +0100 | [diff] [blame] | 1948 | // Assert IsDefined<> resolves true for Reference<> types. |
| 1949 | static_assert(IsDefined<Reference<Bool>>::value, ""); |
| 1950 | static_assert(IsDefined<Reference<Byte>>::value, ""); |
| 1951 | static_assert(IsDefined<Reference<SByte>>::value, ""); |
| 1952 | static_assert(IsDefined<Reference<Short>>::value, ""); |
| 1953 | static_assert(IsDefined<Reference<UShort>>::value, ""); |
| 1954 | static_assert(IsDefined<Reference<Int>>::value, ""); |
| 1955 | static_assert(IsDefined<Reference<Long>>::value, ""); |
| 1956 | static_assert(IsDefined<Reference<UInt>>::value, ""); |
| 1957 | static_assert(IsDefined<Reference<Float>>::value, ""); |
| 1958 | |
Ben Clayton | 351be42 | 2019-04-30 12:26:57 +0100 | [diff] [blame] | 1959 | // Assert IsDefined<> resolves true for C types. |
| 1960 | static_assert(IsDefined<void>::value, ""); |
| 1961 | static_assert(IsDefined<bool>::value, ""); |
| 1962 | static_assert(IsDefined<uint8_t>::value, ""); |
| 1963 | static_assert(IsDefined<int8_t>::value, ""); |
| 1964 | static_assert(IsDefined<int16_t>::value, ""); |
| 1965 | static_assert(IsDefined<uint16_t>::value, ""); |
| 1966 | static_assert(IsDefined<int32_t>::value, ""); |
| 1967 | static_assert(IsDefined<uint64_t>::value, ""); |
| 1968 | static_assert(IsDefined<uint32_t>::value, ""); |
| 1969 | static_assert(IsDefined<float>::value, ""); |