OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 | 997 |
998 // Theoretically, a variation of the branch-free code for integer division by | 998 // Theoretically, a variation of the branch-free code for integer division by |
999 // a power of 2 (calculating the remainder via an additional multiplication | 999 // a power of 2 (calculating the remainder via an additional multiplication |
1000 // (which gets simplified to an 'and') and subtraction) should be faster, and | 1000 // (which gets simplified to an 'and') and subtraction) should be faster, and |
1001 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to | 1001 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
1002 // indicate that positive dividends are heavily favored, so the branching | 1002 // indicate that positive dividends are heavily favored, so the branching |
1003 // version performs better. | 1003 // version performs better. |
1004 HMod* hmod = instr->hydrogen(); | 1004 HMod* hmod = instr->hydrogen(); |
1005 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1005 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
1006 Label dividend_is_not_negative, done; | 1006 Label dividend_is_not_negative, done; |
1007 if (hmod->left()->CanBeNegative()) { | 1007 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
1008 __ testl(dividend, dividend); | 1008 __ testl(dividend, dividend); |
1009 __ j(not_sign, ÷nd_is_not_negative, Label::kNear); | 1009 __ j(not_sign, ÷nd_is_not_negative, Label::kNear); |
1010 // Note that this is correct even for kMinInt operands. | 1010 // Note that this is correct even for kMinInt operands. |
1011 __ negl(dividend); | 1011 __ negl(dividend); |
1012 __ andl(dividend, Immediate(mask)); | 1012 __ andl(dividend, Immediate(mask)); |
1013 __ negl(dividend); | 1013 __ negl(dividend); |
1014 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1014 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1015 DeoptimizeIf(zero, instr->environment()); | 1015 DeoptimizeIf(zero, instr->environment()); |
1016 } | 1016 } |
1017 __ jmp(&done, Label::kNear); | 1017 __ jmp(&done, Label::kNear); |
(...skipping 4621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5639 FixedArray::kHeaderSize - kPointerSize)); | 5639 FixedArray::kHeaderSize - kPointerSize)); |
5640 __ bind(&done); | 5640 __ bind(&done); |
5641 } | 5641 } |
5642 | 5642 |
5643 | 5643 |
5644 #undef __ | 5644 #undef __ |
5645 | 5645 |
5646 } } // namespace v8::internal | 5646 } } // namespace v8::internal |
5647 | 5647 |
5648 #endif // V8_TARGET_ARCH_X64 | 5648 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |