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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 case 4: bits++; // Fall through. | 79 case 4: bits++; // Fall through. |
80 case 2: bits++; // Fall through. | 80 case 2: bits++; // Fall through. |
81 case 1: break; | 81 case 1: break; |
82 } | 82 } |
83 ASSERT_EQ(1 << bits, original_x); | 83 ASSERT_EQ(1 << bits, original_x); |
84 return bits; | 84 return bits; |
85 return 0; | 85 return 0; |
86 } | 86 } |
87 | 87 |
88 | 88 |
| 89 inline int MostSignificantBit(uint32_t x) { |
| 90 static const int msb4[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; |
| 91 int nibble = 0; |
| 92 if (x & 0xffff0000) { |
| 93 nibble += 16; |
| 94 x >>= 16; |
| 95 } |
| 96 if (x & 0xff00) { |
| 97 nibble += 8; |
| 98 x >>= 8; |
| 99 } |
| 100 if (x & 0xf0) { |
| 101 nibble += 4; |
| 102 x >>= 4; |
| 103 } |
| 104 return nibble + msb4[x]; |
| 105 } |
| 106 |
| 107 |
89 // Magic numbers for integer division. | 108 // Magic numbers for integer division. |
90 // These are kind of 2's complement reciprocal of the divisors. | 109 // These are kind of 2's complement reciprocal of the divisors. |
91 // Details and proofs can be found in: | 110 // Details and proofs can be found in: |
92 // - Hacker's Delight, Henry S. Warren, Jr. | 111 // - Hacker's Delight, Henry S. Warren, Jr. |
93 // - The PowerPC Compiler Writer’s Guide | 112 // - The PowerPC Compiler Writer’s Guide |
94 // and probably many others. | 113 // and probably many others. |
95 // See details in the implementation of the algorithm in | 114 // See details in the implementation of the algorithm in |
96 // lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant(). | 115 // lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant(). |
97 struct DivMagicNumbers { | 116 struct DivMagicNumbers { |
98 unsigned M; | 117 unsigned M; |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 | 1128 |
1110 // Every compiled stub starts with this id. | 1129 // Every compiled stub starts with this id. |
1111 static const int kStubEntryId = 5; | 1130 static const int kStubEntryId = 5; |
1112 | 1131 |
1113 int id_; | 1132 int id_; |
1114 }; | 1133 }; |
1115 | 1134 |
1116 } } // namespace v8::internal | 1135 } } // namespace v8::internal |
1117 | 1136 |
1118 #endif // V8_UTILS_H_ | 1137 #endif // V8_UTILS_H_ |
OLD | NEW |