From 15951521cc9a475e8df4416244e90287dd4963b4 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 24 Mar 2014 08:22:24 +0000 Subject: [PATCH] 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 --- src/full-codegen.cc | 25 +++++++++++++++++++++++++ src/hydrogen.cc | 25 +++++++++---------------- src/hydrogen.h | 4 ---- src/runtime.h | 8 ++++---- src/typedarray.js | 12 ++++++------ test/mjsunit/fuzz-natives-part1.js | 7 ++----- test/mjsunit/fuzz-natives-part2.js | 7 ++----- test/mjsunit/fuzz-natives-part3.js | 7 ++----- test/mjsunit/fuzz-natives-part4.js | 7 ++----- 9 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/full-codegen.cc b/src/full-codegen.cc index 2170b84..e401e0c 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -980,6 +980,31 @@ void FullCodeGenerator::EmitConstructDouble(CallRuntime* expr) { } +void FullCodeGenerator::EmitTypedArrayInitialize(CallRuntime* expr) { + ZoneList* 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* 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: diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 0be9dfb..8705f78 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -8439,7 +8439,7 @@ void HGraphBuilder::BuildArrayBufferViewInitialization( } -void HOptimizedGraphBuilder::VisitDataViewInitialize( +void HOptimizedGraphBuilder::GenerateDataViewInitialize( CallRuntime* expr) { ZoneList* arguments = expr->arguments(); @@ -8462,7 +8462,7 @@ void HOptimizedGraphBuilder::VisitDataViewInitialize( } -void HOptimizedGraphBuilder::VisitTypedArrayInitialize( +void HOptimizedGraphBuilder::GenerateTypedArrayInitialize( CallRuntime* expr) { ZoneList* arguments = expr->arguments(); @@ -8581,6 +8581,13 @@ void HOptimizedGraphBuilder::VisitTypedArrayInitialize( } +void HOptimizedGraphBuilder::GenerateMaxSmi(CallRuntime* expr) { + ASSERT(expr->arguments()->length() == 0); + HConstant* max_smi = New(static_cast(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(static_cast(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) == '_'); diff --git a/src/hydrogen.h b/src/hydrogen.h index e91199e..d0bfa02 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -2321,13 +2321,9 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { SmallMapList* types, Handle name); - void VisitTypedArrayInitialize(CallRuntime* expr); - bool IsCallNewArrayInlineable(CallNew* expr); void BuildInlinedCallNewArray(CallNew* expr); - void VisitDataViewInitialize(CallRuntime* expr); - class PropertyAccessInfo { public: PropertyAccessInfo(HOptimizedGraphBuilder* builder, diff --git a/src/runtime.h b/src/runtime.h index aa811a6..18509bd 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -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) //--------------------------------------------------------------------------- diff --git a/src/typedarray.js b/src/typedarray.js index cba8993..a7a6d87 100644 --- a/src/typedarray.js +++ b/src/typedarray.js @@ -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"]); } diff --git a/test/mjsunit/fuzz-natives-part1.js b/test/mjsunit/fuzz-natives-part1.js index e22ac49..1bbe49e 100644 --- a/test/mjsunit/fuzz-natives-part1.js +++ b/test/mjsunit/fuzz-natives-part1.js @@ -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 = { diff --git a/test/mjsunit/fuzz-natives-part2.js b/test/mjsunit/fuzz-natives-part2.js index 293ad7e..394c2d7 100644 --- a/test/mjsunit/fuzz-natives-part2.js +++ b/test/mjsunit/fuzz-natives-part2.js @@ -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 = { diff --git a/test/mjsunit/fuzz-natives-part3.js b/test/mjsunit/fuzz-natives-part3.js index 1f33cef..28c24b0 100644 --- a/test/mjsunit/fuzz-natives-part3.js +++ b/test/mjsunit/fuzz-natives-part3.js @@ -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 = { diff --git a/test/mjsunit/fuzz-natives-part4.js b/test/mjsunit/fuzz-natives-part4.js index 5f1f912..2a336ca 100644 --- a/test/mjsunit/fuzz-natives-part4.js +++ b/test/mjsunit/fuzz-natives-part4.js @@ -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 = { -- 2.7.4