Chromium Code Reviews

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

Issue 2313623002: MIPS: Implement MADD.S, MSUB, MADDF and MSUBF. (Closed)
Patch Set: The test as a template. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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...)
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 void run_madd_msub_maddf_msubf() {
5391 CcTest::InitializeVM();
5392 Isolate* isolate = CcTest::i_isolate();
5393 HandleScope scope(isolate);
5394 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
5395
5396 struct TestCase {
5397 T fr, fs, ft, fd_add, fd_sub;
5398 };
5399
5400 T x = std::sqrt(static_cast<T>(2.0));
5401 T y = std::sqrt(static_cast<T>(3.0));
5402 T z = std::sqrt(static_cast<T>(5.0));
5403 T x2 = 11.11, y2 = 22.22, z2 = 33.33;
5404 TestCase test_cases[] = {
5405 {x, y, z, 0.0, 0.0},
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 {-3.14, 0.2345, -123.000056, 0.0, 0.0},
5414 {7.3, -23.257, -357.1357, 0.0, 0.0},
5415 {x2, y2, z2, 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 };
5424
ivica.bogosavljevic 2016/09/12 12:39:52 I think we should avoid this std::is_same because
Ilija.Pavlovic1 2016/09/12 13:41:35 With using lambda functions we will get repeating
5425 if (std::is_same<T, float>::value) {
5426 __ lwc1(f4, MemOperand(a0, offsetof(TestCase, fr)));
5427 __ lwc1(f6, MemOperand(a0, offsetof(TestCase, fs)));
5428 __ lwc1(f8, MemOperand(a0, offsetof(TestCase, ft)));
5429 __ lwc1(f16, MemOperand(a0, offsetof(TestCase, fr)));
5430 } else if (std::is_same<T, double>::value) {
5431 __ ldc1(f4, MemOperand(a0, offsetof(TestCase, fr)));
5432 __ ldc1(f6, MemOperand(a0, offsetof(TestCase, fs)));
5433 __ ldc1(f8, MemOperand(a0, offsetof(TestCase, ft)));
5434 __ ldc1(f16, MemOperand(a0, offsetof(TestCase, fr)));
5435 }
5436
5437 if (IsMipsArchVariant(kMips32r2)) {
5438 if (std::is_same<T, float>::value) {
5439 __ madd_s(f10, f4, f6, f8);
5440 __ swc1(f10, MemOperand(a0, offsetof(TestCase, fd_add)));
5441 __ msub_s(f16, f4, f6, f8);
5442 __ swc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub)));
5443 } else if (std::is_same<T, double>::value) {
5444 __ madd_d(f10, f4, f6, f8);
5445 __ sdc1(f10, MemOperand(a0, offsetof(TestCase, fd_add)));
5446 __ msub_d(f16, f4, f6, f8);
5447 __ sdc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub)));
5448 }
5449 } else if (IsMipsArchVariant(kMips32r6)) {
5450 if (std::is_same<T, float>::value) {
5451 __ maddf_s(f4, f6, f8);
5452 __ swc1(f4, MemOperand(a0, offsetof(TestCase, fd_add)));
5453 __ msubf_s(f16, f6, f8);
5454 __ swc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub)));
5455 } else if (std::is_same<T, double>::value) {
5456 __ maddf_d(f4, f6, f8);
5457 __ sdc1(f4, MemOperand(a0, offsetof(TestCase, fd_add)));
5458 __ msubf_d(f16, f6, f8);
5459 __ sdc1(f16, MemOperand(a0, offsetof(TestCase, fd_sub)));
5460 }
5461 }
5462
5463 __ jr(ra);
5464 __ nop();
5465
5466 CodeDesc desc;
5467 assm.GetCode(&desc);
5468 Handle<Code> code = isolate->factory()->NewCode(
5469 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
5470 F3 f = FUNCTION_CAST<F3>(code->entry());
5471
5472 const size_t kTableLength = sizeof(test_cases) / sizeof(TestCase);
5473 TestCase tc;
5474 for (size_t i = 0; i < kTableLength; i++) {
5475 tc.fr = test_cases[i].fr;
5476 tc.fs = test_cases[i].fs;
5477 tc.ft = test_cases[i].ft;
5478
5479 (CALL_GENERATED_CODE(isolate, f, &tc, 0, 0, 0, 0));
5480
5481 T res_add = tc.fr + (tc.fs * tc.ft);
5482 T res_sub;
5483 if (IsMipsArchVariant(kMips32r2))
5484 res_sub = (tc.fs * tc.ft) - tc.fr;
5485 else if (IsMipsArchVariant(kMips32r6))
5486 res_sub = tc.fr - (tc.fs * tc.ft);
5487
5488 CHECK_EQ(tc.fd_add, res_add);
5489 CHECK_EQ(tc.fd_sub, res_sub);
5490 }
5491 }
5492
5493 TEST(madd_msub_maddf_msubf_s) { run_madd_msub_maddf_msubf<float>(); }
5494
5495 TEST(madd_msub_maddf_msubf_d) { run_madd_msub_maddf_msubf<double>(); }
5496
5389 #undef __ 5497 #undef __
OLDNEW

Powered by Google App Engine