OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 typedef uint32_t (*HASH_FUNCTION)(); | 45 typedef uint32_t (*HASH_FUNCTION)(); |
46 | 46 |
47 static v8::Persistent<v8::Context> env; | 47 static v8::Persistent<v8::Context> env; |
48 | 48 |
49 #define __ assm-> | 49 #define __ assm-> |
50 | 50 |
51 | 51 |
52 void generate(MacroAssembler* assm, i::Vector<const char> string) { | 52 void generate(MacroAssembler* assm, i::Vector<const char> string) { |
53 #ifdef V8_TARGET_ARCH_IA32 | 53 #ifdef V8_TARGET_ARCH_IA32 |
| 54 __ push(ebx); |
| 55 __ push(ecx); |
54 __ mov(eax, Immediate(0)); | 56 __ mov(eax, Immediate(0)); |
55 if (string.length() > 0) { | 57 if (string.length() > 0) { |
56 __ mov(ebx, Immediate(string.at(0))); | 58 __ mov(ebx, Immediate(string.at(0))); |
57 StringHelper::GenerateHashInit(assm, eax, ebx, ecx); | 59 StringHelper::GenerateHashInit(assm, eax, ebx, ecx); |
58 } | 60 } |
59 for (int i = 1; i < string.length(); i++) { | 61 for (int i = 1; i < string.length(); i++) { |
60 __ mov(ebx, Immediate(string.at(i))); | 62 __ mov(ebx, Immediate(string.at(i))); |
61 StringHelper::GenerateHashAddCharacter(assm, eax, ebx, ecx); | 63 StringHelper::GenerateHashAddCharacter(assm, eax, ebx, ecx); |
62 } | 64 } |
63 StringHelper::GenerateHashGetHash(assm, eax, ecx); | 65 StringHelper::GenerateHashGetHash(assm, eax, ecx); |
| 66 __ pop(ecx); |
| 67 __ pop(ebx); |
64 __ Ret(); | 68 __ Ret(); |
65 #elif V8_TARGET_ARCH_X64 | 69 #elif V8_TARGET_ARCH_X64 |
| 70 __ push(rbx); |
| 71 __ push(rcx); |
66 __ movq(rax, Immediate(0)); | 72 __ movq(rax, Immediate(0)); |
67 if (string.length() > 0) { | 73 if (string.length() > 0) { |
68 __ movq(rbx, Immediate(string.at(0))); | 74 __ movq(rbx, Immediate(string.at(0))); |
69 StringHelper::GenerateHashInit(assm, rax, rbx, rcx); | 75 StringHelper::GenerateHashInit(assm, rax, rbx, rcx); |
70 } | 76 } |
71 for (int i = 1; i < string.length(); i++) { | 77 for (int i = 1; i < string.length(); i++) { |
72 __ movq(rbx, Immediate(string.at(i))); | 78 __ movq(rbx, Immediate(string.at(i))); |
73 StringHelper::GenerateHashAddCharacter(assm, rax, rbx, rcx); | 79 StringHelper::GenerateHashAddCharacter(assm, rax, rbx, rcx); |
74 } | 80 } |
75 StringHelper::GenerateHashGetHash(assm, rax, rcx); | 81 StringHelper::GenerateHashGetHash(assm, rax, rcx); |
| 82 __ pop(rcx); |
| 83 __ pop(rbx); |
76 __ Ret(); | 84 __ Ret(); |
77 #elif V8_TARGET_ARCH_ARM | 85 #elif V8_TARGET_ARCH_ARM |
78 __ mov(r0, Operand(0)); | 86 __ mov(r0, Operand(0)); |
79 if (string.length() > 0) { | 87 if (string.length() > 0) { |
80 __ mov(r1, Operand(string.at(0))); | 88 __ mov(ip, Operand(string.at(0))); |
81 StringHelper::GenerateHashInit(assm, r0, r1); | 89 StringHelper::GenerateHashInit(assm, r0, ip); |
82 } | 90 } |
83 for (int i = 1; i < string.length(); i++) { | 91 for (int i = 1; i < string.length(); i++) { |
84 __ mov(r1, Operand(string.at(i))); | 92 __ mov(ip, Operand(string.at(i))); |
85 StringHelper::GenerateHashAddCharacter(assm, r0, r1); | 93 StringHelper::GenerateHashAddCharacter(assm, r0, ip); |
86 } | 94 } |
87 StringHelper::GenerateHashGetHash(assm, r0); | 95 StringHelper::GenerateHashGetHash(assm, r0); |
88 __ mov(pc, Operand(lr)); | 96 __ mov(pc, Operand(lr)); |
89 #elif V8_TARGET_ARCH_MIPS | 97 #elif V8_TARGET_ARCH_MIPS |
90 __ li(v0, Operand(0)); | 98 __ li(v0, Operand(0)); |
91 if (string.length() > 0) { | 99 if (string.length() > 0) { |
92 __ li(v1, Operand(string.at(0))); | 100 __ li(t1, Operand(string.at(0))); |
93 StringHelper::GenerateHashInit(assm, v0, v1); | 101 StringHelper::GenerateHashInit(assm, v0, t1); |
94 } | 102 } |
95 for (int i = 1; i < string.length(); i++) { | 103 for (int i = 1; i < string.length(); i++) { |
96 __ li(v1, Operand(string.at(i))); | 104 __ li(t1, Operand(string.at(i))); |
97 StringHelper::GenerateHashAddCharacter(assm, v0, v1); | 105 StringHelper::GenerateHashAddCharacter(assm, v0, t1); |
98 } | 106 } |
99 StringHelper::GenerateHashGetHash(assm, v0); | 107 StringHelper::GenerateHashGetHash(assm, v0); |
100 __ jr(ra); | 108 __ jr(ra); |
101 #endif | 109 #endif |
102 } | 110 } |
103 | 111 |
104 | 112 |
105 void check(i::Vector<const char> string) { | 113 void check(i::Vector<const char> string) { |
106 v8::HandleScope scope; | 114 v8::HandleScope scope; |
107 v8::internal::byte buffer[2048]; | 115 v8::internal::byte buffer[2048]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 157 } |
150 check(i::Vector<const char>("", 0)); | 158 check(i::Vector<const char>("", 0)); |
151 check(i::Vector<const char>("*", 1)); | 159 check(i::Vector<const char>("*", 1)); |
152 check(i::Vector<const char>(".zZ", 3)); | 160 check(i::Vector<const char>(".zZ", 3)); |
153 check(i::Vector<const char>("muc", 3)); | 161 check(i::Vector<const char>("muc", 3)); |
154 check(i::Vector<const char>("(>'_')>", 7)); | 162 check(i::Vector<const char>("(>'_')>", 7)); |
155 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); | 163 check(i::Vector<const char>("-=[ vee eight ftw ]=-", 21)); |
156 } | 164 } |
157 | 165 |
158 #undef __ | 166 #undef __ |
OLD | NEW |