summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-assembler-x64.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/test-assembler-x64.cc')
-rw-r--r--deps/v8/test/cctest/test-assembler-x64.cc151
1 files changed, 124 insertions, 27 deletions
diff --git a/deps/v8/test/cctest/test-assembler-x64.cc b/deps/v8/test/cctest/test-assembler-x64.cc
index 23d0be64ae..f5d59ded9b 100644
--- a/deps/v8/test/cctest/test-assembler-x64.cc
+++ b/deps/v8/test/cctest/test-assembler-x64.cc
@@ -25,7 +25,8 @@
// (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>
+#include <cstdlib>
+#include <iostream>
#include "src/v8.h"
@@ -51,9 +52,9 @@ using namespace v8::internal;
typedef int (*F0)();
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);
+typedef unsigned (*F3)(double x);
+typedef uint64_t (*F4)(uint64_t* x, uint64_t* y);
+typedef uint64_t (*F5)(uint64_t x);
#ifdef _WIN64
static const Register arg1 = rcx;
@@ -220,9 +221,9 @@ TEST(AssemblerX64XchglOperations) {
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);
+ uint64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ uint64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ uint64_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);
@@ -245,9 +246,9 @@ TEST(AssemblerX64OrlOperations) {
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);
+ uint64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ uint64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ uint64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 60000000), left);
USE(result);
}
@@ -269,8 +270,8 @@ TEST(AssemblerX64RollOperations) {
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);
+ uint64_t src = V8_2PART_UINT64_C(0x10000000, C0000000);
+ uint64_t result = FUNCTION_CAST<F5>(buffer)(src);
CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 80000001), result);
}
@@ -291,9 +292,9 @@ TEST(AssemblerX64SublOperations) {
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);
+ uint64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ uint64_t right = V8_2PART_UINT64_C(0x30000000, 40000000);
+ uint64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
CHECK_EQ(V8_2PART_UINT64_C(0x10000000, e0000000), left);
USE(result);
}
@@ -321,10 +322,10 @@ TEST(AssemblerX64TestlOperations) {
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);
+ uint64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ uint64_t right = V8_2PART_UINT64_C(0x30000000, 00000000);
+ uint64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
+ CHECK_EQ(1u, result);
}
@@ -344,9 +345,9 @@ TEST(AssemblerX64XorlOperations) {
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);
+ uint64_t left = V8_2PART_UINT64_C(0x10000000, 20000000);
+ uint64_t right = V8_2PART_UINT64_C(0x30000000, 60000000);
+ uint64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right);
CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 40000000), left);
USE(result);
}
@@ -586,7 +587,7 @@ TEST(AssemblerMultiByteNop) {
#ifdef __GNUC__
-#define ELEMENT_COUNT 4
+#define ELEMENT_COUNT 4u
void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope scope(CcTest::isolate());
@@ -603,7 +604,7 @@ void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) {
__ popq(rcx);
// Store input vector on the stack.
- for (int i = 0; i < ELEMENT_COUNT; i++) {
+ for (unsigned i = 0; i < ELEMENT_COUNT; i++) {
__ movl(rax, Immediate(vec->Get(i)->Int32Value()));
__ shlq(rax, Immediate(0x20));
__ orq(rax, Immediate(vec->Get(++i)->Int32Value()));
@@ -657,7 +658,7 @@ TEST(StackAlignmentForSSE2) {
int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 };
v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT);
- for (int i = 0; i < ELEMENT_COUNT; i++) {
+ for (unsigned i = 0; i < ELEMENT_COUNT; i++) {
v8_vec->Set(i, v8_num(vec[i]));
}
@@ -696,9 +697,9 @@ TEST(AssemblerX64Extractps) {
F3 f = FUNCTION_CAST<F3>(code->entry());
uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321);
- CHECK_EQ(0x12345678, f(uint64_to_double(value1)));
+ CHECK_EQ(0x12345678u, f(uint64_to_double(value1)));
uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678);
- CHECK_EQ(0x87654321, f(uint64_to_double(value2)));
+ CHECK_EQ(0x87654321u, f(uint64_to_double(value2)));
}
@@ -1186,4 +1187,100 @@ TEST(AssemblerX64FMA_ss) {
F8 f = FUNCTION_CAST<F8>(code->entry());
CHECK_EQ(0, f(9.26621069e-05f, -2.4607749f, -1.09587872f));
}
+
+
+TEST(AssemblerX64JumpTables1) {
+ // Test jump tables with forward jumps.
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ MacroAssembler assm(isolate, nullptr, 0);
+
+ const int kNumCases = 512;
+ int values[kNumCases];
+ isolate->random_number_generator()->NextBytes(values, sizeof(values));
+ Label labels[kNumCases];
+
+ Label done, table;
+ __ leaq(arg2, Operand(&table));
+ __ jmp(Operand(arg2, arg1, times_8, 0));
+ __ ud2();
+ __ bind(&table);
+ for (int i = 0; i < kNumCases; ++i) {
+ __ dq(&labels[i]);
+ }
+
+ for (int i = 0; i < kNumCases; ++i) {
+ __ bind(&labels[i]);
+ __ movq(rax, Immediate(values[i]));
+ __ jmp(&done);
+ }
+
+ __ bind(&done);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ code->Print(std::cout);
+#endif
+
+ F1 f = FUNCTION_CAST<F1>(code->entry());
+ for (int i = 0; i < kNumCases; ++i) {
+ int res = f(i);
+ PrintF("f(%d) = %d\n", i, res);
+ CHECK_EQ(values[i], res);
+ }
+}
+
+
+TEST(AssemblerX64JumpTables2) {
+ // Test jump tables with backwards jumps.
+ CcTest::InitializeVM();
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ MacroAssembler assm(isolate, nullptr, 0);
+
+ const int kNumCases = 512;
+ int values[kNumCases];
+ isolate->random_number_generator()->NextBytes(values, sizeof(values));
+ Label labels[kNumCases];
+
+ Label done, table;
+ __ leaq(arg2, Operand(&table));
+ __ jmp(Operand(arg2, arg1, times_8, 0));
+ __ ud2();
+
+ for (int i = 0; i < kNumCases; ++i) {
+ __ bind(&labels[i]);
+ __ movq(rax, Immediate(values[i]));
+ __ jmp(&done);
+ }
+
+ __ bind(&done);
+ __ ret(0);
+
+ __ bind(&table);
+ for (int i = 0; i < kNumCases; ++i) {
+ __ dq(&labels[i]);
+ }
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ code->Print(std::cout);
+#endif
+
+ F1 f = FUNCTION_CAST<F1>(code->entry());
+ for (int i = 0; i < kNumCases; ++i) {
+ int res = f(i);
+ PrintF("f(%d) = %d\n", i, res);
+ CHECK_EQ(values[i], res);
+ }
+}
+
#undef __