Commit 5294179e authored by yangguo@chromium.org's avatar yangguo@chromium.org

Remove dead code for inline string hashing.

This has become obsolete since hydrogenized StringAdd.

R=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23689 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 94671afb
...@@ -2919,48 +2919,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, ...@@ -2919,48 +2919,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
} }
void StringHelper::GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character) {
// hash = character + (character << 10);
__ LoadRoot(hash, Heap::kHashSeedRootIndex);
// Untag smi seed and add the character.
__ add(hash, character, Operand(hash, LSR, kSmiTagSize));
// hash += hash << 10;
__ add(hash, hash, Operand(hash, LSL, 10));
// hash ^= hash >> 6;
__ eor(hash, hash, Operand(hash, LSR, 6));
}
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character) {
// hash += character;
__ add(hash, hash, Operand(character));
// hash += hash << 10;
__ add(hash, hash, Operand(hash, LSL, 10));
// hash ^= hash >> 6;
__ eor(hash, hash, Operand(hash, LSR, 6));
}
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
Register hash) {
// hash += hash << 3;
__ add(hash, hash, Operand(hash, LSL, 3));
// hash ^= hash >> 11;
__ eor(hash, hash, Operand(hash, LSR, 11));
// hash += hash << 15;
__ add(hash, hash, Operand(hash, LSL, 15));
__ and_(hash, hash, Operand(String::kHashBitMask), SetCC);
// if (hash == 0) hash = 27;
__ mov(hash, Operand(StringHasher::kZeroHash), LeaveCC, eq);
}
void SubStringStub::Generate(MacroAssembler* masm) { void SubStringStub::Generate(MacroAssembler* masm) {
Label runtime; Label runtime;
......
...@@ -27,19 +27,6 @@ class StringHelper : public AllStatic { ...@@ -27,19 +27,6 @@ class StringHelper : public AllStatic {
Register scratch, Register scratch,
String::Encoding encoding); String::Encoding encoding);
// Generate string hash.
static void GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character);
static void GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character);
static void GenerateHashGetHash(MacroAssembler* masm,
Register hash);
// Compares two flat ASCII strings and returns result in r0. // Compares two flat ASCII strings and returns result in r0.
static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm, static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
Register left, Register left,
......
...@@ -3532,67 +3532,6 @@ void CompareICStub::GenerateMiss(MacroAssembler* masm) { ...@@ -3532,67 +3532,6 @@ void CompareICStub::GenerateMiss(MacroAssembler* masm) {
} }
void StringHelper::GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character) {
DCHECK(!AreAliased(hash, character));
// hash = character + (character << 10);
__ LoadRoot(hash, Heap::kHashSeedRootIndex);
// Untag smi seed and add the character.
__ Add(hash, character, Operand::UntagSmi(hash));
// Compute hashes modulo 2^32 using a 32-bit W register.
Register hash_w = hash.W();
// hash += hash << 10;
__ Add(hash_w, hash_w, Operand(hash_w, LSL, 10));
// hash ^= hash >> 6;
__ Eor(hash_w, hash_w, Operand(hash_w, LSR, 6));
}
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character) {
DCHECK(!AreAliased(hash, character));
// hash += character;
__ Add(hash, hash, character);
// Compute hashes modulo 2^32 using a 32-bit W register.
Register hash_w = hash.W();
// hash += hash << 10;
__ Add(hash_w, hash_w, Operand(hash_w, LSL, 10));
// hash ^= hash >> 6;
__ Eor(hash_w, hash_w, Operand(hash_w, LSR, 6));
}
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch) {
// Compute hashes modulo 2^32 using a 32-bit W register.
Register hash_w = hash.W();
Register scratch_w = scratch.W();
DCHECK(!AreAliased(hash_w, scratch_w));
// hash += hash << 3;
__ Add(hash_w, hash_w, Operand(hash_w, LSL, 3));
// hash ^= hash >> 11;
__ Eor(hash_w, hash_w, Operand(hash_w, LSR, 11));
// hash += hash << 15;
__ Add(hash_w, hash_w, Operand(hash_w, LSL, 15));
__ Ands(hash_w, hash_w, String::kHashBitMask);
// if (hash == 0) hash = 27;
__ Mov(scratch_w, StringHasher::kZeroHash);
__ Csel(hash_w, scratch_w, hash_w, eq);
}
void SubStringStub::Generate(MacroAssembler* masm) { void SubStringStub::Generate(MacroAssembler* masm) {
ASM_LOCATION("SubStringStub::Generate"); ASM_LOCATION("SubStringStub::Generate");
Label runtime; Label runtime;
......
...@@ -16,21 +16,6 @@ void ArrayNativeCode(MacroAssembler* masm, Label* call_generic_code); ...@@ -16,21 +16,6 @@ void ArrayNativeCode(MacroAssembler* masm, Label* call_generic_code);
class StringHelper : public AllStatic { class StringHelper : public AllStatic {
public: public:
// TODO(all): These don't seem to be used any more. Delete them.
// Generate string hash.
static void GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character);
static void GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character);
static void GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch);
// Compares two flat ASCII strings and returns result in x0. // Compares two flat ASCII strings and returns result in x0.
static void GenerateCompareFlatAsciiStrings( static void GenerateCompareFlatAsciiStrings(
MacroAssembler* masm, Register left, Register right, Register scratch1, MacroAssembler* masm, Register left, Register right, Register scratch1,
......
...@@ -2895,74 +2895,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, ...@@ -2895,74 +2895,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
} }
void StringHelper::GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character,
Register scratch) {
// hash = (seed + character) + ((seed + character) << 10);
if (masm->serializer_enabled()) {
__ LoadRoot(scratch, Heap::kHashSeedRootIndex);
__ SmiUntag(scratch);
__ add(scratch, character);
__ mov(hash, scratch);
__ shl(scratch, 10);
__ add(hash, scratch);
} else {
int32_t seed = masm->isolate()->heap()->HashSeed();
__ lea(scratch, Operand(character, seed));
__ shl(scratch, 10);
__ lea(hash, Operand(scratch, character, times_1, seed));
}
// hash ^= hash >> 6;
__ mov(scratch, hash);
__ shr(scratch, 6);
__ xor_(hash, scratch);
}
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character,
Register scratch) {
// hash += character;
__ add(hash, character);
// hash += hash << 10;
__ mov(scratch, hash);
__ shl(scratch, 10);
__ add(hash, scratch);
// hash ^= hash >> 6;
__ mov(scratch, hash);
__ shr(scratch, 6);
__ xor_(hash, scratch);
}
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch) {
// hash += hash << 3;
__ mov(scratch, hash);
__ shl(scratch, 3);
__ add(hash, scratch);
// hash ^= hash >> 11;
__ mov(scratch, hash);
__ shr(scratch, 11);
__ xor_(hash, scratch);
// hash += hash << 15;
__ mov(scratch, hash);
__ shl(scratch, 15);
__ add(hash, scratch);
__ and_(hash, String::kHashBitMask);
// if (hash == 0) hash = 27;
Label hash_not_zero;
__ j(not_zero, &hash_not_zero, Label::kNear);
__ mov(hash, Immediate(StringHasher::kZeroHash));
__ bind(&hash_not_zero);
}
void SubStringStub::Generate(MacroAssembler* masm) { void SubStringStub::Generate(MacroAssembler* masm) {
Label runtime; Label runtime;
......
...@@ -28,21 +28,6 @@ class StringHelper : public AllStatic { ...@@ -28,21 +28,6 @@ class StringHelper : public AllStatic {
Register scratch, Register scratch,
String::Encoding encoding); String::Encoding encoding);
// Generate string hash.
static void GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character,
Register scratch);
static void GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character,
Register scratch);
static void GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch);
// Compares two flat ASCII strings and returns result in eax. // Compares two flat ASCII strings and returns result in eax.
static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm, static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
Register left, Register right, Register left, Register right,
......
...@@ -2846,65 +2846,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, ...@@ -2846,65 +2846,6 @@ void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
} }
void StringHelper::GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character,
Register scratch) {
// hash = (seed + character) + ((seed + character) << 10);
__ LoadRoot(scratch, Heap::kHashSeedRootIndex);
__ SmiToInteger32(scratch, scratch);
__ addl(scratch, character);
__ movl(hash, scratch);
__ shll(scratch, Immediate(10));
__ addl(hash, scratch);
// hash ^= hash >> 6;
__ movl(scratch, hash);
__ shrl(scratch, Immediate(6));
__ xorl(hash, scratch);
}
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character,
Register scratch) {
// hash += character;
__ addl(hash, character);
// hash += hash << 10;
__ movl(scratch, hash);
__ shll(scratch, Immediate(10));
__ addl(hash, scratch);
// hash ^= hash >> 6;
__ movl(scratch, hash);
__ shrl(scratch, Immediate(6));
__ xorl(hash, scratch);
}
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch) {
// hash += hash << 3;
__ leal(hash, Operand(hash, hash, times_8, 0));
// hash ^= hash >> 11;
__ movl(scratch, hash);
__ shrl(scratch, Immediate(11));
__ xorl(hash, scratch);
// hash += hash << 15;
__ movl(scratch, hash);
__ shll(scratch, Immediate(15));
__ addl(hash, scratch);
__ andl(hash, Immediate(String::kHashBitMask));
// if (hash == 0) hash = 27;
Label hash_not_zero;
__ j(not_zero, &hash_not_zero);
__ Set(hash, StringHasher::kZeroHash);
__ bind(&hash_not_zero);
}
void SubStringStub::Generate(MacroAssembler* masm) { void SubStringStub::Generate(MacroAssembler* masm) {
Label runtime; Label runtime;
......
...@@ -25,22 +25,6 @@ class StringHelper : public AllStatic { ...@@ -25,22 +25,6 @@ class StringHelper : public AllStatic {
Register count, Register count,
String::Encoding encoding); String::Encoding encoding);
// Generate string hash.
static void GenerateHashInit(MacroAssembler* masm,
Register hash,
Register character,
Register scratch);
static void GenerateHashAddCharacter(MacroAssembler* masm,
Register hash,
Register character,
Register scratch);
static void GenerateHashGetHash(MacroAssembler* masm,
Register hash,
Register scratch);
// Compares two flat ASCII strings and returns result in rax. // Compares two flat ASCII strings and returns result in rax.
static void GenerateCompareFlatAsciiStrings( static void GenerateCompareFlatAsciiStrings(
MacroAssembler* masm, Register left, Register right, Register scratch1, MacroAssembler* masm, Register left, Register right, Register scratch1,
......
...@@ -47,94 +47,6 @@ typedef uint32_t (*HASH_FUNCTION)(); ...@@ -47,94 +47,6 @@ typedef uint32_t (*HASH_FUNCTION)();
#define __ masm-> #define __ masm->
void generate(MacroAssembler* masm, i::Vector<const uint8_t> string) {
// GenerateHashInit takes the first character as an argument so it can't
// handle the zero length string.
DCHECK(string.length() > 0);
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
__ push(ebx);
__ push(ecx);
__ mov(eax, Immediate(0));
__ mov(ebx, Immediate(string.at(0)));
StringHelper::GenerateHashInit(masm, eax, ebx, ecx);
for (int i = 1; i < string.length(); i++) {
__ mov(ebx, Immediate(string.at(i)));
StringHelper::GenerateHashAddCharacter(masm, eax, ebx, ecx);
}
StringHelper::GenerateHashGetHash(masm, eax, ecx);
__ pop(ecx);
__ pop(ebx);
__ Ret();
#elif V8_TARGET_ARCH_X64
__ pushq(kRootRegister);
__ InitializeRootRegister();
__ pushq(rbx);
__ pushq(rcx);
__ movp(rax, Immediate(0));
__ movp(rbx, Immediate(string.at(0)));
StringHelper::GenerateHashInit(masm, rax, rbx, rcx);
for (int i = 1; i < string.length(); i++) {
__ movp(rbx, Immediate(string.at(i)));
StringHelper::GenerateHashAddCharacter(masm, rax, rbx, rcx);
}
StringHelper::GenerateHashGetHash(masm, rax, rcx);
__ popq(rcx);
__ popq(rbx);
__ popq(kRootRegister);
__ Ret();
#elif V8_TARGET_ARCH_ARM
__ push(kRootRegister);
__ InitializeRootRegister();
__ mov(r0, Operand(0));
__ mov(ip, Operand(string.at(0)));
StringHelper::GenerateHashInit(masm, r0, ip);
for (int i = 1; i < string.length(); i++) {
__ mov(ip, Operand(string.at(i)));
StringHelper::GenerateHashAddCharacter(masm, r0, ip);
}
StringHelper::GenerateHashGetHash(masm, r0);
__ pop(kRootRegister);
__ mov(pc, Operand(lr));
#elif V8_TARGET_ARCH_ARM64
// The ARM64 assembler usually uses jssp (x28) as a stack pointer, but only
// csp is initialized by the calling (C++) code.
Register old_stack_pointer = __ StackPointer();
__ SetStackPointer(csp);
__ Push(root, xzr);
__ InitializeRootRegister();
__ Mov(x0, 0);
__ Mov(x10, Operand(string.at(0)));
StringHelper::GenerateHashInit(masm, x0, x10);
for (int i = 1; i < string.length(); i++) {
__ Mov(x10, Operand(string.at(i)));
StringHelper::GenerateHashAddCharacter(masm, x0, x10);
}
StringHelper::GenerateHashGetHash(masm, x0, x10);
__ Pop(xzr, root);
__ Ret();
__ SetStackPointer(old_stack_pointer);
#elif V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64
__ push(kRootRegister);
__ InitializeRootRegister();
__ mov(v0, zero_reg);
__ li(t1, Operand(string.at(0)));
StringHelper::GenerateHashInit(masm, v0, t1);
for (int i = 1; i < string.length(); i++) {
__ li(t1, Operand(string.at(i)));
StringHelper::GenerateHashAddCharacter(masm, v0, t1);
}
StringHelper::GenerateHashGetHash(masm, v0);
__ pop(kRootRegister);
__ jr(ra);
__ nop();
#else
#error Unsupported architecture.
#endif
}
void generate(MacroAssembler* masm, uint32_t key) { void generate(MacroAssembler* masm, uint32_t key) {
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
__ push(ebx); __ push(ebx);
...@@ -184,44 +96,6 @@ void generate(MacroAssembler* masm, uint32_t key) { ...@@ -184,44 +96,6 @@ void generate(MacroAssembler* masm, uint32_t key) {
} }
void check(i::Vector<const uint8_t> string) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
HandleScope scope(isolate);
v8::internal::byte buffer[2048];
MacroAssembler masm(isolate, buffer, sizeof buffer);
generate(&masm, string);
CodeDesc desc;
masm.GetCode(&desc);
Handle<Object> undefined(isolate->heap()->undefined_value(), isolate);
Handle<Code> code = factory->NewCode(desc,
Code::ComputeFlags(Code::STUB),
undefined);
CHECK(code->IsCode());
HASH_FUNCTION hash = FUNCTION_CAST<HASH_FUNCTION>(code->entry());
Handle<String> v8_string =
factory->NewStringFromOneByte(string).ToHandleChecked();
v8_string->set_hash_field(String::kEmptyHashField);
#ifdef USE_SIMULATOR
uint32_t codegen_hash = static_cast<uint32_t>(
reinterpret_cast<uintptr_t>(CALL_GENERATED_CODE(hash, 0, 0, 0, 0, 0)));
#else
uint32_t codegen_hash = hash();
#endif
uint32_t runtime_hash = v8_string->Hash();
CHECK(runtime_hash == codegen_hash);
}
void check(i::Vector<const char> s) {
check(i::Vector<const uint8_t>::cast(s));
}
void check(uint32_t key) { void check(uint32_t key) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
...@@ -253,38 +127,11 @@ void check(uint32_t key) { ...@@ -253,38 +127,11 @@ void check(uint32_t key) {
} }
void check_twochars(uint8_t a, uint8_t b) {
uint8_t ab[2] = {a, b};
check(i::Vector<const uint8_t>(ab, 2));
}
static uint32_t PseudoRandom(uint32_t i, uint32_t j) { static uint32_t PseudoRandom(uint32_t i, uint32_t j) {
return ~(~((i * 781) ^ (j * 329))); return ~(~((i * 781) ^ (j * 329)));
} }
TEST(StringHash) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(v8::Context::New(isolate));
for (uint8_t a = 0; a < String::kMaxOneByteCharCode; a++) {
// Numbers are hashed differently.
if (a >= '0' && a <= '9') continue;
for (uint8_t b = 0; b < String::kMaxOneByteCharCode; b++) {
if (b >= '0' && b <= '9') continue;
check_twochars(a, b);
}
}
check(i::Vector<const char>("*", 1));
check(i::Vector<const char>(".zZ", 3));
check(i::Vector<const char>("muc", 3));
check(i::Vector<const char>("(>'_')>", 7));
check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21));
}
TEST(NumberHash) { TEST(NumberHash) {
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
......
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