Commit 54194b2d authored by ishell's avatar ishell Committed by Commit bot

[stubs] Cleanup CSA::BitFieldDecode(..) and friends.

This CL also introduces IsSetWord<T>(..) and IsSetWord32<T>(..) operations
to ease checking if the bit field is set or not.

BUG=

Review-Url: https://chromiumcodereview.appspot.com/2436893003
Cr-Commit-Position: refs/heads/master@{#40466}
parent 4490a760
...@@ -207,7 +207,7 @@ void Builtins::Generate_NumberParseFloat(CodeStubAssembler* assembler) { ...@@ -207,7 +207,7 @@ void Builtins::Generate_NumberParseFloat(CodeStubAssembler* assembler) {
{ {
// Just return the {input}s cached array index. // Just return the {input}s cached array index.
Node* input_array_index = Node* input_array_index =
assembler->BitFieldDecodeWord<String::ArrayIndexValueBits>( assembler->DecodeWordFromWord32<String::ArrayIndexValueBits>(
input_hash); input_hash);
assembler->Return(assembler->SmiTag(input_array_index)); assembler->Return(assembler->SmiTag(input_array_index));
} }
...@@ -340,7 +340,8 @@ void Builtins::Generate_NumberParseInt(CodeStubAssembler* assembler) { ...@@ -340,7 +340,8 @@ void Builtins::Generate_NumberParseInt(CodeStubAssembler* assembler) {
// Return the cached array index as result. // Return the cached array index as result.
Node* input_index = Node* input_index =
assembler->BitFieldDecode<String::ArrayIndexValueBits>(input_hash); assembler->DecodeWordFromWord32<String::ArrayIndexValueBits>(
input_hash);
Node* result = assembler->SmiTag(input_index); Node* result = assembler->SmiTag(input_index);
assembler->Return(result); assembler->Return(result);
} }
......
...@@ -488,17 +488,11 @@ void Builtins::Generate_ObjectCreate(CodeStubAssembler* a) { ...@@ -488,17 +488,11 @@ void Builtins::Generate_ObjectCreate(CodeStubAssembler* a) {
a->GotoUnless(a->WordEqual(a->LoadElements(properties), a->GotoUnless(a->WordEqual(a->LoadElements(properties),
a->LoadRoot(Heap::kEmptyFixedArrayRootIndex)), a->LoadRoot(Heap::kEmptyFixedArrayRootIndex)),
&call_runtime); &call_runtime);
// Jump to the runtime for slow objects. // Handle dictionary objects or fast objects with properties in runtime.
Node* bit_field3 = a->LoadMapBitField3(properties_map); Node* bit_field3 = a->LoadMapBitField3(properties_map);
Node* is_fast_map = a->Word32Equal( a->GotoIf(a->IsSetWord32<Map::DictionaryMap>(bit_field3), &call_runtime);
a->BitFieldDecode<Map::DictionaryMap>(bit_field3), a->Int32Constant(0)); a->Branch(a->IsSetWord32<Map::NumberOfOwnDescriptorsBits>(bit_field3),
a->GotoUnless(is_fast_map, &call_runtime); &call_runtime, &no_properties);
a->Branch(
a->WordEqual(
a->BitFieldDecodeWord<Map::NumberOfOwnDescriptorsBits>(bit_field3),
a->IntPtrConstant(0)),
&no_properties, &call_runtime);
} }
// Create a new object with the given prototype. // Create a new object with the given prototype.
......
...@@ -52,8 +52,9 @@ void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, ...@@ -52,8 +52,9 @@ void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged,
// Fail if the array's JSArrayBuffer is not shared. // Fail if the array's JSArrayBuffer is not shared.
a->Bind(&is_typed_array); a->Bind(&is_typed_array);
Node* array_buffer = a->LoadObjectField(tagged, JSTypedArray::kBufferOffset); Node* array_buffer = a->LoadObjectField(tagged, JSTypedArray::kBufferOffset);
Node* is_buffer_shared = a->BitFieldDecode<JSArrayBuffer::IsShared>( Node* is_buffer_shared =
a->LoadObjectField(array_buffer, JSArrayBuffer::kBitFieldSlot)); a->IsSetWord32<JSArrayBuffer::IsShared>(a->LoadObjectField(
array_buffer, JSArrayBuffer::kBitFieldSlot, MachineType::Uint32()));
a->Branch(is_buffer_shared, &is_shared, &not_shared); a->Branch(is_buffer_shared, &is_shared, &not_shared);
a->Bind(&not_shared); a->Bind(&not_shared);
a->Goto(&invalid); a->Goto(&invalid);
......
This diff is collapsed.
...@@ -659,20 +659,45 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -659,20 +659,45 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
// Returns a node that contains a decoded (unsigned!) value of a bit // Returns a node that contains a decoded (unsigned!) value of a bit
// field |T| in |word32|. Returns result as an uint32 node. // field |T| in |word32|. Returns result as an uint32 node.
template <typename T> template <typename T>
compiler::Node* BitFieldDecode(compiler::Node* word32) { compiler::Node* DecodeWord32(compiler::Node* word32) {
return BitFieldDecode(word32, T::kShift, T::kMask); return DecodeWord32(word32, T::kShift, T::kMask);
}
// Returns a node that contains a decoded (unsigned!) value of a bit
// field |T| in |word|. Returns result as a word-size node.
template <typename T>
compiler::Node* DecodeWord(compiler::Node* word) {
return DecodeWord(word, T::kShift, T::kMask);
} }
// Returns a node that contains a decoded (unsigned!) value of a bit // Returns a node that contains a decoded (unsigned!) value of a bit
// field |T| in |word32|. Returns result as a word-size node. // field |T| in |word32|. Returns result as a word-size node.
template <typename T> template <typename T>
compiler::Node* BitFieldDecodeWord(compiler::Node* word32) { compiler::Node* DecodeWordFromWord32(compiler::Node* word32) {
return ChangeUint32ToWord(BitFieldDecode<T>(word32)); return DecodeWord<T>(ChangeUint32ToWord(word32));
} }
// Decodes an unsigned (!) value from |word32| to an uint32 node. // Decodes an unsigned (!) value from |word32| to an uint32 node.
compiler::Node* BitFieldDecode(compiler::Node* word32, uint32_t shift, compiler::Node* DecodeWord32(compiler::Node* word32, uint32_t shift,
uint32_t mask); uint32_t mask);
// Decodes an unsigned (!) value from |word| to a word-size node.
compiler::Node* DecodeWord(compiler::Node* word, uint32_t shift,
uint32_t mask);
// Returns true if any of the |T|'s bits in given |word32| are set.
template <typename T>
compiler::Node* IsSetWord32(compiler::Node* word32) {
return Word32NotEqual(Word32And(word32, Int32Constant(T::kMask)),
Int32Constant(0));
}
// Returns true if any of the |T|'s bits in given |word| are set.
template <typename T>
compiler::Node* IsSetWord(compiler::Node* word) {
return WordNotEqual(WordAnd(word, IntPtrConstant(T::kMask)),
IntPtrConstant(0));
}
void SetCounter(StatsCounter* counter, int value); void SetCounter(StatsCounter* counter, int value);
void IncrementCounter(StatsCounter* counter, int delta); void IncrementCounter(StatsCounter* counter, int delta);
......
...@@ -2107,7 +2107,7 @@ void Interpreter::DoCreateObjectLiteral(InterpreterAssembler* assembler) { ...@@ -2107,7 +2107,7 @@ void Interpreter::DoCreateObjectLiteral(InterpreterAssembler* assembler) {
Label if_fast_clone(assembler), Label if_fast_clone(assembler),
if_not_fast_clone(assembler, Label::kDeferred); if_not_fast_clone(assembler, Label::kDeferred);
Node* fast_clone_properties_count = Node* fast_clone_properties_count =
__ BitFieldDecode<CreateObjectLiteralFlags::FastClonePropertiesCountBits>( __ DecodeWord32<CreateObjectLiteralFlags::FastClonePropertiesCountBits>(
bytecode_flags); bytecode_flags);
__ Branch(fast_clone_properties_count, &if_fast_clone, &if_not_fast_clone); __ Branch(fast_clone_properties_count, &if_fast_clone, &if_not_fast_clone);
......
...@@ -61,13 +61,14 @@ TEST(LoadInstanceType) { ...@@ -61,13 +61,14 @@ TEST(LoadInstanceType) {
Handle<Smi>::cast(result.ToHandleChecked())->value()); Handle<Smi>::cast(result.ToHandleChecked())->value());
} }
TEST(BitFieldDecode) { TEST(DecodeWordFromWord32) {
Isolate* isolate(CcTest::InitIsolateOnce()); Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate); VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor); CodeStubAssemblerTester m(isolate, descriptor);
class TestBitField : public BitField<unsigned, 3, 3> {}; class TestBitField : public BitField<unsigned, 3, 3> {};
m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f)))); m.Return(
m.SmiTag(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2f))));
Handle<Code> code = m.GenerateCode(); Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code); FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call(); MaybeHandle<Object> result = ft.Call();
......
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