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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 case 4: bits++; // Fall through. | 78 case 4: bits++; // Fall through. |
79 case 2: bits++; // Fall through. | 79 case 2: bits++; // Fall through. |
80 case 1: break; | 80 case 1: break; |
81 } | 81 } |
82 ASSERT_EQ(1 << bits, original_x); | 82 ASSERT_EQ(1 << bits, original_x); |
83 return bits; | 83 return bits; |
84 return 0; | 84 return 0; |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 // Magic numbers for integer division. | |
89 // These are kind of 2's complement reciprocal of the divisors. | |
90 // Details and proofs can be found in: | |
91 // - Hacker's Delight, Henry S. Warren, Jr. | |
92 // - The PowerPC Compiler Writer’s Guide | |
93 // and probably many others. | |
94 // See details in the implementation of the algorithm in | |
95 // lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant(). | |
96 struct DivMagicNumbers { | |
97 unsigned M; | |
98 unsigned s; | |
99 }; | |
100 | |
101 const DivMagicNumbers InvalidDivMagicNumber= {0, 0}; | |
102 const DivMagicNumbers DivMagicNumberFor3 = {0x55555556, 0}; | |
103 const DivMagicNumbers DivMagicNumberFor5 = {0x66666667, 1}; | |
104 const DivMagicNumbers DivMagicNumberFor7 = {0x92492493, 2}; | |
105 const DivMagicNumbers DivMagicNumberFor9 = {0x38e38e39, 1}; | |
106 const DivMagicNumbers DivMagicNumberFor11 = {0x2e8ba2e9, 1}; | |
107 const DivMagicNumbers DivMagicNumberFor25 = {0x51eb851f, 3}; | |
108 const DivMagicNumbers DivMagicNumberFor125 = {0x10624dd3, 3}; | |
109 const DivMagicNumbers DivMagicNumberFor625 = {0x68db8bad, 8}; | |
110 | |
111 const DivMagicNumbers DivMagicNumberFor(int32_t divisor); | |
112 | |
113 | |
114 // The C++ standard leaves the semantics of '>>' undefined for | 88 // The C++ standard leaves the semantics of '>>' undefined for |
115 // negative signed operands. Most implementations do the right thing, | 89 // negative signed operands. Most implementations do the right thing, |
116 // though. | 90 // though. |
117 inline int ArithmeticShiftRight(int x, int s) { | 91 inline int ArithmeticShiftRight(int x, int s) { |
118 return x >> s; | 92 return x >> s; |
119 } | 93 } |
120 | 94 |
121 | 95 |
122 // Compute the 0-relative offset of some absolute value x of type T. | 96 // Compute the 0-relative offset of some absolute value x of type T. |
123 // This allows conversion of Addresses and integral types into | 97 // This allows conversion of Addresses and integral types into |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 950 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
977 return 1 << element; | 951 return 1 << element; |
978 } | 952 } |
979 | 953 |
980 T bits_; | 954 T bits_; |
981 }; | 955 }; |
982 | 956 |
983 } } // namespace v8::internal | 957 } } // namespace v8::internal |
984 | 958 |
985 #endif // V8_UTILS_H_ | 959 #endif // V8_UTILS_H_ |
OLD | NEW |