OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 #endif | 299 #endif |
300 F1 f = FUNCTION_CAST<F1>(code->entry()); | 300 F1 f = FUNCTION_CAST<F1>(code->entry()); |
301 for (int i = 0; i < kNumCases; ++i) { | 301 for (int i = 0; i < kNumCases; ++i) { |
302 int64_t res = reinterpret_cast<int64_t>( | 302 int64_t res = reinterpret_cast<int64_t>( |
303 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); | 303 CALL_GENERATED_CODE(isolate, f, i, 0, 0, 0, 0)); |
304 ::printf("f(%d) = %" PRId64 "\n", i, res); | 304 ::printf("f(%d) = %" PRId64 "\n", i, res); |
305 CHECK_EQ(values[i], res); | 305 CHECK_EQ(values[i], res); |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
| 309 |
| 310 static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) { |
| 311 Isolate* isolate = CcTest::i_isolate(); |
| 312 HandleScope scope(isolate); |
| 313 MacroAssembler assembler(isolate, nullptr, 0, |
| 314 v8::internal::CodeObjectRequired::kYes); |
| 315 MacroAssembler* masm = &assembler; |
| 316 |
| 317 __ Lsa(v0, a0, a1, sa); |
| 318 __ jr(ra); |
| 319 __ nop(); |
| 320 |
| 321 CodeDesc desc; |
| 322 assembler.GetCode(&desc); |
| 323 Handle<Code> code = isolate->factory()->NewCode( |
| 324 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 325 |
| 326 F1 f = FUNCTION_CAST<F1>(code->entry()); |
| 327 |
| 328 uint64_t res = reinterpret_cast<uint64_t>( |
| 329 CALL_GENERATED_CODE(isolate, f, rt, rs, 0, 0, 0)); |
| 330 |
| 331 return res; |
| 332 } |
| 333 |
| 334 |
| 335 TEST(Lsa) { |
| 336 CcTest::InitializeVM(); |
| 337 struct TestCaseLsa { |
| 338 int32_t rt; |
| 339 int32_t rs; |
| 340 uint8_t sa; |
| 341 uint64_t expected_res; |
| 342 }; |
| 343 |
| 344 struct TestCaseLsa tc[] = {// rt, rs, sa, expected_res |
| 345 {0x4, 0x1, 1, 0x6}, |
| 346 {0x4, 0x1, 2, 0x8}, |
| 347 {0x4, 0x1, 3, 0xc}, |
| 348 {0x4, 0x1, 4, 0x14}, |
| 349 {0x4, 0x1, 5, 0x24}, |
| 350 {0x0, 0x1, 1, 0x2}, |
| 351 {0x0, 0x1, 2, 0x4}, |
| 352 {0x0, 0x1, 3, 0x8}, |
| 353 {0x0, 0x1, 4, 0x10}, |
| 354 {0x0, 0x1, 5, 0x20}, |
| 355 {0x4, 0x0, 1, 0x4}, |
| 356 {0x4, 0x0, 2, 0x4}, |
| 357 {0x4, 0x0, 3, 0x4}, |
| 358 {0x4, 0x0, 4, 0x4}, |
| 359 {0x4, 0x0, 5, 0x4}, |
| 360 |
| 361 // Shift overflow. |
| 362 {0x4, INT32_MAX, 1, 0x2}, |
| 363 {0x4, INT32_MAX >> 1, 2, 0x0}, |
| 364 {0x4, INT32_MAX >> 2, 3, 0xfffffffffffffffc}, |
| 365 {0x4, INT32_MAX >> 3, 4, 0xfffffffffffffff4}, |
| 366 {0x4, INT32_MAX >> 4, 5, 0xffffffffffffffe4}, |
| 367 |
| 368 // Signed addition overflow. |
| 369 {INT32_MAX - 1, 0x1, 1, 0xffffffff80000000}, |
| 370 {INT32_MAX - 3, 0x1, 2, 0xffffffff80000000}, |
| 371 {INT32_MAX - 7, 0x1, 3, 0xffffffff80000000}, |
| 372 {INT32_MAX - 15, 0x1, 4, 0xffffffff80000000}, |
| 373 {INT32_MAX - 31, 0x1, 5, 0xffffffff80000000}, |
| 374 |
| 375 // Addition overflow. |
| 376 {-2, 0x1, 1, 0x0}, |
| 377 {-4, 0x1, 2, 0x0}, |
| 378 {-8, 0x1, 3, 0x0}, |
| 379 {-16, 0x1, 4, 0x0}, |
| 380 {-32, 0x1, 5, 0x0}}; |
| 381 |
| 382 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
| 383 for (size_t i = 0; i < nr_test_cases; ++i) { |
| 384 uint64_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); |
| 385 PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Lsa(v0, %x, %x, %hhu)\n", |
| 386 tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa); |
| 387 CHECK_EQ(tc[i].expected_res, res); |
| 388 } |
| 389 } |
| 390 |
| 391 |
| 392 static uint64_t run_dlsa(uint64_t rt, uint64_t rs, int8_t sa) { |
| 393 Isolate* isolate = CcTest::i_isolate(); |
| 394 HandleScope scope(isolate); |
| 395 MacroAssembler assembler(isolate, nullptr, 0, |
| 396 v8::internal::CodeObjectRequired::kYes); |
| 397 MacroAssembler* masm = &assembler; |
| 398 |
| 399 __ Dlsa(v0, a0, a1, sa); |
| 400 __ jr(ra); |
| 401 __ nop(); |
| 402 |
| 403 CodeDesc desc; |
| 404 assembler.GetCode(&desc); |
| 405 Handle<Code> code = isolate->factory()->NewCode( |
| 406 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 407 |
| 408 ::F f = FUNCTION_CAST<::F>(code->entry()); |
| 409 |
| 410 uint64_t res = reinterpret_cast<uint64_t>( |
| 411 CALL_GENERATED_CODE(isolate, f, rt, rs, 0, 0, 0)); |
| 412 |
| 413 return res; |
| 414 } |
| 415 |
| 416 |
| 417 TEST(Dlsa) { |
| 418 CcTest::InitializeVM(); |
| 419 struct TestCaseLsa { |
| 420 int64_t rt; |
| 421 int64_t rs; |
| 422 uint8_t sa; |
| 423 uint64_t expected_res; |
| 424 }; |
| 425 |
| 426 struct TestCaseLsa tc[] = {// rt, rs, sa, expected_res |
| 427 {0x4, 0x1, 1, 0x6}, |
| 428 {0x4, 0x1, 2, 0x8}, |
| 429 {0x4, 0x1, 3, 0xc}, |
| 430 {0x4, 0x1, 4, 0x14}, |
| 431 {0x4, 0x1, 5, 0x24}, |
| 432 {0x0, 0x1, 1, 0x2}, |
| 433 {0x0, 0x1, 2, 0x4}, |
| 434 {0x0, 0x1, 3, 0x8}, |
| 435 {0x0, 0x1, 4, 0x10}, |
| 436 {0x0, 0x1, 5, 0x20}, |
| 437 {0x4, 0x0, 1, 0x4}, |
| 438 {0x4, 0x0, 2, 0x4}, |
| 439 {0x4, 0x0, 3, 0x4}, |
| 440 {0x4, 0x0, 4, 0x4}, |
| 441 {0x4, 0x0, 5, 0x4}, |
| 442 |
| 443 // Shift overflow. |
| 444 {0x4, INT64_MAX, 1, 0x2}, |
| 445 {0x4, INT64_MAX >> 1, 2, 0x0}, |
| 446 {0x4, INT64_MAX >> 2, 3, 0xfffffffffffffffc}, |
| 447 {0x4, INT64_MAX >> 3, 4, 0xfffffffffffffff4}, |
| 448 {0x4, INT64_MAX >> 4, 5, 0xffffffffffffffe4}, |
| 449 |
| 450 // Signed addition overflow. |
| 451 {INT64_MAX - 1, 0x1, 1, 0x8000000000000000}, |
| 452 {INT64_MAX - 3, 0x1, 2, 0x8000000000000000}, |
| 453 {INT64_MAX - 7, 0x1, 3, 0x8000000000000000}, |
| 454 {INT64_MAX - 15, 0x1, 4, 0x8000000000000000}, |
| 455 {INT64_MAX - 31, 0x1, 5, 0x8000000000000000}, |
| 456 |
| 457 // Addition overflow. |
| 458 {-2, 0x1, 1, 0x0}, |
| 459 {-4, 0x1, 2, 0x0}, |
| 460 {-8, 0x1, 3, 0x0}, |
| 461 {-16, 0x1, 4, 0x0}, |
| 462 {-32, 0x1, 5, 0x0}}; |
| 463 |
| 464 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
| 465 for (size_t i = 0; i < nr_test_cases; ++i) { |
| 466 uint64_t res = run_dlsa(tc[i].rt, tc[i].rs, tc[i].sa); |
| 467 PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Dlsa(v0, %" PRIx64 ", %" PRIx64 |
| 468 ", %hhu)\n", |
| 469 tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa); |
| 470 CHECK_EQ(tc[i].expected_res, res); |
| 471 } |
| 472 } |
| 473 |
309 #undef __ | 474 #undef __ |
OLD | NEW |