// add more as needed
// Pseudo-types
- reloc_mode_count, // Must be no greater than 14. See RelocInfoWriter.
+ reloc_mode_count, // must be no greater than 14 - see RelocInfoWriter
no_reloc, // never recorded
last_code_enum = code_target,
last_gced_enum = embedded_string
return mode == statement_position;
}
+
inline bool is_external_reference(RelocMode mode) {
return mode == external_reference;
}
-inline bool is_internal_reference(RelocMode mode) {
+
+inline bool is_internal_reference(RelocMode mode) {
return mode == internal_reference;
}
+
// Relocation information consists of the address (pc) of the datum
// to which the relocation information applies, the relocation mode
// (rmode), and an optional data field. The relocation mode may be
static const int kFastSwitchMaxOverheadFactor = 5;
// Minimal number of switch cases required before we allow jump-table
- // optimization.
+ // optimization.
static const int kFastSwitchMinCaseCount = 5;
// Create fast switch implementation if all labels are small integers
// be populated later when the adresses of the targets are known
void Ia32CodeGenerator::GenerateFastCaseSwitchJumpTable(
int min_index, int range, Label *fail_label, Label &table_start) {
- // Notice: Internal references, used by both the jmp instruction and the
- // table entries, need to be relocated if the buffer grows. This prevents
- // the forward use of Labels, since a displacement cannot survive relocation,
- // and it also cannot safely be distinguished from a real address.
- // Instead we put in zero-values as placeholders, and fill in the adresses after
- // the labels have been bound.
-
- __ pop(eax); // supposed Smi
+ // Notice: Internal references, used by both the jmp instruction and
+ // the table entries, need to be relocated if the buffer grows. This
+ // prevents the forward use of Labels, since a displacement cannot
+ // survive relocation, and it also cannot safely be distinguished
+ // from a real address. Instead we put in zero-values as
+ // placeholders, and fill in the adresses after the labels have been
+ // bound.
+
+ __ pop(eax); // supposed smi
// check range of value, if outside [0..length-1] jump to default/end label.
ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
if (min_index != 0) {
- __ sub(Operand(eax), Immediate(min_index * 2)); // Smi subtraction
+ __ sub(Operand(eax), Immediate(min_index * 2)); // smi subtraction
}
- __ test(eax, Immediate(0x80000000 | kSmiTagMask)); // negative or not Smi
+ __ test(eax, Immediate(0x80000000 | kSmiTagMask)); // negative or not smi
__ j(not_equal, fail_label, not_taken);
__ cmp(eax, range * 2);
__ j(greater_equal, fail_label, not_taken);
__ jmp(Operand(eax, times_2, 0x0, internal_reference)); // 0 is placeholder
// calculate address to overwrite later with actual address of table.
- int32_t jump_table_ref = __ pc_offset() - sizeof(int32_t);
-
+ int32_t jump_table_ref = __ pc_offset() - sizeof(int32_t);
+
__ Align(4);
__ bind(&table_start);
__ WriteInternalReference(jump_table_ref, table_start);
-
+
for (int i = 0; i < range; i++) {
- __ dd(0x0, internal_reference); // table entry, 0 is placeholder
+ __ dd(0x0, internal_reference); // table entry, 0 is placeholder
}
}
Label* fail_label = (default_index >= 0 ? &(case_labels[default_index])
: node->break_target());
- // create array of labels to jump to by index.
- // set default jump targets everywhere
+ // Create array of labels to jump to by index and set default jump
+ // targets everywhere.
for (int i = 0; i < range; i++) {
// length => end label
case_targets[i] = fail_label;
}
- // overwrite for values of cases:
- // (reverse order, so that if same label twice, the first one wins)
+
+ // Overwrite for values of cases:
+ // (reverse order, so that if same label twice, the first one wins).
for (int i = length-1; i >= 0 ; i--) {
CaseClause* clause = cases->at(i);
if (!clause->is_default()) {
__ bind(node->break_target());
- // all labels bound now, so we can populate the table with the
+ // All labels bound now, so we can populate the table with the
// correct addresses.
PopulateFastCaseSwitchJumpTable(table_start, case_targets, range);
}
ZoneList<CaseClause*>* cases = node->cases();
int length = cases->length();
- if (length < kFastSwitchMinCaseCount) {
+ if (length < kFastSwitchMinCaseCount) {
return false;
}
-
+
// Test whether fast-case should be used.
int default_index = -1;
int min_index = Smi::kMaxValue;
if (smi > max_index) { max_index = smi; }
}
}
- // all labels are Smi.
+
+ // After this all labels are smis.
int range = max_index - min_index + 1; // |min..max| inclusive
if (range / kFastSwitchMaxOverheadFactor > length) {
return false; // range of labels is too sparse