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 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 left = UseRegisterAtStart(instr->LeastConstantOperand()); | 1296 left = UseRegisterAtStart(instr->LeastConstantOperand()); |
1297 } | 1297 } |
1298 LMulI* mul = new(zone()) LMulI(left, right, temp); | 1298 LMulI* mul = new(zone()) LMulI(left, right, temp); |
1299 if (instr->CheckFlag(HValue::kCanOverflow) || | 1299 if (instr->CheckFlag(HValue::kCanOverflow) || |
1300 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1300 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1301 AssignEnvironment(mul); | 1301 AssignEnvironment(mul); |
1302 } | 1302 } |
1303 return DefineAsRegister(mul); | 1303 return DefineAsRegister(mul); |
1304 | 1304 |
1305 } else if (instr->representation().IsDouble()) { | 1305 } else if (instr->representation().IsDouble()) { |
| 1306 if (instr->UseCount() == 1 && instr->uses().value()->IsAdd()) { |
| 1307 HAdd* add = HAdd::cast(instr->uses().value()); |
| 1308 if (instr == add->left()) { |
| 1309 // This mul is the lhs of an add. The add and mul will be folded |
| 1310 // into a multiply-add. |
| 1311 return NULL; |
| 1312 } |
| 1313 if (instr == add->right() && !add->left()->IsMul()) { |
| 1314 // This mul is the rhs of an add, where the lhs is not another mul. |
| 1315 // The add and mul will be folded into a multiply-add. |
| 1316 return NULL; |
| 1317 } |
| 1318 } |
| 1319 |
1306 return DoArithmeticD(Token::MUL, instr); | 1320 return DoArithmeticD(Token::MUL, instr); |
1307 | |
1308 } else { | 1321 } else { |
1309 return DoArithmeticT(Token::MUL, instr); | 1322 return DoArithmeticT(Token::MUL, instr); |
1310 } | 1323 } |
1311 } | 1324 } |
1312 | 1325 |
1313 | 1326 |
1314 LInstruction* LChunkBuilder::DoSub(HSub* instr) { | 1327 LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
1315 if (instr->representation().IsInteger32()) { | 1328 if (instr->representation().IsInteger32()) { |
1316 ASSERT(instr->left()->representation().IsInteger32()); | 1329 ASSERT(instr->left()->representation().IsInteger32()); |
1317 ASSERT(instr->right()->representation().IsInteger32()); | 1330 ASSERT(instr->right()->representation().IsInteger32()); |
1318 LOperand* left = UseRegisterAtStart(instr->left()); | 1331 LOperand* left = UseRegisterAtStart(instr->left()); |
1319 LOperand* right = UseOrConstantAtStart(instr->right()); | 1332 LOperand* right = UseOrConstantAtStart(instr->right()); |
1320 LSubI* sub = new(zone()) LSubI(left, right); | 1333 LSubI* sub = new(zone()) LSubI(left, right); |
1321 LInstruction* result = DefineAsRegister(sub); | 1334 LInstruction* result = DefineAsRegister(sub); |
1322 if (instr->CheckFlag(HValue::kCanOverflow)) { | 1335 if (instr->CheckFlag(HValue::kCanOverflow)) { |
1323 result = AssignEnvironment(result); | 1336 result = AssignEnvironment(result); |
1324 } | 1337 } |
1325 return result; | 1338 return result; |
1326 } else if (instr->representation().IsDouble()) { | 1339 } else if (instr->representation().IsDouble()) { |
1327 return DoArithmeticD(Token::SUB, instr); | 1340 return DoArithmeticD(Token::SUB, instr); |
1328 } else { | 1341 } else { |
1329 return DoArithmeticT(Token::SUB, instr); | 1342 return DoArithmeticT(Token::SUB, instr); |
1330 } | 1343 } |
1331 } | 1344 } |
1332 | 1345 |
| 1346 LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) { |
| 1347 LOperand* multiplier_op = UseRegisterAtStart(mul->left()); |
| 1348 LOperand* multiplicand_op = UseRegisterAtStart(mul->right()); |
| 1349 LOperand* addend_op = UseRegisterAtStart(addend); |
| 1350 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op, |
| 1351 multiplicand_op)); |
| 1352 } |
1333 | 1353 |
1334 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { | 1354 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
1335 if (instr->representation().IsInteger32()) { | 1355 if (instr->representation().IsInteger32()) { |
1336 ASSERT(instr->left()->representation().IsInteger32()); | 1356 ASSERT(instr->left()->representation().IsInteger32()); |
1337 ASSERT(instr->right()->representation().IsInteger32()); | 1357 ASSERT(instr->right()->representation().IsInteger32()); |
1338 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); | 1358 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
1339 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); | 1359 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
1340 LAddI* add = new(zone()) LAddI(left, right); | 1360 LAddI* add = new(zone()) LAddI(left, right); |
1341 LInstruction* result = DefineAsRegister(add); | 1361 LInstruction* result = DefineAsRegister(add); |
1342 if (instr->CheckFlag(HValue::kCanOverflow)) { | 1362 if (instr->CheckFlag(HValue::kCanOverflow)) { |
1343 result = AssignEnvironment(result); | 1363 result = AssignEnvironment(result); |
1344 } | 1364 } |
1345 return result; | 1365 return result; |
1346 } else if (instr->representation().IsDouble()) { | 1366 } else if (instr->representation().IsDouble()) { |
| 1367 if (instr->left()->IsMul()) |
| 1368 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right()); |
| 1369 |
| 1370 if (instr->right()->IsMul()) { |
| 1371 ASSERT(!instr->left()->IsMul()); |
| 1372 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left()); |
| 1373 } |
| 1374 |
1347 return DoArithmeticD(Token::ADD, instr); | 1375 return DoArithmeticD(Token::ADD, instr); |
1348 } else { | 1376 } else { |
1349 ASSERT(instr->representation().IsTagged()); | 1377 ASSERT(instr->representation().IsTagged()); |
1350 return DoArithmeticT(Token::ADD, instr); | 1378 return DoArithmeticT(Token::ADD, instr); |
1351 } | 1379 } |
1352 } | 1380 } |
1353 | 1381 |
1354 | 1382 |
1355 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { | 1383 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
1356 LOperand* left = NULL; | 1384 LOperand* left = NULL; |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 | 2290 |
2263 | 2291 |
2264 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2292 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2265 LOperand* object = UseRegister(instr->object()); | 2293 LOperand* object = UseRegister(instr->object()); |
2266 LOperand* index = UseRegister(instr->index()); | 2294 LOperand* index = UseRegister(instr->index()); |
2267 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2295 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
2268 } | 2296 } |
2269 | 2297 |
2270 | 2298 |
2271 } } // namespace v8::internal | 2299 } } // namespace v8::internal |
OLD | NEW |