Index: test/cctest/test-assembler-ia32.cc |
diff --git a/test/cctest/test-assembler-ia32.cc b/test/cctest/test-assembler-ia32.cc |
index 880370f0f8736615397be3b290711d6563a6c07b..af29b7ce0be50f677fc119012b50dcc6d8e2d0de 100644 |
--- a/test/cctest/test-assembler-ia32.cc |
+++ b/test/cctest/test-assembler-ia32.cc |
@@ -473,6 +473,99 @@ TEST(AssemblerMultiByteNop) { |
} |
+#ifdef __GNUC__ |
+#define ELEMENT_COUNT 4 |
+ |
+void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
+ HandleScope scope(isolate); |
+ |
+ CHECK(args[0]->IsArray()); |
+ v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
+ CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
+ |
+ v8::internal::byte buffer[256]; |
+ Assembler assm(isolate, buffer, sizeof buffer); |
+ |
+ if (CpuFeatures::IsSupported(SSE2)) { |
Jakob Kummerow
2013/07/02 15:24:18
I think you should just ASSERT(CpuFeatures::IsSupp
|
+ CpuFeatureScope fscope(&assm, SSE2); |
+ |
+ // 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
|
+ __ pop(ecx); |
+ |
+ // Store input vector on the stack |
+ for (int i = 0; i < ELEMENT_COUNT; ++i) |
+ __ push(Immediate(vec->Get(i)->Int32Value())); |
Jakob Kummerow
2013/07/02 15:24:18
nit: {} please
|
+ |
+ // Read vector into a xmm register |
+ __ pxor(xmm0, xmm0); |
+ __ movdqa(xmm0, Operand(esp, 0)); |
+ // Create mask and store it in the return register |
+ __ movmskps(eax, xmm0); |
+ |
+ // Remove unused data from the stack |
+ __ add(esp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); |
+ // Restore return address |
+ __ push(ecx); |
+ |
+ __ ret(0); |
+ } |
+ |
+ CodeDesc desc; |
+ assm.GetCode(&desc); |
+ |
+ Object* code = isolate->heap()->CreateCode( |
+ desc, |
+ Code::ComputeFlags(Code::STUB), |
+ Handle<Code>())->ToObjectChecked(); |
+ CHECK(code->IsCode()); |
+ |
+ F0 f = FUNCTION_CAST<F0>(Code::cast(code)->entry()); |
+#ifdef OBJECT_PRINT |
+ Code::cast(code)->Print(); |
Jakob Kummerow
2013/07/02 15:24:18
debugging leftover?
|
+#endif |
+ int res = f(); |
+ ::printf("f() = %d\n", res); |
Jakob Kummerow
2013/07/02 15:24:18
debugging leftover?
|
+ args.GetReturnValue().Set(v8::Integer::New(res)); |
+} |
+ |
+TEST(StackAlignmentForSSE2) { |
+ CcTest::InitializeVM(); |
+ if (!CpuFeatures::IsSupported(SSE2)) return; |
+ |
+ CHECK_EQ(0, OS::ActivationFrameAlignment() % 16); |
+ |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
+ global_template->Set(v8_str("do_sse2"), v8::FunctionTemplate::New(DoSSE2)); |
+ |
+ LocalContext env(NULL, global_template); |
+ CompileRun( |
+ "function foo(vec) {" |
Jakob Kummerow
2013/07/02 15:24:18
nit: indentation (4 spaces when you break inside a
|
+ " return do_sse2(vec);" |
Jakob Kummerow
2013/07/02 15:24:18
nit: indentation (2 spaces inside function body, i
|
+ "}"); |
+ |
+ v8::Local<v8::Object> global_object = env->Global(); |
+ v8::Local<v8::Function> foo = |
+ 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 '=
|
+ |
+ int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; |
+ v8::Local<v8::Array> v8_vec = v8::Array::New(ELEMENT_COUNT); |
+ for (int i = 0; i < ELEMENT_COUNT; i++) |
+ v8_vec->Set(i, v8_num(vec[i])); |
Jakob Kummerow
2013/07/02 15:24:18
nit: {} please
|
+ |
+ v8::Local<v8::Value> args[] = { v8_vec }; |
+ v8::Local<v8::Value> result = foo->Call(global_object, 1, args); |
+ |
+ // The mask should be 0b1000 |
+ CHECK_EQ(8, result->Int32Value()); |
+} |
+ |
+#undef ELEMENT_COUNT |
+#endif // __GNUC__ |
+ |
+ |
Jakob Kummerow
2013/07/02 15:24:18
nit: two empty lines is enough
|
#undef __ |