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

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

Issue 18300003: Fix stack alignment corruption for MinGW32 build (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 Code::ComputeFlags(Code::STUB), 466 Code::ComputeFlags(Code::STUB),
467 Handle<Code>())->ToObjectChecked()); 467 Handle<Code>())->ToObjectChecked());
468 CHECK(code->IsCode()); 468 CHECK(code->IsCode());
469 469
470 F0 f = FUNCTION_CAST<F0>(code->entry()); 470 F0 f = FUNCTION_CAST<F0>(code->entry());
471 int res = f(); 471 int res = f();
472 CHECK_EQ(42, res); 472 CHECK_EQ(42, res);
473 } 473 }
474 474
475 475
476 #ifdef __GNUC__
477 #define ELEMENT_COUNT 4
478
479 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) {
480 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
481 HandleScope scope(isolate);
482
483 CHECK(args[0]->IsArray());
484 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]);
485 CHECK_EQ(ELEMENT_COUNT, vec->Length());
486
487 v8::internal::byte buffer[256];
488 Assembler assm(isolate, buffer, sizeof buffer);
489
490 if (CpuFeatures::IsSupported(SSE2)) {
Jakob Kummerow 2013/07/02 15:24:18 I think you should just ASSERT(CpuFeatures::IsSupp
491 CpuFeatureScope fscope(&assm, SSE2);
492
493 // Remove return address from the stack for fix stack frame alignment
Jakob Kummerow 2013/07/02 15:24:18 nit: All comments should end with appropriate punc
494 __ pop(ecx);
495
496 // Store input vector on the stack
497 for (int i = 0; i < ELEMENT_COUNT; ++i)
498 __ push(Immediate(vec->Get(i)->Int32Value()));
Jakob Kummerow 2013/07/02 15:24:18 nit: {} please
499
500 // Read vector into a xmm register
501 __ pxor(xmm0, xmm0);
502 __ movdqa(xmm0, Operand(esp, 0));
503 // Create mask and store it in the return register
504 __ movmskps(eax, xmm0);
505
506 // Remove unused data from the stack
507 __ add(esp, Immediate(ELEMENT_COUNT * sizeof(int32_t)));
508 // Restore return address
509 __ push(ecx);
510
511 __ ret(0);
512 }
513
514 CodeDesc desc;
515 assm.GetCode(&desc);
516
517 Object* code = isolate->heap()->CreateCode(
518 desc,
519 Code::ComputeFlags(Code::STUB),
520 Handle<Code>())->ToObjectChecked();
521 CHECK(code->IsCode());
522
523 F0 f = FUNCTION_CAST<F0>(Code::cast(code)->entry());
524 #ifdef OBJECT_PRINT
525 Code::cast(code)->Print();
Jakob Kummerow 2013/07/02 15:24:18 debugging leftover?
526 #endif
527 int res = f();
528 ::printf("f() = %d\n", res);
Jakob Kummerow 2013/07/02 15:24:18 debugging leftover?
529 args.GetReturnValue().Set(v8::Integer::New(res));
530 }
531
532 TEST(StackAlignmentForSSE2) {
533 CcTest::InitializeVM();
534 if (!CpuFeatures::IsSupported(SSE2)) return;
535
536 CHECK_EQ(0, OS::ActivationFrameAlignment() % 16);
537
538 v8::Isolate* isolate = v8::Isolate::GetCurrent();
539 v8::HandleScope handle_scope(isolate);
540 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
541 global_template->Set(v8_str("do_sse2"), v8::FunctionTemplate::New(DoSSE2));
542
543 LocalContext env(NULL, global_template);
544 CompileRun(
545 "function foo(vec) {"
Jakob Kummerow 2013/07/02 15:24:18 nit: indentation (4 spaces when you break inside a
546 " return do_sse2(vec);"
Jakob Kummerow 2013/07/02 15:24:18 nit: indentation (2 spaces inside function body, i
547 "}");
548
549 v8::Local<v8::Object> global_object = env->Global();
550 v8::Local<v8::Function> foo =
551 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo")));
Jakob Kummerow 2013/07/02 15:24:18 nit: indentation (4 spaces when you break after '=
552
553 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 };
554 v8::Local<v8::Array> v8_vec = v8::Array::New(ELEMENT_COUNT);
555 for (int i = 0; i < ELEMENT_COUNT; i++)
556 v8_vec->Set(i, v8_num(vec[i]));
Jakob Kummerow 2013/07/02 15:24:18 nit: {} please
557
558 v8::Local<v8::Value> args[] = { v8_vec };
559 v8::Local<v8::Value> result = foo->Call(global_object, 1, args);
560
561 // The mask should be 0b1000
562 CHECK_EQ(8, result->Int32Value());
563 }
564
565 #undef ELEMENT_COUNT
566 #endif // __GNUC__
567
568
Jakob Kummerow 2013/07/02 15:24:18 nit: two empty lines is enough
476 569
477 570
478 #undef __ 571 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698