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

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: Enable StackAlignment test only for GCC 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
« no previous file with comments | « src/platform-win32.cc ('k') | test/cctest/test-assembler-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ASSERT(CpuFeatures::IsSupported(SSE2));
491 CpuFeatureScope fscope(&assm, SSE2);
492
493 // Remove return address from the stack for fix stack frame alignment.
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()));
499 }
500
501 // Read vector into a xmm register.
502 __ pxor(xmm0, xmm0);
503 __ movdqa(xmm0, Operand(esp, 0));
504 // Create mask and store it in the return register.
505 __ movmskps(eax, xmm0);
506
507 // Remove unused data from the stack.
508 __ add(esp, Immediate(ELEMENT_COUNT * sizeof(int32_t)));
509 // Restore return address.
510 __ push(ecx);
511
512 __ ret(0);
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 int res = f();
525 args.GetReturnValue().Set(v8::Integer::New(res));
526 }
527
528 TEST(StackAlignmentForSSE2) {
529 CcTest::InitializeVM();
530 if (!CpuFeatures::IsSupported(SSE2)) return;
531
532 CHECK_EQ(0, OS::ActivationFrameAlignment() % 16);
533
534 v8::Isolate* isolate = v8::Isolate::GetCurrent();
535 v8::HandleScope handle_scope(isolate);
536 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
537 global_template->Set(v8_str("do_sse2"), v8::FunctionTemplate::New(DoSSE2));
538
539 LocalContext env(NULL, global_template);
540 CompileRun(
541 "function foo(vec) {"
542 " return do_sse2(vec);"
543 "}");
544
545 v8::Local<v8::Object> global_object = env->Global();
546 v8::Local<v8::Function> foo =
547 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo")));
548
549 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 };
550 v8::Local<v8::Array> v8_vec = v8::Array::New(ELEMENT_COUNT);
551 for (int i = 0; i < ELEMENT_COUNT; i++) {
552 v8_vec->Set(i, v8_num(vec[i]));
553 }
554
555 v8::Local<v8::Value> args[] = { v8_vec };
556 v8::Local<v8::Value> result = foo->Call(global_object, 1, args);
557
558 // The mask should be 0b1000.
559 CHECK_EQ(8, result->Int32Value());
560 }
561
562 #undef ELEMENT_COUNT
563 #endif // __GNUC__
476 564
477 565
478 #undef __ 566 #undef __
OLDNEW
« no previous file with comments | « src/platform-win32.cc ('k') | test/cctest/test-assembler-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698