}
-void Assembler::xchg(Register dst, Register src) {
+void Assembler::xchgq(Register dst, Register src) {
EnsureSpace ensure_space(this);
if (src.is(rax) || dst.is(rax)) { // Single-byte encoding
Register other = src.is(rax) ? dst : src;
}
+void Assembler::xchgl(Register dst, Register src) {
+ EnsureSpace ensure_space(this);
+ if (src.is(rax) || dst.is(rax)) { // Single-byte encoding
+ Register other = src.is(rax) ? dst : src;
+ emit_optional_rex_32(other);
+ emit(0x90 | other.low_bits());
+ } else if (dst.low_bits() == 4) {
+ emit_optional_rex_32(dst, src);
+ emit(0x87);
+ emit_modrm(dst, src);
+ } else {
+ emit_optional_rex_32(src, dst);
+ emit(0x87);
+ emit_modrm(src, dst);
+ }
+}
+
+
void Assembler::store_rax(void* dst, RelocInfo::Mode mode) {
EnsureSpace ensure_space(this);
emit(0x48); // REX.W
}
+void Assembler::testl(const Operand& op, Register reg) {
+ EnsureSpace ensure_space(this);
+ emit_optional_rex_32(reg, op);
+ emit(0x85);
+ emit_operand(reg, op);
+}
+
+
void Assembler::testq(const Operand& op, Register reg) {
EnsureSpace ensure_space(this);
emit_rex_64(reg, op);
void cmovl(Condition cc, Register dst, const Operand& src);
// Exchange two registers
- void xchg(Register dst, Register src);
+ void xchgq(Register dst, Register src);
+ void xchgl(Register dst, Register src);
// Arithmetics
void addl(Register dst, Register src) {
arithmetic_op(0x09, src, dst);
}
+ void orl(const Operand& dst, Register src) {
+ arithmetic_op_32(0x09, src, dst);
+ }
+
void or_(Register dst, Immediate src) {
immediate_arithmetic_op(0x1, dst, src);
}
shift(dst, imm8, 0x0);
}
+ void roll(Register dst, Immediate imm8) {
+ shift_32(dst, imm8, 0x0);
+ }
+
void rcr(Register dst, Immediate imm8) {
shift(dst, imm8, 0x3);
}
arithmetic_op_32(0x2B, dst, src);
}
+ void subl(const Operand& dst, Register src) {
+ arithmetic_op_32(0x29, src, dst);
+ }
+
void subl(const Operand& dst, Immediate src) {
immediate_arithmetic_op_32(0x5, dst, src);
}
void testb(const Operand& op, Register reg);
void testl(Register dst, Register src);
void testl(Register reg, Immediate mask);
+ void testl(const Operand& op, Register reg);
void testl(const Operand& op, Immediate mask);
void testq(const Operand& op, Register reg);
void testq(Register dst, Register src);
immediate_arithmetic_op_32(0x6, dst, src);
}
+ void xorl(const Operand& dst, Register src) {
+ arithmetic_op_32(0x31, src, dst);
+ }
+
void xorl(const Operand& dst, Immediate src) {
immediate_arithmetic_op_32(0x6, dst, src);
}
typedef int (*F1)(int64_t x);
typedef int (*F2)(int64_t x, int64_t y);
typedef int (*F3)(double x);
+typedef int64_t (*F4)(int64_t* x, int64_t* y);
+typedef int64_t (*F5)(int64_t x);
#ifdef _WIN64
static const Register arg1 = rcx;
}
+TEST(AssemblerX64XchglOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ __ movq(rax, Operand(arg1, 0));
+ __ movq(rbx, Operand(arg2, 0));
+ __ xchgl(rax, rbx);
+ __ movq(Operand(arg1, 0), rax);
+ __ movq(Operand(arg2, 0), rbx);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 40000000), left);
+ CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 20000000), right);
+ USE(result);
+}
+
+
+TEST(AssemblerX64OrlOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ __ movq(rax, Operand(arg2, 0));
+ __ orl(Operand(arg1, 0), rax);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 60000000), left);
+ USE(result);
+}
+
+
+TEST(AssemblerX64RollOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ __ movq(rax, arg1);
+ __ roll(rax, Immediate(1));
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t src = V8_2PART_UINT64_C(0x10000000, C0000000);
+ int64_t result = FUNCTION_CAST<F5>(buffer)(src);
+ CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 80000001), result);
+}
+
+
+TEST(AssemblerX64SublOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ __ movq(rax, Operand(arg2, 0));
+ __ subl(Operand(arg1, 0), rax);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(V8_2PART_UINT64_C(0x10000000, e0000000), left);
+ USE(result);
+}
+
+
+TEST(AssemblerX64TestlOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ // Set rax with the ZF flag of the testl instruction.
+ Label done;
+ __ movq(rax, Immediate(1));
+ __ movq(rbx, Operand(arg2, 0));
+ __ testl(Operand(arg1, 0), rbx);
+ __ j(zero, &done, Label::kNear);
+ __ movq(rax, Immediate(0));
+ __ bind(&done);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ int64_t right = V8_2PART_UINT64_C(0x30000000, 00000000);
+ int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(static_cast<int64_t>(1), result);
+}
+
+
+TEST(AssemblerX64XorlOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size));
+
+ __ movq(rax, Operand(arg2, 0));
+ __ xorl(Operand(arg1, 0), rax);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ int64_t right = V8_2PART_UINT64_C(0x30000000, 60000000);
+ int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 40000000), left);
+ USE(result);
+}
+
+
TEST(AssemblerX64MemoryOperands) {
// Allocate an executable page of memory.
size_t actual_size;