| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 WasmName module_name = {"test", 4}; | 59 WasmName module_name = {"test", 4}; |
| 60 WasmName function_name = {nullptr, 0}; | 60 WasmName function_name = {nullptr, 0}; |
| 61 Handle<Code> code = CompileWasmToJSWrapper(isolate, module, jsfunc, sig, | 61 Handle<Code> code = CompileWasmToJSWrapper(isolate, module, jsfunc, sig, |
| 62 module_name, function_name); | 62 module_name, function_name); |
| 63 module->instance->function_code[index] = code; | 63 module->instance->function_code[index] = code; |
| 64 return index; | 64 return index; |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 uint32_t AddJSSelector(TestingModule* module, FunctionSig* sig, int which) { | 68 uint32_t AddJSSelector(TestingModule* module, FunctionSig* sig, int which) { |
| 69 const int kMaxParams = 8; | 69 const int kMaxParams = 11; |
| 70 static const char* formals[kMaxParams] = { | 70 static const char* formals[kMaxParams] = {"", |
| 71 "", "a", "a,b", "a,b,c", | 71 "a", |
| 72 "a,b,c,d", "a,b,c,d,e", "a,b,c,d,e,f", "a,b,c,d,e,f,g", | 72 "a,b", |
| 73 }; | 73 "a,b,c", |
| 74 "a,b,c,d", |
| 75 "a,b,c,d,e", |
| 76 "a,b,c,d,e,f", |
| 77 "a,b,c,d,e,f,g", |
| 78 "a,b,c,d,e,f,g,h", |
| 79 "a,b,c,d,e,f,g,h,i", |
| 80 "a,b,c,d,e,f,g,h,i,j"}; |
| 74 CHECK_LT(which, static_cast<int>(sig->parameter_count())); | 81 CHECK_LT(which, static_cast<int>(sig->parameter_count())); |
| 75 CHECK_LT(static_cast<int>(sig->parameter_count()), kMaxParams); | 82 CHECK_LT(static_cast<int>(sig->parameter_count()), kMaxParams); |
| 76 | 83 |
| 77 i::EmbeddedVector<char, 256> source; | 84 i::EmbeddedVector<char, 256> source; |
| 78 char param = 'a' + which; | 85 char param = 'a' + which; |
| 79 SNPrintF(source, "(function(%s) { return %c; })", | 86 SNPrintF(source, "(function(%s) { return %c; })", |
| 80 formals[sig->parameter_count()], param); | 87 formals[sig->parameter_count()], param); |
| 81 | 88 |
| 82 return AddJsFunction(module, sig, source.start()); | 89 return AddJsFunction(module, sig, source.start()); |
| 83 } | 90 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); | 173 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); |
| 167 | 174 |
| 168 EXPECT_CALL(2, jsfunc, 9, 0); | 175 EXPECT_CALL(2, jsfunc, 9, 0); |
| 169 EXPECT_CALL(3, jsfunc, 11, 0); | 176 EXPECT_CALL(3, jsfunc, 11, 0); |
| 170 EXPECT_CALL(6, jsfunc, 0x3F, 0); | 177 EXPECT_CALL(6, jsfunc, 0x3F, 0); |
| 171 | 178 |
| 172 USE(AddJsFunction); | 179 USE(AddJsFunction); |
| 173 } | 180 } |
| 174 | 181 |
| 175 | 182 |
| 176 #if !V8_TARGET_ARCH_ARM64 | |
| 177 // TODO(titzer): dynamic frame alignment on arm64 | |
| 178 TEST(Run_CallJS_Add_jswrapped) { | 183 TEST(Run_CallJS_Add_jswrapped) { |
| 179 TestSignatures sigs; | 184 TestSignatures sigs; |
| 180 TestingModule module; | 185 TestingModule module; |
| 181 WasmFunctionCompiler t(sigs.i_i(), &module); | 186 WasmFunctionCompiler t(sigs.i_i(), &module); |
| 182 uint32_t js_index = | 187 uint32_t js_index = |
| 183 AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })"); | 188 AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })"); |
| 184 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); | 189 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); |
| 185 | 190 |
| 186 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); | 191 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); |
| 187 | 192 |
| 188 EXPECT_CALL(101, jsfunc, 2, -8); | 193 EXPECT_CALL(101, jsfunc, 2, -8); |
| 189 EXPECT_CALL(199, jsfunc, 100, -1); | 194 EXPECT_CALL(199, jsfunc, 100, -1); |
| 190 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); | 195 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); |
| 191 } | 196 } |
| 192 #endif | |
| 193 | 197 |
| 194 | 198 |
| 195 void RunJSSelectTest(int which) { | 199 void RunJSSelectTest(int which) { |
| 196 #if !V8_TARGET_ARCH_ARM | |
| 197 // TODO(titzer): fix tests on arm and reenable | |
| 198 const int kMaxParams = 8; | 200 const int kMaxParams = 8; |
| 199 PredictableInputValues inputs(0x100); | 201 PredictableInputValues inputs(0x100); |
| 200 LocalType type = kAstF64; | 202 LocalType type = kAstF64; |
| 201 LocalType types[kMaxParams + 1] = {type, type, type, type, type, | 203 LocalType types[kMaxParams + 1] = {type, type, type, type, type, |
| 202 type, type, type, type}; | 204 type, type, type, type}; |
| 203 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { | 205 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { |
| 204 HandleScope scope(CcTest::InitIsolateOnce()); | 206 HandleScope scope(CcTest::InitIsolateOnce()); |
| 205 FunctionSig sig(1, num_params, types); | 207 FunctionSig sig(1, num_params, types); |
| 206 | 208 |
| 207 TestingModule module; | 209 TestingModule module; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 | 220 |
| 219 size_t end = code.size(); | 221 size_t end = code.size(); |
| 220 code.push_back(0); | 222 code.push_back(0); |
| 221 t.Build(&code[0], &code[end]); | 223 t.Build(&code[0], &code[end]); |
| 222 } | 224 } |
| 223 | 225 |
| 224 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); | 226 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); |
| 225 double expected = inputs.arg_d(which); | 227 double expected = inputs.arg_d(which); |
| 226 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); | 228 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); |
| 227 } | 229 } |
| 228 #endif | |
| 229 } | 230 } |
| 230 | 231 |
| 231 | 232 |
| 232 TEST(Run_JSSelect_0) { RunJSSelectTest(0); } | 233 TEST(Run_JSSelect_0) { RunJSSelectTest(0); } |
| 233 | 234 |
| 234 TEST(Run_JSSelect_1) { RunJSSelectTest(1); } | 235 TEST(Run_JSSelect_1) { RunJSSelectTest(1); } |
| 235 | 236 |
| 236 TEST(Run_JSSelect_2) { RunJSSelectTest(2); } | 237 TEST(Run_JSSelect_2) { RunJSSelectTest(2); } |
| 237 | 238 |
| 238 TEST(Run_JSSelect_3) { RunJSSelectTest(3); } | 239 TEST(Run_JSSelect_3) { RunJSSelectTest(3); } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 TEST(Run_WASMSelect_5) { RunWASMSelectTest(5); } | 292 TEST(Run_WASMSelect_5) { RunWASMSelectTest(5); } |
| 292 | 293 |
| 293 TEST(Run_WASMSelect_6) { RunWASMSelectTest(6); } | 294 TEST(Run_WASMSelect_6) { RunWASMSelectTest(6); } |
| 294 | 295 |
| 295 TEST(Run_WASMSelect_7) { RunWASMSelectTest(7); } | 296 TEST(Run_WASMSelect_7) { RunWASMSelectTest(7); } |
| 296 | 297 |
| 297 | 298 |
| 298 void RunWASMSelectAlignTest(int num_args, int num_params) { | 299 void RunWASMSelectAlignTest(int num_args, int num_params) { |
| 299 PredictableInputValues inputs(0x300); | 300 PredictableInputValues inputs(0x300); |
| 300 Isolate* isolate = CcTest::InitIsolateOnce(); | 301 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 301 const int kMaxParams = 4; | 302 const int kMaxParams = 10; |
| 302 DCHECK_LE(num_args, kMaxParams); | 303 DCHECK_LE(num_args, kMaxParams); |
| 303 LocalType type = kAstF64; | 304 LocalType type = kAstF64; |
| 304 LocalType types[kMaxParams + 1] = {type, type, type, type, type}; | 305 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type, |
| 306 type, type, type, type, type}; |
| 305 FunctionSig sig(1, num_params, types); | 307 FunctionSig sig(1, num_params, types); |
| 306 | 308 |
| 307 for (int which = 0; which < num_params; which++) { | 309 for (int which = 0; which < num_params; which++) { |
| 308 TestingModule module; | 310 TestingModule module; |
| 309 WasmFunctionCompiler t(&sig, &module); | 311 WasmFunctionCompiler t(&sig, &module); |
| 310 BUILD(t, WASM_GET_LOCAL(which)); | 312 BUILD(t, WASM_GET_LOCAL(which)); |
| 311 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); | 313 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); |
| 312 | 314 |
| 313 Handle<Object> args[] = { | 315 Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)), |
| 314 isolate->factory()->NewNumber(inputs.arg_d(0)), | 316 isolate->factory()->NewNumber(inputs.arg_d(1)), |
| 315 isolate->factory()->NewNumber(inputs.arg_d(1)), | 317 isolate->factory()->NewNumber(inputs.arg_d(2)), |
| 316 isolate->factory()->NewNumber(inputs.arg_d(2)), | 318 isolate->factory()->NewNumber(inputs.arg_d(3)), |
| 317 isolate->factory()->NewNumber(inputs.arg_d(3)), | 319 isolate->factory()->NewNumber(inputs.arg_d(4)), |
| 318 }; | 320 isolate->factory()->NewNumber(inputs.arg_d(5)), |
| 321 isolate->factory()->NewNumber(inputs.arg_d(6)), |
| 322 isolate->factory()->NewNumber(inputs.arg_d(7)), |
| 323 isolate->factory()->NewNumber(inputs.arg_d(8)), |
| 324 isolate->factory()->NewNumber(inputs.arg_d(9))}; |
| 319 | 325 |
| 320 double nan = std::numeric_limits<double>::quiet_NaN(); | 326 double nan = std::numeric_limits<double>::quiet_NaN(); |
| 321 double expected = which < num_args ? inputs.arg_d(which) : nan; | 327 double expected = which < num_args ? inputs.arg_d(which) : nan; |
| 322 EXPECT_CALL(expected, jsfunc, args, num_args); | 328 EXPECT_CALL(expected, jsfunc, args, num_args); |
| 323 } | 329 } |
| 324 } | 330 } |
| 325 | 331 |
| 326 | 332 |
| 327 TEST(Run_WASMSelectAlign_0) { | 333 TEST(Run_WASMSelectAlign_0) { |
| 328 RunWASMSelectAlignTest(0, 1); | 334 RunWASMSelectAlignTest(0, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 346 RunWASMSelectAlignTest(3, 3); | 352 RunWASMSelectAlignTest(3, 3); |
| 347 RunWASMSelectAlignTest(3, 4); | 353 RunWASMSelectAlignTest(3, 4); |
| 348 } | 354 } |
| 349 | 355 |
| 350 | 356 |
| 351 TEST(Run_WASMSelectAlign_4) { | 357 TEST(Run_WASMSelectAlign_4) { |
| 352 RunWASMSelectAlignTest(4, 3); | 358 RunWASMSelectAlignTest(4, 3); |
| 353 RunWASMSelectAlignTest(4, 4); | 359 RunWASMSelectAlignTest(4, 4); |
| 354 } | 360 } |
| 355 | 361 |
| 362 TEST(Run_WASMSelectAlign_7) { |
| 363 RunWASMSelectAlignTest(7, 5); |
| 364 RunWASMSelectAlignTest(7, 6); |
| 365 RunWASMSelectAlignTest(7, 7); |
| 366 } |
| 367 |
| 368 TEST(Run_WASMSelectAlign_8) { |
| 369 RunWASMSelectAlignTest(8, 5); |
| 370 RunWASMSelectAlignTest(8, 6); |
| 371 RunWASMSelectAlignTest(8, 7); |
| 372 RunWASMSelectAlignTest(8, 8); |
| 373 } |
| 374 |
| 375 TEST(Run_WASMSelectAlign_9) { |
| 376 RunWASMSelectAlignTest(9, 6); |
| 377 RunWASMSelectAlignTest(9, 7); |
| 378 RunWASMSelectAlignTest(9, 8); |
| 379 RunWASMSelectAlignTest(9, 9); |
| 380 } |
| 381 |
| 382 TEST(Run_WASMSelectAlign_10) { |
| 383 RunWASMSelectAlignTest(10, 7); |
| 384 RunWASMSelectAlignTest(10, 8); |
| 385 RunWASMSelectAlignTest(10, 9); |
| 386 RunWASMSelectAlignTest(10, 10); |
| 387 } |
| 356 | 388 |
| 357 void RunJSSelectAlignTest(int num_args, int num_params) { | 389 void RunJSSelectAlignTest(int num_args, int num_params) { |
| 358 PredictableInputValues inputs(0x400); | 390 PredictableInputValues inputs(0x400); |
| 359 Isolate* isolate = CcTest::InitIsolateOnce(); | 391 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 360 Factory* factory = isolate->factory(); | 392 Factory* factory = isolate->factory(); |
| 361 const int kMaxParams = 4; | 393 const int kMaxParams = 10; |
| 362 CHECK_LE(num_args, kMaxParams); | 394 CHECK_LE(num_args, kMaxParams); |
| 363 CHECK_LE(num_params, kMaxParams); | 395 CHECK_LE(num_params, kMaxParams); |
| 364 LocalType type = kAstF64; | 396 LocalType type = kAstF64; |
| 365 LocalType types[kMaxParams + 1] = {type, type, type, type, type}; | 397 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type, |
| 398 type, type, type, type, type}; |
| 366 FunctionSig sig(1, num_params, types); | 399 FunctionSig sig(1, num_params, types); |
| 367 | 400 |
| 368 // Build the calling code. | 401 // Build the calling code. |
| 369 std::vector<byte> code; | 402 std::vector<byte> code; |
| 370 ADD_CODE(code, kExprCallFunction, 0); | 403 ADD_CODE(code, kExprCallFunction, 0); |
| 371 | 404 |
| 372 for (int i = 0; i < num_params; i++) { | 405 for (int i = 0; i < num_params; i++) { |
| 373 ADD_CODE(code, WASM_GET_LOCAL(i)); | 406 ADD_CODE(code, WASM_GET_LOCAL(i)); |
| 374 } | 407 } |
| 375 | 408 |
| 376 size_t end = code.size(); | 409 size_t end = code.size(); |
| 377 code.push_back(0); | 410 code.push_back(0); |
| 378 | 411 |
| 379 // Call different select JS functions. | 412 // Call different select JS functions. |
| 380 for (int which = 0; which < num_params; which++) { | 413 for (int which = 0; which < num_params; which++) { |
| 381 HandleScope scope(isolate); | 414 HandleScope scope(isolate); |
| 382 TestingModule module; | 415 TestingModule module; |
| 383 uint32_t js_index = AddJSSelector(&module, &sig, which); | 416 uint32_t js_index = AddJSSelector(&module, &sig, which); |
| 384 CHECK_EQ(0, js_index); | 417 CHECK_EQ(0, js_index); |
| 385 WasmFunctionCompiler t(&sig, &module); | 418 WasmFunctionCompiler t(&sig, &module); |
| 386 t.Build(&code[0], &code[end]); | 419 t.Build(&code[0], &code[end]); |
| 387 | 420 |
| 388 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); | 421 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd()); |
| 389 | 422 |
| 390 Handle<Object> args[] = { | 423 Handle<Object> args[] = { |
| 391 factory->NewNumber(inputs.arg_d(0)), | 424 factory->NewNumber(inputs.arg_d(0)), |
| 392 factory->NewNumber(inputs.arg_d(1)), | 425 factory->NewNumber(inputs.arg_d(1)), |
| 393 factory->NewNumber(inputs.arg_d(2)), | 426 factory->NewNumber(inputs.arg_d(2)), |
| 394 factory->NewNumber(inputs.arg_d(3)), | 427 factory->NewNumber(inputs.arg_d(3)), |
| 428 factory->NewNumber(inputs.arg_d(4)), |
| 429 factory->NewNumber(inputs.arg_d(5)), |
| 430 factory->NewNumber(inputs.arg_d(6)), |
| 431 factory->NewNumber(inputs.arg_d(7)), |
| 432 factory->NewNumber(inputs.arg_d(8)), |
| 433 factory->NewNumber(inputs.arg_d(9)), |
| 395 }; | 434 }; |
| 396 | 435 |
| 397 double nan = std::numeric_limits<double>::quiet_NaN(); | 436 double nan = std::numeric_limits<double>::quiet_NaN(); |
| 398 double expected = which < num_args ? inputs.arg_d(which) : nan; | 437 double expected = which < num_args ? inputs.arg_d(which) : nan; |
| 399 EXPECT_CALL(expected, jsfunc, args, num_args); | 438 EXPECT_CALL(expected, jsfunc, args, num_args); |
| 400 } | 439 } |
| 401 } | 440 } |
| 402 | 441 |
| 403 | 442 |
| 404 TEST(Run_JSSelectAlign_0) { | 443 TEST(Run_JSSelectAlign_0) { |
| 405 RunJSSelectAlignTest(0, 1); | 444 RunJSSelectAlignTest(0, 1); |
| 406 RunJSSelectAlignTest(0, 2); | 445 RunJSSelectAlignTest(0, 2); |
| 407 } | 446 } |
| 408 | 447 |
| 448 TEST(Run_JSSelectAlign_1) { |
| 449 RunJSSelectAlignTest(1, 2); |
| 450 RunJSSelectAlignTest(1, 3); |
| 451 } |
| 409 | 452 |
| 410 TEST(Run_JSSelectAlign_2) { | 453 TEST(Run_JSSelectAlign_2) { |
| 411 RunJSSelectAlignTest(2, 3); | 454 RunJSSelectAlignTest(2, 3); |
| 412 RunJSSelectAlignTest(2, 4); | 455 RunJSSelectAlignTest(2, 4); |
| 413 } | 456 } |
| 414 | 457 |
| 458 TEST(Run_JSSelectAlign_3) { |
| 459 RunJSSelectAlignTest(3, 3); |
| 460 RunJSSelectAlignTest(3, 4); |
| 461 } |
| 415 | 462 |
| 416 TEST(Run_JSSelectAlign_4) { | 463 TEST(Run_JSSelectAlign_4) { |
| 417 RunJSSelectAlignTest(4, 3); | 464 RunJSSelectAlignTest(4, 3); |
| 418 RunJSSelectAlignTest(4, 4); | 465 RunJSSelectAlignTest(4, 4); |
| 419 } | 466 } |
| 420 | 467 |
| 421 | 468 TEST(Run_JSSelectAlign_7) { |
| 422 #if !V8_TARGET_ARCH_ARM64 | 469 RunJSSelectAlignTest(7, 3); |
| 423 // TODO(titzer): dynamic frame alignment on arm64 | 470 RunJSSelectAlignTest(7, 4); |
| 424 TEST(Run_JSSelectAlign_1) { | 471 RunJSSelectAlignTest(7, 4); |
| 425 RunJSSelectAlignTest(1, 2); | 472 RunJSSelectAlignTest(7, 4); |
| 426 RunJSSelectAlignTest(1, 3); | |
| 427 } | 473 } |
| 428 | 474 |
| 475 TEST(Run_JSSelectAlign_8) { |
| 476 RunJSSelectAlignTest(8, 5); |
| 477 RunJSSelectAlignTest(8, 6); |
| 478 RunJSSelectAlignTest(8, 7); |
| 479 RunJSSelectAlignTest(8, 8); |
| 480 } |
| 429 | 481 |
| 430 TEST(Run_JSSelectAlign_3) { | 482 TEST(Run_JSSelectAlign_9) { |
| 431 RunJSSelectAlignTest(3, 3); | 483 RunJSSelectAlignTest(9, 6); |
| 432 RunJSSelectAlignTest(3, 4); | 484 RunJSSelectAlignTest(9, 7); |
| 485 RunJSSelectAlignTest(9, 8); |
| 486 RunJSSelectAlignTest(9, 9); |
| 433 } | 487 } |
| 434 #endif | 488 |
| 489 TEST(Run_JSSelectAlign_10) { |
| 490 RunJSSelectAlignTest(10, 7); |
| 491 RunJSSelectAlignTest(10, 8); |
| 492 RunJSSelectAlignTest(10, 9); |
| 493 RunJSSelectAlignTest(10, 10); |
| 494 } |
| OLD | NEW |