Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: test/cctest/test-assembler-mips.cc

Issue 2313623002: MIPS: Implement MADD.S, MSUB, MADDF and MSUBF. (Closed)
Patch Set: Redesign implementation of the test. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 5368 matching lines...) Expand 10 before | Expand all | Expand 10 after
5379 assm.GetCode(&desc); 5379 assm.GetCode(&desc);
5380 Handle<Code> code = isolate->factory()->NewCode( 5380 Handle<Code> code = isolate->factory()->NewCode(
5381 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 5381 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5382 F2 f = FUNCTION_CAST<F2>(code->entry()); 5382 F2 f = FUNCTION_CAST<F2>(code->entry());
5383 5383
5384 int32_t res = reinterpret_cast<int32_t>( 5384 int32_t res = reinterpret_cast<int32_t>(
5385 CALL_GENERATED_CODE(isolate, f, 42, 42, 0, 0, 0)); 5385 CALL_GENERATED_CODE(isolate, f, 42, 42, 0, 0, 0));
5386 CHECK_EQ(res, 0); 5386 CHECK_EQ(res, 0);
5387 } 5387 }
5388 5388
5389 template <class T>
5390 struct TestCaseMaddMsub {
5391 T fr, fs, ft, fd_add, fd_sub;
5392 };
5393
5394 template <typename T, typename F>
5395 void helper_madd_msub_maddf_msubf(F func) {
5396 CcTest::InitializeVM();
5397 Isolate* isolate = CcTest::i_isolate();
5398 HandleScope scope(isolate);
5399 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
5400
5401 T x = std::sqrt(static_cast<T>(2.0));
5402 T y = std::sqrt(static_cast<T>(3.0));
5403 T z = std::sqrt(static_cast<T>(5.0));
5404 T x2 = 11.11, y2 = 22.22, z2 = 33.33;
5405 TestCaseMaddMsub<T> test_cases[] = {
5406 {x, y, z, 0.0, 0.0},
5407 {x, y, -z, 0.0, 0.0},
5408 {x, -y, z, 0.0, 0.0},
5409 {x, -y, -z, 0.0, 0.0},
5410 {-x, y, z, 0.0, 0.0},
5411 {-x, y, -z, 0.0, 0.0},
5412 {-x, -y, z, 0.0, 0.0},
5413 {-x, -y, -z, 0.0, 0.0},
5414 {-3.14, 0.2345, -123.000056, 0.0, 0.0},
5415 {7.3, -23.257, -357.1357, 0.0, 0.0},
5416 {x2, y2, z2, 0.0, 0.0},
5417 {x2, y2, -z2, 0.0, 0.0},
5418 {x2, -y2, z2, 0.0, 0.0},
5419 {x2, -y2, -z2, 0.0, 0.0},
5420 {-x2, y2, z2, 0.0, 0.0},
5421 {-x2, y2, -z2, 0.0, 0.0},
5422 {-x2, -y2, z2, 0.0, 0.0},
5423 {-x2, -y2, -z2, 0.0, 0.0},
5424 };
5425
5426 if (std::is_same<T, float>::value) {
ivica.bogosavljevic 2016/09/13 07:44:20 Could you use if (sizeof(T) == 4) else if (sizeof(
balazs.kilvady 2016/09/13 10:20:32 Why would that be better? T can be float or double
Ilija.Pavlovic1 2016/09/13 12:57:57 These kind of checkings will remain in the code.
balazs.kilvady 2016/09/14 09:12:01 You could add else { UNREACHABLE(); } if you don't
5427 __ lwc1(f4, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fr)));
5428 __ lwc1(f6, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fs)));
5429 __ lwc1(f8, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, ft)));
5430 __ lwc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fr)));
5431 } else if (std::is_same<T, double>::value) {
5432 __ ldc1(f4, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fr)));
5433 __ ldc1(f6, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fs)));
5434 __ ldc1(f8, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, ft)));
5435 __ ldc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<T>, fr)));
5436 }
5437
5438 func(assm);
5439
5440 __ jr(ra);
5441 __ nop();
5442
5443 CodeDesc desc;
5444 assm.GetCode(&desc);
5445 Handle<Code> code = isolate->factory()->NewCode(
5446 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5447 F3 f = FUNCTION_CAST<F3>(code->entry());
5448
5449 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCaseMaddMsub<T>);
5450 TestCaseMaddMsub<T> tc;
5451 for (size_t i = 0; i < kTableLength; i++) {
5452 tc.fr = test_cases[i].fr;
5453 tc.fs = test_cases[i].fs;
5454 tc.ft = test_cases[i].ft;
5455
5456 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0));
5457
5458 T res_add = tc.fr + (tc.fs * tc.ft);
5459 T res_sub;
5460 if (IsMipsArchVariant(kMips32r2))
ivica.bogosavljevic 2016/09/13 07:44:20 You need to add braces {} here
balazs.kilvady 2016/09/13 10:20:32 I agree. And bellow and for all the multi line `if
Ilija.Pavlovic1 2016/09/13 12:57:57 Done.
5461 res_sub = (tc.fs * tc.ft) - tc.fr;
5462 else if (IsMipsArchVariant(kMips32r6))
5463 res_sub = tc.fr - (tc.fs * tc.ft);
5464
5465 CHECK_EQ(tc.fd_add, res_add);
5466 CHECK_EQ(tc.fd_sub, res_sub);
5467 }
5468 }
5469
5470 TEST(madd_msub_s) {
5471 if (!IsMipsArchVariant(kMips32r2)) return;
5472 helper_madd_msub_maddf_msubf<float>([](MacroAssembler& assm) {
5473 __ madd_s(f10, f4, f6, f8);
5474 __ swc1(f10, MemOperand(a0, offsetof(TestCaseMaddMsub<float>, fd_add)));
5475 __ msub_s(f16, f4, f6, f8);
5476 __ swc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<float>, fd_sub)));
5477 });
5478 }
5479
5480 TEST(madd_msub_d) {
5481 if (!IsMipsArchVariant(kMips32r2)) return;
5482 helper_madd_msub_maddf_msubf<double>([](MacroAssembler& assm) {
5483 __ madd_d(f10, f4, f6, f8);
5484 __ sdc1(f10, MemOperand(a0, offsetof(TestCaseMaddMsub<double>, fd_add)));
5485 __ msub_d(f16, f4, f6, f8);
5486 __ sdc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<double>, fd_sub)));
5487 });
5488 }
5489
5490 TEST(maddf_msubf_s) {
5491 if (!IsMipsArchVariant(kMips32r6)) return;
5492 helper_madd_msub_maddf_msubf<float>([](MacroAssembler& assm) {
5493 __ maddf_s(f4, f6, f8);
5494 __ swc1(f4, MemOperand(a0, offsetof(TestCaseMaddMsub<float>, fd_add)));
5495 __ msubf_s(f16, f6, f8);
5496 __ swc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<float>, fd_sub)));
5497 });
5498 }
5499
5500 TEST(maddf_msubf_d) {
5501 if (!IsMipsArchVariant(kMips32r6)) return;
5502 helper_madd_msub_maddf_msubf<double>([](MacroAssembler& assm) {
5503 __ maddf_d(f4, f6, f8);
5504 __ sdc1(f4, MemOperand(a0, offsetof(TestCaseMaddMsub<double>, fd_add)));
5505 __ msubf_d(f16, f6, f8);
5506 __ sdc1(f16, MemOperand(a0, offsetof(TestCaseMaddMsub<double>, fd_sub)));
5507 });
5508 }
5509
5389 #undef __ 5510 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698