diff options
Diffstat (limited to 'deps/v8/test/cctest/test-code-stub-assembler.cc')
-rw-r--r-- | deps/v8/test/cctest/test-code-stub-assembler.cc | 184 |
1 files changed, 178 insertions, 6 deletions
diff --git a/deps/v8/test/cctest/test-code-stub-assembler.cc b/deps/v8/test/cctest/test-code-stub-assembler.cc index 1ba26a81b8..67aafa8709 100644 --- a/deps/v8/test/cctest/test-code-stub-assembler.cc +++ b/deps/v8/test/cctest/test-code-stub-assembler.cc @@ -1890,13 +1890,21 @@ TEST(AllocateJSObjectFromMap) { "object"))); JSObject::NormalizeProperties(isolate, object, KEEP_INOBJECT_PROPERTIES, 0, "Normalize"); + Handle<HeapObject> properties = + V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL + ? Handle<HeapObject>(object->property_dictionary_swiss(), isolate) + : handle(object->property_dictionary(), isolate); Handle<JSObject> result = Handle<JSObject>::cast( - ft.Call(handle(object->map(), isolate), - handle(object->property_dictionary(), isolate), + ft.Call(handle(object->map(), isolate), properties, handle(object->elements(), isolate)) .ToHandleChecked()); CHECK_EQ(result->map(), object->map()); - CHECK_EQ(result->property_dictionary(), object->property_dictionary()); + if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) { + CHECK_EQ(result->property_dictionary_swiss(), + object->property_dictionary_swiss()); + } else { + CHECK_EQ(result->property_dictionary(), object->property_dictionary()); + } CHECK(!result->HasFastProperties()); #ifdef VERIFY_HEAP isolate->heap()->Verify(); @@ -2445,6 +2453,90 @@ TEST(IsDebugActive) { *debug_is_active = false; } +// Ensure that the kShortBuiltinCallsOldSpaceSizeThreshold constant can be used +// for detecting whether the machine has >= 4GB of physical memory by checking +// the max old space size. +TEST(ShortBuiltinCallsThreshold) { + if (!V8_SHORT_BUILTIN_CALLS_BOOL) return; + + const uint64_t kPhysicalMemoryThreshold = size_t{4} * GB; + + size_t heap_size, old, young; + + // If the physical memory is < kPhysicalMemoryThreshold then the old space + // size must be below the kShortBuiltinCallsOldSpaceThreshold. + heap_size = Heap::HeapSizeFromPhysicalMemory(kPhysicalMemoryThreshold - MB); + i::Heap::GenerationSizesFromHeapSize(heap_size, &young, &old); + CHECK_LT(old, kShortBuiltinCallsOldSpaceSizeThreshold); + + // If the physical memory is >= kPhysicalMemoryThreshold then the old space + // size must be below the kShortBuiltinCallsOldSpaceThreshold. + heap_size = Heap::HeapSizeFromPhysicalMemory(kPhysicalMemoryThreshold); + i::Heap::GenerationSizesFromHeapSize(heap_size, &young, &old); + CHECK_GE(old, kShortBuiltinCallsOldSpaceSizeThreshold); + + heap_size = Heap::HeapSizeFromPhysicalMemory(kPhysicalMemoryThreshold + MB); + i::Heap::GenerationSizesFromHeapSize(heap_size, &young, &old); + CHECK_GE(old, kShortBuiltinCallsOldSpaceSizeThreshold); +} + +TEST(CallBuiltin) { + Isolate* isolate(CcTest::InitIsolateOnce()); + + const int kNumParams = 2; + CodeAssemblerTester asm_tester(isolate, + kNumParams + 1); // Include receiver. + PromiseBuiltinsAssembler m(asm_tester.state()); + + { + auto receiver = m.Parameter<Object>(1); + auto name = m.Parameter<Name>(2); + auto context = m.Parameter<Context>(kNumParams + 3); + + auto value = m.CallBuiltin(Builtins::kGetProperty, context, receiver, name); + m.Return(value); + } + + FunctionTester ft(asm_tester.GenerateCode(), kNumParams); + + Factory* factory = isolate->factory(); + Handle<Name> name = factory->InternalizeUtf8String("a"); + Handle<Object> value(Smi::FromInt(153), isolate); + Handle<JSObject> object = factory->NewJSObjectWithNullProto(); + JSObject::AddProperty(isolate, object, name, value, NONE); + + Handle<Object> result = ft.Call(object, name).ToHandleChecked(); + CHECK_EQ(*value, *result); +} + +TEST(TailCallBuiltin) { + Isolate* isolate(CcTest::InitIsolateOnce()); + + const int kNumParams = 2; + CodeAssemblerTester asm_tester(isolate, + kNumParams + 1); // Include receiver. + PromiseBuiltinsAssembler m(asm_tester.state()); + + { + auto receiver = m.Parameter<Object>(1); + auto name = m.Parameter<Name>(2); + auto context = m.Parameter<Context>(kNumParams + 3); + + m.TailCallBuiltin(Builtins::kGetProperty, context, receiver, name); + } + + FunctionTester ft(asm_tester.GenerateCode(), kNumParams); + + Factory* factory = isolate->factory(); + Handle<Name> name = factory->InternalizeUtf8String("a"); + Handle<Object> value(Smi::FromInt(153), isolate); + Handle<JSObject> object = factory->NewJSObjectWithNullProto(); + JSObject::AddProperty(isolate, object, name, value, NONE); + + Handle<Object> result = ft.Call(object, name).ToHandleChecked(); + CHECK_EQ(*value, *result); +} + class AppendJSArrayCodeStubAssembler : public CodeStubAssembler { public: AppendJSArrayCodeStubAssembler(compiler::CodeAssemblerState* state, @@ -2595,8 +2687,7 @@ TEST(IsPromiseHookEnabled) { CodeStubAssembler m(asm_tester.state()); m.Return( - m.SelectBooleanConstant( - m.IsIsolatePromiseHookEnabledOrHasAsyncEventDelegate())); + m.SelectBooleanConstant(m.IsPromiseHookEnabledOrHasAsyncEventDelegate())); FunctionTester ft(asm_tester.GenerateCode(), kNumParams); Handle<Object> result = @@ -3136,7 +3227,7 @@ TEST(DirectMemoryTest16BitWord32) { for (size_t i = 0; i < element_count; ++i) { for (size_t j = 0; j < element_count; ++j) { - Node* loaded = m.LoadBufferData<Uint16T>( + TNode<Uint16T> loaded = m.LoadBufferData<Uint16T>( buffer_node1, static_cast<int>(i * sizeof(int16_t))); TNode<Word32T> masked = m.Word32And(loaded, constants[j]); if ((buffer[j] & buffer[i]) != 0) { @@ -3881,6 +3972,7 @@ TEST(InstructionSchedulingCallerSavedRegisters) { FLAG_turbo_instruction_scheduling = old_turbo_instruction_scheduling; } +#if V8_ENABLE_WEBASSEMBLY TEST(WasmInt32ToHeapNumber) { Isolate* isolate(CcTest::InitIsolateOnce()); @@ -4107,6 +4199,7 @@ TEST(WasmTaggedToFloat64) { } } } +#endif // V8_ENABLE_WEBASSEMBLY TEST(SmiUntagLeftShiftOptimization) { Isolate* isolate(CcTest::InitIsolateOnce()); @@ -4155,6 +4248,85 @@ TEST(SmiUntagComparisonOptimization) { FunctionTester ft(asm_tester.GenerateCode(options), kNumParams); } +TEST(PopCount) { + Isolate* isolate(CcTest::InitIsolateOnce()); + + CodeAssemblerTester asm_tester(isolate); + CodeStubAssembler m(asm_tester.state()); + + const std::vector<std::pair<uint32_t, int>> test_cases = { + {0, 0}, + {1, 1}, + {(1 << 31), 1}, + {0b01010101010101010101010101010101, 16}, + {0b10101010101010101010101010101010, 16}, + {0b11100011100000011100011111000111, 17} // arbitrarily chosen + }; + + for (std::pair<uint32_t, int> test_case : test_cases) { + uint32_t value32 = test_case.first; + uint64_t value64 = (static_cast<uint64_t>(value32) << 32) | value32; + int expected_pop32 = test_case.second; + int expected_pop64 = 2 * expected_pop32; + + TNode<Int32T> pop32 = m.PopulationCount32(m.Uint32Constant(value32)); + CSA_CHECK(&m, m.Word32Equal(pop32, m.Int32Constant(expected_pop32))); + + if (m.Is64()) { + // TODO(emrich): enable once 64-bit operations are supported on 32-bit + // architectures. + + TNode<Int64T> pop64 = m.PopulationCount64(m.Uint64Constant(value64)); + CSA_CHECK(&m, m.Word64Equal(pop64, m.Int64Constant(expected_pop64))); + } + } + m.Return(m.UndefinedConstant()); + + FunctionTester ft(asm_tester.GenerateCode()); + ft.Call(); +} + +TEST(CountTrailingZeros) { + Isolate* isolate(CcTest::InitIsolateOnce()); + + CodeAssemblerTester asm_tester(isolate); + CodeStubAssembler m(asm_tester.state()); + + const std::vector<std::pair<uint32_t, int>> test_cases = { + {1, 0}, + {2, 1}, + {(0b0101010'0000'0000), 9}, + {(1 << 31), 31}, + {std::numeric_limits<uint32_t>::max(), 0}, + }; + + for (std::pair<uint32_t, int> test_case : test_cases) { + uint32_t value32 = test_case.first; + uint64_t value64 = static_cast<uint64_t>(value32) << 32; + int expected_ctz32 = test_case.second; + int expected_ctz64 = expected_ctz32 + 32; + + TNode<Int32T> pop32 = m.CountTrailingZeros32(m.Uint32Constant(value32)); + CSA_CHECK(&m, m.Word32Equal(pop32, m.Int32Constant(expected_ctz32))); + + if (m.Is64()) { + // TODO(emrich): enable once 64-bit operations are supported on 32-bit + // architectures. + + TNode<Int64T> pop64_ext = + m.CountTrailingZeros64(m.Uint64Constant(value32)); + TNode<Int64T> pop64 = m.CountTrailingZeros64(m.Uint64Constant(value64)); + + CSA_CHECK(&m, m.Word64Equal(pop64_ext, m.Int64Constant(expected_ctz32))); + CSA_CHECK(&m, m.Word64Equal(pop64, m.Int64Constant(expected_ctz64))); + } + } + m.Return(m.UndefinedConstant()); + + FunctionTester ft(asm_tester.GenerateCode()); + ft.Call(); +} + } // namespace compiler } // namespace internal } // namespace v8 |