| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 } | 1138 } |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 | 1141 |
| 1142 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | 1142 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 1143 // Nothing to do. | 1143 // Nothing to do. |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 | 1146 |
| 1147 void LCodeGen::DoModI(LModI* instr) { | 1147 void LCodeGen::DoModI(LModI* instr) { |
| 1148 Register scratch = scratch0(); | 1148 HMod* hmod = instr->hydrogen(); |
| 1149 const Register left = ToRegister(instr->left()); | 1149 HValue* left = hmod->left(); |
| 1150 const Register result = ToRegister(instr->result()); | 1150 HValue* right = hmod->right(); |
| 1151 if (hmod->HasPowerOf2Divisor()) { |
| 1152 const Register scratch = scratch0(); |
| 1153 const Register left_reg = ToRegister(instr->left()); |
| 1154 ASSERT(!left_reg.is(scratch)); |
| 1155 const Register result_reg = ToRegister(instr->result()); |
| 1151 | 1156 |
| 1152 Label done; | 1157 int32_t divisor = Abs(right->GetInteger32Constant()); |
| 1153 | 1158 |
| 1154 if (instr->hydrogen()->HasPowerOf2Divisor()) { | 1159 __ mov(scratch, left_reg); |
| 1155 Register scratch = scratch0(); | |
| 1156 ASSERT(!left.is(scratch)); | |
| 1157 __ mov(scratch, left); | |
| 1158 int32_t p2constant = HConstant::cast( | |
| 1159 instr->hydrogen()->right())->Integer32Value(); | |
| 1160 ASSERT(p2constant != 0); | |
| 1161 // Result always takes the sign of the dividend (left). | |
| 1162 p2constant = abs(p2constant); | |
| 1163 | 1160 |
| 1164 Label positive_dividend; | 1161 Label left_is_not_negative, done; |
| 1165 __ Branch(USE_DELAY_SLOT, &positive_dividend, ge, left, Operand(zero_reg)); | 1162 if (left->CanBeNegative()) { |
| 1166 __ subu(result, zero_reg, left); | 1163 __ Branch(USE_DELAY_SLOT, &left_is_not_negative, |
| 1167 __ And(result, result, p2constant - 1); | 1164 ge, left_reg, Operand(zero_reg)); |
| 1168 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1165 __ subu(result_reg, zero_reg, left_reg); |
| 1169 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); | 1166 __ And(result_reg, result_reg, divisor - 1); |
| 1170 } | 1167 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1171 __ Branch(USE_DELAY_SLOT, &done); | 1168 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); |
| 1172 __ subu(result, zero_reg, result); | 1169 } |
| 1173 __ bind(&positive_dividend); | 1170 __ Branch(USE_DELAY_SLOT, &done); |
| 1174 __ And(result, scratch, p2constant - 1); | 1171 __ subu(result_reg, zero_reg, result_reg); |
| 1175 } else { | |
| 1176 // div runs in the background while we check for special cases. | |
| 1177 Register right = EmitLoadRegister(instr->right(), scratch); | |
| 1178 __ div(left, right); | |
| 1179 | |
| 1180 // Check for x % 0. | |
| 1181 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | |
| 1182 DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); | |
| 1183 } | 1172 } |
| 1184 | 1173 |
| 1185 // Check for (kMinInt % -1). | 1174 __ bind(&left_is_not_negative); |
| 1186 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { | 1175 __ And(result_reg, scratch, divisor - 1); |
| 1176 __ bind(&done); |
| 1177 |
| 1178 } else { |
| 1179 // TODO(svenpanne) Add right->has_fixed_right_arg() case. |
| 1180 |
| 1181 const Register scratch = scratch0(); |
| 1182 const Register left_reg = ToRegister(instr->left()); |
| 1183 const Register result_reg = ToRegister(instr->result()); |
| 1184 |
| 1185 // div runs in the background while we check for special cases. |
| 1186 Register right_reg = EmitLoadRegister(instr->right(), scratch); |
| 1187 __ div(left_reg, right_reg); |
| 1188 |
| 1189 Label done; |
| 1190 // Check for x % 0, we have to deopt in this case because we can't return a |
| 1191 // NaN. |
| 1192 if (right->CanBeZero()) { |
| 1193 DeoptimizeIf(eq, instr->environment(), right_reg, Operand(zero_reg)); |
| 1194 } |
| 1195 |
| 1196 // Check for kMinInt % -1, we have to deopt if we care about -0, because we |
| 1197 // can't return that. |
| 1198 if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) { |
| 1187 Label left_not_min_int; | 1199 Label left_not_min_int; |
| 1188 __ Branch(&left_not_min_int, ne, left, Operand(kMinInt)); | 1200 __ Branch(&left_not_min_int, ne, left_reg, Operand(kMinInt)); |
| 1189 DeoptimizeIf(eq, instr->environment(), right, Operand(-1)); | 1201 // TODO(svenpanne) Don't deopt when we don't care about -0. |
| 1202 DeoptimizeIf(eq, instr->environment(), right_reg, Operand(-1)); |
| 1190 __ bind(&left_not_min_int); | 1203 __ bind(&left_not_min_int); |
| 1191 } | 1204 } |
| 1192 | 1205 |
| 1193 __ Branch(USE_DELAY_SLOT, &done, ge, left, Operand(zero_reg)); | 1206 // TODO(svenpanne) Only emit the test/deopt if we have to. |
| 1194 __ mfhi(result); | 1207 __ Branch(USE_DELAY_SLOT, &done, ge, left_reg, Operand(zero_reg)); |
| 1208 __ mfhi(result_reg); |
| 1195 | 1209 |
| 1196 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1210 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1197 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); | 1211 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); |
| 1198 } | 1212 } |
| 1213 __ bind(&done); |
| 1199 } | 1214 } |
| 1200 __ bind(&done); | |
| 1201 } | 1215 } |
| 1202 | 1216 |
| 1203 | 1217 |
| 1204 void LCodeGen::DoDivI(LDivI* instr) { | 1218 void LCodeGen::DoDivI(LDivI* instr) { |
| 1205 const Register left = ToRegister(instr->left()); | 1219 const Register left = ToRegister(instr->left()); |
| 1206 const Register right = ToRegister(instr->right()); | 1220 const Register right = ToRegister(instr->right()); |
| 1207 const Register result = ToRegister(instr->result()); | 1221 const Register result = ToRegister(instr->result()); |
| 1208 | 1222 |
| 1209 // On MIPS div is asynchronous - it will run in the background while we | 1223 // On MIPS div is asynchronous - it will run in the background while we |
| 1210 // check for special cases. | 1224 // check for special cases. |
| (...skipping 4485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5696 __ Subu(scratch, result, scratch); | 5710 __ Subu(scratch, result, scratch); |
| 5697 __ lw(result, FieldMemOperand(scratch, | 5711 __ lw(result, FieldMemOperand(scratch, |
| 5698 FixedArray::kHeaderSize - kPointerSize)); | 5712 FixedArray::kHeaderSize - kPointerSize)); |
| 5699 __ bind(&done); | 5713 __ bind(&done); |
| 5700 } | 5714 } |
| 5701 | 5715 |
| 5702 | 5716 |
| 5703 #undef __ | 5717 #undef __ |
| 5704 | 5718 |
| 5705 } } // namespace v8::internal | 5719 } } // namespace v8::internal |
| OLD | NEW |