155
174
FastNewContextStub stub(heap_slots);
156
175
__ CallStub(&stub);
158
__ CallRuntime(Runtime::kNewContext, 1);
177
__ CallRuntime(Runtime::kNewFunctionContext, 1);
160
RecordSafepoint(Safepoint::kNoDeoptimizationIndex);
179
RecordSafepoint(Safepoint::kNoLazyDeopt);
161
180
// Context is returned in both r0 and cp. It replaces the context
162
181
// passed to us. It's saved in the stack and kept live in cp.
163
182
__ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
164
183
// Copy any necessary parameters into the context.
165
184
int num_parameters = scope()->num_parameters();
166
185
for (int i = 0; i < num_parameters; i++) {
167
Slot* slot = scope()->parameter(i)->AsSlot();
168
if (slot != NULL && slot->type() == Slot::CONTEXT) {
186
Variable* var = scope()->parameter(i);
187
if (var->IsContextSlot()) {
169
188
int parameter_offset = StandardFrameConstants::kCallerSPOffset +
170
189
(num_parameters - 1 - i) * kPointerSize;
171
190
// Load parameter from stack.
172
191
__ ldr(r0, MemOperand(fp, parameter_offset));
173
192
// Store it in the context.
174
__ mov(r1, Operand(Context::SlotOffset(slot->index())));
193
__ mov(r1, Operand(Context::SlotOffset(var->index())));
175
194
__ str(r0, MemOperand(cp, r1));
176
195
// Update the write barrier. This clobbers all involved
177
196
// registers, so we have to use two more registers to avoid
208
227
instr->CompileToNative(this);
230
EnsureSpaceForLazyDeopt();
211
231
return !is_aborted();
215
LInstruction* LCodeGen::GetNextInstruction() {
216
if (current_instruction_ < instructions_->length() - 1) {
217
return instructions_->at(current_instruction_ + 1);
224
235
bool LCodeGen::GenerateDeferredCode() {
225
236
ASSERT(is_generating());
226
for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
227
LDeferredCode* code = deferred_[i];
228
__ bind(code->entry());
230
__ jmp(code->exit());
237
if (deferred_.length() > 0) {
238
for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
239
LDeferredCode* code = deferred_[i];
240
__ bind(code->entry());
242
__ jmp(code->exit());
233
// Force constant pool emission at the end of deferred code to make
234
// sure that no constant pools are emitted after the official end of
235
// the instruction sequence.
246
// Force constant pool emission at the end of the deferred code to make
247
// sure that no constant pools are emitted after.
236
248
masm()->CheckConstPool(true, false);
238
// Deferred code is the last part of the instruction sequence. Mark
239
// the generated code as done unless we bailed out.
250
return !is_aborted();
254
bool LCodeGen::GenerateDeoptJumpTable() {
255
// Check that the jump table is accessible from everywhere in the function
256
// code, ie that offsets to the table can be encoded in the 24bit signed
257
// immediate of a branch instruction.
258
// To simplify we consider the code size from the first instruction to the
259
// end of the jump table. We also don't consider the pc load delta.
260
// Each entry in the jump table generates one instruction and inlines one
261
// 32bit data after it.
262
if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) +
263
deopt_jump_table_.length() * 2)) {
264
Abort("Generated code is too large");
267
// Block the constant pool emission during the jump table emission.
268
__ BlockConstPoolFor(deopt_jump_table_.length());
269
__ RecordComment("[ Deoptimisation jump table");
271
__ bind(&table_start);
272
for (int i = 0; i < deopt_jump_table_.length(); i++) {
273
__ bind(&deopt_jump_table_[i].label);
274
__ ldr(pc, MemOperand(pc, Assembler::kInstrSize - Assembler::kPcLoadDelta));
275
__ dd(reinterpret_cast<uint32_t>(deopt_jump_table_[i].address));
277
ASSERT(masm()->InstructionsGeneratedSince(&table_start) ==
278
deopt_jump_table_.length() * 2);
279
__ RecordComment("]");
281
// The deoptimization jump table is the last part of the instruction
282
// sequence. Mark the generated code as done unless we bailed out.
240
283
if (!is_aborted()) status_ = DONE;
241
284
return !is_aborted();
499
549
LInstruction* instr) {
500
550
__ CallRuntimeSaveDoubles(id);
501
551
RecordSafepointWithRegisters(
502
instr->pointer_map(), argc, Safepoint::kNoDeoptimizationIndex);
506
void LCodeGen::RegisterLazyDeoptimization(LInstruction* instr,
507
SafepointMode safepoint_mode) {
508
// Create the environment to bailout to. If the call has side effects
509
// execution has to continue after the call otherwise execution can continue
510
// from a previous bailout point repeating the call.
511
LEnvironment* deoptimization_environment;
512
if (instr->HasDeoptimizationEnvironment()) {
513
deoptimization_environment = instr->deoptimization_environment();
515
deoptimization_environment = instr->environment();
518
RegisterEnvironmentForDeoptimization(deoptimization_environment);
519
if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
520
RecordSafepoint(instr->pointer_map(),
521
deoptimization_environment->deoptimization_index());
523
ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
524
RecordSafepointWithRegisters(
525
instr->pointer_map(),
527
deoptimization_environment->deoptimization_index());
532
void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment) {
552
instr->pointer_map(), argc, Safepoint::kNoLazyDeopt);
556
void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
557
Safepoint::DeoptMode mode) {
533
558
if (!environment->HasBeenRegistered()) {
534
559
// Physical stack frame layout:
535
560
// -x ............. -4 0 ..................................... y
680
720
void LCodeGen::RecordSafepoint(LPointerMap* pointers,
681
int deoptimization_index) {
682
RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index);
721
Safepoint::DeoptMode deopt_mode) {
722
RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode);
686
void LCodeGen::RecordSafepoint(int deoptimization_index) {
726
void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) {
687
727
LPointerMap empty_pointers(RelocInfo::kNoPosition);
688
RecordSafepoint(&empty_pointers, deoptimization_index);
728
RecordSafepoint(&empty_pointers, deopt_mode);
692
732
void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
694
int deoptimization_index) {
695
RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments,
696
deoptimization_index);
734
Safepoint::DeoptMode deopt_mode) {
736
pointers, Safepoint::kWithRegisters, arguments, deopt_mode);
700
740
void LCodeGen::RecordSafepointWithRegistersAndDoubles(
701
741
LPointerMap* pointers,
703
int deoptimization_index) {
704
RecordSafepoint(pointers, Safepoint::kWithRegistersAndDoubles, arguments,
705
deoptimization_index);
743
Safepoint::DeoptMode deopt_mode) {
745
pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode);
709
749
void LCodeGen::RecordPosition(int position) {
710
if (!FLAG_debug_info || position == RelocInfo::kNoPosition) return;
750
if (position == RelocInfo::kNoPosition) return;
711
751
masm()->positions_recorder()->RecordPosition(position);
813
844
void LCodeGen::DoModI(LModI* instr) {
814
class DeferredModI: public LDeferredCode {
816
DeferredModI(LCodeGen* codegen, LModI* instr)
817
: LDeferredCode(codegen), instr_(instr) { }
818
virtual void Generate() {
819
codegen()->DoDeferredBinaryOpStub(instr_, Token::MOD);
845
if (instr->hydrogen()->HasPowerOf2Divisor()) {
846
Register dividend = ToRegister(instr->InputAt(0));
847
Register result = ToRegister(instr->result());
850
HConstant::cast(instr->hydrogen()->right())->Integer32Value();
852
if (divisor < 0) divisor = -divisor;
854
Label positive_dividend, done;
855
__ cmp(dividend, Operand(0));
856
__ b(pl, &positive_dividend);
857
__ rsb(result, dividend, Operand(0));
858
__ and_(result, result, Operand(divisor - 1), SetCC);
859
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
860
DeoptimizeIf(eq, instr->environment());
862
__ rsb(result, result, Operand(0));
864
__ bind(&positive_dividend);
865
__ and_(result, dividend, Operand(divisor - 1));
824
870
// These registers hold untagged 32 bit values.
825
871
Register left = ToRegister(instr->InputAt(0));
826
872
Register right = ToRegister(instr->InputAt(1));
827
873
Register result = ToRegister(instr->result());
828
875
Register scratch = scratch0();
830
Label deoptimize, done;
876
Register scratch2 = ToRegister(instr->TempAt(0));
877
DwVfpRegister dividend = ToDoubleRegister(instr->TempAt(1));
878
DwVfpRegister divisor = ToDoubleRegister(instr->TempAt(2));
879
DwVfpRegister quotient = double_scratch0();
881
ASSERT(!dividend.is(divisor));
882
ASSERT(!dividend.is(quotient));
883
ASSERT(!divisor.is(quotient));
884
ASSERT(!scratch.is(left));
885
ASSERT(!scratch.is(right));
886
ASSERT(!scratch.is(result));
888
Label done, vfp_modulo, both_positive, right_negative;
831
890
// Check for x % 0.
832
891
if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
833
__ tst(right, Operand(right));
834
__ b(eq, &deoptimize);
837
// Check for (0 % -x) that will produce negative zero.
838
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
840
__ tst(left, Operand(left));
842
__ tst(right, Operand(right));
844
__ b(al, &deoptimize);
848
// Try a few common cases before using the stub.
892
__ cmp(right, Operand(0));
893
DeoptimizeIf(eq, instr->environment());
896
__ Move(result, left);
898
// (0 % x) must yield 0 (if x is finite, which is the case here).
899
__ cmp(left, Operand(0));
901
// Preload right in a vfp register.
902
__ vmov(divisor.low(), right);
903
__ b(lt, &vfp_modulo);
905
__ cmp(left, Operand(right));
908
// Check for (positive) power of two on the right hand side.
909
__ JumpIfNotPowerOfTwoOrZeroAndNeg(right,
913
// Perform modulo operation (scratch contains right - 1).
914
__ and_(result, scratch, Operand(left));
917
__ bind(&right_negative);
918
// Negate right. The sign of the divisor does not matter.
919
__ rsb(right, right, Operand(0));
921
__ bind(&both_positive);
850
922
const int kUnfolds = 3;
851
// Skip if either side is negative.
852
__ cmp(left, Operand(0));
853
__ cmp(right, Operand(0), NegateCondition(mi));
854
__ b(mi, &call_stub);
855
923
// If the right hand side is smaller than the (nonnegative)
856
// left hand side, it is the result. Else try a few subtractions
857
// of the left hand side.
924
// left hand side, the left hand side is the result.
925
// Else try a few subtractions of the left hand side.
858
926
__ mov(scratch, left);
859
927
for (int i = 0; i < kUnfolds; i++) {
860
928
// Check if the left hand side is less or equal than the
861
929
// the right hand side.
862
__ cmp(scratch, right);
930
__ cmp(scratch, Operand(right));
863
931
__ mov(result, scratch, LeaveCC, lt);
865
933
// If not, reduce the left hand side by the right hand
867
935
if (i < kUnfolds - 1) __ sub(scratch, scratch, right);
870
// Check for power of two on the right hand side.
871
__ JumpIfNotPowerOfTwoOrZero(right, scratch, &call_stub);
872
// Perform modulo operation (scratch contains right - 1).
873
__ and_(result, scratch, Operand(left));
876
// Call the stub. The numbers in r0 and r1 have
877
// to be tagged to Smis. If that is not possible, deoptimize.
878
DeferredModI* deferred = new DeferredModI(this, instr);
879
__ TrySmiTag(left, &deoptimize, scratch);
880
__ TrySmiTag(right, &deoptimize, scratch);
882
__ b(al, deferred->entry());
883
__ bind(deferred->exit());
885
// If the result in r0 is a Smi, untag it, else deoptimize.
886
__ JumpIfNotSmi(result, &deoptimize);
890
__ bind(&deoptimize);
891
DeoptimizeIf(al, instr->environment());
938
__ bind(&vfp_modulo);
939
// Load the arguments in VFP registers.
940
// The divisor value is preloaded before. Be careful that 'right' is only live
942
__ vmov(dividend.low(), left);
943
// From here on don't use right as it may have been reallocated (for example
947
__ vcvt_f64_s32(dividend, dividend.low());
948
__ vcvt_f64_s32(divisor, divisor.low());
950
// We do not care about the sign of the divisor.
951
__ vabs(divisor, divisor);
952
// Compute the quotient and round it to a 32bit integer.
953
__ vdiv(quotient, dividend, divisor);
954
__ vcvt_s32_f64(quotient.low(), quotient);
955
__ vcvt_f64_s32(quotient, quotient.low());
957
// Compute the remainder in result.
958
DwVfpRegister double_scratch = dividend;
959
__ vmul(double_scratch, divisor, quotient);
960
__ vcvt_s32_f64(double_scratch.low(), double_scratch);
961
__ vmov(scratch, double_scratch.low());
963
if (!instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
964
__ sub(result, left, scratch);
968
__ sub(scratch2, left, scratch, SetCC);
970
__ cmp(left, Operand(0));
971
DeoptimizeIf(mi, instr->environment());
973
// Load the result and we are done.
974
__ mov(result, scratch2);
1007
1092
void LCodeGen::DoMulI(LMulI* instr) {
1008
1093
Register scratch = scratch0();
1094
Register result = ToRegister(instr->result());
1095
// Note that result may alias left.
1009
1096
Register left = ToRegister(instr->InputAt(0));
1010
Register right = EmitLoadRegister(instr->InputAt(1), scratch);
1012
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero) &&
1013
!instr->InputAt(1)->IsConstantOperand()) {
1014
__ orr(ToRegister(instr->TempAt(0)), left, right);
1017
if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1018
// scratch:left = left * right.
1019
__ smull(left, scratch, left, right);
1020
__ mov(ip, Operand(left, ASR, 31));
1021
__ cmp(ip, Operand(scratch));
1022
DeoptimizeIf(ne, instr->environment());
1097
LOperand* right_op = instr->InputAt(1);
1099
bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1100
bool bailout_on_minus_zero =
1101
instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
1103
if (right_op->IsConstantOperand() && !can_overflow) {
1104
// Use optimized code for specific constants.
1105
int32_t constant = ToInteger32(LConstantOperand::cast(right_op));
1107
if (bailout_on_minus_zero && (constant < 0)) {
1108
// The case of a null constant will be handled separately.
1109
// If constant is negative and left is null, the result should be -0.
1110
__ cmp(left, Operand(0));
1111
DeoptimizeIf(eq, instr->environment());
1116
__ rsb(result, left, Operand(0));
1119
if (bailout_on_minus_zero) {
1120
// If left is strictly negative and the constant is null, the
1121
// result is -0. Deoptimize if required, otherwise return 0.
1122
__ cmp(left, Operand(0));
1123
DeoptimizeIf(mi, instr->environment());
1125
__ mov(result, Operand(0));
1128
__ Move(result, left);
1131
// Multiplying by powers of two and powers of two plus or minus
1132
// one can be done faster with shifted operands.
1133
// For other constants we emit standard code.
1134
int32_t mask = constant >> 31;
1135
uint32_t constant_abs = (constant + mask) ^ mask;
1137
if (IsPowerOf2(constant_abs) ||
1138
IsPowerOf2(constant_abs - 1) ||
1139
IsPowerOf2(constant_abs + 1)) {
1140
if (IsPowerOf2(constant_abs)) {
1141
int32_t shift = WhichPowerOf2(constant_abs);
1142
__ mov(result, Operand(left, LSL, shift));
1143
} else if (IsPowerOf2(constant_abs - 1)) {
1144
int32_t shift = WhichPowerOf2(constant_abs - 1);
1145
__ add(result, left, Operand(left, LSL, shift));
1146
} else if (IsPowerOf2(constant_abs + 1)) {
1147
int32_t shift = WhichPowerOf2(constant_abs + 1);
1148
__ rsb(result, left, Operand(left, LSL, shift));
1151
// Correct the sign of the result is the constant is negative.
1152
if (constant < 0) __ rsb(result, result, Operand(0));
1155
// Generate standard code.
1156
__ mov(ip, Operand(constant));
1157
__ mul(result, left, ip);
1024
__ mul(left, left, right);
1162
Register right = EmitLoadRegister(right_op, scratch);
1163
if (bailout_on_minus_zero) {
1164
__ orr(ToRegister(instr->TempAt(0)), left, right);
1027
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1028
// Bail out if the result is supposed to be negative zero.
1030
__ tst(left, Operand(left));
1032
if (instr->InputAt(1)->IsConstantOperand()) {
1033
if (ToInteger32(LConstantOperand::cast(instr->InputAt(1))) <= 0) {
1034
DeoptimizeIf(al, instr->environment());
1168
// scratch:result = left * right.
1169
__ smull(result, scratch, left, right);
1170
__ cmp(scratch, Operand(result, ASR, 31));
1171
DeoptimizeIf(ne, instr->environment());
1037
// Test the non-zero operand for negative sign.
1173
__ mul(result, left, right);
1176
if (bailout_on_minus_zero) {
1177
// Bail out if the result is supposed to be negative zero.
1179
__ cmp(result, Operand(0));
1038
1181
__ cmp(ToRegister(instr->TempAt(0)), Operand(0));
1039
1182
DeoptimizeIf(mi, instr->environment());
1046
1189
void LCodeGen::DoBitI(LBitI* instr) {
1047
LOperand* left = instr->InputAt(0);
1048
LOperand* right = instr->InputAt(1);
1049
ASSERT(left->Equals(instr->result()));
1050
ASSERT(left->IsRegister());
1051
Register result = ToRegister(left);
1052
Register right_reg = EmitLoadRegister(right, ip);
1190
LOperand* left_op = instr->InputAt(0);
1191
LOperand* right_op = instr->InputAt(1);
1192
ASSERT(left_op->IsRegister());
1193
Register left = ToRegister(left_op);
1194
Register result = ToRegister(instr->result());
1195
Operand right(no_reg);
1197
if (right_op->IsStackSlot() || right_op->IsArgument()) {
1198
right = Operand(EmitLoadRegister(right_op, ip));
1200
ASSERT(right_op->IsRegister() || right_op->IsConstantOperand());
1201
right = ToOperand(right_op);
1053
1204
switch (instr->op()) {
1054
1205
case Token::BIT_AND:
1055
__ and_(result, ToRegister(left), Operand(right_reg));
1206
__ and_(result, left, right);
1057
1208
case Token::BIT_OR:
1058
__ orr(result, ToRegister(left), Operand(right_reg));
1209
__ orr(result, left, right);
1060
1211
case Token::BIT_XOR:
1061
__ eor(result, ToRegister(left), Operand(right_reg));
1212
__ eor(result, left, right);
1070
1221
void LCodeGen::DoShiftI(LShiftI* instr) {
1222
// Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so
1223
// result may alias either of them.
1224
LOperand* right_op = instr->InputAt(1);
1225
Register left = ToRegister(instr->InputAt(0));
1226
Register result = ToRegister(instr->result());
1071
1227
Register scratch = scratch0();
1072
LOperand* left = instr->InputAt(0);
1073
LOperand* right = instr->InputAt(1);
1074
ASSERT(left->Equals(instr->result()));
1075
ASSERT(left->IsRegister());
1076
Register result = ToRegister(left);
1077
if (right->IsRegister()) {
1078
// Mask the right operand.
1079
__ and_(scratch, ToRegister(right), Operand(0x1F));
1228
if (right_op->IsRegister()) {
1229
// Mask the right_op operand.
1230
__ and_(scratch, ToRegister(right_op), Operand(0x1F));
1080
1231
switch (instr->op()) {
1081
1232
case Token::SAR:
1082
__ mov(result, Operand(result, ASR, scratch));
1233
__ mov(result, Operand(left, ASR, scratch));
1084
1235
case Token::SHR:
1085
1236
if (instr->can_deopt()) {
1086
__ mov(result, Operand(result, LSR, scratch), SetCC);
1237
__ mov(result, Operand(left, LSR, scratch), SetCC);
1087
1238
DeoptimizeIf(mi, instr->environment());
1089
__ mov(result, Operand(result, LSR, scratch));
1240
__ mov(result, Operand(left, LSR, scratch));
1092
1243
case Token::SHL:
1093
__ mov(result, Operand(result, LSL, scratch));
1244
__ mov(result, Operand(left, LSL, scratch));
1100
int value = ToInteger32(LConstantOperand::cast(right));
1251
// Mask the right_op operand.
1252
int value = ToInteger32(LConstantOperand::cast(right_op));
1101
1253
uint8_t shift_count = static_cast<uint8_t>(value & 0x1F);
1102
1254
switch (instr->op()) {
1103
1255
case Token::SAR:
1104
1256
if (shift_count != 0) {
1105
__ mov(result, Operand(result, ASR, shift_count));
1257
__ mov(result, Operand(left, ASR, shift_count));
1259
__ Move(result, left);
1108
1262
case Token::SHR:
1109
if (shift_count == 0 && instr->can_deopt()) {
1110
__ tst(result, Operand(0x80000000));
1111
DeoptimizeIf(ne, instr->environment());
1263
if (shift_count != 0) {
1264
__ mov(result, Operand(left, LSR, shift_count));
1113
__ mov(result, Operand(result, LSR, shift_count));
1266
if (instr->can_deopt()) {
1267
__ tst(left, Operand(0x80000000));
1268
DeoptimizeIf(ne, instr->environment());
1270
__ Move(result, left);
1116
1273
case Token::SHL:
1117
1274
if (shift_count != 0) {
1118
__ mov(result, Operand(result, LSL, shift_count));
1275
__ mov(result, Operand(left, LSL, shift_count));
1277
__ Move(result, left);
1167
void LCodeGen::DoPixelArrayLength(LPixelArrayLength* instr) {
1336
void LCodeGen::DoFixedArrayBaseLength(LFixedArrayBaseLength* instr) {
1168
1337
Register result = ToRegister(instr->result());
1169
1338
Register array = ToRegister(instr->InputAt(0));
1170
__ ldr(result, FieldMemOperand(array, PixelArray::kLengthOffset));
1339
__ ldr(result, FieldMemOperand(array, FixedArrayBase::kLengthOffset));
1174
void LCodeGen::DoFixedArrayLength(LFixedArrayLength* instr) {
1343
void LCodeGen::DoElementsKind(LElementsKind* instr) {
1175
1344
Register result = ToRegister(instr->result());
1176
Register array = ToRegister(instr->InputAt(0));
1177
__ ldr(result, FieldMemOperand(array, FixedArray::kLengthOffset));
1345
Register input = ToRegister(instr->InputAt(0));
1347
// Load map into |result|.
1348
__ ldr(result, FieldMemOperand(input, HeapObject::kMapOffset));
1349
// Load the map's "bit field 2" into |result|. We only need the first byte,
1350
// but the following bit field extraction takes care of that anyway.
1351
__ ldr(result, FieldMemOperand(result, Map::kBitField2Offset));
1352
// Retrieve elements_kind from bit field 2.
1353
__ ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount);
1233
1417
void LCodeGen::DoArithmeticD(LArithmeticD* instr) {
1234
1418
DoubleRegister left = ToDoubleRegister(instr->InputAt(0));
1235
1419
DoubleRegister right = ToDoubleRegister(instr->InputAt(1));
1420
DoubleRegister result = ToDoubleRegister(instr->result());
1236
1421
switch (instr->op()) {
1237
1422
case Token::ADD:
1238
__ vadd(left, left, right);
1423
__ vadd(result, left, right);
1240
1425
case Token::SUB:
1241
__ vsub(left, left, right);
1426
__ vsub(result, left, right);
1243
1428
case Token::MUL:
1244
__ vmul(left, left, right);
1429
__ vmul(result, left, right);
1246
1431
case Token::DIV:
1247
__ vdiv(left, left, right);
1432
__ vdiv(result, left, right);
1249
1434
case Token::MOD: {
1250
1435
// Save r0-r3 on the stack.
1251
1436
__ stm(db_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit());
1253
__ PrepareCallCFunction(4, scratch0());
1254
__ vmov(r0, r1, left);
1255
__ vmov(r2, r3, right);
1256
__ CallCFunction(ExternalReference::double_fp_operation(Token::MOD), 4);
1438
__ PrepareCallCFunction(0, 2, scratch0());
1439
__ SetCallCDoubleArguments(left, right);
1441
ExternalReference::double_fp_operation(Token::MOD, isolate()),
1257
1443
// Move the result in the double result register.
1258
__ GetCFunctionDoubleResult(ToDoubleRegister(instr->result()));
1444
__ GetCFunctionDoubleResult(result);
1260
1446
// Restore r0-r3.
1261
1447
__ ldm(ia_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit());
1321
1508
// Test the double value. Zero and NaN are false.
1322
1509
__ VFPCompareAndLoadFlags(reg, 0.0, scratch);
1323
1510
__ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit));
1324
EmitBranch(true_block, false_block, ne);
1511
EmitBranch(true_block, false_block, eq);
1326
1513
ASSERT(r.IsTagged());
1327
1514
Register reg = ToRegister(instr->InputAt(0));
1328
if (instr->hydrogen()->type().IsBoolean()) {
1329
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
1515
HType type = instr->hydrogen()->value()->type();
1516
if (type.IsBoolean()) {
1517
__ CompareRoot(reg, Heap::kTrueValueRootIndex);
1331
1518
EmitBranch(true_block, false_block, eq);
1519
} else if (type.IsSmi()) {
1520
__ cmp(reg, Operand(0));
1521
EmitBranch(true_block, false_block, ne);
1333
1523
Label* true_label = chunk_->GetAssemblyLabel(true_block);
1334
1524
Label* false_label = chunk_->GetAssemblyLabel(false_block);
1336
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1338
__ b(eq, false_label);
1339
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
1341
__ b(eq, true_label);
1342
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
1344
__ b(eq, false_label);
1345
__ cmp(reg, Operand(0));
1346
__ b(eq, false_label);
1347
__ tst(reg, Operand(kSmiTagMask));
1348
__ b(eq, true_label);
1350
// Test double values. Zero and NaN are false.
1352
DoubleRegister dbl_scratch = d0;
1353
Register scratch = scratch0();
1354
__ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset));
1355
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
1356
__ cmp(scratch, Operand(ip));
1357
__ b(ne, &call_stub);
1358
__ sub(ip, reg, Operand(kHeapObjectTag));
1359
__ vldr(dbl_scratch, ip, HeapNumber::kValueOffset);
1360
__ VFPCompareAndLoadFlags(dbl_scratch, 0.0, scratch);
1361
__ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit));
1362
__ b(ne, false_label);
1365
// The conversion stub doesn't cause garbage collections so it's
1366
// safe to not record a safepoint after the call.
1367
__ bind(&call_stub);
1368
ToBooleanStub stub(reg);
1369
RegList saved_regs = kJSCallerSaved | kCalleeSaved;
1370
__ stm(db_w, sp, saved_regs);
1372
__ cmp(reg, Operand(0));
1373
__ ldm(ia_w, sp, saved_regs);
1374
EmitBranch(true_block, false_block, ne);
1526
ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types();
1527
// Avoid deopts in the case where we've never executed this path before.
1528
if (expected.IsEmpty()) expected = ToBooleanStub::all_types();
1530
if (expected.Contains(ToBooleanStub::UNDEFINED)) {
1531
// undefined -> false.
1532
__ CompareRoot(reg, Heap::kUndefinedValueRootIndex);
1533
__ b(eq, false_label);
1535
if (expected.Contains(ToBooleanStub::BOOLEAN)) {
1536
// Boolean -> its value.
1537
__ CompareRoot(reg, Heap::kTrueValueRootIndex);
1538
__ b(eq, true_label);
1539
__ CompareRoot(reg, Heap::kFalseValueRootIndex);
1540
__ b(eq, false_label);
1542
if (expected.Contains(ToBooleanStub::NULL_TYPE)) {
1544
__ CompareRoot(reg, Heap::kNullValueRootIndex);
1545
__ b(eq, false_label);
1548
if (expected.Contains(ToBooleanStub::SMI)) {
1549
// Smis: 0 -> false, all other -> true.
1550
__ cmp(reg, Operand(0));
1551
__ b(eq, false_label);
1552
__ JumpIfSmi(reg, true_label);
1553
} else if (expected.NeedsMap()) {
1554
// If we need a map later and have a Smi -> deopt.
1555
__ tst(reg, Operand(kSmiTagMask));
1556
DeoptimizeIf(eq, instr->environment());
1559
const Register map = scratch0();
1560
if (expected.NeedsMap()) {
1561
__ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset));
1563
if (expected.CanBeUndetectable()) {
1564
// Undetectable -> false.
1565
__ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset));
1566
__ tst(ip, Operand(1 << Map::kIsUndetectable));
1567
__ b(ne, false_label);
1571
if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) {
1572
// spec object -> true.
1573
__ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE);
1574
__ b(ge, true_label);
1577
if (expected.Contains(ToBooleanStub::STRING)) {
1578
// String value -> false iff empty.
1580
__ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE);
1581
__ b(ge, ¬_string);
1582
__ ldr(ip, FieldMemOperand(reg, String::kLengthOffset));
1583
__ cmp(ip, Operand(0));
1584
__ b(ne, true_label);
1586
__ bind(¬_string);
1589
if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
1590
// heap number -> false iff +0, -0, or NaN.
1591
DoubleRegister dbl_scratch = double_scratch0();
1592
Label not_heap_number;
1593
__ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
1594
__ b(ne, ¬_heap_number);
1595
__ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
1596
__ VFPCompareAndSetFlags(dbl_scratch, 0.0);
1597
__ b(vs, false_label); // NaN -> false.
1598
__ b(eq, false_label); // +0, -0 -> false.
1600
__ bind(¬_heap_number);
1603
// We've seen something for the first time -> deopt.
1604
DeoptimizeIf(al, instr->environment());
1380
void LCodeGen::EmitGoto(int block, LDeferredCode* deferred_stack_check) {
1610
void LCodeGen::EmitGoto(int block) {
1381
1611
block = chunk_->LookupDestination(block);
1382
1612
int next_block = GetNextEmittedBlock(current_block_);
1383
1613
if (block != next_block) {
1384
// Perform stack overflow check if this goto needs it before jumping.
1385
if (deferred_stack_check != NULL) {
1386
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
1387
__ cmp(sp, Operand(ip));
1388
__ b(hs, chunk_->GetAssemblyLabel(block));
1389
__ jmp(deferred_stack_check->entry());
1390
deferred_stack_check->SetExit(chunk_->GetAssemblyLabel(block));
1392
__ jmp(chunk_->GetAssemblyLabel(block));
1614
__ jmp(chunk_->GetAssemblyLabel(block));
1398
void LCodeGen::DoDeferredStackCheck(LGoto* instr) {
1399
PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters);
1400
CallRuntimeFromDeferred(Runtime::kStackGuard, 0, instr);
1404
1619
void LCodeGen::DoGoto(LGoto* instr) {
1405
class DeferredStackCheck: public LDeferredCode {
1407
DeferredStackCheck(LCodeGen* codegen, LGoto* instr)
1408
: LDeferredCode(codegen), instr_(instr) { }
1409
virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); }
1414
DeferredStackCheck* deferred = NULL;
1415
if (instr->include_stack_check()) {
1416
deferred = new DeferredStackCheck(this, instr);
1418
EmitGoto(instr->block_id(), deferred);
1620
EmitGoto(instr->block_id());
1505
void LCodeGen::DoCmpJSObjectEq(LCmpJSObjectEq* instr) {
1506
Register left = ToRegister(instr->InputAt(0));
1507
Register right = ToRegister(instr->InputAt(1));
1508
Register result = ToRegister(instr->result());
1510
__ cmp(left, Operand(right));
1511
__ LoadRoot(result, Heap::kTrueValueRootIndex, eq);
1512
__ LoadRoot(result, Heap::kFalseValueRootIndex, ne);
1516
void LCodeGen::DoCmpJSObjectEqAndBranch(LCmpJSObjectEqAndBranch* instr) {
1517
Register left = ToRegister(instr->InputAt(0));
1518
Register right = ToRegister(instr->InputAt(1));
1519
int false_block = chunk_->LookupDestination(instr->false_block_id());
1520
int true_block = chunk_->LookupDestination(instr->true_block_id());
1522
__ cmp(left, Operand(right));
1523
EmitBranch(true_block, false_block, eq);
1527
void LCodeGen::DoIsNull(LIsNull* instr) {
1528
Register reg = ToRegister(instr->InputAt(0));
1529
Register result = ToRegister(instr->result());
1531
__ LoadRoot(ip, Heap::kNullValueRootIndex);
1533
if (instr->is_strict()) {
1534
__ LoadRoot(result, Heap::kTrueValueRootIndex, eq);
1535
__ LoadRoot(result, Heap::kFalseValueRootIndex, ne);
1537
Label true_value, false_value, done;
1538
__ b(eq, &true_value);
1539
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1541
__ b(eq, &true_value);
1542
__ tst(reg, Operand(kSmiTagMask));
1543
__ b(eq, &false_value);
1544
// Check for undetectable objects by looking in the bit field in
1545
// the map. The object has already been smi checked.
1546
Register scratch = result;
1547
__ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset));
1548
__ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
1549
__ tst(scratch, Operand(1 << Map::kIsUndetectable));
1550
__ b(ne, &true_value);
1551
__ bind(&false_value);
1552
__ LoadRoot(result, Heap::kFalseValueRootIndex);
1554
__ bind(&true_value);
1555
__ LoadRoot(result, Heap::kTrueValueRootIndex);
1679
void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
1680
Register left = ToRegister(instr->InputAt(0));
1681
Register right = ToRegister(instr->InputAt(1));
1682
int false_block = chunk_->LookupDestination(instr->false_block_id());
1683
int true_block = chunk_->LookupDestination(instr->true_block_id());
1685
__ cmp(left, Operand(right));
1686
EmitBranch(true_block, false_block, eq);
1690
void LCodeGen::DoCmpConstantEqAndBranch(LCmpConstantEqAndBranch* instr) {
1691
Register left = ToRegister(instr->InputAt(0));
1692
int true_block = chunk_->LookupDestination(instr->true_block_id());
1693
int false_block = chunk_->LookupDestination(instr->false_block_id());
1695
__ cmp(left, Operand(instr->hydrogen()->right()));
1696
EmitBranch(true_block, false_block, eq);
1612
1750
// Load instance type and check that it is in object type range.
1613
1751
__ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset));
1614
__ cmp(temp2, Operand(FIRST_JS_OBJECT_TYPE));
1752
__ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
1615
1753
__ b(lt, is_not_object);
1616
__ cmp(temp2, Operand(LAST_JS_OBJECT_TYPE));
1754
__ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
1621
void LCodeGen::DoIsObject(LIsObject* instr) {
1622
Register reg = ToRegister(instr->InputAt(0));
1623
Register result = ToRegister(instr->result());
1624
Register temp = scratch0();
1625
Label is_false, is_true, done;
1627
Condition true_cond = EmitIsObject(reg, result, temp, &is_false, &is_true);
1628
__ b(true_cond, &is_true);
1631
__ LoadRoot(result, Heap::kFalseValueRootIndex);
1635
__ LoadRoot(result, Heap::kTrueValueRootIndex);
1641
1759
void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) {
1642
1760
Register reg = ToRegister(instr->InputAt(0));
1643
1761
Register temp1 = ToRegister(instr->TempAt(0));
1644
Register temp2 = scratch0();
1646
1763
int true_block = chunk_->LookupDestination(instr->true_block_id());
1647
1764
int false_block = chunk_->LookupDestination(instr->false_block_id());
1781
1871
Register temp2) {
1782
1872
ASSERT(!input.is(temp));
1783
1873
ASSERT(!temp.is(temp2)); // But input and temp2 may be the same register.
1784
__ tst(input, Operand(kSmiTagMask));
1786
__ CompareObjectType(input, temp, temp2, FIRST_JS_OBJECT_TYPE);
1874
__ JumpIfSmi(input, is_false);
1875
__ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE);
1787
1876
__ b(lt, is_false);
1789
1878
// Map is now in temp.
1790
1879
// Functions have class 'Function'.
1791
__ CompareInstanceType(temp, temp2, JS_FUNCTION_TYPE);
1880
__ CompareInstanceType(temp, temp2, FIRST_CALLABLE_SPEC_OBJECT_TYPE);
1792
1881
if (class_name->IsEqualTo(CStrVector("Function"))) {
1798
1887
// Check if the constructor in the map is a function.
1799
1888
__ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset));
1801
// As long as JS_FUNCTION_TYPE is the last instance type and it is
1802
// right after LAST_JS_OBJECT_TYPE, we can avoid checking for
1803
// LAST_JS_OBJECT_TYPE.
1804
ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
1805
ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1);
1890
// As long as LAST_CALLABLE_SPEC_OBJECT_TYPE is the last instance type and
1891
// FIRST_CALLABLE_SPEC_OBJECT_TYPE comes right after
1892
// LAST_NONCALLABLE_SPEC_OBJECT_TYPE, we can avoid checking for the latter.
1893
STATIC_ASSERT(LAST_TYPE == LAST_CALLABLE_SPEC_OBJECT_TYPE);
1894
STATIC_ASSERT(FIRST_CALLABLE_SPEC_OBJECT_TYPE ==
1895
LAST_NONCALLABLE_SPEC_OBJECT_TYPE + 1);
1807
1897
// Objects with a non-function constructor have class 'Object'.
1808
1898
__ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE);
2227
void LCodeGen::EmitLoadFieldOrConstantFunction(Register result,
2230
Handle<String> name) {
2231
LookupResult lookup;
2232
type->LookupInDescriptors(NULL, *name, &lookup);
2233
ASSERT(lookup.IsProperty() &&
2234
(lookup.type() == FIELD || lookup.type() == CONSTANT_FUNCTION));
2235
if (lookup.type() == FIELD) {
2236
int index = lookup.GetLocalFieldIndexFromMap(*type);
2237
int offset = index * kPointerSize;
2239
// Negative property indices are in-object properties, indexed
2240
// from the end of the fixed part of the object.
2241
__ ldr(result, FieldMemOperand(object, offset + type->instance_size()));
2243
// Non-negative property indices are in the properties array.
2244
__ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
2245
__ ldr(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize));
2248
Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type));
2249
LoadHeapObject(result, Handle<HeapObject>::cast(function));
2254
void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) {
2255
Register object = ToRegister(instr->object());
2256
Register result = ToRegister(instr->result());
2257
Register scratch = scratch0();
2258
int map_count = instr->hydrogen()->types()->length();
2259
Handle<String> name = instr->hydrogen()->name();
2260
if (map_count == 0) {
2261
ASSERT(instr->hydrogen()->need_generic());
2262
__ mov(r2, Operand(name));
2263
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
2264
CallCode(ic, RelocInfo::CODE_TARGET, instr);
2267
__ ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
2268
for (int i = 0; i < map_count - 1; ++i) {
2269
Handle<Map> map = instr->hydrogen()->types()->at(i);
2271
__ cmp(scratch, Operand(map));
2273
EmitLoadFieldOrConstantFunction(result, object, map, name);
2277
Handle<Map> map = instr->hydrogen()->types()->last();
2278
__ cmp(scratch, Operand(map));
2279
if (instr->hydrogen()->need_generic()) {
2282
EmitLoadFieldOrConstantFunction(result, object, map, name);
2285
__ mov(r2, Operand(name));
2286
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
2287
CallCode(ic, RelocInfo::CODE_TARGET, instr);
2289
DeoptimizeIf(ne, instr->environment());
2290
EmitLoadFieldOrConstantFunction(result, object, map, name);
2165
2297
void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) {
2166
2298
ASSERT(ToRegister(instr->object()).is(r0));
2167
2299
ASSERT(ToRegister(instr->result()).is(r0));
2169
2301
// Name is always in r2.
2170
2302
__ mov(r2, Operand(instr->name()));
2171
Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
2303
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
2172
2304
CallCode(ic, RelocInfo::CODE_TARGET, instr);
2225
2357
__ ldr(result, FieldMemOperand(input, JSObject::kElementsOffset));
2226
2358
if (FLAG_debug_code) {
2228
2360
__ ldr(scratch, FieldMemOperand(result, HeapObject::kMapOffset));
2229
2361
__ LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
2230
2362
__ cmp(scratch, ip);
2231
2363
__ b(eq, &done);
2232
__ LoadRoot(ip, Heap::kPixelArrayMapRootIndex);
2233
__ cmp(scratch, ip);
2235
2364
__ LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex);
2236
2365
__ cmp(scratch, ip);
2237
__ Check(eq, "Check for fast elements failed.");
2367
// |scratch| still contains |input|'s map.
2368
__ ldr(scratch, FieldMemOperand(scratch, Map::kBitField2Offset));
2369
__ ubfx(scratch, scratch, Map::kElementsKindShift,
2370
Map::kElementsKindBitCount);
2371
__ cmp(scratch, Operand(FAST_ELEMENTS));
2373
__ cmp(scratch, Operand(FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND));
2375
__ cmp(scratch, Operand(LAST_EXTERNAL_ARRAY_ELEMENTS_KIND));
2378
__ Abort("Check for fast or external elements failed.");
2238
2379
__ bind(&done);
2243
void LCodeGen::DoLoadPixelArrayExternalPointer(
2244
LLoadPixelArrayExternalPointer* instr) {
2384
void LCodeGen::DoLoadExternalArrayPointer(
2385
LLoadExternalArrayPointer* instr) {
2245
2386
Register to_reg = ToRegister(instr->result());
2246
2387
Register from_reg = ToRegister(instr->InputAt(0));
2247
__ ldr(to_reg, FieldMemOperand(from_reg, PixelArray::kExternalPointerOffset));
2388
__ ldr(to_reg, FieldMemOperand(from_reg,
2389
ExternalArray::kExternalPointerOffset));
2271
2413
Register key = EmitLoadRegister(instr->key(), scratch0());
2272
2414
Register result = ToRegister(instr->result());
2273
2415
Register scratch = scratch0();
2274
ASSERT(result.is(elements));
2276
2417
// Load the result.
2277
2418
__ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2));
2278
2419
__ ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize));
2280
2421
// Check for the hole value.
2281
__ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
2282
__ cmp(result, scratch);
2283
DeoptimizeIf(eq, instr->environment());
2287
void LCodeGen::DoLoadPixelArrayElement(LLoadPixelArrayElement* instr) {
2288
Register external_elements = ToRegister(instr->external_pointer());
2289
Register key = ToRegister(instr->key());
2290
Register result = ToRegister(instr->result());
2293
__ ldrb(result, MemOperand(external_elements, key));
2422
if (instr->hydrogen()->RequiresHoleCheck()) {
2423
__ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
2424
__ cmp(result, scratch);
2425
DeoptimizeIf(eq, instr->environment());
2430
void LCodeGen::DoLoadKeyedFastDoubleElement(
2431
LLoadKeyedFastDoubleElement* instr) {
2432
Register elements = ToRegister(instr->elements());
2433
bool key_is_constant = instr->key()->IsConstantOperand();
2434
Register key = no_reg;
2435
DwVfpRegister result = ToDoubleRegister(instr->result());
2436
Register scratch = scratch0();
2439
ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
2440
int constant_key = 0;
2441
if (key_is_constant) {
2442
constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
2443
if (constant_key & 0xF0000000) {
2444
Abort("array index constant value too big.");
2447
key = ToRegister(instr->key());
2450
Operand operand = key_is_constant
2451
? Operand(constant_key * (1 << shift_size) +
2452
FixedDoubleArray::kHeaderSize - kHeapObjectTag)
2453
: Operand(key, LSL, shift_size);
2454
__ add(elements, elements, operand);
2455
if (!key_is_constant) {
2456
__ add(elements, elements,
2457
Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag));
2460
if (instr->hydrogen()->RequiresHoleCheck()) {
2461
// TODO(danno): If no hole check is required, there is no need to allocate
2462
// elements into a temporary register, instead scratch can be used.
2463
__ ldr(scratch, MemOperand(elements, sizeof(kHoleNanLower32)));
2464
__ cmp(scratch, Operand(kHoleNanUpper32));
2465
DeoptimizeIf(eq, instr->environment());
2468
__ vldr(result, elements, 0);
2472
void LCodeGen::DoLoadKeyedSpecializedArrayElement(
2473
LLoadKeyedSpecializedArrayElement* instr) {
2474
Register external_pointer = ToRegister(instr->external_pointer());
2475
Register key = no_reg;
2476
ElementsKind elements_kind = instr->elements_kind();
2477
bool key_is_constant = instr->key()->IsConstantOperand();
2478
int constant_key = 0;
2479
if (key_is_constant) {
2480
constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
2481
if (constant_key & 0xF0000000) {
2482
Abort("array index constant value too big.");
2485
key = ToRegister(instr->key());
2487
int shift_size = ElementsKindToShiftSize(elements_kind);
2489
if (elements_kind == EXTERNAL_FLOAT_ELEMENTS ||
2490
elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
2491
CpuFeatures::Scope scope(VFP3);
2492
DwVfpRegister result = ToDoubleRegister(instr->result());
2493
Operand operand = key_is_constant
2494
? Operand(constant_key * (1 << shift_size))
2495
: Operand(key, LSL, shift_size);
2496
__ add(scratch0(), external_pointer, operand);
2497
if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
2498
__ vldr(result.low(), scratch0(), 0);
2499
__ vcvt_f64_f32(result, result.low());
2500
} else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
2501
__ vldr(result, scratch0(), 0);
2504
Register result = ToRegister(instr->result());
2505
MemOperand mem_operand(key_is_constant
2506
? MemOperand(external_pointer, constant_key * (1 << shift_size))
2507
: MemOperand(external_pointer, key, LSL, shift_size));
2508
switch (elements_kind) {
2509
case EXTERNAL_BYTE_ELEMENTS:
2510
__ ldrsb(result, mem_operand);
2512
case EXTERNAL_PIXEL_ELEMENTS:
2513
case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
2514
__ ldrb(result, mem_operand);
2516
case EXTERNAL_SHORT_ELEMENTS:
2517
__ ldrsh(result, mem_operand);
2519
case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
2520
__ ldrh(result, mem_operand);
2522
case EXTERNAL_INT_ELEMENTS:
2523
__ ldr(result, mem_operand);
2525
case EXTERNAL_UNSIGNED_INT_ELEMENTS:
2526
__ ldr(result, mem_operand);
2527
__ cmp(result, Operand(0x80000000));
2528
// TODO(danno): we could be more clever here, perhaps having a special
2529
// version of the stub that detects if the overflow case actually
2530
// happens, and generate code that returns a double rather than int.
2531
DeoptimizeIf(cs, instr->environment());
2533
case EXTERNAL_FLOAT_ELEMENTS:
2534
case EXTERNAL_DOUBLE_ELEMENTS:
2535
case FAST_DOUBLE_ELEMENTS:
2537
case DICTIONARY_ELEMENTS:
2538
case NON_STRICT_ARGUMENTS_ELEMENTS:
2625
2902
// Move the result back to general purpose register r0.
2626
2903
__ vmov(result, single_scratch);
2630
__ cmp(result, Operand(0));
2632
__ vmov(scratch1, input.high());
2633
__ tst(scratch1, Operand(HeapNumber::kSignMask));
2634
DeoptimizeIf(ne, instr->environment());
2905
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
2908
__ cmp(result, Operand(0));
2910
__ vmov(scratch1, input.high());
2911
__ tst(scratch1, Operand(HeapNumber::kSignMask));
2912
DeoptimizeIf(ne, instr->environment());
2639
2918
void LCodeGen::DoMathRound(LUnaryMathOperation* instr) {
2640
2919
DoubleRegister input = ToDoubleRegister(instr->InputAt(0));
2641
2920
Register result = ToRegister(instr->result());
2642
Register scratch1 = scratch0();
2643
Register scratch2 = result;
2644
__ EmitVFPTruncate(kRoundToNearest,
2921
Register scratch = scratch0();
2922
Label done, check_sign_on_zero;
2924
// Extract exponent bits.
2925
__ vmov(result, input.high());
2928
HeapNumber::kExponentShift,
2929
HeapNumber::kExponentBits);
2931
// If the number is in ]-0.5, +0.5[, the result is +/- 0.
2932
__ cmp(scratch, Operand(HeapNumber::kExponentBias - 2));
2933
__ mov(result, Operand(0), LeaveCC, le);
2934
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
2935
__ b(le, &check_sign_on_zero);
2940
// The following conversion will not work with numbers
2941
// outside of ]-2^32, 2^32[.
2942
__ cmp(scratch, Operand(HeapNumber::kExponentBias + 32));
2943
DeoptimizeIf(ge, instr->environment());
2945
// Save the original sign for later comparison.
2946
__ and_(scratch, result, Operand(HeapNumber::kSignMask));
2948
__ Vmov(double_scratch0(), 0.5);
2949
__ vadd(double_scratch0(), input, double_scratch0());
2951
// Check sign of the result: if the sign changed, the input
2952
// value was in ]0.5, 0[ and the result should be -0.
2953
__ vmov(result, double_scratch0().high());
2954
__ eor(result, result, Operand(scratch), SetCC);
2955
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
2956
DeoptimizeIf(mi, instr->environment());
2958
__ mov(result, Operand(0), LeaveCC, mi);
2962
__ EmitVFPTruncate(kRoundToMinusInf,
2645
2963
double_scratch0().low(),
2649
2967
DeoptimizeIf(ne, instr->environment());
2650
2968
__ vmov(result, double_scratch0().low());
2654
__ cmp(result, Operand(0));
2656
__ vmov(scratch1, input.high());
2657
__ tst(scratch1, Operand(HeapNumber::kSignMask));
2658
DeoptimizeIf(ne, instr->environment());
2970
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
2972
__ cmp(result, Operand(0));
2974
__ bind(&check_sign_on_zero);
2975
__ vmov(scratch, input.high());
2976
__ tst(scratch, Operand(HeapNumber::kSignMask));
2977
DeoptimizeIf(ne, instr->environment());
2659
2979
__ bind(&done);
2663
2983
void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) {
2664
2984
DoubleRegister input = ToDoubleRegister(instr->InputAt(0));
2665
ASSERT(ToDoubleRegister(instr->result()).is(input));
2666
__ vsqrt(input, input);
2985
DoubleRegister result = ToDoubleRegister(instr->result());
2986
__ vsqrt(result, input);
2990
void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) {
2991
DoubleRegister input = ToDoubleRegister(instr->InputAt(0));
2992
DoubleRegister result = ToDoubleRegister(instr->result());
2993
// Add +0 to convert -0 to +0.
2994
__ vadd(result, input, kDoubleRegZero);
2995
__ vsqrt(result, result);
2675
3004
Representation exponent_type = instr->hydrogen()->right()->representation();
2676
3005
if (exponent_type.IsDouble()) {
2677
3006
// Prepare arguments and call C function.
2678
__ PrepareCallCFunction(4, scratch);
2679
__ vmov(r0, r1, ToDoubleRegister(left));
2680
__ vmov(r2, r3, ToDoubleRegister(right));
2681
__ CallCFunction(ExternalReference::power_double_double_function(), 4);
3007
__ PrepareCallCFunction(0, 2, scratch);
3008
__ SetCallCDoubleArguments(ToDoubleRegister(left),
3009
ToDoubleRegister(right));
3011
ExternalReference::power_double_double_function(isolate()), 0, 2);
2682
3012
} else if (exponent_type.IsInteger32()) {
2683
3013
ASSERT(ToRegister(right).is(r0));
2684
3014
// Prepare arguments and call C function.
2685
__ PrepareCallCFunction(4, scratch);
2686
__ mov(r2, ToRegister(right));
2687
__ vmov(r0, r1, ToDoubleRegister(left));
2688
__ CallCFunction(ExternalReference::power_double_int_function(), 4);
3015
__ PrepareCallCFunction(1, 1, scratch);
3016
__ SetCallCDoubleArguments(ToDoubleRegister(left), ToRegister(right));
3018
ExternalReference::power_double_int_function(isolate()), 1, 1);
2690
3020
ASSERT(exponent_type.IsTagged());
2691
3021
ASSERT(instr->hydrogen()->left()->representation().IsDouble());
2716
3046
// Prepare arguments and call C function.
2717
3047
__ bind(&call);
2718
__ PrepareCallCFunction(4, scratch);
2719
__ vmov(r0, r1, ToDoubleRegister(left));
2720
__ vmov(r2, r3, result_reg);
2721
__ CallCFunction(ExternalReference::power_double_double_function(), 4);
3048
__ PrepareCallCFunction(0, 2, scratch);
3049
__ SetCallCDoubleArguments(ToDoubleRegister(left), result_reg);
3051
ExternalReference::power_double_double_function(isolate()), 0, 2);
2723
3053
// Store the result in the result register.
2724
3054
__ GetCFunctionDoubleResult(result_reg);
3058
void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
3059
ASSERT(ToDoubleRegister(instr->result()).is(d2));
3060
TranscendentalCacheStub stub(TranscendentalCache::LOG,
3061
TranscendentalCacheStub::UNTAGGED);
3062
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3066
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
3067
ASSERT(ToDoubleRegister(instr->result()).is(d2));
3068
TranscendentalCacheStub stub(TranscendentalCache::COS,
3069
TranscendentalCacheStub::UNTAGGED);
3070
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3074
void LCodeGen::DoMathSin(LUnaryMathOperation* instr) {
3075
ASSERT(ToDoubleRegister(instr->result()).is(d2));
3076
TranscendentalCacheStub stub(TranscendentalCache::SIN,
3077
TranscendentalCacheStub::UNTAGGED);
3078
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2728
3082
void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) {
2729
3083
switch (instr->op()) {
3276
void LCodeGen::DoStoreKeyedFastDoubleElement(
3277
LStoreKeyedFastDoubleElement* instr) {
3278
DwVfpRegister value = ToDoubleRegister(instr->value());
3279
Register elements = ToRegister(instr->elements());
3280
Register key = no_reg;
3281
Register scratch = scratch0();
3282
bool key_is_constant = instr->key()->IsConstantOperand();
3283
int constant_key = 0;
3286
// Calculate the effective address of the slot in the array to store the
3288
if (key_is_constant) {
3289
constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3290
if (constant_key & 0xF0000000) {
3291
Abort("array index constant value too big.");
3294
key = ToRegister(instr->key());
3296
int shift_size = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
3297
Operand operand = key_is_constant
3298
? Operand(constant_key * (1 << shift_size) +
3299
FixedDoubleArray::kHeaderSize - kHeapObjectTag)
3300
: Operand(key, LSL, shift_size);
3301
__ add(scratch, elements, operand);
3302
if (!key_is_constant) {
3303
__ add(scratch, scratch,
3304
Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag));
3307
// Check for NaN. All NaNs must be canonicalized.
3308
__ VFPCompareAndSetFlags(value, value);
3310
// Only load canonical NaN if the comparison above set the overflow.
3311
__ Vmov(value, FixedDoubleArray::canonical_not_the_hole_nan_as_double(), vs);
3314
__ vstr(value, scratch, 0);
3318
void LCodeGen::DoStoreKeyedSpecializedArrayElement(
3319
LStoreKeyedSpecializedArrayElement* instr) {
3321
Register external_pointer = ToRegister(instr->external_pointer());
3322
Register key = no_reg;
3323
ElementsKind elements_kind = instr->elements_kind();
3324
bool key_is_constant = instr->key()->IsConstantOperand();
3325
int constant_key = 0;
3326
if (key_is_constant) {
3327
constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3328
if (constant_key & 0xF0000000) {
3329
Abort("array index constant value too big.");
3332
key = ToRegister(instr->key());
3334
int shift_size = ElementsKindToShiftSize(elements_kind);
3336
if (elements_kind == EXTERNAL_FLOAT_ELEMENTS ||
3337
elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
3338
CpuFeatures::Scope scope(VFP3);
3339
DwVfpRegister value(ToDoubleRegister(instr->value()));
3340
Operand operand(key_is_constant ? Operand(constant_key * (1 << shift_size))
3341
: Operand(key, LSL, shift_size));
3342
__ add(scratch0(), external_pointer, operand);
3343
if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
3344
__ vcvt_f32_f64(double_scratch0().low(), value);
3345
__ vstr(double_scratch0().low(), scratch0(), 0);
3346
} else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
3347
__ vstr(value, scratch0(), 0);
3350
Register value(ToRegister(instr->value()));
3351
MemOperand mem_operand(key_is_constant
3352
? MemOperand(external_pointer, constant_key * (1 << shift_size))
3353
: MemOperand(external_pointer, key, LSL, shift_size));
3354
switch (elements_kind) {
3355
case EXTERNAL_PIXEL_ELEMENTS:
3356
case EXTERNAL_BYTE_ELEMENTS:
3357
case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3358
__ strb(value, mem_operand);
3360
case EXTERNAL_SHORT_ELEMENTS:
3361
case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3362
__ strh(value, mem_operand);
3364
case EXTERNAL_INT_ELEMENTS:
3365
case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3366
__ str(value, mem_operand);
3368
case EXTERNAL_FLOAT_ELEMENTS:
3369
case EXTERNAL_DOUBLE_ELEMENTS:
3370
case FAST_DOUBLE_ELEMENTS:
3372
case DICTIONARY_ELEMENTS:
3373
case NON_STRICT_ARGUMENTS_ELEMENTS:
2892
3381
void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) {
2893
3382
ASSERT(ToRegister(instr->object()).is(r2));
2894
3383
ASSERT(ToRegister(instr->key()).is(r1));
2895
3384
ASSERT(ToRegister(instr->value()).is(r0));
2897
Handle<Code> ic(Builtins::builtin(
2898
info_->is_strict() ? Builtins::KeyedStoreIC_Initialize_Strict
2899
: Builtins::KeyedStoreIC_Initialize));
3386
Handle<Code> ic = instr->strict_mode()
3387
? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
3388
: isolate()->builtins()->KeyedStoreIC_Initialize();
2900
3389
CallCode(ic, RelocInfo::CODE_TARGET, instr);
3393
void LCodeGen::DoStringAdd(LStringAdd* instr) {
3394
__ push(ToRegister(instr->left()));
3395
__ push(ToRegister(instr->right()));
3396
StringAddStub stub(NO_STRING_CHECK_IN_STUB);
3397
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2904
3401
void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
2905
3402
class DeferredStringCharCodeAt: public LDeferredCode {
2911
3408
LStringCharCodeAt* instr_;
2914
Register scratch = scratch0();
2915
3411
Register string = ToRegister(instr->string());
2916
Register index = no_reg;
2917
int const_index = -1;
2918
if (instr->index()->IsConstantOperand()) {
2919
const_index = ToInteger32(LConstantOperand::cast(instr->index()));
2920
STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
2921
if (!Smi::IsValid(const_index)) {
2922
// Guaranteed to be out of bounds because of the assert above.
2923
// So the bounds check that must dominate this instruction must
2924
// have deoptimized already.
2925
if (FLAG_debug_code) {
2926
__ Abort("StringCharCodeAt: out of bounds index.");
2928
// No code needs to be generated.
2932
index = ToRegister(instr->index());
3412
Register index = ToRegister(instr->index());
2934
3413
Register result = ToRegister(instr->result());
2936
3415
DeferredStringCharCodeAt* deferred =
2937
3416
new DeferredStringCharCodeAt(this, instr);
2939
Label flat_string, ascii_string, done;
2941
3418
// Fetch the instance type of the receiver into result register.
2942
3419
__ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
2943
3420
__ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
2945
// We need special handling for non-flat strings.
2946
STATIC_ASSERT(kSeqStringTag == 0);
2947
__ tst(result, Operand(kStringRepresentationMask));
2948
__ b(eq, &flat_string);
2950
// Handle non-flat strings.
2951
__ tst(result, Operand(kIsConsStringMask));
2952
__ b(eq, deferred->entry());
3422
// We need special handling for indirect strings.
3423
Label check_sequential;
3424
__ tst(result, Operand(kIsIndirectStringMask));
3425
__ b(eq, &check_sequential);
3427
// Dispatch on the indirect string shape: slice or cons.
3429
__ tst(result, Operand(kSlicedNotConsMask));
3430
__ b(eq, &cons_string);
3433
Label indirect_string_loaded;
3434
__ ldr(result, FieldMemOperand(string, SlicedString::kOffsetOffset));
3435
__ add(index, index, Operand(result, ASR, kSmiTagSize));
3436
__ ldr(string, FieldMemOperand(string, SlicedString::kParentOffset));
3437
__ jmp(&indirect_string_loaded);
2955
3440
// Check whether the right hand side is the empty string (i.e. if
2956
3441
// this is really a flat string in a cons string). If that is not
2957
3442
// the case we would rather go to the runtime system now to flatten
2959
__ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset));
3444
__ bind(&cons_string);
3445
__ ldr(result, FieldMemOperand(string, ConsString::kSecondOffset));
2960
3446
__ LoadRoot(ip, Heap::kEmptyStringRootIndex);
2961
__ cmp(scratch, ip);
2962
3448
__ b(ne, deferred->entry());
2963
3449
// Get the first of the two strings and load its instance type.
2964
3450
__ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset));
3452
__ bind(&indirect_string_loaded);
2965
3453
__ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
2966
3454
__ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));
2967
// If the first cons component is also non-flat, then go to runtime.
3456
// Check whether the string is sequential. The only non-sequential
3457
// shapes we support have just been unwrapped above.
3458
__ bind(&check_sequential);
2968
3459
STATIC_ASSERT(kSeqStringTag == 0);
2969
3460
__ tst(result, Operand(kStringRepresentationMask));
2970
3461
__ b(ne, deferred->entry());
2972
// Check for 1-byte or 2-byte string.
2973
__ bind(&flat_string);
2974
STATIC_ASSERT(kAsciiStringTag != 0);
3463
// Dispatch on the encoding: ASCII or two-byte.
3465
STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
3466
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2975
3467
__ tst(result, Operand(kStringEncodingMask));
2976
3468
__ b(ne, &ascii_string);
2979
// Load the 2-byte character code into the result register.
2980
STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
2981
if (instr->index()->IsConstantOperand()) {
2983
FieldMemOperand(string,
2984
SeqTwoByteString::kHeaderSize + 2 * const_index));
2988
Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2989
__ ldrh(result, MemOperand(scratch, index, LSL, 1));
3471
// Load the two-byte character code into the result register.
3475
Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3476
__ ldrh(result, MemOperand(result, index, LSL, 1));
2993
3479
// ASCII string.
2994
3480
// Load the byte into the result register.
2995
3481
__ bind(&ascii_string);
2996
if (instr->index()->IsConstantOperand()) {
2997
__ ldrb(result, FieldMemOperand(string,
2998
SeqAsciiString::kHeaderSize + const_index));
3002
Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag));
3003
__ ldrb(result, MemOperand(scratch, index));
3484
Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag));
3485
__ ldrb(result, MemOperand(result, index));
3005
3487
__ bind(&done);
3006
3488
__ bind(deferred->exit());
3524
void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) {
3525
class DeferredStringCharFromCode: public LDeferredCode {
3527
DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr)
3528
: LDeferredCode(codegen), instr_(instr) { }
3529
virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); }
3531
LStringCharFromCode* instr_;
3534
DeferredStringCharFromCode* deferred =
3535
new DeferredStringCharFromCode(this, instr);
3537
ASSERT(instr->hydrogen()->value()->representation().IsInteger32());
3538
Register char_code = ToRegister(instr->char_code());
3539
Register result = ToRegister(instr->result());
3540
ASSERT(!char_code.is(result));
3542
__ cmp(char_code, Operand(String::kMaxAsciiCharCode));
3543
__ b(hi, deferred->entry());
3544
__ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex);
3545
__ add(result, result, Operand(char_code, LSL, kPointerSizeLog2));
3546
__ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize));
3547
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
3549
__ b(eq, deferred->entry());
3550
__ bind(deferred->exit());
3554
void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) {
3555
Register char_code = ToRegister(instr->char_code());
3556
Register result = ToRegister(instr->result());
3558
// TODO(3095996): Get rid of this. For now, we need to make the
3559
// result register contain a valid pointer because it is already
3560
// contained in the register pointer map.
3561
__ mov(result, Operand(0));
3563
PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters);
3564
__ SmiTag(char_code);
3566
CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr);
3567
__ StoreToSafepointRegisterSlot(r0, result);
3042
3571
void LCodeGen::DoStringLength(LStringLength* instr) {
3043
3572
Register string = ToRegister(instr->InputAt(0));
3044
3573
Register result = ToRegister(instr->result());
3182
3711
LOperand* input = instr->InputAt(0);
3183
3712
ASSERT(input->IsRegister() && input->Equals(instr->result()));
3184
3713
if (instr->needs_check()) {
3185
__ tst(ToRegister(input), Operand(kSmiTagMask));
3186
DeoptimizeIf(ne, instr->environment());
3714
STATIC_ASSERT(kHeapObjectTag == 1);
3715
// If the input is a HeapObject, SmiUntag will set the carry flag.
3716
__ SmiUntag(ToRegister(input), SetCC);
3717
DeoptimizeIf(cs, instr->environment());
3719
__ SmiUntag(ToRegister(input));
3188
__ SmiUntag(ToRegister(input));
3192
3724
void LCodeGen::EmitNumberUntagD(Register input_reg,
3193
3725
DoubleRegister result_reg,
3726
bool deoptimize_on_undefined,
3194
3727
LEnvironment* env) {
3195
3728
Register scratch = scratch0();
3196
SwVfpRegister flt_scratch = s0;
3197
ASSERT(!result_reg.is(d0));
3729
SwVfpRegister flt_scratch = double_scratch0().low();
3730
ASSERT(!result_reg.is(double_scratch0()));
3199
3732
Label load_smi, heap_number, done;
3202
__ tst(input_reg, Operand(kSmiTagMask));
3203
__ b(eq, &load_smi);
3735
__ JumpIfSmi(input_reg, &load_smi);
3205
3737
// Heap number map check.
3206
3738
__ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
3207
3739
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3208
3740
__ cmp(scratch, Operand(ip));
3209
__ b(eq, &heap_number);
3211
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
3212
__ cmp(input_reg, Operand(ip));
3213
DeoptimizeIf(ne, env);
3215
// Convert undefined to NaN.
3216
__ LoadRoot(ip, Heap::kNanValueRootIndex);
3217
__ sub(ip, ip, Operand(kHeapObjectTag));
3218
__ vldr(result_reg, ip, HeapNumber::kValueOffset);
3741
if (deoptimize_on_undefined) {
3742
DeoptimizeIf(ne, env);
3745
__ b(eq, &heap_number);
3747
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
3748
__ cmp(input_reg, Operand(ip));
3749
DeoptimizeIf(ne, env);
3751
// Convert undefined to NaN.
3752
__ LoadRoot(ip, Heap::kNanValueRootIndex);
3753
__ sub(ip, ip, Operand(kHeapObjectTag));
3754
__ vldr(result_reg, ip, HeapNumber::kValueOffset);
3757
__ bind(&heap_number);
3221
3759
// Heap number to double register conversion.
3222
__ bind(&heap_number);
3223
3760
__ sub(ip, input_reg, Operand(kHeapObjectTag));
3224
3761
__ vldr(result_reg, ip, HeapNumber::kValueOffset);
3247
3784
void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) {
3249
3785
Register input_reg = ToRegister(instr->InputAt(0));
3250
Register scratch = scratch0();
3251
DoubleRegister dbl_scratch = d0;
3252
SwVfpRegister flt_scratch = s0;
3253
DoubleRegister dbl_tmp = ToDoubleRegister(instr->TempAt(0));
3786
Register scratch1 = scratch0();
3787
Register scratch2 = ToRegister(instr->TempAt(0));
3788
DwVfpRegister double_scratch = double_scratch0();
3789
SwVfpRegister single_scratch = double_scratch.low();
3791
ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2));
3792
ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1));
3796
// The input was optimistically untagged; revert it.
3797
// The carry flag is set when we reach this deferred code as we just executed
3798
// SmiUntag(heap_object, SetCC)
3799
STATIC_ASSERT(kHeapObjectTag == 1);
3800
__ adc(input_reg, input_reg, Operand(input_reg));
3255
3802
// Heap number map check.
3256
__ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
3803
__ ldr(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset));
3257
3804
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3258
__ cmp(scratch, Operand(ip));
3805
__ cmp(scratch1, Operand(ip));
3260
3807
if (instr->truncating()) {
3808
Register scratch3 = ToRegister(instr->TempAt(1));
3809
DwVfpRegister double_scratch2 = ToDoubleRegister(instr->TempAt(2));
3810
ASSERT(!scratch3.is(input_reg) &&
3811
!scratch3.is(scratch1) &&
3812
!scratch3.is(scratch2));
3813
// Performs a truncating conversion of a floating point number as used by
3814
// the JS bitwise operations.
3261
3815
Label heap_number;
3262
3816
__ b(eq, &heap_number);
3263
3817
// Check for undefined. Undefined is converted to zero for truncating
3271
3825
__ bind(&heap_number);
3272
__ sub(ip, input_reg, Operand(kHeapObjectTag));
3273
__ vldr(dbl_tmp, ip, HeapNumber::kValueOffset);
3274
__ vcmp(dbl_tmp, 0.0); // Sets overflow bit in FPSCR flags if NaN.
3275
__ vcvt_s32_f64(flt_scratch, dbl_tmp);
3276
__ vmov(input_reg, flt_scratch); // 32-bit result of conversion.
3277
__ vmrs(pc); // Move vector status bits to normal status bits.
3278
// Overflow bit is set if dbl_tmp is Nan.
3279
__ cmn(input_reg, Operand(1), vc); // 0x7fffffff + 1 -> overflow.
3280
__ cmp(input_reg, Operand(1), vc); // 0x80000000 - 1 -> overflow.
3281
DeoptimizeIf(vs, instr->environment()); // Saturation may have occured.
3826
__ sub(scratch1, input_reg, Operand(kHeapObjectTag));
3827
__ vldr(double_scratch2, scratch1, HeapNumber::kValueOffset);
3829
__ EmitECMATruncate(input_reg,
3837
CpuFeatures::Scope scope(VFP3);
3284
3838
// Deoptimize if we don't have a heap number.
3285
3839
DeoptimizeIf(ne, instr->environment());
3287
3841
__ sub(ip, input_reg, Operand(kHeapObjectTag));
3288
__ vldr(dbl_tmp, ip, HeapNumber::kValueOffset);
3289
__ vcvt_s32_f64(flt_scratch, dbl_tmp);
3290
__ vmov(input_reg, flt_scratch); // 32-bit result of conversion.
3291
// Non-truncating conversion means that we cannot lose bits, so we convert
3292
// back to check; note that using non-overlapping s and d regs would be
3294
__ vcvt_f64_s32(dbl_scratch, flt_scratch);
3295
__ VFPCompareAndSetFlags(dbl_scratch, dbl_tmp);
3296
DeoptimizeIf(ne, instr->environment()); // Not equal or unordered.
3842
__ vldr(double_scratch, ip, HeapNumber::kValueOffset);
3843
__ EmitVFPTruncate(kRoundToZero,
3848
kCheckForInexactConversion);
3849
DeoptimizeIf(ne, instr->environment());
3851
__ vmov(input_reg, single_scratch);
3297
3853
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3298
__ tst(input_reg, Operand(input_reg));
3854
__ cmp(input_reg, Operand(0));
3299
3855
__ b(ne, &done);
3300
__ vmov(lr, ip, dbl_tmp);
3301
__ tst(ip, Operand(1 << 31)); // Test sign bit.
3856
__ vmov(scratch1, double_scratch.high());
3857
__ tst(scratch1, Operand(HeapNumber::kSignMask));
3302
3858
DeoptimizeIf(ne, instr->environment());
3335
3890
Register input_reg = ToRegister(input);
3336
3891
DoubleRegister result_reg = ToDoubleRegister(result);
3338
EmitNumberUntagD(input_reg, result_reg, instr->environment());
3893
EmitNumberUntagD(input_reg, result_reg,
3894
instr->hydrogen()->deoptimize_on_undefined(),
3895
instr->environment());
3342
3899
void LCodeGen::DoDoubleToI(LDoubleToI* instr) {
3343
LOperand* input = instr->InputAt(0);
3344
ASSERT(input->IsDoubleRegister());
3345
LOperand* result = instr->result();
3346
ASSERT(result->IsRegister());
3348
DoubleRegister double_input = ToDoubleRegister(input);
3349
Register result_reg = ToRegister(result);
3350
SwVfpRegister single_scratch = double_scratch0().low();
3900
Register result_reg = ToRegister(instr->result());
3351
3901
Register scratch1 = scratch0();
3352
3902
Register scratch2 = ToRegister(instr->TempAt(0));
3354
__ EmitVFPTruncate(kRoundToZero,
3360
// Deoptimize if we had a vfp invalid exception.
3361
DeoptimizeIf(ne, instr->environment());
3363
// Retrieve the result.
3364
__ vmov(result_reg, single_scratch);
3366
if (!instr->truncating()) {
3367
// Convert result back to double and compare with input
3368
// to check if the conversion was exact.
3369
__ vmov(single_scratch, result_reg);
3370
__ vcvt_f64_s32(double_scratch0(), single_scratch);
3371
__ VFPCompareAndSetFlags(double_scratch0(), double_input);
3903
DwVfpRegister double_input = ToDoubleRegister(instr->InputAt(0));
3904
SwVfpRegister single_scratch = double_scratch0().low();
3908
if (instr->truncating()) {
3909
Register scratch3 = ToRegister(instr->TempAt(1));
3910
__ EmitECMATruncate(result_reg,
3917
VFPRoundingMode rounding_mode = kRoundToMinusInf;
3918
__ EmitVFPTruncate(rounding_mode,
3923
kCheckForInexactConversion);
3924
// Deoptimize if we had a vfp invalid exception,
3925
// including inexact operation.
3372
3926
DeoptimizeIf(ne, instr->environment());
3373
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3375
__ cmp(result_reg, Operand(0));
3378
__ vmov(scratch1, double_input.high());
3379
__ tst(scratch1, Operand(HeapNumber::kSignMask));
3380
DeoptimizeIf(ne, instr->environment());
3927
// Retrieve the result.
3928
__ vmov(result_reg, single_scratch);
3388
3934
void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
3389
3935
LOperand* input = instr->InputAt(0);
3390
ASSERT(input->IsRegister());
3391
__ tst(ToRegister(input), Operand(kSmiTagMask));
3392
DeoptimizeIf(instr->condition(), instr->environment());
3936
__ tst(ToRegister(input), Operand(kSmiTagMask));
3937
DeoptimizeIf(ne, instr->environment());
3941
void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
3942
LOperand* input = instr->InputAt(0);
3943
__ tst(ToRegister(input), Operand(kSmiTagMask));
3944
DeoptimizeIf(eq, instr->environment());
3396
3948
void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) {
3397
3949
Register input = ToRegister(instr->InputAt(0));
3398
3950
Register scratch = scratch0();
3399
InstanceType first = instr->hydrogen()->first();
3400
InstanceType last = instr->hydrogen()->last();
3402
3952
__ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
3403
3953
__ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
3404
__ cmp(scratch, Operand(first));
3406
// If there is only one type in the interval check for equality.
3407
if (first == last) {
3408
DeoptimizeIf(ne, instr->environment());
3955
if (instr->hydrogen()->is_interval_check()) {
3958
instr->hydrogen()->GetCheckInterval(&first, &last);
3960
__ cmp(scratch, Operand(first));
3962
// If there is only one type in the interval check for equality.
3963
if (first == last) {
3964
DeoptimizeIf(ne, instr->environment());
3966
DeoptimizeIf(lo, instr->environment());
3967
// Omit check for the last type.
3968
if (last != LAST_TYPE) {
3969
__ cmp(scratch, Operand(last));
3970
DeoptimizeIf(hi, instr->environment());
3410
DeoptimizeIf(lo, instr->environment());
3411
// Omit check for the last type.
3412
if (last != LAST_TYPE) {
3413
__ cmp(scratch, Operand(last));
3414
DeoptimizeIf(hi, instr->environment());
3976
instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
3978
if (IsPowerOf2(mask)) {
3979
ASSERT(tag == 0 || IsPowerOf2(tag));
3980
__ tst(scratch, Operand(mask));
3981
DeoptimizeIf(tag == 0 ? ne : eq, instr->environment());
3983
__ and_(scratch, scratch, Operand(mask));
3984
__ cmp(scratch, Operand(tag));
3985
DeoptimizeIf(ne, instr->environment());
4010
void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) {
4011
DoubleRegister value_reg = ToDoubleRegister(instr->unclamped());
4012
Register result_reg = ToRegister(instr->result());
4013
DoubleRegister temp_reg = ToDoubleRegister(instr->TempAt(0));
4014
__ ClampDoubleToUint8(result_reg, value_reg, temp_reg);
4018
void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) {
4019
Register unclamped_reg = ToRegister(instr->unclamped());
4020
Register result_reg = ToRegister(instr->result());
4021
__ ClampUint8(result_reg, unclamped_reg);
4025
void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {
4026
Register scratch = scratch0();
4027
Register input_reg = ToRegister(instr->unclamped());
4028
Register result_reg = ToRegister(instr->result());
4029
DoubleRegister temp_reg = ToDoubleRegister(instr->TempAt(0));
4030
Label is_smi, done, heap_number;
4032
// Both smi and heap number cases are handled.
4033
__ JumpIfSmi(input_reg, &is_smi);
4035
// Check for heap number
4036
__ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
4037
__ cmp(scratch, Operand(factory()->heap_number_map()));
4038
__ b(eq, &heap_number);
4040
// Check for undefined. Undefined is converted to zero for clamping
4042
__ cmp(input_reg, Operand(factory()->undefined_value()));
4043
DeoptimizeIf(ne, instr->environment());
4044
__ mov(result_reg, Operand(0));
4048
__ bind(&heap_number);
4049
__ vldr(double_scratch0(), FieldMemOperand(input_reg,
4050
HeapNumber::kValueOffset));
4051
__ ClampDoubleToUint8(result_reg, double_scratch0(), temp_reg);
4056
__ SmiUntag(result_reg, input_reg);
4057
__ ClampUint8(result_reg, result_reg);
3439
4063
void LCodeGen::LoadHeapObject(Register result,
3440
4064
Handle<HeapObject> object) {
3441
if (Heap::InNewSpace(*object)) {
4065
if (heap()->InNewSpace(*object)) {
3442
4066
Handle<JSGlobalPropertyCell> cell =
3443
Factory::NewJSGlobalPropertyCell(object);
4067
factory()->NewJSGlobalPropertyCell(object);
3444
4068
__ mov(result, Operand(cell));
3445
4069
__ ldr(result, FieldMemOperand(result, JSGlobalPropertyCell::kValueOffset));
3650
4259
Handle<String> type_name) {
3651
4260
Condition final_branch_condition = kNoCondition;
3652
4261
Register scratch = scratch0();
3653
if (type_name->Equals(Heap::number_symbol())) {
3654
__ tst(input, Operand(kSmiTagMask));
3655
__ b(eq, true_label);
4262
if (type_name->Equals(heap()->number_symbol())) {
4263
__ JumpIfSmi(input, true_label);
3656
4264
__ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset));
3657
4265
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3658
4266
__ cmp(input, Operand(ip));
3659
4267
final_branch_condition = eq;
3661
} else if (type_name->Equals(Heap::string_symbol())) {
3662
__ tst(input, Operand(kSmiTagMask));
3663
__ b(eq, false_label);
3664
__ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset));
4269
} else if (type_name->Equals(heap()->string_symbol())) {
4270
__ JumpIfSmi(input, false_label);
4271
__ CompareObjectType(input, input, scratch, FIRST_NONSTRING_TYPE);
4272
__ b(ge, false_label);
3665
4273
__ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset));
3666
4274
__ tst(ip, Operand(1 << Map::kIsUndetectable));
3667
__ b(ne, false_label);
3668
__ CompareInstanceType(input, scratch, FIRST_NONSTRING_TYPE);
3669
final_branch_condition = lo;
3671
} else if (type_name->Equals(Heap::boolean_symbol())) {
3672
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
3674
__ b(eq, true_label);
3675
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
3677
final_branch_condition = eq;
3679
} else if (type_name->Equals(Heap::undefined_symbol())) {
3680
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
3682
__ b(eq, true_label);
3683
__ tst(input, Operand(kSmiTagMask));
3684
__ b(eq, false_label);
4275
final_branch_condition = eq;
4277
} else if (type_name->Equals(heap()->boolean_symbol())) {
4278
__ CompareRoot(input, Heap::kTrueValueRootIndex);
4279
__ b(eq, true_label);
4280
__ CompareRoot(input, Heap::kFalseValueRootIndex);
4281
final_branch_condition = eq;
4283
} else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_symbol())) {
4284
__ CompareRoot(input, Heap::kNullValueRootIndex);
4285
final_branch_condition = eq;
4287
} else if (type_name->Equals(heap()->undefined_symbol())) {
4288
__ CompareRoot(input, Heap::kUndefinedValueRootIndex);
4289
__ b(eq, true_label);
4290
__ JumpIfSmi(input, false_label);
3685
4291
// Check for undetectable objects => true.
3686
4292
__ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset));
3687
4293
__ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset));
3688
4294
__ tst(ip, Operand(1 << Map::kIsUndetectable));
3689
4295
final_branch_condition = ne;
3691
} else if (type_name->Equals(Heap::function_symbol())) {
3692
__ tst(input, Operand(kSmiTagMask));
3693
__ b(eq, false_label);
3694
__ CompareObjectType(input, input, scratch, JS_FUNCTION_TYPE);
3695
__ b(eq, true_label);
3696
// Regular expressions => 'function' (they are callable).
3697
__ CompareInstanceType(input, scratch, JS_REGEXP_TYPE);
3698
final_branch_condition = eq;
4297
} else if (type_name->Equals(heap()->function_symbol())) {
4298
__ JumpIfSmi(input, false_label);
4299
__ CompareObjectType(input, input, scratch,
4300
FIRST_CALLABLE_SPEC_OBJECT_TYPE);
4301
final_branch_condition = ge;
3700
} else if (type_name->Equals(Heap::object_symbol())) {
3701
__ tst(input, Operand(kSmiTagMask));
3702
__ b(eq, false_label);
3703
__ LoadRoot(ip, Heap::kNullValueRootIndex);
3705
__ b(eq, true_label);
3706
// Regular expressions => 'function', not 'object'.
3707
__ CompareObjectType(input, input, scratch, JS_REGEXP_TYPE);
3708
__ b(eq, false_label);
4303
} else if (type_name->Equals(heap()->object_symbol())) {
4304
__ JumpIfSmi(input, false_label);
4305
if (!FLAG_harmony_typeof) {
4306
__ CompareRoot(input, Heap::kNullValueRootIndex);
4307
__ b(eq, true_label);
4309
__ CompareObjectType(input, input, scratch,
4310
FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
4311
__ b(lt, false_label);
4312
__ CompareInstanceType(input, scratch, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
4313
__ b(gt, false_label);
3709
4314
// Check for undetectable objects => false.
3710
4315
__ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset));
3711
4316
__ tst(ip, Operand(1 << Map::kIsUndetectable));
3712
__ b(ne, false_label);
3713
// Check for JS objects => true.
3714
__ CompareInstanceType(input, scratch, FIRST_JS_OBJECT_TYPE);
3715
__ b(lo, false_label);
3716
__ CompareInstanceType(input, scratch, LAST_JS_OBJECT_TYPE);
3717
final_branch_condition = ls;
4317
final_branch_condition = eq;
3720
4320
final_branch_condition = ne;
3794
4394
__ Push(object, key, strict);
3795
4395
ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment());
3796
4396
LPointerMap* pointers = instr->pointer_map();
3797
LEnvironment* env = instr->deoptimization_environment();
3798
RecordPosition(pointers->position());
3799
RegisterEnvironmentForDeoptimization(env);
3800
SafepointGenerator safepoint_generator(this,
3802
env->deoptimization_index());
3803
__ InvokeBuiltin(Builtins::DELETE, CALL_JS, &safepoint_generator);
4397
RecordPosition(pointers->position());
4398
SafepointGenerator safepoint_generator(
4399
this, pointers, Safepoint::kLazyDeopt);
4400
__ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator);
4404
void LCodeGen::DoIn(LIn* instr) {
4405
Register obj = ToRegister(instr->object());
4406
Register key = ToRegister(instr->key());
4408
ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment());
4409
LPointerMap* pointers = instr->pointer_map();
4410
RecordPosition(pointers->position());
4411
SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt);
4412
__ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator);
4416
void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) {
4417
PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters);
4418
__ CallRuntimeSaveDoubles(Runtime::kStackGuard);
4419
RecordSafepointWithLazyDeopt(
4420
instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
4421
ASSERT(instr->HasEnvironment());
4422
LEnvironment* env = instr->environment();
4423
safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
3807
4427
void LCodeGen::DoStackCheck(LStackCheck* instr) {
3808
// Perform stack overflow check.
3810
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
3811
__ cmp(sp, Operand(ip));
3813
StackCheckStub stub;
3814
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
4428
class DeferredStackCheck: public LDeferredCode {
4430
DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr)
4431
: LDeferredCode(codegen), instr_(instr) { }
4432
virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); }
4434
LStackCheck* instr_;
4437
ASSERT(instr->HasEnvironment());
4438
LEnvironment* env = instr->environment();
4439
// There is no LLazyBailout instruction for stack-checks. We have to
4440
// prepare for lazy deoptimization explicitly here.
4441
if (instr->hydrogen()->is_function_entry()) {
4442
// Perform stack overflow check.
4444
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
4445
__ cmp(sp, Operand(ip));
4447
StackCheckStub stub;
4448
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
4449
EnsureSpaceForLazyDeopt();
4451
RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
4452
safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
4454
ASSERT(instr->hydrogen()->is_backwards_branch());
4455
// Perform stack overflow check if this goto needs it before jumping.
4456
DeferredStackCheck* deferred_stack_check =
4457
new DeferredStackCheck(this, instr);
4458
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
4459
__ cmp(sp, Operand(ip));
4460
__ b(lo, deferred_stack_check->entry());
4461
EnsureSpaceForLazyDeopt();
4462
__ bind(instr->done_label());
4463
deferred_stack_check->SetExit(instr->done_label());
4464
RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
4465
// Don't record a deoptimization index for the safepoint here.
4466
// This will be done explicitly when emitting call and the safepoint in
4467
// the deferred code.