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 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 __ bind(&positive_dividend); | 972 __ bind(&positive_dividend); |
973 __ and_(result, dividend, Operand(divisor - 1)); | 973 __ and_(result, dividend, Operand(divisor - 1)); |
974 __ bind(&done); | 974 __ bind(&done); |
975 return; | 975 return; |
976 } | 976 } |
977 | 977 |
978 // These registers hold untagged 32 bit values. | 978 // These registers hold untagged 32 bit values. |
979 Register left = ToRegister(instr->left()); | 979 Register left = ToRegister(instr->left()); |
980 Register right = ToRegister(instr->right()); | 980 Register right = ToRegister(instr->right()); |
981 Register result = ToRegister(instr->result()); | 981 Register result = ToRegister(instr->result()); |
982 #if CAN_USE_INTEGER_DIVISION | |
danno
2012/09/27 15:28:09
Need to be a runtime check rather than a compile-t
| |
983 // Check for x % 0. | |
984 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | |
985 __ cmp(right, Operand(0)); | |
986 DeoptimizeIf(eq, instr->environment()); | |
987 } | |
982 | 988 |
989 Label done; | |
990 // For r3 = r1 % r2; we can have the following ARM code | |
991 // sdiv r3, r1, r2 | |
992 // mls r3, r3, r2, r1 | |
993 | |
994 __ sdiv(result, left, right); | |
995 __ mls(result, result, right, left); | |
996 __ cmp(result, Operand(0)); | |
997 __ b(ne, &done); | |
998 | |
999 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
1000 __ cmp(left, Operand(0)); | |
1001 DeoptimizeIf(lt, instr->environment()); | |
1002 } | |
1003 #else | |
983 Register scratch = scratch0(); | 1004 Register scratch = scratch0(); |
984 Register scratch2 = ToRegister(instr->temp()); | 1005 Register scratch2 = ToRegister(instr->temp()); |
985 DwVfpRegister dividend = ToDoubleRegister(instr->temp2()); | 1006 DwVfpRegister dividend = ToDoubleRegister(instr->temp2()); |
986 DwVfpRegister divisor = ToDoubleRegister(instr->temp3()); | 1007 DwVfpRegister divisor = ToDoubleRegister(instr->temp3()); |
987 DwVfpRegister quotient = double_scratch0(); | 1008 DwVfpRegister quotient = double_scratch0(); |
988 | 1009 |
989 ASSERT(!dividend.is(divisor)); | 1010 ASSERT(!dividend.is(divisor)); |
990 ASSERT(!dividend.is(quotient)); | 1011 ASSERT(!dividend.is(quotient)); |
991 ASSERT(!divisor.is(quotient)); | 1012 ASSERT(!divisor.is(quotient)); |
992 ASSERT(!scratch.is(left)); | 1013 ASSERT(!scratch.is(left)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 Label ok; | 1095 Label ok; |
1075 // Check for -0. | 1096 // Check for -0. |
1076 __ sub(scratch2, left, scratch, SetCC); | 1097 __ sub(scratch2, left, scratch, SetCC); |
1077 __ b(ne, &ok); | 1098 __ b(ne, &ok); |
1078 __ cmp(left, Operand(0)); | 1099 __ cmp(left, Operand(0)); |
1079 DeoptimizeIf(mi, instr->environment()); | 1100 DeoptimizeIf(mi, instr->environment()); |
1080 __ bind(&ok); | 1101 __ bind(&ok); |
1081 // Load the result and we are done. | 1102 // Load the result and we are done. |
1082 __ mov(result, scratch2); | 1103 __ mov(result, scratch2); |
1083 } | 1104 } |
1084 | 1105 #endif |
1085 __ bind(&done); | 1106 __ bind(&done); |
1086 } | 1107 } |
1087 | 1108 |
1088 | 1109 |
1089 void LCodeGen::EmitSignedIntegerDivisionByConstant( | 1110 void LCodeGen::EmitSignedIntegerDivisionByConstant( |
danno
2012/09/27 15:28:09
Are there not cases in here that might also benefi
| |
1090 Register result, | 1111 Register result, |
1091 Register dividend, | 1112 Register dividend, |
1092 int32_t divisor, | 1113 int32_t divisor, |
1093 Register remainder, | 1114 Register remainder, |
1094 Register scratch, | 1115 Register scratch, |
1095 LEnvironment* environment) { | 1116 LEnvironment* environment) { |
1096 ASSERT(!AreAliased(dividend, scratch, ip)); | 1117 ASSERT(!AreAliased(dividend, scratch, ip)); |
1097 ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); | 1118 ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); |
1098 | 1119 |
1099 uint32_t divisor_abs = abs(divisor); | 1120 uint32_t divisor_abs = abs(divisor); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 __ JumpIfNotSmi(result, &deoptimize); | 1278 __ JumpIfNotSmi(result, &deoptimize); |
1258 __ SmiUntag(result); | 1279 __ SmiUntag(result); |
1259 __ b(&done); | 1280 __ b(&done); |
1260 | 1281 |
1261 __ bind(&deoptimize); | 1282 __ bind(&deoptimize); |
1262 DeoptimizeIf(al, instr->environment()); | 1283 DeoptimizeIf(al, instr->environment()); |
1263 __ bind(&done); | 1284 __ bind(&done); |
1264 } | 1285 } |
1265 | 1286 |
1266 | 1287 |
1267 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { | 1288 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
danno
2012/09/27 15:28:09
This could definitely benefit from sdiv, too.
| |
1268 const Register result = ToRegister(instr->result()); | 1289 const Register result = ToRegister(instr->result()); |
1269 const Register left = ToRegister(instr->left()); | 1290 const Register left = ToRegister(instr->left()); |
1270 const Register remainder = ToRegister(instr->temp()); | 1291 const Register remainder = ToRegister(instr->temp()); |
1271 const Register scratch = scratch0(); | 1292 const Register scratch = scratch0(); |
1272 | 1293 |
1273 // We only optimize this for division by constants, because the standard | 1294 // We only optimize this for division by constants, because the standard |
1274 // integer division routine is usually slower than transitionning to VFP. | 1295 // integer division routine is usually slower than transitionning to VFP. |
1275 // This could be optimized on processors with SDIV available. | 1296 // This could be optimized on processors with SDIV available. |
1276 ASSERT(instr->right()->IsConstantOperand()); | 1297 ASSERT(instr->right()->IsConstantOperand()); |
1277 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); | 1298 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
(...skipping 4382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5660 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); | 5681 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
5661 __ ldr(result, FieldMemOperand(scratch, | 5682 __ ldr(result, FieldMemOperand(scratch, |
5662 FixedArray::kHeaderSize - kPointerSize)); | 5683 FixedArray::kHeaderSize - kPointerSize)); |
5663 __ bind(&done); | 5684 __ bind(&done); |
5664 } | 5685 } |
5665 | 5686 |
5666 | 5687 |
5667 #undef __ | 5688 #undef __ |
5668 | 5689 |
5669 } } // namespace v8::internal | 5690 } } // namespace v8::internal |
OLD | NEW |