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

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

Issue 1628453002: MIPS: Use PC realitive instructions on r6. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 MacroAssembler assembler(isolate, nullptr, 0, 272 MacroAssembler assembler(isolate, nullptr, 0,
273 v8::internal::CodeObjectRequired::kYes); 273 v8::internal::CodeObjectRequired::kYes);
274 MacroAssembler* masm = &assembler; 274 MacroAssembler* masm = &assembler;
275 275
276 const int kNumCases = 512; 276 const int kNumCases = 512;
277 int values[kNumCases]; 277 int values[kNumCases];
278 isolate->random_number_generator()->NextBytes(values, sizeof(values)); 278 isolate->random_number_generator()->NextBytes(values, sizeof(values));
279 Label labels[kNumCases]; 279 Label labels[kNumCases];
280 Label done; 280 Label done;
281 281
282 __ addiu(sp, sp, -4); 282 __ Push(ra);
283 __ sw(ra, MemOperand(sp));
284 283
285 { 284 {
286 __ BlockTrampolinePoolFor(kNumCases * 2 + 7 + 1); 285 __ BlockTrampolinePoolFor(kNumCases + 6 + 1);
287 PredictableCodeSizeScope predictable( 286 PredictableCodeSizeScope predictable(
288 masm, kNumCases * kPointerSize + ((7 + 1) * Assembler::kInstrSize)); 287 masm, kNumCases * kPointerSize + ((6 + 1) * Assembler::kInstrSize));
289 Label here;
290 288
291 __ bal(&here); 289 __ addiupc(at, 6 + 1);
292 __ sll(at, a0, 2); // In delay slot. 290 __ lsa(at, at, a0, 2);
293 __ bind(&here); 291 __ lw(at, MemOperand(at));
294 __ addu(at, at, ra);
295 __ lw(at, MemOperand(at, 6 * Assembler::kInstrSize));
296 __ jalr(at); 292 __ jalr(at);
297 __ nop(); // Branch delay slot nop. 293 __ nop(); // Branch delay slot nop.
298 __ bc(&done); 294 __ bc(&done);
295 // A nop instruction must be generated by the forbidden slot guard
296 // (Assembler::dd(Label*)).
299 for (int i = 0; i < kNumCases; ++i) { 297 for (int i = 0; i < kNumCases; ++i) {
300 __ dd(&labels[i]); 298 __ dd(&labels[i]);
301 } 299 }
302 } 300 }
303 301
304 for (int i = 0; i < kNumCases; ++i) { 302 for (int i = 0; i < kNumCases; ++i) {
305 __ bind(&labels[i]); 303 __ bind(&labels[i]);
306 __ lui(v0, (values[i] >> 16) & 0xffff); 304 __ li(v0, values[i]);
307 __ ori(v0, v0, values[i] & 0xffff);
308 __ jr(ra); 305 __ jr(ra);
309 __ nop(); 306 __ nop();
310 } 307 }
311 308
312 __ bind(&done); 309 __ bind(&done);
313 __ lw(ra, MemOperand(sp)); 310 __ Pop(ra);
314 __ addiu(sp, sp, 4);
315 __ jr(ra); 311 __ jr(ra);
316 __ nop(); 312 __ nop();
317 313
318 CodeDesc desc; 314 CodeDesc desc;
319 masm->GetCode(&desc); 315 masm->GetCode(&desc);
320 Handle<Code> code = isolate->factory()->NewCode( 316 Handle<Code> code = isolate->factory()->NewCode(
321 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); 317 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
322 #ifdef OBJECT_PRINT 318 #ifdef OBJECT_PRINT
323 code->Print(std::cout); 319 code->Print(std::cout);
324 #endif 320 #endif
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 402
407 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa); 403 size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa);
408 for (size_t i = 0; i < nr_test_cases; ++i) { 404 for (size_t i = 0; i < nr_test_cases; ++i) {
409 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); 405 uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa);
410 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res, 406 PrintF("0x%x =? 0x%x == lsa(v0, %x, %x, %hhu)\n", tc[i].expected_res, res,
411 tc[i].rt, tc[i].rs, tc[i].sa); 407 tc[i].rt, tc[i].rs, tc[i].sa);
412 CHECK_EQ(tc[i].expected_res, res); 408 CHECK_EQ(tc[i].expected_res, res);
413 } 409 }
414 } 410 }
415 411
412
413 static uint32_t run_addiupc(int32_t imm21, uint32_t& PC) {
414 Isolate* isolate = CcTest::i_isolate();
415 HandleScope scope(isolate);
416
417 MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes);
418 MacroAssembler* masm = &assm;
419
420 __ Addiupc(v0, imm21);
421 __ jr(ra);
422 __ nop();
423
424 CodeDesc desc;
425 assm.GetCode(&desc);
426 Handle<Code> code = isolate->factory()->NewCode(
427 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
428
429 ::F f = FUNCTION_CAST<::F>(code->entry());
430 PC = reinterpret_cast<uint32_t>(f); // Set the program counter.
431
432 uint32_t rs = reinterpret_cast<uint32_t>(
433 CALL_GENERATED_CODE(isolate, f, imm21, 0, 0, 0, 0));
434
435 return rs;
436 }
437
438
439 TEST(Addiupc) {
440 if (!IsMipsArchVariant(kMips32r6)) return;
441
442 CcTest::InitializeVM();
443
444 int32_t tc[] = {
445 INT32_MIN >> 11, // Min. int21.
446 -4, // -1 instruction.
447 0, // 0 offset.
448 4, // 1 instruction.
449 ((1 << 20) - 1) & ~3 // Max. int21.
450 };
451
452 size_t nr_test_cases = sizeof(tc) / sizeof(int32_t);
453 uint32_t PC = 0;
454 for (size_t i = 0; i < nr_test_cases; ++i) {
455 uint32_t res = run_addiupc(tc[i], PC);
456 // Now, the program_counter (PC) is set.
457 uint32_t expected_res = PC + tc[i];
458 CHECK_EQ(expected_res, res);
459 }
460 }
461
416 #undef __ 462 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698