Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 * Please notice that this is the byte offset, not the character offset! | 44 * Please notice that this is the byte offset, not the character offset! |
| 45 * - esi : end of input (points to byte after last character in input). | 45 * - esi : end of input (points to byte after last character in input). |
| 46 * - ebp : points to the location above the registers on the stack, | 46 * - ebp : points to the location above the registers on the stack, |
| 47 * as if by the "enter <register_count>" opcode. | 47 * as if by the "enter <register_count>" opcode. |
| 48 * - esp : points to tip of backtracking stack. | 48 * - esp : points to tip of backtracking stack. |
| 49 * | 49 * |
| 50 * The registers eax, ebx and ecx are free to use for computations. | 50 * The registers eax, ebx and ecx are free to use for computations. |
| 51 * | 51 * |
| 52 * Each call to a public method should retain this convention. | 52 * Each call to a public method should retain this convention. |
| 53 * The stack will have the following structure: | 53 * The stack will have the following structure: |
| 54 * - at_start (if 1, start at start of string, if 0, don't) | |
| 54 * - int* capture_array (int[num_saved_registers_], for output). | 55 * - int* capture_array (int[num_saved_registers_], for output). |
| 55 * - end of input (index of end of string, relative to *string_base) | 56 * - end of input (index of end of string, relative to *string_base) |
| 56 * - start of input (index of first character in string, relative | 57 * - start of input (index of first character in string, relative |
| 57 * to *string_base) | 58 * to *string_base) |
| 58 * - void** string_base (location of a handle containing the string) | 59 * - void** string_base (location of a handle containing the string) |
| 59 * - return address | 60 * - return address |
| 60 * - backup of esi | 61 * - backup of esi |
| 61 * - backup of edi | 62 * - backup of edi |
| 63 * - backup of ebx | |
| 62 * ebp-> - old ebp | 64 * ebp-> - old ebp |
| 63 * - register 0 ebp[-4] (Only positions must be stored in the first | 65 * - register 0 ebp[-4] (Only positions must be stored in the first |
| 64 * - register 1 ebp[-8] num_saved_registers_ registers) | 66 * - register 1 ebp[-8] num_saved_registers_ registers) |
| 65 * - ... | 67 * - ... |
| 66 * | 68 * |
| 67 * The first num_saved_registers_ registers are initialized to point to | 69 * The first num_saved_registers_ registers are initialized to point to |
| 68 * "character -1" in the string (i.e., char_size() bytes before the first | 70 * "character -1" in the string (i.e., char_size() bytes before the first |
| 69 * character of the string). The remaining registers starts out as garbage. | 71 * character of the string). The remaining registers starts out as garbage. |
| 70 * | 72 * |
| 71 * The data up to the return address must be placed there by the calling | 73 * The data up to the return address must be placed there by the calling |
| 72 * code, e.g., by calling the code as cast to: | 74 * code, e.g., by calling the code as cast to: |
| 73 * bool (*match)(String** string_base, | 75 * bool (*match)(String** string_base, |
| 74 * int start_offset, | 76 * int start_offset, |
| 75 * int end_offset, | 77 * int end_offset, |
| 76 * int* capture_output_array) | 78 * int* capture_output_array, |
| 79 * bool at_start) | |
| 77 */ | 80 */ |
| 78 | 81 |
| 79 #define __ masm_-> | 82 #define __ masm_-> |
| 80 | 83 |
| 81 RegExpMacroAssemblerIA32::RegExpMacroAssemblerIA32( | 84 RegExpMacroAssemblerIA32::RegExpMacroAssemblerIA32( |
| 82 Mode mode, | 85 Mode mode, |
| 83 int registers_to_save) | 86 int registers_to_save) |
| 84 : masm_(new MacroAssembler(NULL, kRegExpCodeSize)), | 87 : masm_(new MacroAssembler(NULL, kRegExpCodeSize)), |
| 85 constants_(kRegExpConstantsSize), | 88 constants_(kRegExpConstantsSize), |
| 86 mode_(mode), | 89 mode_(mode), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 131 |
| 129 | 132 |
| 130 void RegExpMacroAssemblerIA32::Bind(Label* label) { | 133 void RegExpMacroAssemblerIA32::Bind(Label* label) { |
| 131 __ bind(label); | 134 __ bind(label); |
| 132 } | 135 } |
| 133 | 136 |
| 134 void RegExpMacroAssemblerIA32::CheckBitmap(uc16 start, | 137 void RegExpMacroAssemblerIA32::CheckBitmap(uc16 start, |
| 135 Label* bitmap, | 138 Label* bitmap, |
| 136 Label* on_zero) { | 139 Label* on_zero) { |
| 137 UNREACHABLE(); | 140 UNREACHABLE(); |
| 138 ReadCurrentChar(eax); | 141 ReadCurrentChar(eax); |
|
Erik Corry
2008/11/30 19:39:27
The intention of this operation is that it operate
Lasse Reichstein
2008/12/04 15:18:37
The ReadCurrentChar function merely moves the alre
| |
| 139 __ sub(Operand(eax), Immediate(start)); | 142 __ sub(Operand(eax), Immediate(start)); |
| 140 __ cmp(eax, 64); // FIXME: 64 = length_of_bitmap_in_bits. | 143 __ cmp(eax, 64); // FIXME: 64 = length_of_bitmap_in_bits. |
| 141 BranchOrBacktrack(greater_equal, on_zero); | 144 BranchOrBacktrack(greater_equal, on_zero); |
| 142 __ mov(ebx, eax); | 145 __ mov(ebx, eax); |
| 143 __ shr(ebx, 3); | 146 __ shr(ebx, 3); |
| 144 // TODO(lrn): Where is the bitmap stored? Pass the bitmap as argument instead. | 147 // TODO(lrn): Where is the bitmap stored? Pass the bitmap as argument instead. |
| 145 // __ mov(ecx, position_of_bitmap); | 148 // __ mov(ecx, position_of_bitmap); |
| 146 __ movzx_b(ebx, Operand(ecx, ebx, times_1, 0)); | 149 __ movzx_b(ebx, Operand(ecx, ebx, times_1, 0)); |
| 147 __ and_(eax, (1<<3)-1); | 150 __ and_(eax, (1<<3)-1); |
| 148 __ bt(Operand(ebx), eax); | 151 __ bt(Operand(ebx), eax); |
| 149 __ j(carry, on_zero); | 152 __ j(carry, on_zero); |
| 150 } | 153 } |
| 151 | 154 |
| 152 | 155 |
| 153 void RegExpMacroAssemblerIA32::CheckCharacter(uc16 c, Label* on_equal) { | 156 void RegExpMacroAssemblerIA32::CheckCharacter(uc16 c, Label* on_equal) { |
| 154 __ cmp(edx, c); | 157 __ cmp(edx, c); |
| 155 BranchOrBacktrack(equal, on_equal); | 158 BranchOrBacktrack(equal, on_equal); |
| 156 } | 159 } |
| 157 | 160 |
| 158 | 161 |
| 159 void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) { | 162 void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) { |
| 160 __ cmp(edx, limit); | 163 __ cmp(edx, limit); |
| 161 BranchOrBacktrack(greater, on_greater); | 164 BranchOrBacktrack(greater, on_greater); |
| 162 } | 165 } |
| 163 | 166 |
| 164 | 167 |
| 165 void RegExpMacroAssemblerIA32::CheckNotAtStart(Label* on_not_at_start) { | 168 void RegExpMacroAssemblerIA32::CheckNotAtStart(Label* on_not_at_start) { |
| 166 UNIMPLEMENTED(); | 169 __ test(Operand(ebp, kAtStart), Immediate(0xffffffff)); |
|
Erik Corry
2008/11/30 19:39:27
I think a cmp against zero is less confusing here.
Lasse Reichstein
2008/12/04 15:18:37
Done.
| |
| 170 BranchOrBacktrack(equal, on_not_at_start); | |
| 171 __ mov(eax, Operand(ebp, kInputEndOffset)); | |
| 172 __ add(eax, Operand(edi)); | |
| 173 __ cmp(eax, Operand(ebp, kInputStartOffset)); | |
| 174 BranchOrBacktrack(not_equal, on_not_at_start); | |
| 167 } | 175 } |
| 168 | 176 |
| 169 | 177 |
| 170 void RegExpMacroAssemblerIA32::CheckCharacterLT(uc16 limit, Label* on_less) { | 178 void RegExpMacroAssemblerIA32::CheckCharacterLT(uc16 limit, Label* on_less) { |
| 171 __ cmp(edx, limit); | 179 __ cmp(edx, limit); |
| 172 BranchOrBacktrack(less, on_less); | 180 BranchOrBacktrack(less, on_less); |
| 173 } | 181 } |
| 174 | 182 |
| 175 | 183 |
| 176 void RegExpMacroAssemblerIA32::CheckCharacters(Vector<const uc16> str, | 184 void RegExpMacroAssemblerIA32::CheckCharacters(Vector<const uc16> str, |
| 177 int cp_offset, | 185 int cp_offset, |
| 178 Label* on_failure) { | 186 Label* on_failure) { |
| 179 int byte_length = str.length() * char_size(); | 187 int byte_length = str.length() * char_size(); |
| 180 int byte_offset = cp_offset * char_size(); | 188 int byte_offset = cp_offset * char_size(); |
| 181 __ mov(ebx, edi); | 189 __ cmp(Operand(edi), Immediate(-(byte_offset + byte_length))); |
| 182 __ add(Operand(ebx), Immediate(byte_offset + byte_length)); | 190 BranchOrBacktrack(greater, on_failure); |
| 183 BranchOrBacktrack(greater_equal, on_failure); | 191 |
| 192 if (str.length() <= kMaxInlineStringTests) { | |
| 193 for (int i = 0; i < str.length(); i++) { | |
| 194 if (mode_ == ASCII) { | |
| 195 __ cmpb(Operand(esi, edi, times_1, byte_offset + i), | |
| 196 static_cast<int8_t>(str[i])); | |
| 197 } else { | |
| 198 ASSERT(mode_ == UC16); | |
| 199 __ cmpw(Operand(esi, edi, times_1, byte_offset + i * sizeof(uc16)), | |
| 200 Immediate(str[i])); | |
| 201 } | |
| 202 __ j(not_equal, on_failure); | |
| 203 } | |
| 204 return; | |
| 205 } | |
| 184 | 206 |
| 185 ArraySlice constant_buffer = constants_.GetBuffer(str.length(), char_size()); | 207 ArraySlice constant_buffer = constants_.GetBuffer(str.length(), char_size()); |
| 186 if (mode_ == ASCII) { | 208 if (mode_ == ASCII) { |
| 187 for (int i = 0; i < str.length(); i++) { | 209 for (int i = 0; i < str.length(); i++) { |
| 188 constant_buffer.at<char>(i) = static_cast<char>(str[i]); | 210 constant_buffer.at<char>(i) = static_cast<char>(str[i]); |
| 189 } | 211 } |
| 190 } else { | 212 } else { |
| 191 memcpy(constant_buffer.location(), | 213 memcpy(constant_buffer.location(), |
| 192 str.start(), | 214 str.start(), |
| 193 str.length() * sizeof(uc16)); | 215 str.length() * sizeof(uc16)); |
| 194 } | 216 } |
| 195 | 217 |
| 196 __ mov(eax, edi); | 218 __ mov(eax, edi); |
| 197 __ mov(ebx, esi); | 219 __ mov(ebx, esi); |
| 198 __ lea(edi, Operand(esi, edi, times_1, byte_offset)); | 220 __ lea(edi, Operand(esi, edi, times_1, byte_offset)); |
| 199 LoadConstantBufferAddress(esi, &constant_buffer); | 221 LoadConstantBufferAddress(esi, &constant_buffer); |
| 200 __ mov(ecx, str.length() * char_size()); | 222 __ mov(ecx, str.length()); |
| 201 __ rep_cmpsb(); | 223 if (char_size() == 1) { |
| 224 __ rep_cmpsb(); | |
| 225 } else { | |
| 226 ASSERT(char_size() == 2); | |
| 227 __ rep_cmpsw(); | |
| 228 } | |
| 202 __ mov(esi, ebx); | 229 __ mov(esi, ebx); |
| 203 __ mov(edi, eax); | 230 __ mov(edi, eax); |
| 204 BranchOrBacktrack(not_equal, on_failure); | 231 BranchOrBacktrack(not_equal, on_failure); |
| 205 } | 232 } |
| 206 | 233 |
| 207 | 234 |
| 208 void RegExpMacroAssemblerIA32::CheckCurrentPosition(int register_index, | 235 void RegExpMacroAssemblerIA32::CheckCurrentPosition(int register_index, |
| 209 Label* on_equal) { | 236 Label* on_equal) { |
| 210 __ cmp(edi, register_location(register_index)); | 237 __ cmp(edi, register_location(register_index)); |
| 211 BranchOrBacktrack(equal, on_equal); | 238 BranchOrBacktrack(equal, on_equal); |
| 212 } | 239 } |
| 213 | 240 |
| 214 | 241 |
| 215 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase( | 242 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase( |
| 216 int start_reg, Label* on_no_match) { | 243 int start_reg, Label* on_no_match) { |
| 217 UNIMPLEMENTED(); | 244 Label fallthrough; |
| 245 __ mov(eax, register_location(start_reg)); | |
| 246 __ mov(ecx, register_location(start_reg + 1)); | |
| 247 __ sub(ecx, Operand(eax)); // Length to check. | |
| 248 __ j(less, on_no_match); | |
| 249 __ j(equal, &fallthrough); | |
| 250 | |
| 251 UNIMPLEMENTED(); // TODO(lrn): Call runtime function to do test. | |
| 252 | |
| 253 __ bind(&fallthrough); | |
| 218 } | 254 } |
| 219 | 255 |
| 220 | 256 |
| 221 void RegExpMacroAssemblerIA32::CheckNotBackReference( | 257 void RegExpMacroAssemblerIA32::CheckNotBackReference( |
| 222 int start_reg, Label* on_no_match) { | 258 int start_reg, Label* on_no_match) { |
| 223 Label fallthrough; | 259 Label fallthrough; |
| 224 __ mov(eax, register_location(start_reg)); | 260 __ mov(eax, register_location(start_reg)); |
| 225 __ mov(ecx, register_location(start_reg + 1)); | 261 __ mov(ecx, register_location(start_reg + 1)); |
| 226 __ sub(ecx, Operand(eax)); // Length to check. | 262 __ sub(ecx, Operand(eax)); // Length to check. |
| 227 __ j(equal, &fallthrough); // Covers the case where it's not bound (-1,-1). | 263 __ j(less, on_no_match); |
| 264 __ j(equal, &fallthrough); | |
| 265 // check that there are sufficient characters left in the input | |
| 266 __ mov(ebx, edi); | |
| 267 __ add(ebx, Operand(ecx)); | |
| 268 __ j(greater, on_no_match); | |
| 228 __ mov(ebx, Operand(edi)); | 269 __ mov(ebx, Operand(edi)); |
| 229 __ push(esi); | 270 __ push(esi); |
| 230 __ add(edi, Operand(esi)); | 271 __ add(edi, Operand(esi)); |
| 231 __ add(esi, Operand(eax)); | 272 __ add(esi, Operand(eax)); |
| 232 if (char_size() > 0) { | |
| 233 ASSERT(char_size() == 2); | |
| 234 __ add(ecx, Operand(ecx)); | |
| 235 } | |
| 236 __ rep_cmpsb(); | 273 __ rep_cmpsb(); |
| 237 __ pop(esi); | 274 __ pop(esi); |
| 238 __ mov(edi, Operand(ebx)); | 275 __ mov(edi, Operand(ebx)); |
| 239 BranchOrBacktrack(not_equal, on_no_match); | 276 BranchOrBacktrack(not_equal, on_no_match); |
| 240 __ bind(&fallthrough); | 277 __ bind(&fallthrough); |
| 241 } | 278 } |
| 242 | 279 |
| 243 | 280 |
| 244 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1, | 281 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1, |
| 245 int reg2, | 282 int reg2, |
| 246 Label* on_not_equal) { | 283 Label* on_not_equal) { |
| 247 __ mov(eax, register_location(reg1)); | 284 __ mov(eax, register_location(reg1)); |
| 248 __ mov(ecx, register_location(reg2)); | 285 __ cmp(eax, register_location(reg2)); |
| 249 __ cmp(ecx, Operand(eax)); | |
| 250 BranchOrBacktrack(not_equal, on_not_equal); | 286 BranchOrBacktrack(not_equal, on_not_equal); |
| 251 } | 287 } |
| 252 | 288 |
| 253 | 289 |
| 254 void RegExpMacroAssemblerIA32::CheckNotCharacter(uc16 c, Label* on_not_equal) { | 290 void RegExpMacroAssemblerIA32::CheckNotCharacter(uc16 c, Label* on_not_equal) { |
| 255 __ cmp(edx, c); | 291 __ cmp(edx, c); |
| 256 BranchOrBacktrack(not_equal, on_not_equal); | 292 BranchOrBacktrack(not_equal, on_not_equal); |
| 257 } | 293 } |
| 258 | 294 |
| 259 | 295 |
| 260 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterOr(uc16 c, | 296 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterOr(uc16 c, |
| 261 uc16 mask, | 297 uc16 mask, |
| 262 Label* on_not_equal) { | 298 Label* on_not_equal) { |
| 263 __ mov(eax, Operand(edx)); | 299 ReadCurrentChar(eax); |
|
Erik Corry
2008/11/30 19:39:27
This operation should also use the current charact
| |
| 264 __ or_(eax, mask); | 300 __ or_(eax, mask); |
| 265 __ cmp(eax, c); | 301 __ cmp(eax, c); |
| 266 BranchOrBacktrack(not_equal, on_not_equal); | 302 BranchOrBacktrack(not_equal, on_not_equal); |
| 267 } | 303 } |
| 268 | 304 |
| 269 | 305 |
| 270 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterMinusOr( | 306 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterMinusOr( |
| 271 uc16 c, | 307 uc16 c, |
| 272 uc16 mask, | 308 uc16 mask, |
| 273 Label* on_not_equal) { | 309 Label* on_not_equal) { |
| 274 __ lea(eax, Operand(edx, -mask)); | 310 __ lea(eax, Operand(edx, -mask)); |
| 275 __ or_(eax, mask); | 311 __ or_(eax, mask); |
| 276 __ cmp(eax, c); | 312 __ cmp(eax, c); |
| 277 BranchOrBacktrack(not_equal, on_not_equal); | 313 BranchOrBacktrack(not_equal, on_not_equal); |
| 278 } | 314 } |
| 279 | 315 |
| 280 | 316 |
| 281 void RegExpMacroAssemblerIA32::DispatchHalfNibbleMap( | 317 void RegExpMacroAssemblerIA32::DispatchHalfNibbleMap( |
| 282 uc16 start, | 318 uc16 start, |
| 283 Label* half_nibble_map, | 319 Label* half_nibble_map, |
| 284 const Vector<Label*>& destinations) { | 320 const Vector<Label*>& destinations) { |
| 321 UNIMPLEMENTED(); | |
| 285 ReadCurrentChar(eax); | 322 ReadCurrentChar(eax); |
|
Erik Corry
2008/11/30 19:39:27
And again.
| |
| 286 __ sub(Operand(eax), Immediate(start)); | 323 __ sub(Operand(eax), Immediate(start)); |
| 287 | 324 |
| 288 __ mov(ecx, eax); | 325 __ mov(ecx, eax); |
| 289 __ shr(eax, 2); | 326 __ shr(eax, 2); |
| 290 // FIXME: ecx must hold address of map | 327 // FIXME: ecx must hold address of map |
| 291 __ movzx_b(eax, Operand(ecx, eax, times_1, 0)); | 328 __ movzx_b(eax, Operand(ecx, eax, times_1, 0)); |
| 292 __ and_(ecx, 0x03); | 329 __ and_(ecx, 0x03); |
| 293 __ add(ecx, Operand(ecx)); | 330 __ add(ecx, Operand(ecx)); |
| 294 __ shr(eax); // Shift right cl times | 331 __ shr(eax); // Shift right cl times |
| 295 | 332 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 311 __ bind(&case_3); | 348 __ bind(&case_3); |
| 312 // Case 3: | 349 // Case 3: |
| 313 __ jmp(destinations[3]); | 350 __ jmp(destinations[3]); |
| 314 } | 351 } |
| 315 | 352 |
| 316 | 353 |
| 317 void RegExpMacroAssemblerIA32::DispatchByteMap( | 354 void RegExpMacroAssemblerIA32::DispatchByteMap( |
| 318 uc16 start, | 355 uc16 start, |
| 319 Label* byte_map, | 356 Label* byte_map, |
| 320 const Vector<Label*>& destinations) { | 357 const Vector<Label*>& destinations) { |
| 358 UNIMPLEMENTED(); | |
| 359 | |
| 321 Label fallthrough; | 360 Label fallthrough; |
| 322 ReadCurrentChar(eax); | 361 ReadCurrentChar(eax); |
|
Erik Corry
2008/11/30 19:39:27
Ditto.
| |
| 323 __ sub(Operand(eax), Immediate(start)); | 362 __ sub(Operand(eax), Immediate(start)); |
| 324 __ cmp(eax, 64); // FIXME: 64 = size of map. Found somehow?? | 363 __ cmp(eax, 64); // FIXME: 64 = size of map. Found somehow?? |
| 325 __ j(greater_equal, &fallthrough); | 364 __ j(greater_equal, &fallthrough); |
| 326 // TODO(lrn): ecx must hold address of map | 365 // TODO(lrn): ecx must hold address of map |
| 327 __ movzx_b(eax, Operand(ecx, eax, times_1, 0)); | 366 __ movzx_b(eax, Operand(ecx, eax, times_1, 0)); |
| 328 // jump table: jump to destinations[eax]; | 367 // jump table: jump to destinations[eax]; |
| 329 | 368 |
| 330 __ bind(&fallthrough); | 369 __ bind(&fallthrough); |
| 331 } | 370 } |
| 332 | 371 |
| 333 | 372 |
| 334 void RegExpMacroAssemblerIA32::DispatchHighByteMap( | 373 void RegExpMacroAssemblerIA32::DispatchHighByteMap( |
| 335 byte start, | 374 byte start, |
| 336 Label* byte_map, | 375 Label* byte_map, |
| 337 const Vector<Label*>& destinations) { | 376 const Vector<Label*>& destinations) { |
| 338 UNREACHABLE(); | 377 UNIMPLEMENTED(); |
| 339 | 378 |
| 340 Label fallthrough; | 379 Label fallthrough; |
| 341 ReadCurrentChar(eax); | 380 ReadCurrentChar(eax); |
|
Erik Corry
2008/11/30 19:39:27
Ditto
| |
| 342 __ shr(eax, 8); | 381 __ shr(eax, 8); |
| 343 __ sub(Operand(eax), Immediate(start)); | 382 __ sub(Operand(eax), Immediate(start)); |
| 344 __ cmp(eax, destinations.length() - start); | 383 __ cmp(eax, destinations.length() - start); |
| 345 __ j(greater_equal, &fallthrough); | 384 __ j(greater_equal, &fallthrough); |
| 346 | 385 |
| 347 // TODO(lrn) jumptable: jump to destinations[eax] | 386 // TODO(lrn) jumptable: jump to destinations[eax] |
| 348 __ bind(&fallthrough); | 387 __ bind(&fallthrough); |
| 349 } | 388 } |
| 350 | 389 |
| 351 | 390 |
| 352 void RegExpMacroAssemblerIA32::EmitOrLink(Label* label) { | 391 void RegExpMacroAssemblerIA32::EmitOrLink(Label* label) { |
| 353 UNREACHABLE(); // Has no use. | 392 UNIMPLEMENTED(); // Has no use. |
| 354 } | 393 } |
| 355 | 394 |
| 356 | 395 |
| 357 void RegExpMacroAssemblerIA32::Fail() { | 396 void RegExpMacroAssemblerIA32::Fail() { |
| 358 __ xor_(eax, Operand(eax)); // zero eax. | 397 __ xor_(eax, Operand(eax)); // zero eax. |
| 359 __ jmp(&exit_label_); | 398 __ jmp(&exit_label_); |
| 360 } | 399 } |
| 361 | 400 |
| 362 | 401 |
| 363 Handle<Object> RegExpMacroAssemblerIA32::GetCode() { | 402 Handle<Object> RegExpMacroAssemblerIA32::GetCode() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 388 // Fill saved registers with initial value = start offset - 1 | 427 // Fill saved registers with initial value = start offset - 1 |
| 389 __ mov(ecx, -num_saved_registers_); | 428 __ mov(ecx, -num_saved_registers_); |
| 390 __ mov(eax, Operand(edi)); | 429 __ mov(eax, Operand(edi)); |
| 391 __ sub(Operand(eax), Immediate(char_size())); | 430 __ sub(Operand(eax), Immediate(char_size())); |
| 392 Label init_loop; | 431 Label init_loop; |
| 393 __ bind(&init_loop); | 432 __ bind(&init_loop); |
| 394 __ mov(Operand(ebp, ecx, times_4, +0), eax); | 433 __ mov(Operand(ebp, ecx, times_4, +0), eax); |
| 395 __ inc(ecx); | 434 __ inc(ecx); |
| 396 __ j(not_equal, &init_loop); | 435 __ j(not_equal, &init_loop); |
| 397 } | 436 } |
| 437 // Load previous char as initial value of current-character. | |
| 438 Label at_start; | |
| 439 __ test(Operand(ebp, kAtStart), Immediate(0xffffffff)); | |
| 440 __ j(not_equal, &at_start); | |
| 441 ReadChar(edx, -1); | |
| 398 __ jmp(&start_label_); | 442 __ jmp(&start_label_); |
| 443 __ bind(&at_start); | |
| 444 __ mov(edx, '\n'); | |
| 445 __ jmp(&start_label_); | |
| 446 | |
| 399 | 447 |
| 400 // Exit code: | 448 // Exit code: |
| 401 __ bind(&success_label_); | 449 __ bind(&success_label_); |
| 402 if (num_saved_registers_ > 0) { | 450 if (num_saved_registers_ > 0) { |
| 403 // copy captures to output | 451 // copy captures to output |
| 404 __ mov(ebx, Operand(ebp, kRegisterOutput)); | 452 __ mov(ebx, Operand(ebp, kRegisterOutput)); |
| 405 __ mov(ecx, Operand(ebp, kInputEndOffset)); | 453 __ mov(ecx, Operand(ebp, kInputEndOffset)); |
| 406 __ sub(ecx, Operand(ebp, kInputStartOffset)); | 454 __ sub(ecx, Operand(ebp, kInputStartOffset)); |
| 407 for (int i = 0; i < num_saved_registers_; i++) { | 455 for (int i = 0; i < num_saved_registers_; i++) { |
| 408 __ mov(eax, register_location(i)); | 456 __ mov(eax, register_location(i)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 432 LOG(CodeCreateEvent("RegExp", *code, "(Compiled RegExp)")); | 480 LOG(CodeCreateEvent("RegExp", *code, "(Compiled RegExp)")); |
| 433 return Handle<Object>::cast(code); | 481 return Handle<Object>::cast(code); |
| 434 } | 482 } |
| 435 | 483 |
| 436 | 484 |
| 437 void RegExpMacroAssemblerIA32::GoTo(Label* to) { | 485 void RegExpMacroAssemblerIA32::GoTo(Label* to) { |
| 438 __ jmp(to); | 486 __ jmp(to); |
| 439 } | 487 } |
| 440 | 488 |
| 441 | 489 |
| 442 | |
| 443 void RegExpMacroAssemblerIA32::IfRegisterGE(int reg, | 490 void RegExpMacroAssemblerIA32::IfRegisterGE(int reg, |
| 444 int comparand, | 491 int comparand, |
| 445 Label* if_ge) { | 492 Label* if_ge) { |
| 446 __ cmp(register_location(reg), Immediate(comparand)); | 493 __ cmp(register_location(reg), Immediate(comparand)); |
| 447 BranchOrBacktrack(greater_equal, if_ge); | 494 BranchOrBacktrack(greater_equal, if_ge); |
| 448 } | 495 } |
| 449 | 496 |
| 450 | 497 |
| 451 | |
| 452 void RegExpMacroAssemblerIA32::IfRegisterLT(int reg, | 498 void RegExpMacroAssemblerIA32::IfRegisterLT(int reg, |
| 453 int comparand, | 499 int comparand, |
| 454 Label* if_lt) { | 500 Label* if_lt) { |
| 455 __ cmp(register_location(reg), Immediate(comparand)); | 501 __ cmp(register_location(reg), Immediate(comparand)); |
| 456 BranchOrBacktrack(less, if_lt); | 502 BranchOrBacktrack(less, if_lt); |
| 457 } | 503 } |
| 458 | 504 |
| 459 | 505 |
| 460 | |
| 461 RegExpMacroAssembler::IrregexpImplementation | 506 RegExpMacroAssembler::IrregexpImplementation |
| 462 RegExpMacroAssemblerIA32::Implementation() { | 507 RegExpMacroAssemblerIA32::Implementation() { |
| 463 return kIA32Implementation; | 508 return kIA32Implementation; |
| 464 } | 509 } |
| 465 | 510 |
| 466 | 511 |
| 467 | |
| 468 void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset, | 512 void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset, |
| 469 Label* on_end_of_input) { | 513 Label* on_end_of_input) { |
| 470 ASSERT(cp_offset >= 0); | 514 ASSERT(cp_offset >= 0); |
| 471 ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works) | 515 ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works) |
| 472 __ cmp(edi, -cp_offset * char_size()); | 516 __ cmp(edi, -cp_offset * char_size()); |
| 473 BranchOrBacktrack(greater_equal, on_end_of_input); | 517 BranchOrBacktrack(greater_equal, on_end_of_input); |
| 474 ReadChar(edx, cp_offset); | 518 ReadChar(edx, cp_offset); |
| 475 } | 519 } |
| 476 | 520 |
| 477 | 521 |
| 478 void RegExpMacroAssemblerIA32::PopCurrentPosition() { | 522 void RegExpMacroAssemblerIA32::PopCurrentPosition() { |
| 479 __ pop(edi); | 523 __ pop(edi); |
| 480 } | 524 } |
| 481 | 525 |
| 482 | 526 |
| 483 void RegExpMacroAssemblerIA32::PopRegister(int register_index) { | 527 void RegExpMacroAssemblerIA32::PopRegister(int register_index) { |
| 484 RecordRegister(register_index); | |
| 485 __ pop(register_location(register_index)); | 528 __ pop(register_location(register_index)); |
| 486 } | 529 } |
| 487 | 530 |
| 488 | 531 |
| 489 void RegExpMacroAssemblerIA32::PushBacktrack(Label* label) { | 532 void RegExpMacroAssemblerIA32::PushBacktrack(Label* label) { |
| 490 // CheckStackLimit(); // Not ready yet. | 533 // CheckStackLimit(); // Not ready yet. |
| 491 __ push(label, RelocInfo::NONE); | 534 __ push(label, RelocInfo::NONE); |
| 492 } | 535 } |
| 493 | 536 |
| 494 | 537 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 507 } | 550 } |
| 508 | 551 |
| 509 | 552 |
| 510 void RegExpMacroAssemblerIA32::ReadStackPointerFromRegister(int reg) { | 553 void RegExpMacroAssemblerIA32::ReadStackPointerFromRegister(int reg) { |
| 511 __ mov(esp, register_location(reg)); | 554 __ mov(esp, register_location(reg)); |
| 512 } | 555 } |
| 513 | 556 |
| 514 | 557 |
| 515 void RegExpMacroAssemblerIA32::SetRegister(int register_index, int to) { | 558 void RegExpMacroAssemblerIA32::SetRegister(int register_index, int to) { |
| 516 ASSERT(register_index >= num_saved_registers_); // Reserved for positions! | 559 ASSERT(register_index >= num_saved_registers_); // Reserved for positions! |
| 517 RecordRegister(register_index); | |
| 518 __ mov(register_location(register_index), Immediate(to)); | 560 __ mov(register_location(register_index), Immediate(to)); |
| 519 } | 561 } |
| 520 | 562 |
| 521 | 563 |
| 522 void RegExpMacroAssemblerIA32::Succeed() { | 564 void RegExpMacroAssemblerIA32::Succeed() { |
| 523 __ jmp(&success_label_); | 565 __ jmp(&success_label_); |
| 524 } | 566 } |
| 525 | 567 |
| 526 | 568 |
| 527 void RegExpMacroAssemblerIA32::WriteCurrentPositionToRegister( | 569 void RegExpMacroAssemblerIA32::WriteCurrentPositionToRegister(int reg) { |
| 528 int register_index) { | 570 __ mov(register_location(reg), edi); |
| 529 RecordRegister(register_index); | |
| 530 __ mov(register_location(register_index), edi); | |
| 531 } | 571 } |
| 532 | 572 |
| 533 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { | 573 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { |
| 534 __ mov(register_location(reg), esp); | 574 __ mov(register_location(reg), esp); |
| 535 } | 575 } |
| 536 | 576 |
| 537 | 577 |
| 538 // Private methods: | 578 // Private methods: |
| 539 | 579 |
| 540 Operand RegExpMacroAssemblerIA32::register_location( | 580 Operand RegExpMacroAssemblerIA32::register_location(int register_index) { |
| 541 int register_index) { | |
| 542 ASSERT(register_index < (1<<30)); | 581 ASSERT(register_index < (1<<30)); |
| 582 if (num_registers_ <= register_index) { | |
| 583 num_registers_ = register_index + 1; | |
| 584 } | |
| 543 return Operand(ebp, -(register_index + 1) * kPointerSize); | 585 return Operand(ebp, -(register_index + 1) * kPointerSize); |
| 544 } | 586 } |
| 545 | 587 |
| 546 | 588 |
| 547 size_t RegExpMacroAssemblerIA32::char_size() { | 589 size_t RegExpMacroAssemblerIA32::char_size() { |
| 548 return static_cast<size_t>(mode_); | 590 return static_cast<size_t>(mode_); |
| 549 } | 591 } |
| 550 | 592 |
| 551 | 593 |
| 552 void RegExpMacroAssemblerIA32::BranchOrBacktrack(Condition condition, | 594 void RegExpMacroAssemblerIA32::BranchOrBacktrack(Condition condition, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 __ pop(edi); | 659 __ pop(edi); |
| 618 __ mov(esi, Operand(ebp, kInputBuffer)); | 660 __ mov(esi, Operand(ebp, kInputBuffer)); |
| 619 __ mov(esi, Operand(esi, 0)); | 661 __ mov(esi, Operand(esi, 0)); |
| 620 __ add(esi, Operand(ebp, kInputEndOffset)); | 662 __ add(esi, Operand(ebp, kInputEndOffset)); |
| 621 | 663 |
| 622 __ bind(&no_preempt); | 664 __ bind(&no_preempt); |
| 623 } | 665 } |
| 624 } | 666 } |
| 625 | 667 |
| 626 | 668 |
| 627 void RegExpMacroAssemblerIA32::RecordRegister(int register_index) { | |
| 628 if (register_index >= num_registers_) { | |
| 629 num_registers_ = register_index + 1; | |
| 630 } | |
| 631 } | |
| 632 | |
| 633 | |
| 634 void RegExpMacroAssemblerIA32::ReadChar(Register destination, int offset) { | 669 void RegExpMacroAssemblerIA32::ReadChar(Register destination, int offset) { |
| 635 if (mode_ == ASCII) { | 670 if (mode_ == ASCII) { |
| 636 __ movzx_b(destination, Operand(esi, edi, times_1, offset)); | 671 __ movzx_b(destination, Operand(esi, edi, times_1, offset)); |
| 637 return; | 672 return; |
| 638 } | 673 } |
| 639 ASSERT(mode_ == UC16); | 674 ASSERT(mode_ == UC16); |
| 640 __ movzx_w(destination, Operand(esi, edi, times_1, offset * 2)); | 675 __ movzx_w(destination, Operand(esi, edi, times_1, offset * sizeof(uc16))); |
| 641 } | 676 } |
| 642 | 677 |
| 643 | 678 |
| 644 void RegExpMacroAssemblerIA32::ReadCurrentChar(Register destination) { | 679 void RegExpMacroAssemblerIA32::ReadCurrentChar(Register destination) { |
| 645 __ mov(destination, edx); | 680 __ mov(destination, edx); |
| 646 } | 681 } |
| 647 | 682 |
| 648 | 683 |
| 649 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, | 684 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, |
| 650 ArraySlice* buffer) { | 685 ArraySlice* buffer) { |
| 651 __ mov(reg, buffer->array()); | 686 __ mov(reg, buffer->array()); |
| 652 __ add(Operand(reg), Immediate(buffer->base_offset())); | 687 __ add(Operand(reg), Immediate(buffer->base_offset())); |
| 653 } | 688 } |
| 654 | 689 |
| 655 #undef __ | 690 #undef __ |
| 656 }} // namespace v8::internal | 691 }} // namespace v8::internal |
| OLD | NEW |