V8 Project
regexp-macro-assembler-arm64.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_ARM64_REGEXP_MACRO_ASSEMBLER_ARM64_H_
6 #define V8_ARM64_REGEXP_MACRO_ASSEMBLER_ARM64_H_
7 
8 #include "src/macro-assembler.h"
9 
12 
13 namespace v8 {
14 namespace internal {
15 
16 
17 #ifndef V8_INTERPRETED_REGEXP
19  public:
20  RegExpMacroAssemblerARM64(Mode mode, int registers_to_save, Zone* zone);
22  virtual int stack_limit_slack();
23  virtual void AdvanceCurrentPosition(int by);
24  virtual void AdvanceRegister(int reg, int by);
25  virtual void Backtrack();
26  virtual void Bind(Label* label);
27  virtual void CheckAtStart(Label* on_at_start);
28  virtual void CheckCharacter(unsigned c, Label* on_equal);
29  virtual void CheckCharacterAfterAnd(unsigned c,
30  unsigned mask,
31  Label* on_equal);
32  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
33  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
35  int cp_offset,
36  Label* on_failure,
37  bool check_end_of_string);
38  // A "greedy loop" is a loop that is both greedy and with a simple
39  // body. It has a particularly simple implementation.
40  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
41  virtual void CheckNotAtStart(Label* on_not_at_start);
42  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
43  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
44  Label* on_no_match);
45  virtual void CheckNotCharacter(unsigned c, Label* on_not_equal);
46  virtual void CheckNotCharacterAfterAnd(unsigned c,
47  unsigned mask,
48  Label* on_not_equal);
50  uc16 minus,
51  uc16 mask,
52  Label* on_not_equal);
53  virtual void CheckCharacterInRange(uc16 from,
54  uc16 to,
55  Label* on_in_range);
56  virtual void CheckCharacterNotInRange(uc16 from,
57  uc16 to,
58  Label* on_not_in_range);
59  virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set);
60 
61  // Checks whether the given offset from the current position is before
62  // the end of the string.
63  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
64  virtual bool CheckSpecialCharacterClass(uc16 type,
65  Label* on_no_match);
66  virtual void Fail();
68  virtual void GoTo(Label* label);
69  virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
70  virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
71  virtual void IfRegisterEqPos(int reg, Label* if_eq);
73  virtual void LoadCurrentCharacter(int cp_offset,
74  Label* on_end_of_input,
75  bool check_bounds = true,
76  int characters = 1);
77  virtual void PopCurrentPosition();
78  virtual void PopRegister(int register_index);
79  virtual void PushBacktrack(Label* label);
80  virtual void PushCurrentPosition();
81  virtual void PushRegister(int register_index,
82  StackCheckFlag check_stack_limit);
83  virtual void ReadCurrentPositionFromRegister(int reg);
84  virtual void ReadStackPointerFromRegister(int reg);
85  virtual void SetCurrentPositionFromEnd(int by);
86  virtual void SetRegister(int register_index, int to);
87  virtual bool Succeed();
88  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
89  virtual void ClearRegisters(int reg_from, int reg_to);
90  virtual void WriteStackPointerToRegister(int reg);
91  virtual bool CanReadUnaligned();
92 
93  // Called from RegExp if the stack-guard is triggered.
94  // If the code object is relocated, the return address is fixed before
95  // returning.
96  static int CheckStackGuardState(Address* return_address,
97  Code* re_code,
98  Address re_frame,
99  int start_offset,
100  const byte** input_start,
101  const byte** input_end);
102 
103  private:
104  // Above the frame pointer - Stored registers and stack passed parameters.
105  // Callee-saved registers x19-x29, where x29 is the old frame pointer.
106  static const int kCalleeSavedRegisters = 0;
107  // Return address.
108  // It is placed above the 11 callee-saved registers.
111  // Stack parameter placed by caller.
113 
114  // Below the frame pointer.
115  // Register parameters stored by setup code.
117  static const int kStackBase = kDirectCall - kPointerSize;
118  static const int kOutputSize = kStackBase - kPointerSize;
119  static const int kInput = kOutputSize - kPointerSize;
120  // When adding local variables remember to push space for them in
121  // the frame in GetCode.
122  static const int kSuccessCounter = kInput - kPointerSize;
123  // First position register address on the stack. Following positions are
124  // below it. A position is a 32 bit value.
126  // A capture is a 64 bit value holding two position.
128 
129  // Initial size of code buffer.
130  static const size_t kRegExpCodeSize = 1024;
131 
132  // When initializing registers to a non-position value we can unroll
133  // the loop. Set the limit of registers to unroll.
134  static const int kNumRegistersToUnroll = 16;
135 
136  // We are using x0 to x7 as a register cache. Each hardware register must
137  // contain one capture, that is two 32 bit registers. We can cache at most
138  // 16 registers.
139  static const int kNumCachedRegisters = 16;
140 
141  // Load a number of characters at the given offset from the
142  // current position, into the current-character register.
143  void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
144 
145  // Check whether preemption has been requested.
147 
148  // Check whether we are exceeding the stack limit on the backtrack stack.
150 
151  // Generate a call to CheckStackGuardState.
153 
154  // Location of a 32 bit position register.
155  MemOperand register_location(int register_index);
156 
157  // Location of a 64 bit capture, combining two position registers.
158  MemOperand capture_location(int register_index, Register scratch);
159 
160  // Register holding the current input position as negative offset from
161  // the end of the string.
162  Register current_input_offset() { return w21; }
163 
164  // The register containing the current character after LoadCurrentCharacter.
165  Register current_character() { return w22; }
166 
167  // Register holding address of the end of the input string.
168  Register input_end() { return x25; }
169 
170  // Register holding address of the start of the input string.
171  Register input_start() { return x26; }
172 
173  // Register holding the offset from the start of the string where we should
174  // start matching.
175  Register start_offset() { return w27; }
176 
177  // Pointer to the output array's first element.
178  Register output_array() { return x28; }
179 
180  // Register holding the frame address. Local variables, parameters and
181  // regexp registers are addressed relative to this.
182  Register frame_pointer() { return fp; }
183 
184  // The register containing the backtrack stack top. Provides a meaningful
185  // name to the register.
187 
188  // Register holding pointer to the current code object.
189  Register code_pointer() { return x20; }
190 
191  // Register holding the value used for clearing capture registers.
192  Register non_position_value() { return w24; }
193  // The top 32 bit of this register is used to store this value
194  // twice. This is used for clearing more than one register at a time.
196 
197  // Byte size of chars in the string to match (decided by the Mode argument)
198  int char_size() { return static_cast<int>(mode_); }
199 
200  // Equivalent to a conditional branch to the label, unless the label
201  // is NULL, in which case it is a conditional Backtrack.
202  void BranchOrBacktrack(Condition condition, Label* to);
203 
204  // Compares reg against immmediate before calling BranchOrBacktrack.
205  // It makes use of the Cbz and Cbnz instructions.
207  int immediate,
208  Condition condition,
209  Label* to);
210 
211  inline void CallIf(Label* to, Condition condition);
212 
213  // Save and restore the link register on the stack in a way that
214  // is GC-safe.
215  inline void SaveLinkRegister();
216  inline void RestoreLinkRegister();
217 
218  // Pushes the value of a register on the backtrack stack. Decrements the
219  // stack pointer by a word size and stores the register's value there.
220  inline void Push(Register source);
221 
222  // Pops a value from the backtrack stack. Reads the word at the stack pointer
223  // and increments it by a word size.
224  inline void Pop(Register target);
225 
226  // This state indicates where the register actually is.
228  STACKED, // Resides in memory.
229  CACHED_LSW, // Least Significant Word of a 64 bit hardware register.
230  CACHED_MSW // Most Significant Word of a 64 bit hardware register.
231  };
232 
233  RegisterState GetRegisterState(int register_index) {
234  DCHECK(register_index >= 0);
235  if (register_index >= kNumCachedRegisters) {
236  return STACKED;
237  } else {
238  if ((register_index % 2) == 0) {
239  return CACHED_LSW;
240  } else {
241  return CACHED_MSW;
242  }
243  }
244  }
245 
246  // Store helper that takes the state of the register into account.
247  inline void StoreRegister(int register_index, Register source);
248 
249  // Returns a hardware W register that holds the value of the capture
250  // register.
251  //
252  // This function will try to use an existing cache register (w0-w7) for the
253  // result. Otherwise, it will load the value into maybe_result.
254  //
255  // If the returned register is anything other than maybe_result, calling code
256  // must not write to it.
257  inline Register GetRegister(int register_index, Register maybe_result);
258 
259  // Returns the harware register (x0-x7) holding the value of the capture
260  // register.
261  // This assumes that the state of the register is not STACKED.
262  inline Register GetCachedRegister(int register_index);
263 
264  Isolate* isolate() const { return masm_->isolate(); }
265 
267 
268  // Which mode to generate code for (LATIN1 or UC16).
270 
271  // One greater than maximal register index actually used.
273 
274  // Number of registers to output at the end (the saved registers
275  // are always 0..num_saved_registers_-1)
277 
278  // Labels used internally.
283  Label exit_label_;
286 };
287 
288 #endif // V8_INTERPRETED_REGEXP
289 
290 
291 }} // namespace v8::internal
292 
293 #endif // V8_ARM64_REGEXP_MACRO_ASSEMBLER_ARM64_H_
Isolate * isolate() const
Definition: assembler.h:62
virtual IrregexpImplementation Implementation()
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask, Label *on_not_equal)
RegisterState GetRegisterState(int register_index)
virtual void GoTo(Label *label)
virtual void CheckCharacterLT(uc16 limit, Label *on_less)
virtual void CheckAtStart(Label *on_at_start)
void StoreRegister(int register_index, Register source)
virtual void CheckCharacter(unsigned c, Label *on_equal)
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)
MemOperand register_location(int register_index)
void CallCheckStackGuardState(Register scratch)
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)
void LoadCurrentCharacterUnchecked(int cp_offset, int character_count)
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)
MemOperand capture_location(int register_index, Register scratch)
virtual void Bind(Label *label)
virtual void ReadStackPointerFromRegister(int reg)
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 mask, Label *on_not_equal)
virtual void ReadCurrentPositionFromRegister(int reg)
virtual void WriteStackPointerToRegister(int reg)
Register GetCachedRegister(int register_index)
RegExpMacroAssemblerARM64(Mode mode, int registers_to_save, Zone *zone)
virtual void AdvanceCurrentPosition(int by)
virtual void CheckCharacters(Vector< const uc16 > str, int cp_offset, Label *on_failure, bool check_end_of_string)
virtual void PushBacktrack(Label *label)
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)
Register GetRegister(int register_index, Register maybe_result)
virtual void CheckNotAtStart(Label *on_not_at_start)
virtual void CheckCharacterAfterAnd(unsigned c, unsigned mask, Label *on_equal)
virtual void PopRegister(int register_index)
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)
virtual void SetRegister(int register_index, int to)
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)
virtual void AdvanceRegister(int reg, int by)
virtual Handle< HeapObject > GetCode(Handle< String > source)
virtual void CheckPosition(int cp_offset, Label *on_outside_input)
static int CheckStackGuardState(Address *return_address, Code *re_code, Address re_frame, int start_offset, const byte **input_start, const byte **input_end)
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)
void CallIf(Label *to, Condition condition)
void CompareAndBranchOrBacktrack(Register reg, int immediate, Condition condition, Label *to)
virtual void CheckNotCharacter(unsigned c, Label *on_not_equal)
virtual void IfRegisterEqPos(int reg, Label *if_eq)
void BranchOrBacktrack(Condition condition, Label *to)
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)
virtual void ClearRegisters(int reg_from, int reg_to)
virtual void SetCurrentPositionFromEnd(int by)
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
#define DCHECK(condition)
Definition: logging.h:205
const int kPointerSize
Definition: globals.h:129
const Register fp
byte * Address
Definition: globals.h:101
const unsigned kXRegSize
const unsigned kWRegSize
uint16_t uc16
Definition: globals.h:184
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20