| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Extracts the bit field from the value. | 169 // Extracts the bit field from the value. |
| 170 static T decode(uint32_t value) { | 170 static T decode(uint32_t value) { |
| 171 return static_cast<T>((value >> shift) & ((1U << (size)) - 1)); | 171 return static_cast<T>((value >> shift) & ((1U << (size)) - 1)); |
| 172 } | 172 } |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 | 175 |
| 176 // ---------------------------------------------------------------------------- | 176 // ---------------------------------------------------------------------------- |
| 177 // Support for compressed, machine-independent encoding | |
| 178 // and decoding of integer values of arbitrary size. | |
| 179 | |
| 180 // Encoding and decoding from/to a buffer at position p; | |
| 181 // the result is the position after the encoded integer. | |
| 182 // Small signed integers in the range -64 <= x && x < 64 | |
| 183 // are encoded in 1 byte; larger values are encoded in 2 | |
| 184 // or more bytes. At most sizeof(int) + 1 bytes are used | |
| 185 // in the worst case. | |
| 186 byte* EncodeInt(byte* p, int x); | |
| 187 byte* DecodeInt(byte* p, int* x); | |
| 188 | |
| 189 | |
| 190 // Encoding and decoding from/to a buffer at position p - 1 | |
| 191 // moving backward; the result is the position of the last | |
| 192 // byte written. These routines are useful to read/write | |
| 193 // into a buffer starting at the end of the buffer. | |
| 194 byte* EncodeUnsignedIntBackward(byte* p, unsigned int x); | |
| 195 | |
| 196 // The decoding function is inlined since its performance is | |
| 197 // important to mark-sweep garbage collection. | |
| 198 inline byte* DecodeUnsignedIntBackward(byte* p, unsigned int* x) { | |
| 199 byte b = *--p; | |
| 200 if (b >= 128) { | |
| 201 *x = static_cast<unsigned int>(b) - 128; | |
| 202 return p; | |
| 203 } | |
| 204 unsigned int r = static_cast<unsigned int>(b); | |
| 205 unsigned int s = 7; | |
| 206 b = *--p; | |
| 207 while (b < 128) { | |
| 208 r |= static_cast<unsigned int>(b) << s; | |
| 209 s += 7; | |
| 210 b = *--p; | |
| 211 } | |
| 212 // b >= 128 | |
| 213 *x = r | ((static_cast<unsigned int>(b) - 128) << s); | |
| 214 return p; | |
| 215 } | |
| 216 | |
| 217 | |
| 218 // ---------------------------------------------------------------------------- | |
| 219 // Hash function. | 177 // Hash function. |
| 220 | 178 |
| 221 uint32_t ComputeIntegerHash(uint32_t key); | 179 uint32_t ComputeIntegerHash(uint32_t key); |
| 222 | 180 |
| 223 | 181 |
| 224 // ---------------------------------------------------------------------------- | 182 // ---------------------------------------------------------------------------- |
| 225 // I/O support. | 183 // I/O support. |
| 226 | 184 |
| 227 // Our version of printf(). Avoids compilation errors that we get | 185 // Our version of printf(). Avoids compilation errors that we get |
| 228 // with standard printf when attempting to print pointers, etc. | 186 // with standard printf when attempting to print pointers, etc. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 541 } |
| 584 } | 542 } |
| 585 | 543 |
| 586 | 544 |
| 587 // Calculate 10^exponent. | 545 // Calculate 10^exponent. |
| 588 int TenToThe(int exponent); | 546 int TenToThe(int exponent); |
| 589 | 547 |
| 590 } } // namespace v8::internal | 548 } } // namespace v8::internal |
| 591 | 549 |
| 592 #endif // V8_UTILS_H_ | 550 #endif // V8_UTILS_H_ |
| OLD | NEW |