Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. Use of this |
| 2 | // source code is governed by a BSD-style license that can be found in the |
| 3 | // LICENSE file. |
| 4 | |
| 5 | #include "test/cctest/cctest.h" |
| 6 | #include "test/cctest/compiler/codegen-tester.h" |
| 7 | #include "test/cctest/compiler/value-helper.h" |
| 8 | |
| 9 | namespace v8 { |
| 10 | namespace internal { |
| 11 | namespace compiler { |
| 12 | |
| 13 | template <typename T> |
| 14 | void TestExternalReferenceRoundingFunction( |
| 15 | BufferedRawMachineAssemblerTester<int32_t>* m, ExternalReference ref, |
| 16 | T (*comparison)(T)) { |
| 17 | T parameter; |
| 18 | |
| 19 | Node* function = m->ExternalConstant(ref); |
| 20 | m->CallCFunction1(MachineType::Pointer(), MachineType::Pointer(), function, |
| 21 | m->PointerConstant(¶meter)); |
| 22 | m->Return(m->Int32Constant(4356)); |
| 23 | FOR_FLOAT64_INPUTS(i) { |
| 24 | parameter = *i; |
| 25 | m->Call(); |
| 26 | CHECK_DOUBLE_EQ(comparison(*i), parameter); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | TEST(RunCallF32Trunc) { |
| 31 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 32 | ExternalReference ref = ExternalReference::wasm_f32_trunc(m.isolate()); |
| 33 | TestExternalReferenceRoundingFunction<float>(&m, ref, truncf); |
| 34 | } |
| 35 | |
| 36 | TEST(RunCallF32Floor) { |
| 37 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 38 | ExternalReference ref = ExternalReference::wasm_f32_floor(m.isolate()); |
| 39 | TestExternalReferenceRoundingFunction<float>(&m, ref, floorf); |
| 40 | } |
| 41 | |
| 42 | TEST(RunCallF32Ceil) { |
| 43 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 44 | ExternalReference ref = ExternalReference::wasm_f32_ceil(m.isolate()); |
| 45 | TestExternalReferenceRoundingFunction<float>(&m, ref, ceilf); |
| 46 | } |
| 47 | |
| 48 | TEST(RunCallF32RoundTiesEven) { |
| 49 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 50 | ExternalReference ref = ExternalReference::wasm_f32_nearest_int(m.isolate()); |
| 51 | TestExternalReferenceRoundingFunction<float>(&m, ref, nearbyintf); |
| 52 | } |
| 53 | |
| 54 | TEST(RunCallF64Trunc) { |
| 55 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 56 | ExternalReference ref = ExternalReference::wasm_f64_trunc(m.isolate()); |
| 57 | TestExternalReferenceRoundingFunction<double>(&m, ref, trunc); |
| 58 | } |
| 59 | |
| 60 | TEST(RunCallF64Floor) { |
| 61 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 62 | ExternalReference ref = ExternalReference::wasm_f64_floor(m.isolate()); |
| 63 | TestExternalReferenceRoundingFunction<double>(&m, ref, floor); |
| 64 | } |
| 65 | |
| 66 | TEST(RunCallF64Ceil) { |
| 67 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 68 | ExternalReference ref = ExternalReference::wasm_f64_ceil(m.isolate()); |
| 69 | TestExternalReferenceRoundingFunction<double>(&m, ref, ceil); |
| 70 | } |
| 71 | |
| 72 | TEST(RunCallF64RoundTiesEven) { |
| 73 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 74 | ExternalReference ref = ExternalReference::wasm_f64_nearest_int(m.isolate()); |
| 75 | TestExternalReferenceRoundingFunction<double>(&m, ref, nearbyint); |
| 76 | } |
| 77 | |
| 78 | TEST(RunCallInt64ToFloat32) { |
| 79 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 80 | ExternalReference ref = ExternalReference::wasm_int64_to_float32(m.isolate()); |
| 81 | |
| 82 | int64_t input; |
| 83 | float output; |
| 84 | |
| 85 | Node* function = m.ExternalConstant(ref); |
| 86 | m.CallCFunction2(MachineType::Pointer(), MachineType::Pointer(), |
| 87 | MachineType::Pointer(), function, m.PointerConstant(&input), |
| 88 | m.PointerConstant(&output)); |
| 89 | m.Return(m.Int32Constant(4356)); |
| 90 | FOR_INT64_INPUTS(i) { |
| 91 | input = *i; |
| 92 | m.Call(); |
| 93 | CHECK_FLOAT_EQ(static_cast<float>(*i), output); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | TEST(RunCallUint64ToFloat32) { |
| 98 | struct { |
| 99 | uint64_t input; |
| 100 | uint32_t expected; |
| 101 | } values[] = {{0x0, 0x0}, |
| 102 | {0x1, 0x3f800000}, |
| 103 | {0xffffffff, 0x4f800000}, |
| 104 | {0x1b09788b, 0x4dd84bc4}, |
| 105 | {0x4c5fce8, 0x4c98bf9d}, |
| 106 | {0xcc0de5bf, 0x4f4c0de6}, |
| 107 | {0x2, 0x40000000}, |
| 108 | {0x3, 0x40400000}, |
| 109 | {0x4, 0x40800000}, |
| 110 | {0x5, 0x40a00000}, |
| 111 | {0x8, 0x41000000}, |
| 112 | {0x9, 0x41100000}, |
| 113 | {0xffffffffffffffff, 0x5f800000}, |
| 114 | {0xfffffffffffffffe, 0x5f800000}, |
| 115 | {0xfffffffffffffffd, 0x5f800000}, |
| 116 | {0x0, 0x0}, |
| 117 | {0x100000000, 0x4f800000}, |
| 118 | {0xffffffff00000000, 0x5f800000}, |
| 119 | {0x1b09788b00000000, 0x5dd84bc4}, |
| 120 | {0x4c5fce800000000, 0x5c98bf9d}, |
| 121 | {0xcc0de5bf00000000, 0x5f4c0de6}, |
| 122 | {0x200000000, 0x50000000}, |
| 123 | {0x300000000, 0x50400000}, |
| 124 | {0x400000000, 0x50800000}, |
| 125 | {0x500000000, 0x50a00000}, |
| 126 | {0x800000000, 0x51000000}, |
| 127 | {0x900000000, 0x51100000}, |
| 128 | {0x273a798e187937a3, 0x5e1ce9e6}, |
| 129 | {0xece3af835495a16b, 0x5f6ce3b0}, |
| 130 | {0xb668ecc11223344, 0x5d3668ed}, |
| 131 | {0x9e, 0x431e0000}, |
| 132 | {0x43, 0x42860000}, |
| 133 | {0xaf73, 0x472f7300}, |
| 134 | {0x116b, 0x458b5800}, |
| 135 | {0x658ecc, 0x4acb1d98}, |
| 136 | {0x2b3b4c, 0x4a2ced30}, |
| 137 | {0x88776655, 0x4f087766}, |
| 138 | {0x70000000, 0x4ee00000}, |
| 139 | {0x7200000, 0x4ce40000}, |
| 140 | {0x7fffffff, 0x4f000000}, |
| 141 | {0x56123761, 0x4eac246f}, |
| 142 | {0x7fffff00, 0x4efffffe}, |
| 143 | {0x761c4761eeeeeeee, 0x5eec388f}, |
| 144 | {0x80000000eeeeeeee, 0x5f000000}, |
| 145 | {0x88888888dddddddd, 0x5f088889}, |
| 146 | {0xa0000000dddddddd, 0x5f200000}, |
| 147 | {0xddddddddaaaaaaaa, 0x5f5dddde}, |
| 148 | {0xe0000000aaaaaaaa, 0x5f600000}, |
| 149 | {0xeeeeeeeeeeeeeeee, 0x5f6eeeef}, |
| 150 | {0xfffffffdeeeeeeee, 0x5f800000}, |
| 151 | {0xf0000000dddddddd, 0x5f700000}, |
| 152 | {0x7fffffdddddddd, 0x5b000000}, |
| 153 | {0x3fffffaaaaaaaa, 0x5a7fffff}, |
| 154 | {0x1fffffaaaaaaaa, 0x59fffffd}, |
| 155 | {0xfffff, 0x497ffff0}, |
| 156 | {0x7ffff, 0x48ffffe0}, |
| 157 | {0x3ffff, 0x487fffc0}, |
| 158 | {0x1ffff, 0x47ffff80}, |
| 159 | {0xffff, 0x477fff00}, |
| 160 | {0x7fff, 0x46fffe00}, |
| 161 | {0x3fff, 0x467ffc00}, |
| 162 | {0x1fff, 0x45fff800}, |
| 163 | {0xfff, 0x457ff000}, |
| 164 | {0x7ff, 0x44ffe000}, |
| 165 | {0x3ff, 0x447fc000}, |
| 166 | {0x1ff, 0x43ff8000}, |
| 167 | {0x3fffffffffff, 0x56800000}, |
| 168 | {0x1fffffffffff, 0x56000000}, |
| 169 | {0xfffffffffff, 0x55800000}, |
| 170 | {0x7ffffffffff, 0x55000000}, |
| 171 | {0x3ffffffffff, 0x54800000}, |
| 172 | {0x1ffffffffff, 0x54000000}, |
| 173 | {0x8000008000000000, 0x5f000000}, |
| 174 | {0x8000008000000001, 0x5f000001}, |
| 175 | {0x8000008000000002, 0x5f000001}, |
| 176 | {0x8000008000000004, 0x5f000001}, |
| 177 | {0x8000008000000008, 0x5f000001}, |
| 178 | {0x8000008000000010, 0x5f000001}, |
| 179 | {0x8000008000000020, 0x5f000001}, |
| 180 | {0x8000009000000000, 0x5f000001}, |
| 181 | {0x800000a000000000, 0x5f000001}, |
| 182 | {0x8000008000100000, 0x5f000001}, |
| 183 | {0x8000000000000400, 0x5f000000}, |
| 184 | {0x8000000000000401, 0x5f000000}}; |
| 185 | |
| 186 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 187 | ExternalReference ref = |
| 188 | ExternalReference::wasm_uint64_to_float32(m.isolate()); |
| 189 | |
| 190 | uint64_t input; |
| 191 | float output; |
| 192 | |
| 193 | Node* function = m.ExternalConstant(ref); |
| 194 | m.CallCFunction2(MachineType::Pointer(), MachineType::Pointer(), |
| 195 | MachineType::Pointer(), function, m.PointerConstant(&input), |
| 196 | m.PointerConstant(&output)); |
| 197 | m.Return(m.Int32Constant(4356)); |
| 198 | |
| 199 | for (size_t i = 0; i < arraysize(values); i++) { |
| 200 | input = values[i].input; |
| 201 | m.Call(); |
| 202 | CHECK_EQ(values[i].expected, bit_cast<uint32_t>(output)); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | TEST(RunCallInt64ToFloat64) { |
| 207 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 208 | ExternalReference ref = ExternalReference::wasm_int64_to_float64(m.isolate()); |
| 209 | |
| 210 | int64_t input; |
| 211 | double output; |
| 212 | |
| 213 | Node* function = m.ExternalConstant(ref); |
| 214 | m.CallCFunction2(MachineType::Pointer(), MachineType::Pointer(), |
| 215 | MachineType::Pointer(), function, m.PointerConstant(&input), |
| 216 | m.PointerConstant(&output)); |
| 217 | m.Return(m.Int32Constant(4356)); |
| 218 | FOR_INT64_INPUTS(i) { |
| 219 | input = *i; |
| 220 | m.Call(); |
| 221 | CHECK_DOUBLE_EQ(static_cast<double>(*i), output); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | TEST(RunCallUint64ToFloat64) { |
| 226 | struct { |
| 227 | uint64_t input; |
| 228 | uint64_t expected; |
| 229 | } values[] = {{0x0, 0x0}, |
| 230 | {0x1, 0x3ff0000000000000}, |
| 231 | {0xffffffff, 0x41efffffffe00000}, |
| 232 | {0x1b09788b, 0x41bb09788b000000}, |
| 233 | {0x4c5fce8, 0x419317f3a0000000}, |
| 234 | {0xcc0de5bf, 0x41e981bcb7e00000}, |
| 235 | {0x2, 0x4000000000000000}, |
| 236 | {0x3, 0x4008000000000000}, |
| 237 | {0x4, 0x4010000000000000}, |
| 238 | {0x5, 0x4014000000000000}, |
| 239 | {0x8, 0x4020000000000000}, |
| 240 | {0x9, 0x4022000000000000}, |
| 241 | {0xffffffffffffffff, 0x43f0000000000000}, |
| 242 | {0xfffffffffffffffe, 0x43f0000000000000}, |
| 243 | {0xfffffffffffffffd, 0x43f0000000000000}, |
| 244 | {0x100000000, 0x41f0000000000000}, |
| 245 | {0xffffffff00000000, 0x43efffffffe00000}, |
| 246 | {0x1b09788b00000000, 0x43bb09788b000000}, |
| 247 | {0x4c5fce800000000, 0x439317f3a0000000}, |
| 248 | {0xcc0de5bf00000000, 0x43e981bcb7e00000}, |
| 249 | {0x200000000, 0x4200000000000000}, |
| 250 | {0x300000000, 0x4208000000000000}, |
| 251 | {0x400000000, 0x4210000000000000}, |
| 252 | {0x500000000, 0x4214000000000000}, |
| 253 | {0x800000000, 0x4220000000000000}, |
| 254 | {0x900000000, 0x4222000000000000}, |
| 255 | {0x273a798e187937a3, 0x43c39d3cc70c3c9c}, |
| 256 | {0xece3af835495a16b, 0x43ed9c75f06a92b4}, |
| 257 | {0xb668ecc11223344, 0x43a6cd1d98224467}, |
| 258 | {0x9e, 0x4063c00000000000}, |
| 259 | {0x43, 0x4050c00000000000}, |
| 260 | {0xaf73, 0x40e5ee6000000000}, |
| 261 | {0x116b, 0x40b16b0000000000}, |
| 262 | {0x658ecc, 0x415963b300000000}, |
| 263 | {0x2b3b4c, 0x41459da600000000}, |
| 264 | {0x88776655, 0x41e10eeccaa00000}, |
| 265 | {0x70000000, 0x41dc000000000000}, |
| 266 | {0x7200000, 0x419c800000000000}, |
| 267 | {0x7fffffff, 0x41dfffffffc00000}, |
| 268 | {0x56123761, 0x41d5848dd8400000}, |
| 269 | {0x7fffff00, 0x41dfffffc0000000}, |
| 270 | {0x761c4761eeeeeeee, 0x43dd8711d87bbbbc}, |
| 271 | {0x80000000eeeeeeee, 0x43e00000001dddde}, |
| 272 | {0x88888888dddddddd, 0x43e11111111bbbbc}, |
| 273 | {0xa0000000dddddddd, 0x43e40000001bbbbc}, |
| 274 | {0xddddddddaaaaaaaa, 0x43ebbbbbbbb55555}, |
| 275 | {0xe0000000aaaaaaaa, 0x43ec000000155555}, |
| 276 | {0xeeeeeeeeeeeeeeee, 0x43edddddddddddde}, |
| 277 | {0xfffffffdeeeeeeee, 0x43efffffffbdddde}, |
| 278 | {0xf0000000dddddddd, 0x43ee0000001bbbbc}, |
| 279 | {0x7fffffdddddddd, 0x435ffffff7777777}, |
| 280 | {0x3fffffaaaaaaaa, 0x434fffffd5555555}, |
| 281 | {0x1fffffaaaaaaaa, 0x433fffffaaaaaaaa}, |
| 282 | {0xfffff, 0x412ffffe00000000}, |
| 283 | {0x7ffff, 0x411ffffc00000000}, |
| 284 | {0x3ffff, 0x410ffff800000000}, |
| 285 | {0x1ffff, 0x40fffff000000000}, |
| 286 | {0xffff, 0x40efffe000000000}, |
| 287 | {0x7fff, 0x40dfffc000000000}, |
| 288 | {0x3fff, 0x40cfff8000000000}, |
| 289 | {0x1fff, 0x40bfff0000000000}, |
| 290 | {0xfff, 0x40affe0000000000}, |
| 291 | {0x7ff, 0x409ffc0000000000}, |
| 292 | {0x3ff, 0x408ff80000000000}, |
| 293 | {0x1ff, 0x407ff00000000000}, |
| 294 | {0x3fffffffffff, 0x42cfffffffffff80}, |
| 295 | {0x1fffffffffff, 0x42bfffffffffff00}, |
| 296 | {0xfffffffffff, 0x42affffffffffe00}, |
| 297 | {0x7ffffffffff, 0x429ffffffffffc00}, |
| 298 | {0x3ffffffffff, 0x428ffffffffff800}, |
| 299 | {0x1ffffffffff, 0x427ffffffffff000}, |
| 300 | {0x8000008000000000, 0x43e0000010000000}, |
| 301 | {0x8000008000000001, 0x43e0000010000000}, |
| 302 | {0x8000000000000400, 0x43e0000000000000}, |
| 303 | {0x8000000000000401, 0x43e0000000000001}, |
| 304 | {0x8000000000000402, 0x43e0000000000001}, |
| 305 | {0x8000000000000404, 0x43e0000000000001}, |
| 306 | {0x8000000000000408, 0x43e0000000000001}, |
| 307 | {0x8000000000000410, 0x43e0000000000001}, |
| 308 | {0x8000000000000420, 0x43e0000000000001}, |
| 309 | {0x8000000000000440, 0x43e0000000000001}, |
| 310 | {0x8000000000000480, 0x43e0000000000001}, |
| 311 | {0x8000000000000500, 0x43e0000000000001}, |
| 312 | {0x8000000000000600, 0x43e0000000000001}}; |
| 313 | |
| 314 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 315 | ExternalReference ref = |
| 316 | ExternalReference::wasm_uint64_to_float64(m.isolate()); |
| 317 | |
| 318 | uint64_t input; |
| 319 | double output; |
| 320 | |
| 321 | Node* function = m.ExternalConstant(ref); |
| 322 | m.CallCFunction2(MachineType::Pointer(), MachineType::Pointer(), |
| 323 | MachineType::Pointer(), function, m.PointerConstant(&input), |
| 324 | m.PointerConstant(&output)); |
| 325 | m.Return(m.Int32Constant(4356)); |
| 326 | |
| 327 | for (size_t i = 0; i < arraysize(values); i++) { |
| 328 | input = values[i].input; |
| 329 | m.Call(); |
| 330 | CHECK_EQ(values[i].expected, bit_cast<uint64_t>(output)); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | TEST(RunCallFloat32ToInt64) { |
| 335 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 336 | ExternalReference ref = ExternalReference::wasm_float32_to_int64(m.isolate()); |
| 337 | |
| 338 | float input; |
| 339 | int64_t output; |
| 340 | |
| 341 | Node* function = m.ExternalConstant(ref); |
| 342 | m.Return(m.CallCFunction2( |
| 343 | MachineType::Int32(), MachineType::Pointer(), MachineType::Pointer(), |
| 344 | function, m.PointerConstant(&input), m.PointerConstant(&output))); |
| 345 | FOR_FLOAT32_INPUTS(i) { |
| 346 | input = *i; |
| 347 | if (*i >= static_cast<float>(std::numeric_limits<int64_t>::min()) && |
| 348 | *i < static_cast<float>(std::numeric_limits<int64_t>::max())) { |
| 349 | CHECK_EQ(1, m.Call()); |
| 350 | CHECK_EQ(static_cast<int64_t>(*i), output); |
| 351 | } else { |
| 352 | CHECK_EQ(0, m.Call()); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | TEST(RunCallFloat32ToUint64) { |
| 358 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 359 | ExternalReference ref = |
| 360 | ExternalReference::wasm_float32_to_uint64(m.isolate()); |
| 361 | |
| 362 | float input; |
| 363 | uint64_t output; |
| 364 | |
| 365 | Node* function = m.ExternalConstant(ref); |
| 366 | m.Return(m.CallCFunction2( |
| 367 | MachineType::Int32(), MachineType::Pointer(), MachineType::Pointer(), |
| 368 | function, m.PointerConstant(&input), m.PointerConstant(&output))); |
| 369 | FOR_FLOAT32_INPUTS(i) { |
| 370 | input = *i; |
| 371 | if (*i > -1.0 && |
| 372 | *i < static_cast<float>(std::numeric_limits<uint64_t>::max())) { |
| 373 | CHECK_EQ(1, m.Call()); |
| 374 | CHECK_EQ(static_cast<uint64_t>(*i), output); |
| 375 | } else { |
| 376 | CHECK_EQ(0, m.Call()); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | TEST(RunCallFloat64ToInt64) { |
| 382 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 383 | ExternalReference ref = ExternalReference::wasm_float64_to_int64(m.isolate()); |
| 384 | |
| 385 | double input; |
| 386 | int64_t output; |
| 387 | |
| 388 | Node* function = m.ExternalConstant(ref); |
| 389 | m.Return(m.CallCFunction2( |
| 390 | MachineType::Int32(), MachineType::Pointer(), MachineType::Pointer(), |
| 391 | function, m.PointerConstant(&input), m.PointerConstant(&output))); |
| 392 | FOR_FLOAT64_INPUTS(i) { |
| 393 | input = *i; |
| 394 | if (*i >= static_cast<double>(std::numeric_limits<int64_t>::min()) && |
| 395 | *i < static_cast<double>(std::numeric_limits<int64_t>::max())) { |
| 396 | CHECK_EQ(1, m.Call()); |
| 397 | CHECK_EQ(static_cast<int64_t>(*i), output); |
| 398 | } else { |
| 399 | CHECK_EQ(0, m.Call()); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | TEST(RunCallFloat64ToUint64) { |
| 405 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 406 | ExternalReference ref = |
| 407 | ExternalReference::wasm_float64_to_uint64(m.isolate()); |
| 408 | |
| 409 | double input; |
| 410 | uint64_t output; |
| 411 | |
| 412 | Node* function = m.ExternalConstant(ref); |
| 413 | m.Return(m.CallCFunction2( |
| 414 | MachineType::Int32(), MachineType::Pointer(), MachineType::Pointer(), |
| 415 | function, m.PointerConstant(&input), m.PointerConstant(&output))); |
| 416 | FOR_FLOAT64_INPUTS(i) { |
| 417 | input = *i; |
| 418 | if (*i > -1.0 && |
| 419 | *i < static_cast<double>(std::numeric_limits<uint64_t>::max())) { |
| 420 | CHECK_EQ(1, m.Call()); |
| 421 | CHECK_EQ(static_cast<uint64_t>(*i), output); |
| 422 | } else { |
| 423 | CHECK_EQ(0, m.Call()); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | TEST(RunCallInt64Div) { |
| 429 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 430 | ExternalReference ref = ExternalReference::wasm_int64_div(m.isolate()); |
| 431 | |
| 432 | int64_t dst; |
| 433 | int64_t src; |
| 434 | |
| 435 | Node* function = m.ExternalConstant(ref); |
| 436 | m.Return(m.CallCFunction2(MachineType::Int32(), MachineType::Pointer(), |
| 437 | MachineType::Pointer(), function, |
| 438 | m.PointerConstant(&dst), m.PointerConstant(&src))); |
| 439 | FOR_INT64_INPUTS(i) { |
| 440 | FOR_INT64_INPUTS(j) { |
| 441 | dst = *i; |
| 442 | src = *j; |
| 443 | if (src == 0) { |
| 444 | CHECK_EQ(0, m.Call()); |
| 445 | } else if (src == -1 && dst == std::numeric_limits<int64_t>::min()) { |
| 446 | CHECK_EQ(-1, m.Call()); |
| 447 | } else { |
| 448 | CHECK_EQ(1, m.Call()); |
| 449 | CHECK_EQ(*i / *j, dst); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | TEST(RunCallInt64Mod) { |
| 456 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 457 | ExternalReference ref = ExternalReference::wasm_int64_mod(m.isolate()); |
| 458 | |
| 459 | int64_t dst; |
| 460 | int64_t src; |
| 461 | |
| 462 | Node* function = m.ExternalConstant(ref); |
| 463 | m.Return(m.CallCFunction2(MachineType::Int32(), MachineType::Pointer(), |
| 464 | MachineType::Pointer(), function, |
| 465 | m.PointerConstant(&dst), m.PointerConstant(&src))); |
| 466 | FOR_INT64_INPUTS(i) { |
| 467 | FOR_INT64_INPUTS(j) { |
| 468 | dst = *i; |
| 469 | src = *j; |
| 470 | if (src == 0) { |
| 471 | CHECK_EQ(0, m.Call()); |
| 472 | } else { |
| 473 | CHECK_EQ(1, m.Call()); |
| 474 | CHECK_EQ(*i % *j, dst); |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | TEST(RunCallUint64Div) { |
| 481 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 482 | ExternalReference ref = ExternalReference::wasm_uint64_div(m.isolate()); |
| 483 | |
| 484 | uint64_t dst; |
| 485 | uint64_t src; |
| 486 | |
| 487 | Node* function = m.ExternalConstant(ref); |
| 488 | m.Return(m.CallCFunction2(MachineType::Int32(), MachineType::Pointer(), |
| 489 | MachineType::Pointer(), function, |
| 490 | m.PointerConstant(&dst), m.PointerConstant(&src))); |
| 491 | FOR_UINT64_INPUTS(i) { |
| 492 | FOR_UINT64_INPUTS(j) { |
| 493 | dst = *i; |
| 494 | src = *j; |
| 495 | if (src == 0) { |
| 496 | CHECK_EQ(0, m.Call()); |
| 497 | } else { |
| 498 | CHECK_EQ(1, m.Call()); |
| 499 | CHECK_EQ(*i / *j, dst); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | TEST(RunCallUint64Mod) { |
| 506 | BufferedRawMachineAssemblerTester<int32_t> m; |
| 507 | ExternalReference ref = ExternalReference::wasm_uint64_mod(m.isolate()); |
| 508 | |
| 509 | uint64_t dst; |
| 510 | uint64_t src; |
| 511 | |
| 512 | Node* function = m.ExternalConstant(ref); |
| 513 | m.Return(m.CallCFunction2(MachineType::Int32(), MachineType::Pointer(), |
| 514 | MachineType::Pointer(), function, |
| 515 | m.PointerConstant(&dst), m.PointerConstant(&src))); |
| 516 | FOR_UINT64_INPUTS(i) { |
| 517 | FOR_UINT64_INPUTS(j) { |
| 518 | dst = *i; |
| 519 | src = *j; |
| 520 | if (src == 0) { |
| 521 | CHECK_EQ(0, m.Call()); |
| 522 | } else { |
| 523 | CHECK_EQ(1, m.Call()); |
| 524 | CHECK_EQ(*i % *j, dst); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | } // namespace compiler |
| 530 | } // namespace internal |
| 531 | } // namespace v8 |