Commit 15951521 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Refactor inlined typed array runtime functions.

R=dslomov@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20177 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 493c6b35
......@@ -980,6 +980,31 @@ void FullCodeGenerator::EmitConstructDouble(CallRuntime* expr) {
}
void FullCodeGenerator::EmitTypedArrayInitialize(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
ASSERT(args->length() == 5);
for (int i = 0; i < 5; i++) VisitForStackValue(args->at(i));
masm()->CallRuntime(Runtime::kTypedArrayInitialize, 5);
context()->Plug(result_register());
}
void FullCodeGenerator::EmitDataViewInitialize(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
ASSERT(args->length() == 4);
for (int i = 0; i < 4; i++) VisitForStackValue(args->at(i));
masm()->CallRuntime(Runtime::kDataViewInitialize, 4);
context()->Plug(result_register());
}
void FullCodeGenerator::EmitMaxSmi(CallRuntime* expr) {
ASSERT(expr->arguments()->length() == 0);
masm()->CallRuntime(Runtime::kMaxSmi, 0);
context()->Plug(result_register());
}
void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
switch (expr->op()) {
case Token::COMMA:
......
......@@ -8439,7 +8439,7 @@ void HGraphBuilder::BuildArrayBufferViewInitialization(
}
void HOptimizedGraphBuilder::VisitDataViewInitialize(
void HOptimizedGraphBuilder::GenerateDataViewInitialize(
CallRuntime* expr) {
ZoneList<Expression*>* arguments = expr->arguments();
......@@ -8462,7 +8462,7 @@ void HOptimizedGraphBuilder::VisitDataViewInitialize(
}
void HOptimizedGraphBuilder::VisitTypedArrayInitialize(
void HOptimizedGraphBuilder::GenerateTypedArrayInitialize(
CallRuntime* expr) {
ZoneList<Expression*>* arguments = expr->arguments();
......@@ -8581,6 +8581,13 @@ void HOptimizedGraphBuilder::VisitTypedArrayInitialize(
}
void HOptimizedGraphBuilder::GenerateMaxSmi(CallRuntime* expr) {
ASSERT(expr->arguments()->length() == 0);
HConstant* max_smi = New<HConstant>(static_cast<int32_t>(Smi::kMaxValue));
return ast_context()->ReturnInstruction(max_smi, expr->id());
}
void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
......@@ -8592,20 +8599,6 @@ void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
const Runtime::Function* function = expr->function();
ASSERT(function != NULL);
if (function->function_id == Runtime::kDataViewInitialize) {
return VisitDataViewInitialize(expr);
}
if (function->function_id == Runtime::kTypedArrayInitialize) {
return VisitTypedArrayInitialize(expr);
}
if (function->function_id == Runtime::kMaxSmi) {
ASSERT(expr->arguments()->length() == 0);
HConstant* max_smi = New<HConstant>(static_cast<int32_t>(Smi::kMaxValue));
return ast_context()->ReturnInstruction(max_smi, expr->id());
}
if (function->intrinsic_type == Runtime::INLINE) {
ASSERT(expr->name()->length() > 0);
ASSERT(expr->name()->Get(0) == '_');
......
......@@ -2321,13 +2321,9 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
SmallMapList* types,
Handle<String> name);
void VisitTypedArrayInitialize(CallRuntime* expr);
bool IsCallNewArrayInlineable(CallNew* expr);
void BuildInlinedCallNewArray(CallNew* expr);
void VisitDataViewInitialize(CallRuntime* expr);
class PropertyAccessInfo {
public:
PropertyAccessInfo(HOptimizedGraphBuilder* builder,
......
......@@ -111,7 +111,6 @@ namespace internal {
F(FlattenString, 1, 1) \
F(TryMigrateInstance, 1, 1) \
F(NotifyContextDisposed, 0, 1) \
F(MaxSmi, 0, 1) \
\
/* Array join support */ \
F(PushIfAbsent, 2, 1) \
......@@ -368,7 +367,6 @@ namespace internal {
F(ArrayBufferIsView, 1, 1) \
F(ArrayBufferNeuter, 1, 1) \
\
F(TypedArrayInitialize, 5, 1) \
F(TypedArrayInitializeFromArrayLike, 4, 1) \
F(TypedArrayGetBuffer, 1, 1) \
F(TypedArrayGetByteLength, 1, 1) \
......@@ -376,7 +374,6 @@ namespace internal {
F(TypedArrayGetLength, 1, 1) \
F(TypedArraySetFastCases, 3, 1) \
\
F(DataViewInitialize, 4, 1) \
F(DataViewGetBuffer, 1, 1) \
F(DataViewGetByteLength, 1, 1) \
F(DataViewGetByteOffset, 1, 1) \
......@@ -662,7 +659,10 @@ namespace internal {
F(NumberToString, 1, 1) \
F(DoubleHi, 1, 1) \
F(DoubleLo, 1, 1) \
F(ConstructDouble, 2, 1)
F(ConstructDouble, 2, 1) \
F(TypedArrayInitialize, 5, 1) \
F(DataViewInitialize, 4, 1) \
F(MaxSmi, 0, 1)
//---------------------------------------------------------------------------
......
......@@ -87,28 +87,28 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
newByteLength = newLength * ELEMENT_SIZE;
}
if ((offset + newByteLength > bufferByteLength)
|| (newLength > %MaxSmi())) {
|| (newLength > %_MaxSmi())) {
throw MakeRangeError("invalid_typed_array_length");
}
%TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
%_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
}
function NAMEConstructByLength(obj, length) {
var l = IS_UNDEFINED(length) ?
0 : ToPositiveInteger(length, "invalid_typed_array_length");
if (l > %MaxSmi()) {
if (l > %_MaxSmi()) {
throw MakeRangeError("invalid_typed_array_length");
}
var byteLength = l * ELEMENT_SIZE;
var buffer = new $ArrayBuffer(byteLength);
%TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
%_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
}
function NAMEConstructByArrayLike(obj, arrayLike) {
var length = arrayLike.length;
var l = ToPositiveInteger(length, "invalid_typed_array_length");
if (l > %MaxSmi()) {
if (l > %_MaxSmi()) {
throw MakeRangeError("invalid_typed_array_length");
}
if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
......@@ -350,7 +350,7 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
if (length < 0 || offset + length > bufferByteLength) {
throw new MakeRangeError('invalid_data_view_length');
}
%DataViewInitialize(this, buffer, offset, length);
%_DataViewInitialize(this, buffer, offset, length);
} else {
throw MakeTypeError('constructor_not_function', ["DataView"]);
}
......
......@@ -206,17 +206,14 @@ var knownProblems = {
"_TwoByteSeqStringSetChar": true,
// Only applicable to TypedArrays.
"TypedArrayInitialize": true,
"_TypedArrayInitialize": true,
// Only applicable to generators.
"_GeneratorNext": true,
"_GeneratorThrow": true,
// Only applicable to DataViews.
"DataViewInitialize": true,
"DataViewGetBuffer": true,
"DataViewGetByteLength": true,
"DataViewGetByteOffset": true
"_DataViewInitialize": true,
};
var currentlyUncallable = {
......
......@@ -207,17 +207,14 @@ var knownProblems = {
"_TwoByteSeqStringSetChar": true,
// Only applicable to TypedArrays.
"TypedArrayInitialize": true,
"_TypedArrayInitialize": true,
// Only applicable to generators.
"_GeneratorNext": true,
"_GeneratorThrow": true,
// Only applicable to DataViews.
"DataViewInitialize": true,
"DataViewGetBuffer": true,
"DataViewGetByteLength": true,
"DataViewGetByteOffset": true
"_DataViewInitialize": true,
};
var currentlyUncallable = {
......
......@@ -206,17 +206,14 @@ var knownProblems = {
"_TwoByteSeqStringSetChar": true,
// Only applicable to TypedArrays.
"TypedArrayInitialize": true,
"_TypedArrayInitialize": true,
// Only applicable to generators.
"_GeneratorNext": true,
"_GeneratorThrow": true,
// Only applicable to DataViews.
"DataViewInitialize":true,
"DataViewGetBuffer": true,
"DataViewGetByteLength": true,
"DataViewGetByteOffset": true,
"_DataViewInitialize":true,
};
var currentlyUncallable = {
......
......@@ -206,17 +206,14 @@ var knownProblems = {
"_TwoByteSeqStringSetChar": true,
// Only applicable to TypedArrays.
"TypedArrayInitialize": true,
"_TypedArrayInitialize": true,
// Only applicable to generators.
"_GeneratorNext": true,
"_GeneratorThrow": true,
// Only applicable to DataViews.
"DataViewInitialize": true,
"DataViewGetBuffer": true,
"DataViewGetByteLength": true,
"DataViewGetByteOffset": true
"_DataViewInitialize": true,
};
var currentlyUncallable = {
......
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