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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 __ jmp(&done, Label::kNear); | 879 __ jmp(&done, Label::kNear); |
880 | 880 |
881 __ bind(&remainder_eq_dividend); | 881 __ bind(&remainder_eq_dividend); |
882 __ movl(result_reg, left_reg); | 882 __ movl(result_reg, left_reg); |
883 | 883 |
884 __ bind(&done); | 884 __ bind(&done); |
885 } | 885 } |
886 } | 886 } |
887 | 887 |
888 | 888 |
| 889 void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
| 890 ASSERT(instr->InputAt(1)->IsConstantOperand()); |
| 891 |
| 892 const Register dividend = ToRegister(instr->InputAt(0)); |
| 893 int32_t divisor = ToInteger32(LConstantOperand::cast(instr->InputAt(1))); |
| 894 const Register result = ToRegister(instr->result()); |
| 895 |
| 896 switch (divisor) { |
| 897 case 0: |
| 898 DeoptimizeIf(no_condition, instr->environment()); |
| 899 return; |
| 900 |
| 901 case 1: |
| 902 if (!result.is(dividend)) { |
| 903 __ movl(result, dividend); |
| 904 } |
| 905 return; |
| 906 |
| 907 case -1: |
| 908 if (!result.is(dividend)) { |
| 909 __ movl(result, dividend); |
| 910 } |
| 911 __ negl(result); |
| 912 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 913 DeoptimizeIf(zero, instr->environment()); |
| 914 } |
| 915 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 916 DeoptimizeIf(overflow, instr->environment()); |
| 917 } |
| 918 return; |
| 919 } |
| 920 |
| 921 uint32_t divisor_abs = abs(divisor); |
| 922 if (IsPowerOf2(divisor_abs)) { |
| 923 int32_t power = WhichPowerOf2(divisor_abs); |
| 924 if (divisor < 0) { |
| 925 __ movsxlq(result, dividend); |
| 926 __ neg(result); |
| 927 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 928 DeoptimizeIf(zero, instr->environment()); |
| 929 } |
| 930 __ sar(result, Immediate(power)); |
| 931 } else { |
| 932 if (!result.is(dividend)) { |
| 933 __ movl(result, dividend); |
| 934 } |
| 935 __ sarl(result, Immediate(power)); |
| 936 } |
| 937 } else { |
| 938 Register reg1 = ToRegister(instr->TempAt(0)); |
| 939 Register reg2 = ToRegister(instr->result()); |
| 940 |
| 941 // Find b which: 2^b < divisor_abs < 2^(b+1). |
| 942 unsigned b = 31 - CompilerIntrinsics::CountLeadingZeros(divisor_abs); |
| 943 unsigned shift = 32 + b; // Precision +1bit (effectively). |
| 944 double multiplier_f = |
| 945 static_cast<double>(static_cast<uint64_t>(1) << shift) / divisor_abs; |
| 946 int64_t multiplier; |
| 947 if (multiplier_f - floor(multiplier_f) < 0.5) { |
| 948 multiplier = floor(multiplier_f); |
| 949 } else { |
| 950 multiplier = floor(multiplier_f) + 1; |
| 951 } |
| 952 // The multiplier is a uint32. |
| 953 ASSERT(multiplier > 0 && |
| 954 multiplier < (static_cast<int64_t>(1) << 32)); |
| 955 // The multiply is int64, so sign-extend to r64. |
| 956 __ movsxlq(reg1, dividend); |
| 957 if (divisor < 0 && |
| 958 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 959 __ neg(reg1); |
| 960 DeoptimizeIf(zero, instr->environment()); |
| 961 } |
| 962 __ movq(reg2, multiplier, RelocInfo::NONE); |
| 963 // Result just fit in r64, because it's int32 * uint32. |
| 964 __ imul(reg2, reg1); |
| 965 |
| 966 __ addq(reg2, Immediate(1 << 30)); |
| 967 __ sar(reg2, Immediate(shift)); |
| 968 } |
| 969 } |
| 970 |
| 971 |
889 void LCodeGen::DoDivI(LDivI* instr) { | 972 void LCodeGen::DoDivI(LDivI* instr) { |
890 LOperand* right = instr->InputAt(1); | 973 LOperand* right = instr->InputAt(1); |
891 ASSERT(ToRegister(instr->result()).is(rax)); | 974 ASSERT(ToRegister(instr->result()).is(rax)); |
892 ASSERT(ToRegister(instr->InputAt(0)).is(rax)); | 975 ASSERT(ToRegister(instr->InputAt(0)).is(rax)); |
893 ASSERT(!ToRegister(instr->InputAt(1)).is(rax)); | 976 ASSERT(!ToRegister(instr->InputAt(1)).is(rax)); |
894 ASSERT(!ToRegister(instr->InputAt(1)).is(rdx)); | 977 ASSERT(!ToRegister(instr->InputAt(1)).is(rdx)); |
895 | 978 |
896 Register left_reg = rax; | 979 Register left_reg = rax; |
897 | 980 |
898 // Check for x / 0. | 981 // Check for x / 0. |
(...skipping 4049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4948 FixedArray::kHeaderSize - kPointerSize)); | 5031 FixedArray::kHeaderSize - kPointerSize)); |
4949 __ bind(&done); | 5032 __ bind(&done); |
4950 } | 5033 } |
4951 | 5034 |
4952 | 5035 |
4953 #undef __ | 5036 #undef __ |
4954 | 5037 |
4955 } } // namespace v8::internal | 5038 } } // namespace v8::internal |
4956 | 5039 |
4957 #endif // V8_TARGET_ARCH_X64 | 5040 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |