2011-10-03 11:44:39 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2008-08-22 13:33:59 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/disassembler.h"
|
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/macro-assembler.h"
|
|
|
|
#include "src/serialize.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
|
|
|
|
|
|
|
|
typedef int (*F0)();
|
|
|
|
typedef int (*F1)(int x);
|
|
|
|
typedef int (*F2)(int x, int y);
|
|
|
|
|
|
|
|
|
|
|
|
#define __ assm.
|
|
|
|
|
|
|
|
TEST(AssemblerIa320) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ mov(eax, Operand(esp, 4));
|
|
|
|
__ add(eax, Operand(esp, 8));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-01-03 09:32:42 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
2014-04-16 11:38:56 +00:00
|
|
|
F2 f = FUNCTION_CAST<F2>(code->entry());
|
2008-08-22 13:33:59 +00:00
|
|
|
int res = f(3, 4);
|
|
|
|
::printf("f() = %d\n", res);
|
|
|
|
CHECK_EQ(7, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(AssemblerIa321) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
Label L, C;
|
|
|
|
|
|
|
|
__ mov(edx, Operand(esp, 4));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(eax, eax); // clear eax
|
2008-08-22 13:33:59 +00:00
|
|
|
__ jmp(&C);
|
|
|
|
|
|
|
|
__ bind(&L);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(eax, edx);
|
|
|
|
__ sub(edx, Immediate(1));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ bind(&C);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(edx, edx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_zero, &L);
|
2008-08-22 13:33:59 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-01-03 09:32:42 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
2014-04-16 11:38:56 +00:00
|
|
|
F1 f = FUNCTION_CAST<F1>(code->entry());
|
2008-08-22 13:33:59 +00:00
|
|
|
int res = f(100);
|
|
|
|
::printf("f() = %d\n", res);
|
|
|
|
CHECK_EQ(5050, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(AssemblerIa322) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
Label L, C;
|
|
|
|
|
|
|
|
__ mov(edx, Operand(esp, 4));
|
|
|
|
__ mov(eax, 1);
|
|
|
|
__ jmp(&C);
|
|
|
|
|
|
|
|
__ bind(&L);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ imul(eax, edx);
|
|
|
|
__ sub(edx, Immediate(1));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ bind(&C);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(edx, edx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_zero, &L);
|
2008-08-22 13:33:59 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// some relocated stuff here, not executed
|
2013-06-04 10:30:05 +00:00
|
|
|
__ mov(eax, isolate->factory()->true_value());
|
2008-09-22 13:57:03 +00:00
|
|
|
__ jmp(NULL, RelocInfo::RUNTIME_ENTRY);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-01-03 09:32:42 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
2014-04-16 11:38:56 +00:00
|
|
|
F1 f = FUNCTION_CAST<F1>(code->entry());
|
2008-08-22 13:33:59 +00:00
|
|
|
int res = f(10);
|
|
|
|
::printf("f() = %d\n", res);
|
|
|
|
CHECK_EQ(3628800, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef int (*F3)(float x);
|
|
|
|
|
|
|
|
TEST(AssemblerIa323) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2011-03-31 16:17:37 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-05-09 13:01:50 +00:00
|
|
|
__ cvttss2si(eax, Operand(esp, 4));
|
|
|
|
__ ret(0);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2008-08-22 13:33:59 +00:00
|
|
|
// don't print the code - our disassembler can't handle cvttss2si
|
|
|
|
// instead print bytes
|
|
|
|
Disassembler::Dump(stdout,
|
|
|
|
code->instruction_start(),
|
|
|
|
code->instruction_start() + code->instruction_size());
|
|
|
|
F3 f = FUNCTION_CAST<F3>(code->entry());
|
|
|
|
int res = f(static_cast<float>(-3.1415));
|
|
|
|
::printf("f() = %d\n", res);
|
|
|
|
CHECK_EQ(-3, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef int (*F4)(double x);
|
|
|
|
|
|
|
|
TEST(AssemblerIa324) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2011-03-31 16:17:37 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ cvttsd2si(eax, Operand(esp, 4));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2008-08-22 13:33:59 +00:00
|
|
|
// don't print the code - our disassembler can't handle cvttsd2si
|
|
|
|
// instead print bytes
|
|
|
|
Disassembler::Dump(stdout,
|
|
|
|
code->instruction_start(),
|
|
|
|
code->instruction_start() + code->instruction_size());
|
|
|
|
F4 f = FUNCTION_CAST<F4>(code->entry());
|
|
|
|
int res = f(2.718281828);
|
|
|
|
::printf("f() = %d\n", res);
|
|
|
|
CHECK_EQ(2, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int baz = 42;
|
|
|
|
TEST(AssemblerIa325) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-01-04 10:56:24 +00:00
|
|
|
__ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE32));
|
2008-08-22 13:33:59 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2008-08-22 13:33:59 +00:00
|
|
|
F0 f = FUNCTION_CAST<F0>(code->entry());
|
|
|
|
int res = f();
|
|
|
|
CHECK_EQ(42, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef double (*F5)(double x, double y);
|
|
|
|
|
|
|
|
TEST(AssemblerIa326) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2011-03-31 16:17:37 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-10-18 10:54:45 +00:00
|
|
|
__ movsd(xmm0, Operand(esp, 1 * kPointerSize));
|
|
|
|
__ movsd(xmm1, Operand(esp, 3 * kPointerSize));
|
2008-08-22 13:33:59 +00:00
|
|
|
__ addsd(xmm0, xmm1);
|
|
|
|
__ mulsd(xmm0, xmm1);
|
|
|
|
__ subsd(xmm0, xmm1);
|
|
|
|
__ divsd(xmm0, xmm1);
|
2008-09-01 06:41:12 +00:00
|
|
|
// Copy xmm0 to st(0) using eight bytes of stack.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(8));
|
2013-10-18 10:54:45 +00:00
|
|
|
__ movsd(Operand(esp, 0), xmm0);
|
2008-09-01 06:41:12 +00:00
|
|
|
__ fld_d(Operand(esp, 0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(8));
|
2008-08-22 13:33:59 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2008-08-22 13:33:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
::printf("\n---\n");
|
|
|
|
// don't print the code - our disassembler can't handle SSE instructions
|
|
|
|
// instead print bytes
|
|
|
|
Disassembler::Dump(stdout,
|
|
|
|
code->instruction_start(),
|
|
|
|
code->instruction_start() + code->instruction_size());
|
|
|
|
#endif
|
|
|
|
F5 f = FUNCTION_CAST<F5>(code->entry());
|
|
|
|
double res = f(2.2, 1.1);
|
|
|
|
::printf("f() = %f\n", res);
|
|
|
|
CHECK(2.29 < res && res < 2.31);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef double (*F6)(int x);
|
|
|
|
|
|
|
|
TEST(AssemblerIa328) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2011-03-31 16:17:37 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
__ mov(eax, Operand(esp, 4));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, eax);
|
2008-09-01 06:41:12 +00:00
|
|
|
// Copy xmm0 to st(0) using eight bytes of stack.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(8));
|
2013-10-18 10:54:45 +00:00
|
|
|
__ movsd(Operand(esp, 0), xmm0);
|
2008-09-01 06:41:12 +00:00
|
|
|
__ fld_d(Operand(esp, 0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(8));
|
2008-08-22 13:33:59 +00:00
|
|
|
__ ret(0);
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-01-03 09:32:42 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
2014-04-16 11:38:56 +00:00
|
|
|
F6 f = FUNCTION_CAST<F6>(code->entry());
|
2008-08-22 13:33:59 +00:00
|
|
|
double res = f(12);
|
|
|
|
|
|
|
|
::printf("f() = %f\n", res);
|
|
|
|
CHECK(11.99 < res && res < 12.001);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef int (*F7)(double x, double y);
|
|
|
|
|
|
|
|
TEST(AssemblerIa329) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::internal::byte buffer[256];
|
2013-02-25 14:46:09 +00:00
|
|
|
MacroAssembler assm(isolate, buffer, sizeof buffer);
|
2008-08-22 13:33:59 +00:00
|
|
|
enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 };
|
|
|
|
Label equal_l, less_l, greater_l, nan_l;
|
|
|
|
__ fld_d(Operand(esp, 3 * kPointerSize));
|
|
|
|
__ fld_d(Operand(esp, 1 * kPointerSize));
|
|
|
|
__ FCmp();
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(parity_even, &nan_l);
|
|
|
|
__ j(equal, &equal_l);
|
|
|
|
__ j(below, &less_l);
|
|
|
|
__ j(above, &greater_l);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ mov(eax, kUndefined);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&equal_l);
|
|
|
|
__ mov(eax, kEqual);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&greater_l);
|
|
|
|
__ mov(eax, kGreater);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&less_l);
|
|
|
|
__ mov(eax, kLess);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&nan_l);
|
|
|
|
__ mov(eax, kNaN);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-01-03 09:32:42 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2008-08-22 13:33:59 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
F7 f = FUNCTION_CAST<F7>(code->entry());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(kLess, f(1.1, 2.2));
|
|
|
|
CHECK_EQ(kEqual, f(2.2, 2.2));
|
|
|
|
CHECK_EQ(kGreater, f(3.3, 2.2));
|
2014-06-30 13:25:46 +00:00
|
|
|
CHECK_EQ(kNaN, f(v8::base::OS::nan_value(), 1.1));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 07:36:31 +00:00
|
|
|
|
|
|
|
TEST(AssemblerIa3210) {
|
|
|
|
// Test chaining of label usages within instructions (issue 1644).
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, NULL, 0);
|
2011-08-30 07:36:31 +00:00
|
|
|
|
|
|
|
Label target;
|
|
|
|
__ j(equal, &target);
|
|
|
|
__ j(not_equal, &target);
|
|
|
|
__ bind(&target);
|
|
|
|
__ nop();
|
|
|
|
}
|
|
|
|
|
2011-12-02 10:01:50 +00:00
|
|
|
|
|
|
|
TEST(AssemblerMultiByteNop) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2011-12-02 10:01:50 +00:00
|
|
|
v8::internal::byte buffer[1024];
|
2013-02-25 14:46:09 +00:00
|
|
|
Assembler assm(isolate, buffer, sizeof(buffer));
|
2011-12-02 10:01:50 +00:00
|
|
|
__ push(ebx);
|
|
|
|
__ push(ecx);
|
|
|
|
__ push(edx);
|
|
|
|
__ push(edi);
|
|
|
|
__ push(esi);
|
|
|
|
__ mov(eax, 1);
|
|
|
|
__ mov(ebx, 2);
|
|
|
|
__ mov(ecx, 3);
|
|
|
|
__ mov(edx, 4);
|
|
|
|
__ mov(edi, 5);
|
|
|
|
__ mov(esi, 6);
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
int before = assm.pc_offset();
|
|
|
|
__ Nop(i);
|
|
|
|
CHECK_EQ(assm.pc_offset() - before, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Label fail;
|
|
|
|
__ cmp(eax, 1);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ cmp(ebx, 2);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ cmp(ecx, 3);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ cmp(edx, 4);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ cmp(edi, 5);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ cmp(esi, 6);
|
|
|
|
__ j(not_equal, &fail);
|
|
|
|
__ mov(eax, 42);
|
|
|
|
__ pop(esi);
|
|
|
|
__ pop(edi);
|
|
|
|
__ pop(edx);
|
|
|
|
__ pop(ecx);
|
|
|
|
__ pop(ebx);
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&fail);
|
|
|
|
__ mov(eax, 13);
|
|
|
|
__ pop(esi);
|
|
|
|
__ pop(edi);
|
|
|
|
__ pop(edx);
|
|
|
|
__ pop(ecx);
|
|
|
|
__ pop(ebx);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2011-12-02 10:01:50 +00:00
|
|
|
CHECK(code->IsCode());
|
|
|
|
|
|
|
|
F0 f = FUNCTION_CAST<F0>(code->entry());
|
|
|
|
int res = f();
|
|
|
|
CHECK_EQ(42, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-29 12:12:39 +00:00
|
|
|
#ifdef __GNUC__
|
2013-07-05 08:34:17 +00:00
|
|
|
#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);
|
|
|
|
|
|
|
|
// Remove return address from the stack for fix stack frame alignment.
|
|
|
|
__ pop(ecx);
|
|
|
|
|
|
|
|
// Store input vector on the stack.
|
|
|
|
for (int i = 0; i < ELEMENT_COUNT; ++i) {
|
|
|
|
__ push(Immediate(vec->Get(i)->Int32Value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
F0 f = FUNCTION_CAST<F0>(code->entry());
|
2013-07-05 08:34:17 +00:00
|
|
|
int res = f();
|
2014-01-03 14:31:17 +00:00
|
|
|
args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res));
|
2013-07-05 08:34:17 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-07-05 08:34:17 +00:00
|
|
|
TEST(StackAlignmentForSSE2) {
|
|
|
|
CcTest::InitializeVM();
|
2014-06-30 13:25:46 +00:00
|
|
|
CHECK_EQ(0, v8::base::OS::ActivationFrameAlignment() % 16);
|
2013-07-05 08:34:17 +00:00
|
|
|
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-07-05 08:34:17 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global_template =
|
|
|
|
v8::ObjectTemplate::New(isolate);
|
2013-12-18 10:31:42 +00:00
|
|
|
global_template->Set(v8_str("do_sse2"),
|
|
|
|
v8::FunctionTemplate::New(isolate, DoSSE2));
|
2013-07-05 08:34:17 +00:00
|
|
|
|
|
|
|
LocalContext env(NULL, global_template);
|
|
|
|
CompileRun(
|
|
|
|
"function foo(vec) {"
|
|
|
|
" return do_sse2(vec);"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
v8::Local<v8::Object> global_object = env->Global();
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo")));
|
|
|
|
|
|
|
|
int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 };
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT);
|
2013-07-05 08:34:17 +00:00
|
|
|
for (int i = 0; i < ELEMENT_COUNT; i++) {
|
|
|
|
v8_vec->Set(i, v8_num(vec[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2013-07-29 12:12:39 +00:00
|
|
|
#endif // __GNUC__
|
2011-12-02 10:01:50 +00:00
|
|
|
|
|
|
|
|
2013-10-15 12:51:58 +00:00
|
|
|
TEST(AssemblerIa32Extractps) {
|
|
|
|
CcTest::InitializeVM();
|
2014-05-09 13:01:50 +00:00
|
|
|
if (!CpuFeatures::IsSupported(SSE4_1)) return;
|
2013-10-15 12:51:58 +00:00
|
|
|
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
v8::internal::byte buffer[256];
|
|
|
|
MacroAssembler assm(isolate, buffer, sizeof buffer);
|
2014-05-09 13:01:50 +00:00
|
|
|
{ CpuFeatureScope fscope41(&assm, SSE4_1);
|
2013-10-18 10:54:45 +00:00
|
|
|
__ movsd(xmm1, Operand(esp, 4));
|
2013-10-15 12:51:58 +00:00
|
|
|
__ extractps(eax, xmm1, 0x1);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2013-10-15 12:51:58 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2013-10-15 12:51:58 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
F4 f = FUNCTION_CAST<F4>(code->entry());
|
2013-10-15 14:04:49 +00:00
|
|
|
uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321);
|
|
|
|
CHECK_EQ(0x12345678, f(uint64_to_double(value1)));
|
|
|
|
uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678);
|
|
|
|
CHECK_EQ(0x87654321, f(uint64_to_double(value2)));
|
2013-10-15 12:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 15:24:41 +00:00
|
|
|
typedef int (*F8)(float x, float y);
|
|
|
|
TEST(AssemblerIa32SSE) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
v8::internal::byte buffer[256];
|
|
|
|
MacroAssembler assm(isolate, buffer, sizeof buffer);
|
|
|
|
{
|
|
|
|
__ movss(xmm0, Operand(esp, kPointerSize));
|
|
|
|
__ movss(xmm1, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ shufps(xmm0, xmm0, 0x0);
|
|
|
|
__ shufps(xmm1, xmm1, 0x0);
|
|
|
|
__ movaps(xmm2, xmm1);
|
|
|
|
__ addps(xmm2, xmm0);
|
|
|
|
__ mulps(xmm2, xmm1);
|
|
|
|
__ subps(xmm2, xmm0);
|
|
|
|
__ divps(xmm2, xmm1);
|
|
|
|
__ cvttss2si(eax, xmm2);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(&desc);
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<Code> code = isolate->factory()->NewCode(
|
|
|
|
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
|
2013-11-18 15:24:41 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
2014-07-07 09:57:29 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
code->Print(os);
|
2013-11-18 15:24:41 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
F8 f = FUNCTION_CAST<F8>(code->entry());
|
2013-11-18 15:24:41 +00:00
|
|
|
CHECK_EQ(2, f(1.0, 2.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
#undef __
|