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 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1884 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1885 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1885 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1886 | 1886 |
1887 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); | 1887 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); |
1888 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); | 1888 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); |
1889 bool needs_environment = can_overflow || bailout_on_minus_zero; | 1889 bool needs_environment = can_overflow || bailout_on_minus_zero; |
1890 | 1890 |
1891 HValue* least_const = instr->BetterLeftOperand(); | 1891 HValue* least_const = instr->BetterLeftOperand(); |
1892 HValue* most_const = instr->BetterRightOperand(); | 1892 HValue* most_const = instr->BetterRightOperand(); |
1893 | 1893 |
1894 LOperand* left = UseRegisterAtStart(least_const); | 1894 LOperand* left; |
1895 | 1895 |
1896 // LMulConstI can handle a subset of constants: | 1896 // LMulConstI can handle a subset of constants: |
1897 // With support for overflow detection: | 1897 // With support for overflow detection: |
1898 // -1, 0, 1, 2 | 1898 // -1, 0, 1, 2 |
| 1899 // 2^n, -(2^n) |
1899 // Without support for overflow detection: | 1900 // Without support for overflow detection: |
1900 // 2^n, -(2^n) | |
1901 // 2^n + 1, -(2^n - 1) | 1901 // 2^n + 1, -(2^n - 1) |
1902 if (most_const->IsConstant()) { | 1902 if (most_const->IsConstant()) { |
1903 int32_t constant = HConstant::cast(most_const)->Integer32Value(); | 1903 int32_t constant = HConstant::cast(most_const)->Integer32Value(); |
1904 int32_t constant_abs = (constant >= 0) ? constant : -constant; | 1904 bool small_constant = (constant >= -1) && (constant <= 2); |
| 1905 bool end_range_constant = (constant <= -kMaxInt) || (constant == kMaxInt); |
| 1906 int32_t constant_abs = Abs(constant); |
1905 | 1907 |
1906 if (((constant >= -1) && (constant <= 2)) || | 1908 if (!end_range_constant && |
1907 (!can_overflow && (IsPowerOf2(constant_abs) || | 1909 (small_constant || |
1908 IsPowerOf2(constant_abs + 1) || | 1910 (IsPowerOf2(constant_abs)) || |
1909 IsPowerOf2(constant_abs - 1)))) { | 1911 (!can_overflow && (IsPowerOf2(constant_abs + 1) || |
| 1912 IsPowerOf2(constant_abs - 1))))) { |
1910 LConstantOperand* right = UseConstant(most_const); | 1913 LConstantOperand* right = UseConstant(most_const); |
| 1914 bool need_register = IsPowerOf2(constant_abs) && !small_constant; |
| 1915 left = need_register ? UseRegister(least_const) |
| 1916 : UseRegisterAtStart(least_const); |
1911 LMulConstIS* mul = new(zone()) LMulConstIS(left, right); | 1917 LMulConstIS* mul = new(zone()) LMulConstIS(left, right); |
1912 if (needs_environment) AssignEnvironment(mul); | 1918 if (needs_environment) AssignEnvironment(mul); |
1913 return DefineAsRegister(mul); | 1919 return DefineAsRegister(mul); |
1914 } | 1920 } |
1915 } | 1921 } |
1916 | 1922 |
| 1923 left = UseRegisterAtStart(least_const); |
1917 // LMulI/S can handle all cases, but it requires that a register is | 1924 // LMulI/S can handle all cases, but it requires that a register is |
1918 // allocated for the second operand. | 1925 // allocated for the second operand. |
1919 LInstruction* result; | 1926 LInstruction* result; |
1920 if (instr->representation().IsSmi()) { | 1927 if (instr->representation().IsSmi()) { |
1921 LOperand* right = UseRegisterAtStart(most_const); | 1928 LOperand* right = UseRegisterAtStart(most_const); |
1922 result = DefineAsRegister(new(zone()) LMulS(left, right)); | 1929 result = DefineAsRegister(new(zone()) LMulS(left, right)); |
1923 } else { | 1930 } else { |
1924 LOperand* right = UseRegisterAtStart(most_const); | 1931 LOperand* right = UseRegisterAtStart(most_const); |
1925 result = DefineAsRegister(new(zone()) LMulI(left, right)); | 1932 result = DefineAsRegister(new(zone()) LMulI(left, right)); |
1926 } | 1933 } |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2561 | 2568 |
2562 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { | 2569 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { |
2563 LOperand* receiver = UseRegister(instr->receiver()); | 2570 LOperand* receiver = UseRegister(instr->receiver()); |
2564 LOperand* function = UseRegister(instr->function()); | 2571 LOperand* function = UseRegister(instr->function()); |
2565 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); | 2572 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); |
2566 return AssignEnvironment(DefineAsRegister(result)); | 2573 return AssignEnvironment(DefineAsRegister(result)); |
2567 } | 2574 } |
2568 | 2575 |
2569 | 2576 |
2570 } } // namespace v8::internal | 2577 } } // namespace v8::internal |
OLD | NEW |