OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved.7 | 1 // Copyright 2012 the V8 project authors. All rights reserved.7 |
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 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 if (divisor < 0) __ Subu(result, zero_reg, result); | 1235 if (divisor < 0) __ Subu(result, zero_reg, result); |
1236 | 1236 |
1237 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1237 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
1238 __ Mul(scratch0(), result, Operand(divisor)); | 1238 __ Mul(scratch0(), result, Operand(divisor)); |
1239 __ Subu(scratch0(), scratch0(), dividend); | 1239 __ Subu(scratch0(), scratch0(), dividend); |
1240 DeoptimizeIf(ne, instr->environment(), scratch0(), Operand(zero_reg)); | 1240 DeoptimizeIf(ne, instr->environment(), scratch0(), Operand(zero_reg)); |
1241 } | 1241 } |
1242 } | 1242 } |
1243 | 1243 |
1244 | 1244 |
| 1245 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
1245 void LCodeGen::DoDivI(LDivI* instr) { | 1246 void LCodeGen::DoDivI(LDivI* instr) { |
1246 HBinaryOperation* hdiv = instr->hydrogen(); | 1247 HBinaryOperation* hdiv = instr->hydrogen(); |
1247 const Register left = ToRegister(instr->left()); | 1248 Register dividend = ToRegister(instr->dividend()); |
1248 const Register right = ToRegister(instr->right()); | 1249 Register divisor = ToRegister(instr->divisor()); |
1249 const Register result = ToRegister(instr->result()); | 1250 const Register result = ToRegister(instr->result()); |
1250 | 1251 |
1251 // On MIPS div is asynchronous - it will run in the background while we | 1252 // On MIPS div is asynchronous - it will run in the background while we |
1252 // check for special cases. | 1253 // check for special cases. |
1253 __ div(left, right); | 1254 __ div(dividend, divisor); |
1254 | 1255 |
1255 // Check for x / 0. | 1256 // Check for x / 0. |
1256 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1257 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
1257 DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); | 1258 DeoptimizeIf(eq, instr->environment(), divisor, Operand(zero_reg)); |
1258 } | 1259 } |
1259 | 1260 |
1260 // Check for (0 / -x) that will produce negative zero. | 1261 // Check for (0 / -x) that will produce negative zero. |
1261 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1262 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1262 Label left_not_zero; | 1263 Label left_not_zero; |
1263 __ Branch(&left_not_zero, ne, left, Operand(zero_reg)); | 1264 __ Branch(&left_not_zero, ne, dividend, Operand(zero_reg)); |
1264 DeoptimizeIf(lt, instr->environment(), right, Operand(zero_reg)); | 1265 DeoptimizeIf(lt, instr->environment(), divisor, Operand(zero_reg)); |
1265 __ bind(&left_not_zero); | 1266 __ bind(&left_not_zero); |
1266 } | 1267 } |
1267 | 1268 |
1268 // Check for (kMinInt / -1). | 1269 // Check for (kMinInt / -1). |
1269 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1270 if (hdiv->CheckFlag(HValue::kCanOverflow) && |
1270 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | 1271 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1271 Label left_not_min_int; | 1272 Label left_not_min_int; |
1272 __ Branch(&left_not_min_int, ne, left, Operand(kMinInt)); | 1273 __ Branch(&left_not_min_int, ne, dividend, Operand(kMinInt)); |
1273 DeoptimizeIf(eq, instr->environment(), right, Operand(-1)); | 1274 DeoptimizeIf(eq, instr->environment(), divisor, Operand(-1)); |
1274 __ bind(&left_not_min_int); | 1275 __ bind(&left_not_min_int); |
1275 } | 1276 } |
1276 | 1277 |
1277 if (hdiv->IsMathFloorOfDiv()) { | 1278 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1278 // We performed a truncating division. Correct the result if necessary. | |
1279 Label done; | |
1280 Register remainder = scratch0(); | |
1281 __ mfhi(remainder); | |
1282 __ mflo(result); | |
1283 __ Branch(&done, eq, remainder, Operand(zero_reg), USE_DELAY_SLOT); | |
1284 __ Xor(remainder, remainder, Operand(right)); | |
1285 __ Branch(&done, ge, remainder, Operand(zero_reg)); | |
1286 __ Subu(result, result, Operand(1)); | |
1287 __ bind(&done); | |
1288 } else if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
1289 __ mfhi(result); | 1279 __ mfhi(result); |
1290 DeoptimizeIf(ne, instr->environment(), result, Operand(zero_reg)); | 1280 DeoptimizeIf(ne, instr->environment(), result, Operand(zero_reg)); |
1291 __ mflo(result); | 1281 __ mflo(result); |
1292 } else { | 1282 } else { |
1293 __ mflo(result); | 1283 __ mflo(result); |
1294 } | 1284 } |
1295 } | 1285 } |
1296 | 1286 |
1297 | 1287 |
1298 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { | 1288 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 __ jmp(&done); | 1381 __ jmp(&done); |
1392 __ bind(&needs_adjustment); | 1382 __ bind(&needs_adjustment); |
1393 __ Addu(temp, dividend, Operand(divisor > 0 ? 1 : -1)); | 1383 __ Addu(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
1394 __ TruncatingDiv(result, temp, Abs(divisor)); | 1384 __ TruncatingDiv(result, temp, Abs(divisor)); |
1395 if (divisor < 0) __ Subu(result, zero_reg, result); | 1385 if (divisor < 0) __ Subu(result, zero_reg, result); |
1396 __ Subu(result, result, Operand(1)); | 1386 __ Subu(result, result, Operand(1)); |
1397 __ bind(&done); | 1387 __ bind(&done); |
1398 } | 1388 } |
1399 | 1389 |
1400 | 1390 |
| 1391 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1392 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1393 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1394 Register dividend = ToRegister(instr->dividend()); |
| 1395 Register divisor = ToRegister(instr->divisor()); |
| 1396 const Register result = ToRegister(instr->result()); |
| 1397 |
| 1398 // On MIPS div is asynchronous - it will run in the background while we |
| 1399 // check for special cases. |
| 1400 __ div(dividend, divisor); |
| 1401 |
| 1402 // Check for x / 0. |
| 1403 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1404 DeoptimizeIf(eq, instr->environment(), divisor, Operand(zero_reg)); |
| 1405 } |
| 1406 |
| 1407 // Check for (0 / -x) that will produce negative zero. |
| 1408 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1409 Label left_not_zero; |
| 1410 __ Branch(&left_not_zero, ne, dividend, Operand(zero_reg)); |
| 1411 DeoptimizeIf(lt, instr->environment(), divisor, Operand(zero_reg)); |
| 1412 __ bind(&left_not_zero); |
| 1413 } |
| 1414 |
| 1415 // Check for (kMinInt / -1). |
| 1416 if (hdiv->CheckFlag(HValue::kCanOverflow) && |
| 1417 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1418 Label left_not_min_int; |
| 1419 __ Branch(&left_not_min_int, ne, dividend, Operand(kMinInt)); |
| 1420 DeoptimizeIf(eq, instr->environment(), divisor, Operand(-1)); |
| 1421 __ bind(&left_not_min_int); |
| 1422 } |
| 1423 |
| 1424 // We performed a truncating division. Correct the result if necessary. |
| 1425 Label done; |
| 1426 Register remainder = scratch0(); |
| 1427 __ mfhi(remainder); |
| 1428 __ mflo(result); |
| 1429 __ Branch(&done, eq, remainder, Operand(zero_reg), USE_DELAY_SLOT); |
| 1430 __ Xor(remainder, remainder, Operand(divisor)); |
| 1431 __ Branch(&done, ge, remainder, Operand(zero_reg)); |
| 1432 __ Subu(result, result, Operand(1)); |
| 1433 __ bind(&done); |
| 1434 } |
| 1435 |
| 1436 |
1401 void LCodeGen::DoMulI(LMulI* instr) { | 1437 void LCodeGen::DoMulI(LMulI* instr) { |
1402 Register scratch = scratch0(); | 1438 Register scratch = scratch0(); |
1403 Register result = ToRegister(instr->result()); | 1439 Register result = ToRegister(instr->result()); |
1404 // Note that result may alias left. | 1440 // Note that result may alias left. |
1405 Register left = ToRegister(instr->left()); | 1441 Register left = ToRegister(instr->left()); |
1406 LOperand* right_op = instr->right(); | 1442 LOperand* right_op = instr->right(); |
1407 | 1443 |
1408 bool bailout_on_minus_zero = | 1444 bool bailout_on_minus_zero = |
1409 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | 1445 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
1410 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1446 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
(...skipping 4452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5863 __ lw(result, FieldMemOperand(scratch, | 5899 __ lw(result, FieldMemOperand(scratch, |
5864 FixedArray::kHeaderSize - kPointerSize)); | 5900 FixedArray::kHeaderSize - kPointerSize)); |
5865 __ bind(deferred->exit()); | 5901 __ bind(deferred->exit()); |
5866 __ bind(&done); | 5902 __ bind(&done); |
5867 } | 5903 } |
5868 | 5904 |
5869 | 5905 |
5870 #undef __ | 5906 #undef __ |
5871 | 5907 |
5872 } } // namespace v8::internal | 5908 } } // namespace v8::internal |
OLD | NEW |