| 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 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 // Record the address of the first unknown OSR value as the place to enter. | 1050 // Record the address of the first unknown OSR value as the place to enter. |
| 1051 if (osr_pc_offset_ == -1) osr_pc_offset_ = masm()->pc_offset(); | 1051 if (osr_pc_offset_ == -1) osr_pc_offset_ = masm()->pc_offset(); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 | 1054 |
| 1055 void LCodeGen::DoModI(LModI* instr) { | 1055 void LCodeGen::DoModI(LModI* instr) { |
| 1056 HMod* hmod = instr->hydrogen(); | 1056 HMod* hmod = instr->hydrogen(); |
| 1057 HValue* left = hmod->left(); | 1057 HValue* left = hmod->left(); |
| 1058 HValue* right = hmod->right(); | 1058 HValue* right = hmod->right(); |
| 1059 if (hmod->HasPowerOf2Divisor()) { | 1059 if (hmod->HasPowerOf2Divisor()) { |
| 1060 const Register scratch = scratch0(); | |
| 1061 const Register left_reg = ToRegister(instr->left()); | 1060 const Register left_reg = ToRegister(instr->left()); |
| 1062 ASSERT(!left_reg.is(scratch)); | |
| 1063 const Register result_reg = ToRegister(instr->result()); | 1061 const Register result_reg = ToRegister(instr->result()); |
| 1064 | 1062 |
| 1065 // Note: The code below even works when right contains kMinInt. | 1063 // Note: The code below even works when right contains kMinInt. |
| 1066 int32_t divisor = Abs(right->GetInteger32Constant()); | 1064 int32_t divisor = Abs(right->GetInteger32Constant()); |
| 1067 | 1065 |
| 1068 __ mov(scratch, left_reg); | |
| 1069 | |
| 1070 Label left_is_not_negative, done; | 1066 Label left_is_not_negative, done; |
| 1071 if (left->CanBeNegative()) { | 1067 if (left->CanBeNegative()) { |
| 1072 __ Branch(USE_DELAY_SLOT, &left_is_not_negative, | 1068 __ Branch(left_reg.is(result_reg) ? PROTECT : USE_DELAY_SLOT, |
| 1073 ge, left_reg, Operand(zero_reg)); | 1069 &left_is_not_negative, ge, left_reg, Operand(zero_reg)); |
| 1074 __ subu(result_reg, zero_reg, left_reg); | 1070 __ subu(result_reg, zero_reg, left_reg); |
| 1075 __ And(result_reg, result_reg, divisor - 1); | 1071 __ And(result_reg, result_reg, divisor - 1); |
| 1076 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1072 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1077 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); | 1073 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); |
| 1078 } | 1074 } |
| 1079 __ Branch(USE_DELAY_SLOT, &done); | 1075 __ Branch(USE_DELAY_SLOT, &done); |
| 1080 __ subu(result_reg, zero_reg, result_reg); | 1076 __ subu(result_reg, zero_reg, result_reg); |
| 1081 } | 1077 } |
| 1082 | 1078 |
| 1083 __ bind(&left_is_not_negative); | 1079 __ bind(&left_is_not_negative); |
| 1084 __ And(result_reg, scratch, divisor - 1); | 1080 __ And(result_reg, left_reg, divisor - 1); |
| 1085 __ bind(&done); | 1081 __ bind(&done); |
| 1086 | 1082 |
| 1087 } else if (hmod->fixed_right_arg().has_value) { | 1083 } else if (hmod->fixed_right_arg().has_value) { |
| 1088 const Register scratch = scratch0(); | |
| 1089 const Register left_reg = ToRegister(instr->left()); | 1084 const Register left_reg = ToRegister(instr->left()); |
| 1090 const Register result_reg = ToRegister(instr->result()); | 1085 const Register result_reg = ToRegister(instr->result()); |
| 1091 | 1086 const Register right_reg = ToRegister(instr->right()); |
| 1092 Register right_reg = EmitLoadRegister(instr->right(), scratch); | |
| 1093 | 1087 |
| 1094 int32_t divisor = hmod->fixed_right_arg().value; | 1088 int32_t divisor = hmod->fixed_right_arg().value; |
| 1095 ASSERT(IsPowerOf2(divisor)); | 1089 ASSERT(IsPowerOf2(divisor)); |
| 1096 | 1090 |
| 1097 // Check if our assumption of a fixed right operand still holds. | 1091 // Check if our assumption of a fixed right operand still holds. |
| 1098 DeoptimizeIf(ne, instr->environment(), right_reg, Operand(divisor)); | 1092 DeoptimizeIf(ne, instr->environment(), right_reg, Operand(divisor)); |
| 1099 | 1093 |
| 1100 Label left_is_not_negative, done; | 1094 Label left_is_not_negative, done; |
| 1101 if (left->CanBeNegative()) { | 1095 if (left->CanBeNegative()) { |
| 1102 __ Branch(USE_DELAY_SLOT, &left_is_not_negative, | 1096 __ Branch(left_reg.is(result_reg) ? PROTECT : USE_DELAY_SLOT, |
| 1103 ge, left_reg, Operand(zero_reg)); | 1097 &left_is_not_negative, ge, left_reg, Operand(zero_reg)); |
| 1104 __ subu(result_reg, zero_reg, left_reg); | 1098 __ subu(result_reg, zero_reg, left_reg); |
| 1105 __ And(result_reg, result_reg, divisor - 1); | 1099 __ And(result_reg, result_reg, divisor - 1); |
| 1106 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1100 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1107 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); | 1101 DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); |
| 1108 } | 1102 } |
| 1109 __ Branch(USE_DELAY_SLOT, &done); | 1103 __ Branch(USE_DELAY_SLOT, &done); |
| 1110 __ subu(result_reg, zero_reg, result_reg); | 1104 __ subu(result_reg, zero_reg, result_reg); |
| 1111 } | 1105 } |
| 1112 | 1106 |
| 1113 __ bind(&left_is_not_negative); | 1107 __ bind(&left_is_not_negative); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 | 1147 |
| 1154 | 1148 |
| 1155 void LCodeGen::EmitSignedIntegerDivisionByConstant( | 1149 void LCodeGen::EmitSignedIntegerDivisionByConstant( |
| 1156 Register result, | 1150 Register result, |
| 1157 Register dividend, | 1151 Register dividend, |
| 1158 int32_t divisor, | 1152 int32_t divisor, |
| 1159 Register remainder, | 1153 Register remainder, |
| 1160 Register scratch, | 1154 Register scratch, |
| 1161 LEnvironment* environment) { | 1155 LEnvironment* environment) { |
| 1162 ASSERT(!AreAliased(dividend, scratch, at, no_reg)); | 1156 ASSERT(!AreAliased(dividend, scratch, at, no_reg)); |
| 1163 ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); | |
| 1164 | 1157 |
| 1165 uint32_t divisor_abs = abs(divisor); | 1158 uint32_t divisor_abs = abs(divisor); |
| 1166 | 1159 |
| 1167 int32_t power_of_2_factor = | 1160 int32_t power_of_2_factor = |
| 1168 CompilerIntrinsics::CountTrailingZeros(divisor_abs); | 1161 CompilerIntrinsics::CountTrailingZeros(divisor_abs); |
| 1169 | 1162 |
| 1170 switch (divisor_abs) { | 1163 switch (divisor_abs) { |
| 1171 case 0: | 1164 case 0: |
| 1172 DeoptimizeIf(al, environment); | 1165 DeoptimizeIf(al, environment); |
| 1173 return; | 1166 return; |
| (...skipping 4668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5842 __ Subu(scratch, result, scratch); | 5835 __ Subu(scratch, result, scratch); |
| 5843 __ lw(result, FieldMemOperand(scratch, | 5836 __ lw(result, FieldMemOperand(scratch, |
| 5844 FixedArray::kHeaderSize - kPointerSize)); | 5837 FixedArray::kHeaderSize - kPointerSize)); |
| 5845 __ bind(&done); | 5838 __ bind(&done); |
| 5846 } | 5839 } |
| 5847 | 5840 |
| 5848 | 5841 |
| 5849 #undef __ | 5842 #undef __ |
| 5850 | 5843 |
| 5851 } } // namespace v8::internal | 5844 } } // namespace v8::internal |
| OLD | NEW |