if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
DeoptimizeIf(eq, instr->environment());
}
- if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- // Note that we could emit branch-free code, but that would need one more
- // register.
- if (divisor == -1) {
- DeoptimizeIf(vs, instr->environment());
- __ mov(result, Operand(dividend, ASR, shift));
- } else {
- __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
- __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc);
- }
- } else {
+
+ // If the negation could not overflow, simply shifting is OK.
+ if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
__ mov(result, Operand(dividend, ASR, shift));
+ return;
}
+
+ // Dividing by -1 is basically negation, unless we overflow.
+ if (divisor == -1) {
+ DeoptimizeIf(vs, instr->environment());
+ return;
+ }
+
+ __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
+ __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc);
}
}
// If the divisor is negative, we have to negate and handle edge cases.
- Label not_kmin_int, done;
__ Negs(result, dividend);
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
DeoptimizeIf(eq, instr->environment());
}
- if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- // Note that we could emit branch-free code, but that would need one more
- // register.
- if (divisor == -1) {
- DeoptimizeIf(vs, instr->environment());
- } else {
- __ B(vc, ¬_kmin_int);
- __ Mov(result, kMinInt / divisor);
- __ B(&done);
- }
+
+ // If the negation could not overflow, simply shifting is OK.
+ if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+ __ Mov(result, Operand(dividend, ASR, shift));
+ return;
}
+
+ // Dividing by -1 is basically negation, unless we overflow.
+ if (divisor == -1) {
+ DeoptimizeIf(vs, instr->environment());
+ return;
+ }
+
+ // Using a conditional data processing instruction would need 1 more register.
+ Label not_kmin_int, done;
+ __ B(vc, ¬_kmin_int);
+ __ Mov(result, kMinInt / divisor);
+ __ B(&done);
__ bind(¬_kmin_int);
__ Mov(result, Operand(dividend, ASR, shift));
__ bind(&done);
}
// If the divisor is negative, we have to negate and handle edge cases.
- Label not_kmin_int, done;
__ neg(dividend);
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
DeoptimizeIf(zero, instr->environment());
}
- if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- // Note that we could emit branch-free code, but that would need one more
- // register.
- if (divisor == -1) {
- DeoptimizeIf(overflow, instr->environment());
- } else {
- __ j(no_overflow, ¬_kmin_int, Label::kNear);
- __ mov(dividend, Immediate(kMinInt / divisor));
- __ jmp(&done, Label::kNear);
- }
+
+ if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+ __ sar(dividend, shift);
+ return;
}
+
+ // Dividing by -1 is basically negation, unless we overflow.
+ if (divisor == -1) {
+ DeoptimizeIf(overflow, instr->environment());
+ return;
+ }
+
+ Label not_kmin_int, done;
+ __ j(no_overflow, ¬_kmin_int, Label::kNear);
+ __ mov(dividend, Immediate(kMinInt / divisor));
+ __ jmp(&done, Label::kNear);
__ bind(¬_kmin_int);
__ sar(dividend, shift);
__ bind(&done);
}
// If the divisor is negative, we have to negate and handle edge cases.
- Label not_kmin_int, done;
__ negl(dividend);
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
DeoptimizeIf(zero, instr->environment());
}
- if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- // Note that we could emit branch-free code, but that would need one more
- // register.
- __ j(no_overflow, ¬_kmin_int, Label::kNear);
- if (divisor == -1) {
- DeoptimizeIf(no_condition, instr->environment());
- } else {
- __ movl(dividend, Immediate(kMinInt / divisor));
- __ jmp(&done, Label::kNear);
- }
+
+ // If the negation could not overflow, simply shifting is OK.
+ if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+ __ sarl(dividend, Immediate(shift));
+ return;
}
+
+ // Note that we could emit branch-free code, but that would need one more
+ // register.
+ if (divisor == -1) {
+ DeoptimizeIf(overflow, instr->environment());
+ return;
+ }
+
+ Label not_kmin_int, done;
+ __ j(no_overflow, ¬_kmin_int, Label::kNear);
+ __ movl(dividend, Immediate(kMinInt / divisor));
+ __ jmp(&done, Label::kNear);
__ bind(¬_kmin_int);
__ sarl(dividend, Immediate(shift));
__ bind(&done);