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