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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 382 |
383 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); | 383 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); |
384 for (size_t i = 0; i < nr_test_cases; ++i) { | 384 for (size_t i = 0; i < nr_test_cases; ++i) { |
385 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); | 385 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); |
386 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, | 386 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, |
387 tc[i].rt, tc[i].rs, tc[i].sa); | 387 tc[i].rt, tc[i].rs, tc[i].sa); |
388 CHECK_EQ(tc[i].expected_res, res); | 388 CHECK_EQ(tc[i].expected_res, res); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
| 392 static const std::vector<uint32_t> uint32_test_values() { |
| 393 static const uint32_t kValues[] = {0x00000000, 0x00000001, 0x00ffff00, |
| 394 0x7fffffff, 0x80000000, 0x80000001, |
| 395 0x80ffff00, 0x8fffffff, 0xffffffff}; |
| 396 return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
| 397 } |
| 398 |
| 399 static const std::vector<int32_t> int32_test_values() { |
| 400 static const int32_t kValues[] = { |
| 401 static_cast<int32_t>(0x00000000), static_cast<int32_t>(0x00000001), |
| 402 static_cast<int32_t>(0x00ffff00), static_cast<int32_t>(0x7fffffff), |
| 403 static_cast<int32_t>(0x80000000), static_cast<int32_t>(0x80000001), |
| 404 static_cast<int32_t>(0x80ffff00), static_cast<int32_t>(0x8fffffff), |
| 405 static_cast<int32_t>(0xffffffff)}; |
| 406 return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
| 407 } |
| 408 |
| 409 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... } |
| 410 #define FOR_INPUTS(ctype, itype, var) \ |
| 411 std::vector<ctype> var##_vec = itype##_test_values(); \ |
| 412 for (std::vector<ctype>::iterator var = var##_vec.begin(); \ |
| 413 var != var##_vec.end(); ++var) |
| 414 |
| 415 #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var) |
| 416 #define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var) |
| 417 |
| 418 template <typename RET_TYPE, typename IN_TYPE, typename Func> |
| 419 RET_TYPE run_Cvt(IN_TYPE x, Func GenerateConvertInstructionFunc) { |
| 420 typedef RET_TYPE (*F_CVT)(IN_TYPE x0, int x1, int x2, int x3, int x4); |
| 421 |
| 422 Isolate* isolate = CcTest::i_isolate(); |
| 423 HandleScope scope(isolate); |
| 424 MacroAssembler assm(isolate, nullptr, 0, |
| 425 v8::internal::CodeObjectRequired::kYes); |
| 426 MacroAssembler* masm = &assm; |
| 427 |
| 428 __ mtc1(a0, f4); |
| 429 GenerateConvertInstructionFunc(masm); |
| 430 __ mfc1(v0, f2); |
| 431 __ jr(ra); |
| 432 __ nop(); |
| 433 |
| 434 CodeDesc desc; |
| 435 assm.GetCode(&desc); |
| 436 Handle<Code> code = isolate->factory()->NewCode( |
| 437 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 438 |
| 439 F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); |
| 440 |
| 441 return reinterpret_cast<RET_TYPE>( |
| 442 CALL_GENERATED_CODE(isolate, f, x, 0, 0, 0, 0)); |
| 443 } |
| 444 |
| 445 TEST(cvt_s_w_Trunc_uw_s) { |
| 446 CcTest::InitializeVM(); |
| 447 FOR_UINT32_INPUTS(i) { |
| 448 uint32_t input = *i; |
| 449 CHECK_EQ(static_cast<float>(input), |
| 450 run_Cvt<uint32_t>(input, [](MacroAssembler* masm) { |
| 451 __ cvt_s_w(f0, f4); |
| 452 __ Trunc_uw_s(f2, f0, f1); |
| 453 })); |
| 454 } |
| 455 } |
| 456 |
| 457 TEST(cvt_d_w_Trunc_w_d) { |
| 458 CcTest::InitializeVM(); |
| 459 FOR_INT32_INPUTS(i) { |
| 460 int32_t input = *i; |
| 461 CHECK_EQ(static_cast<double>(input), |
| 462 run_Cvt<int32_t>(input, [](MacroAssembler* masm) { |
| 463 __ cvt_d_w(f0, f4); |
| 464 __ Trunc_w_d(f2, f0); |
| 465 })); |
| 466 } |
| 467 } |
| 468 |
392 #undef __ | 469 #undef __ |
OLD | NEW |