Commit b994ad45 authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Length and index2 are unsigned in CheckedLoad/CheckedStore.

Also factor out test cases from test-run-machops.cc into test-run-load-store.cc

BUG=chromium:599717
LOG=Y

Review URL: https://codereview.chromium.org/1858323003

Cr-Commit-Position: refs/heads/master@{#35651}
parent ed9b7d92
...@@ -43,6 +43,10 @@ class InstructionOperandConverter { ...@@ -43,6 +43,10 @@ class InstructionOperandConverter {
return ToConstant(instr_->InputAt(index)).ToInt32(); return ToConstant(instr_->InputAt(index)).ToInt32();
} }
uint32_t InputUint32(size_t index) {
return bit_cast<uint32_t>(InputInt32(index));
}
int64_t InputInt64(size_t index) { int64_t InputInt64(size_t index) {
return ToConstant(instr_->InputAt(index)).ToInt64(); return ToConstant(instr_->InputAt(index)).ToInt64();
} }
......
...@@ -374,13 +374,12 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -374,13 +374,12 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
} \ } \
} while (0) } while (0)
#define ASSEMBLE_CHECKED_LOAD_FLOAT(asm_instr) \ #define ASSEMBLE_CHECKED_LOAD_FLOAT(asm_instr) \
do { \ do { \
auto result = i.OutputDoubleRegister(); \ auto result = i.OutputDoubleRegister(); \
auto buffer = i.InputRegister(0); \ auto buffer = i.InputRegister(0); \
auto index1 = i.InputRegister(1); \ auto index1 = i.InputRegister(1); \
auto index2 = i.InputInt32(2); \ auto index2 = i.InputUint32(2); \
OutOfLineCode* ool; \ OutOfLineCode* ool; \
if (instr->InputAt(3)->IsRegister()) { \ if (instr->InputAt(3)->IsRegister()) { \
auto length = i.InputRegister(3); \ auto length = i.InputRegister(3); \
...@@ -388,9 +387,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -388,9 +387,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ cmpl(index1, length); \ __ cmpl(index1, length); \
ool = new (zone()) OutOfLineLoadNaN(this, result); \ ool = new (zone()) OutOfLineLoadNaN(this, result); \
} else { \ } else { \
auto length = i.InputInt32(3); \ auto length = i.InputUint32(3); \
DCHECK_LE(index2, length); \ DCHECK_LE(index2, length); \
__ cmpq(index1, Immediate(length - index2)); \ __ cmpl(index1, Immediate(length - index2)); \
class OutOfLineLoadFloat final : public OutOfLineCode { \ class OutOfLineLoadFloat final : public OutOfLineCode { \
public: \ public: \
OutOfLineLoadFloat(CodeGenerator* gen, XMMRegister result, \ OutOfLineLoadFloat(CodeGenerator* gen, XMMRegister result, \
...@@ -427,13 +426,12 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -427,13 +426,12 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ bind(ool->exit()); \ __ bind(ool->exit()); \
} while (false) } while (false)
#define ASSEMBLE_CHECKED_LOAD_INTEGER(asm_instr) \ #define ASSEMBLE_CHECKED_LOAD_INTEGER(asm_instr) \
do { \ do { \
auto result = i.OutputRegister(); \ auto result = i.OutputRegister(); \
auto buffer = i.InputRegister(0); \ auto buffer = i.InputRegister(0); \
auto index1 = i.InputRegister(1); \ auto index1 = i.InputRegister(1); \
auto index2 = i.InputInt32(2); \ auto index2 = i.InputUint32(2); \
OutOfLineCode* ool; \ OutOfLineCode* ool; \
if (instr->InputAt(3)->IsRegister()) { \ if (instr->InputAt(3)->IsRegister()) { \
auto length = i.InputRegister(3); \ auto length = i.InputRegister(3); \
...@@ -441,9 +439,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -441,9 +439,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ cmpl(index1, length); \ __ cmpl(index1, length); \
ool = new (zone()) OutOfLineLoadZero(this, result); \ ool = new (zone()) OutOfLineLoadZero(this, result); \
} else { \ } else { \
auto length = i.InputInt32(3); \ auto length = i.InputUint32(3); \
DCHECK_LE(index2, length); \ DCHECK_LE(index2, length); \
__ cmpq(index1, Immediate(length - index2)); \ __ cmpl(index1, Immediate(length - index2)); \
class OutOfLineLoadInteger final : public OutOfLineCode { \ class OutOfLineLoadInteger final : public OutOfLineCode { \
public: \ public: \
OutOfLineLoadInteger(CodeGenerator* gen, Register result, \ OutOfLineLoadInteger(CodeGenerator* gen, Register result, \
...@@ -483,12 +481,11 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -483,12 +481,11 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ bind(ool->exit()); \ __ bind(ool->exit()); \
} while (false) } while (false)
#define ASSEMBLE_CHECKED_STORE_FLOAT(asm_instr) \ #define ASSEMBLE_CHECKED_STORE_FLOAT(asm_instr) \
do { \ do { \
auto buffer = i.InputRegister(0); \ auto buffer = i.InputRegister(0); \
auto index1 = i.InputRegister(1); \ auto index1 = i.InputRegister(1); \
auto index2 = i.InputInt32(2); \ auto index2 = i.InputUint32(2); \
auto value = i.InputDoubleRegister(4); \ auto value = i.InputDoubleRegister(4); \
if (instr->InputAt(3)->IsRegister()) { \ if (instr->InputAt(3)->IsRegister()) { \
auto length = i.InputRegister(3); \ auto length = i.InputRegister(3); \
...@@ -499,9 +496,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -499,9 +496,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ asm_instr(Operand(buffer, index1, times_1, index2), value); \ __ asm_instr(Operand(buffer, index1, times_1, index2), value); \
__ bind(&done); \ __ bind(&done); \
} else { \ } else { \
auto length = i.InputInt32(3); \ auto length = i.InputUint32(3); \
DCHECK_LE(index2, length); \ DCHECK_LE(index2, length); \
__ cmpq(index1, Immediate(length - index2)); \ __ cmpl(index1, Immediate(length - index2)); \
class OutOfLineStoreFloat final : public OutOfLineCode { \ class OutOfLineStoreFloat final : public OutOfLineCode { \
public: \ public: \
OutOfLineStoreFloat(CodeGenerator* gen, Register buffer, \ OutOfLineStoreFloat(CodeGenerator* gen, Register buffer, \
...@@ -537,12 +534,11 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -537,12 +534,11 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
} \ } \
} while (false) } while (false)
#define ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Value) \ #define ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Value) \
do { \ do { \
auto buffer = i.InputRegister(0); \ auto buffer = i.InputRegister(0); \
auto index1 = i.InputRegister(1); \ auto index1 = i.InputRegister(1); \
auto index2 = i.InputInt32(2); \ auto index2 = i.InputUint32(2); \
if (instr->InputAt(3)->IsRegister()) { \ if (instr->InputAt(3)->IsRegister()) { \
auto length = i.InputRegister(3); \ auto length = i.InputRegister(3); \
DCHECK_EQ(0, index2); \ DCHECK_EQ(0, index2); \
...@@ -552,9 +548,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -552,9 +548,9 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ asm_instr(Operand(buffer, index1, times_1, index2), value); \ __ asm_instr(Operand(buffer, index1, times_1, index2), value); \
__ bind(&done); \ __ bind(&done); \
} else { \ } else { \
auto length = i.InputInt32(3); \ auto length = i.InputUint32(3); \
DCHECK_LE(index2, length); \ DCHECK_LE(index2, length); \
__ cmpq(index1, Immediate(length - index2)); \ __ cmpl(index1, Immediate(length - index2)); \
class OutOfLineStoreInteger final : public OutOfLineCode { \ class OutOfLineStoreInteger final : public OutOfLineCode { \
public: \ public: \
OutOfLineStoreInteger(CodeGenerator* gen, Register buffer, \ OutOfLineStoreInteger(CodeGenerator* gen, Register buffer, \
...@@ -590,7 +586,6 @@ class OutOfLineRecordWrite final : public OutOfLineCode { ...@@ -590,7 +586,6 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
} \ } \
} while (false) } while (false)
#define ASSEMBLE_CHECKED_STORE_INTEGER(asm_instr) \ #define ASSEMBLE_CHECKED_STORE_INTEGER(asm_instr) \
do { \ do { \
if (instr->InputAt(4)->IsRegister()) { \ if (instr->InputAt(4)->IsRegister()) { \
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
'compiler/test-run-jsexceptions.cc', 'compiler/test-run-jsexceptions.cc',
'compiler/test-run-jsobjects.cc', 'compiler/test-run-jsobjects.cc',
'compiler/test-run-jsops.cc', 'compiler/test-run-jsops.cc',
'compiler/test-run-load-store.cc',
'compiler/test-run-machops.cc', 'compiler/test-run-machops.cc',
'compiler/test-run-native-calls.cc', 'compiler/test-run-native-calls.cc',
'compiler/test-run-stackcheck.cc', 'compiler/test-run-stackcheck.cc',
......
This diff is collapsed.
...@@ -1207,94 +1207,6 @@ TEST(RunSwitch4) { ...@@ -1207,94 +1207,6 @@ TEST(RunSwitch4) {
} }
TEST(RunLoadInt32) {
RawMachineAssemblerTester<int32_t> m;
int32_t p1 = 0; // loads directly from this location.
m.Return(m.LoadFromPointer(&p1, MachineType::Int32()));
FOR_INT32_INPUTS(i) {
p1 = *i;
CHECK_EQ(p1, m.Call());
}
}
TEST(RunLoadInt32Offset) {
int32_t p1 = 0; // loads directly from this location.
int32_t offsets[] = {-2000000, -100, -101, 1, 3,
7, 120, 2000, 2000000000, 0xff};
for (size_t i = 0; i < arraysize(offsets); i++) {
RawMachineAssemblerTester<int32_t> m;
int32_t offset = offsets[i];
byte* pointer = reinterpret_cast<byte*>(&p1) - offset;
// generate load [#base + #index]
m.Return(m.LoadFromPointer(pointer, MachineType::Int32(), offset));
FOR_INT32_INPUTS(j) {
p1 = *j;
CHECK_EQ(p1, m.Call());
}
}
}
TEST(RunLoadStoreFloat32Offset) {
float p1 = 0.0f; // loads directly from this location.
float p2 = 0.0f; // and stores directly into this location.
FOR_INT32_INPUTS(i) {
int32_t magic = 0x2342aabb + *i * 3;
RawMachineAssemblerTester<int32_t> m;
int32_t offset = *i;
byte* from = reinterpret_cast<byte*>(&p1) - offset;
byte* to = reinterpret_cast<byte*>(&p2) - offset;
// generate load [#base + #index]
Node* load = m.Load(MachineType::Float32(), m.PointerConstant(from),
m.IntPtrConstant(offset));
m.Store(MachineRepresentation::kFloat32, m.PointerConstant(to),
m.IntPtrConstant(offset), load, kNoWriteBarrier);
m.Return(m.Int32Constant(magic));
FOR_FLOAT32_INPUTS(j) {
p1 = *j;
p2 = *j - 5;
CHECK_EQ(magic, m.Call());
CHECK_DOUBLE_EQ(p1, p2);
}
}
}
TEST(RunLoadStoreFloat64Offset) {
double p1 = 0; // loads directly from this location.
double p2 = 0; // and stores directly into this location.
FOR_INT32_INPUTS(i) {
int32_t magic = 0x2342aabb + *i * 3;
RawMachineAssemblerTester<int32_t> m;
int32_t offset = *i;
byte* from = reinterpret_cast<byte*>(&p1) - offset;
byte* to = reinterpret_cast<byte*>(&p2) - offset;
// generate load [#base + #index]
Node* load = m.Load(MachineType::Float64(), m.PointerConstant(from),
m.IntPtrConstant(offset));
m.Store(MachineRepresentation::kFloat64, m.PointerConstant(to),
m.IntPtrConstant(offset), load, kNoWriteBarrier);
m.Return(m.Int32Constant(magic));
FOR_FLOAT64_INPUTS(j) {
p1 = *j;
p2 = *j - 5;
CHECK_EQ(magic, m.Call());
CHECK_DOUBLE_EQ(p1, p2);
}
}
}
TEST(RunInt32AddP) { TEST(RunInt32AddP) {
RawMachineAssemblerTester<int32_t> m; RawMachineAssemblerTester<int32_t> m;
Int32BinopTester bt(&m); Int32BinopTester bt(&m);
...@@ -3635,92 +3547,6 @@ TEST(RunDeadInt32Binops) { ...@@ -3635,92 +3547,6 @@ TEST(RunDeadInt32Binops) {
} }
template <typename Type>
static void RunLoadImmIndex(MachineType rep) {
const int kNumElems = 3;
Type buffer[kNumElems];
// initialize the buffer with some raw data.
byte* raw = reinterpret_cast<byte*>(buffer);
for (size_t i = 0; i < sizeof(buffer); i++) {
raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA);
}
// Test with various large and small offsets.
for (int offset = -1; offset <= 200000; offset *= -5) {
for (int i = 0; i < kNumElems; i++) {
BufferedRawMachineAssemblerTester<Type> m;
Node* base = m.PointerConstant(buffer - offset);
Node* index = m.Int32Constant((offset + i) * sizeof(buffer[0]));
m.Return(m.Load(rep, base, index));
volatile Type expected = buffer[i];
volatile Type actual = m.Call();
CHECK_EQ(expected, actual);
}
}
}
TEST(RunLoadImmIndex) {
RunLoadImmIndex<int8_t>(MachineType::Int8());
RunLoadImmIndex<uint8_t>(MachineType::Uint8());
RunLoadImmIndex<int16_t>(MachineType::Int16());
RunLoadImmIndex<uint16_t>(MachineType::Uint16());
RunLoadImmIndex<int32_t>(MachineType::Int32());
RunLoadImmIndex<uint32_t>(MachineType::Uint32());
RunLoadImmIndex<int32_t*>(MachineType::AnyTagged());
RunLoadImmIndex<float>(MachineType::Float32());
RunLoadImmIndex<double>(MachineType::Float64());
if (kPointerSize == 8) {
RunLoadImmIndex<int64_t>(MachineType::Int64());
}
// TODO(titzer): test various indexing modes.
}
template <typename CType>
static void RunLoadStore(MachineType rep) {
const int kNumElems = 4;
CType buffer[kNumElems];
for (int32_t x = 0; x < kNumElems; x++) {
int32_t y = kNumElems - x - 1;
// initialize the buffer with raw data.
byte* raw = reinterpret_cast<byte*>(buffer);
for (size_t i = 0; i < sizeof(buffer); i++) {
raw[i] = static_cast<byte>((i + sizeof(buffer)) ^ 0xAA);
}
RawMachineAssemblerTester<int32_t> m;
int32_t OK = 0x29000 + x;
Node* base = m.PointerConstant(buffer);
Node* index0 = m.IntPtrConstant(x * sizeof(buffer[0]));
Node* load = m.Load(rep, base, index0);
Node* index1 = m.IntPtrConstant(y * sizeof(buffer[0]));
m.Store(rep.representation(), base, index1, load, kNoWriteBarrier);
m.Return(m.Int32Constant(OK));
CHECK(buffer[x] != buffer[y]);
CHECK_EQ(OK, m.Call());
CHECK(buffer[x] == buffer[y]);
}
}
TEST(RunLoadStore) {
RunLoadStore<int8_t>(MachineType::Int8());
RunLoadStore<uint8_t>(MachineType::Uint8());
RunLoadStore<int16_t>(MachineType::Int16());
RunLoadStore<uint16_t>(MachineType::Uint16());
RunLoadStore<int32_t>(MachineType::Int32());
RunLoadStore<uint32_t>(MachineType::Uint32());
RunLoadStore<void*>(MachineType::AnyTagged());
RunLoadStore<float>(MachineType::Float32());
RunLoadStore<double>(MachineType::Float64());
}
TEST(RunFloat32Add) { TEST(RunFloat32Add) {
BufferedRawMachineAssemblerTester<float> m(MachineType::Float32(), BufferedRawMachineAssemblerTester<float> m(MachineType::Float32(),
MachineType::Float32()); MachineType::Float32());
...@@ -5087,45 +4913,6 @@ TEST(RunFloat64LessThan) { ...@@ -5087,45 +4913,6 @@ TEST(RunFloat64LessThan) {
} }
template <typename IntType>
static void LoadStoreTruncation(MachineType kRepresentation) {
IntType input;
RawMachineAssemblerTester<int32_t> m;
Node* a = m.LoadFromPointer(&input, kRepresentation);
Node* ap1 = m.Int32Add(a, m.Int32Constant(1));
m.StoreToPointer(&input, kRepresentation.representation(), ap1);
m.Return(ap1);
const IntType max = std::numeric_limits<IntType>::max();
const IntType min = std::numeric_limits<IntType>::min();
// Test upper bound.
input = max;
CHECK_EQ(max + 1, m.Call());
CHECK_EQ(min, input);
// Test lower bound.
input = min;
CHECK_EQ(static_cast<IntType>(max + 2), m.Call());
CHECK_EQ(min + 1, input);
// Test all one byte values that are not one byte bounds.
for (int i = -127; i < 127; i++) {
input = i;
int expected = i >= 0 ? i + 1 : max + (i - min) + 2;
CHECK_EQ(static_cast<IntType>(expected), m.Call());
CHECK_EQ(static_cast<IntType>(i + 1), input);
}
}
TEST(RunLoadStoreTruncation) {
LoadStoreTruncation<int8_t>(MachineType::Int8());
LoadStoreTruncation<int16_t>(MachineType::Int16());
}
static void IntPtrCompare(intptr_t left, intptr_t right) { static void IntPtrCompare(intptr_t left, intptr_t right) {
for (int test = 0; test < 7; test++) { for (int test = 0; test < 7; test++) {
RawMachineAssemblerTester<bool> m(MachineType::Pointer(), RawMachineAssemblerTester<bool> m(MachineType::Pointer(),
...@@ -5973,50 +5760,6 @@ TEST(RunCallCFunction8) { ...@@ -5973,50 +5760,6 @@ TEST(RunCallCFunction8) {
#if V8_TARGET_ARCH_64_BIT #if V8_TARGET_ARCH_64_BIT
// TODO(titzer): run int64 tests on all platforms when supported. // TODO(titzer): run int64 tests on all platforms when supported.
TEST(RunCheckedLoadInt64) {
int64_t buffer[] = {0x66bbccddeeff0011LL, 0x1122334455667788LL};
RawMachineAssemblerTester<int64_t> m(MachineType::Int32());
Node* base = m.PointerConstant(buffer);
Node* index = m.Parameter(0);
Node* length = m.Int32Constant(16);
Node* load = m.AddNode(m.machine()->CheckedLoad(MachineType::Int64()), base,
index, length);
m.Return(load);
CHECK_EQ(buffer[0], m.Call(0));
CHECK_EQ(buffer[1], m.Call(8));
CHECK_EQ(0, m.Call(16));
}
TEST(RunCheckedStoreInt64) {
const int64_t write = 0x5566778899aabbLL;
const int64_t before = 0x33bbccddeeff0011LL;
int64_t buffer[] = {before, before};
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
Node* base = m.PointerConstant(buffer);
Node* index = m.Parameter(0);
Node* length = m.Int32Constant(16);
Node* value = m.Int64Constant(write);
Node* store =
m.AddNode(m.machine()->CheckedStore(MachineRepresentation::kWord64), base,
index, length, value);
USE(store);
m.Return(m.Int32Constant(11));
CHECK_EQ(11, m.Call(16));
CHECK_EQ(before, buffer[0]);
CHECK_EQ(before, buffer[1]);
CHECK_EQ(11, m.Call(0));
CHECK_EQ(write, buffer[0]);
CHECK_EQ(before, buffer[1]);
CHECK_EQ(11, m.Call(8));
CHECK_EQ(write, buffer[0]);
CHECK_EQ(write, buffer[1]);
}
TEST(RunBitcastInt64ToFloat64) { TEST(RunBitcastInt64ToFloat64) {
int64_t input = 1; int64_t input = 1;
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm
function __f_61(stdlib, buffer) {
"use asm";
var __v_14 = new stdlib.Float64Array(buffer);
function __f_74() {
var __v_35 = 6.0;
__v_14[2] = __v_35 + 1.0;
}
return {__f_74: __f_74};
}
var ok = false;
try {
var __v_12 = new ArrayBuffer(2147483648);
ok = true;
} catch (e) {
// Can happen on 32 bit systems.
}
if (ok) {
var module = Wasm.instantiateModuleFromAsm( __f_61.toString(), null, __v_12);
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --expose-wasm
function __f_7() {
%DeoptimizeFunction(__f_5);
}
function __f_8(global, env) {
"use asm";
var __f_7 = env.__f_7;
function __f_9(i4, i5) {
i4 = i4 | 0;
i5 = i5 | 0;
__f_7();
}
return {'__f_9': __f_9}
}
function __f_5() {
var __v_5 = Wasm.instantiateModuleFromAsm( __f_8.toString(), {'__f_7': __f_7});
__v_5.__f_9(0, 0, 0);
}
__f_5();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment