OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | 867 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
868 // Nothing to do. | 868 // Nothing to do. |
869 } | 869 } |
870 | 870 |
871 | 871 |
872 void LCodeGen::DoModI(LModI* instr) { | 872 void LCodeGen::DoModI(LModI* instr) { |
873 Register scratch = scratch0(); | 873 Register scratch = scratch0(); |
874 const Register left = ToRegister(instr->InputAt(0)); | 874 const Register left = ToRegister(instr->InputAt(0)); |
875 const Register result = ToRegister(instr->result()); | 875 const Register result = ToRegister(instr->result()); |
876 | 876 |
877 // p2constant holds the right side value if it's a power of 2 constant. | 877 Label done; |
878 // In other cases it is 0. | |
879 int32_t p2constant = 0; | |
880 | 878 |
881 if (instr->InputAt(1)->IsConstantOperand()) { | 879 if (instr->hydrogen()->HasPowerOf2Divisor()) { |
882 p2constant = ToInteger32(LConstantOperand::cast(instr->InputAt(1))); | 880 Register scratch = scratch0(); |
883 if (p2constant % 2 != 0) { | 881 ASSERT(!left.is(scratch)); |
884 p2constant = 0; | 882 __ mov(scratch, left); |
885 } | 883 int32_t p2constant = HConstant::cast( |
886 // Result always takes the sign of the dividend (left). | 884 instr->hydrogen()->right())->Integer32Value(); |
887 p2constant = abs(p2constant); | 885 ASSERT(p2constant != 0); |
| 886 // Result always takes the sign of the dividend (left). |
| 887 p2constant = abs(p2constant); |
| 888 |
| 889 Label positive_dividend; |
| 890 __ Branch(USE_DELAY_SLOT, &positive_dividend, ge, left, Operand(zero_reg)); |
| 891 __ subu(result, zero_reg, left); |
| 892 __ And(result, result, p2constant - 1); |
| 893 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 894 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
| 895 } |
| 896 __ Branch(USE_DELAY_SLOT, &done); |
| 897 __ subu(result, zero_reg, result); |
| 898 __ bind(&positive_dividend); |
| 899 __ And(result, scratch, p2constant - 1); |
| 900 } else { |
| 901 // div runs in the background while we check for special cases. |
| 902 Register right = EmitLoadRegister(instr->InputAt(1), scratch); |
| 903 __ div(left, right); |
| 904 |
| 905 // Check for x % 0. |
| 906 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 907 DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); |
| 908 } |
| 909 |
| 910 __ Branch(USE_DELAY_SLOT, &done, ge, left, Operand(zero_reg)); |
| 911 __ mfhi(result); |
| 912 |
| 913 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 914 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
| 915 } |
888 } | 916 } |
889 | 917 __ bind(&done); |
890 // div runs in the background while we check for special cases. | |
891 Register right = EmitLoadRegister(instr->InputAt(1), scratch); | |
892 __ div(left, right); | |
893 | |
894 // Check for x % 0. | |
895 if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { | |
896 DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); | |
897 } | |
898 | |
899 Label skip_div, do_div; | |
900 if (p2constant != 0) { | |
901 // Fall back to the result of the div instruction if we could have sign | |
902 // problems. | |
903 __ Branch(&do_div, lt, left, Operand(zero_reg)); | |
904 // Modulo by masking. | |
905 __ And(scratch, left, p2constant - 1); | |
906 __ Branch(&skip_div); | |
907 } | |
908 | |
909 __ bind(&do_div); | |
910 __ mfhi(scratch); | |
911 __ bind(&skip_div); | |
912 | |
913 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
914 // Result always takes the sign of the dividend (left). | |
915 Label done; | |
916 __ Branch(USE_DELAY_SLOT, &done, ge, left, Operand(zero_reg)); | |
917 __ mov(result, scratch); | |
918 DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); | |
919 __ bind(&done); | |
920 } else { | |
921 __ Move(result, scratch); | |
922 } | |
923 } | 918 } |
924 | 919 |
925 | 920 |
926 void LCodeGen::DoDivI(LDivI* instr) { | 921 void LCodeGen::DoDivI(LDivI* instr) { |
927 const Register left = ToRegister(instr->InputAt(0)); | 922 const Register left = ToRegister(instr->InputAt(0)); |
928 const Register right = ToRegister(instr->InputAt(1)); | 923 const Register right = ToRegister(instr->InputAt(1)); |
929 const Register result = ToRegister(instr->result()); | 924 const Register result = ToRegister(instr->result()); |
930 | 925 |
931 // On MIPS div is asynchronous - it will run in the background while we | 926 // On MIPS div is asynchronous - it will run in the background while we |
932 // check for special cases. | 927 // check for special cases. |
(...skipping 3689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4622 ASSERT(!environment->HasBeenRegistered()); | 4617 ASSERT(!environment->HasBeenRegistered()); |
4623 RegisterEnvironmentForDeoptimization(environment); | 4618 RegisterEnvironmentForDeoptimization(environment); |
4624 ASSERT(osr_pc_offset_ == -1); | 4619 ASSERT(osr_pc_offset_ == -1); |
4625 osr_pc_offset_ = masm()->pc_offset(); | 4620 osr_pc_offset_ = masm()->pc_offset(); |
4626 } | 4621 } |
4627 | 4622 |
4628 | 4623 |
4629 #undef __ | 4624 #undef __ |
4630 | 4625 |
4631 } } // namespace v8::internal | 4626 } } // namespace v8::internal |
OLD | NEW |