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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_UTILS_H_ | 28 #ifndef V8_UTILS_H_ |
29 #define V8_UTILS_H_ | 29 #define V8_UTILS_H_ |
30 | 30 |
| 31 #include <stdlib.h> |
| 32 |
31 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
32 | 34 |
33 // ---------------------------------------------------------------------------- | 35 // ---------------------------------------------------------------------------- |
34 // General helper functions | 36 // General helper functions |
35 | 37 |
36 // Returns true iff x is a power of 2. Does not work for zero. | 38 // Returns true iff x is a power of 2. Does not work for zero. |
37 template <typename T> | 39 template <typename T> |
38 static inline bool IsPowerOf2(T x) { | 40 static inline bool IsPowerOf2(T x) { |
39 return (x & (x - 1)) == 0; | 41 return (x & (x - 1)) == 0; |
40 } | 42 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 src += kStepSize; | 503 src += kStepSize; |
502 } | 504 } |
503 } | 505 } |
504 #endif | 506 #endif |
505 while (dest < limit) { | 507 while (dest < limit) { |
506 *dest++ = static_cast<sinkchar>(*src++); | 508 *dest++ = static_cast<sinkchar>(*src++); |
507 } | 509 } |
508 } | 510 } |
509 | 511 |
510 | 512 |
511 static inline int Load16(const byte* pc) { | 513 static inline int Load16(const byte* ptr) { |
512 #ifdef CAN_READ_UNALIGNED | 514 #ifdef CAN_READ_UNALIGNED |
513 return *reinterpret_cast<const uint16_t*>(pc); | 515 return *reinterpret_cast<const uint16_t*>(ptr); |
514 #else | 516 #else |
515 uint32_t word; | 517 uint32_t word; |
516 word = pc[1]; | 518 word = ptr[1]; |
517 word |= pc[0] << 8; | 519 word |= ptr[0] << 8; |
518 return word; | 520 return word; |
519 #endif | 521 #endif |
520 } | 522 } |
521 | 523 |
522 | 524 |
523 static inline int Load32(const byte* pc) { | 525 static inline int Load32(const byte* ptr) { |
524 #ifdef CAN_READ_UNALIGNED | 526 #ifdef CAN_READ_UNALIGNED |
525 return *reinterpret_cast<const uint32_t*>(pc); | 527 return *reinterpret_cast<const uint32_t*>(ptr); |
526 #else | 528 #else |
527 uint32_t word; | 529 uint32_t word; |
528 word = pc[3]; | 530 word = ptr[3]; |
529 word |= pc[2] << 8; | 531 word |= ptr[2] << 8; |
530 word |= pc[1] << 16; | 532 word |= ptr[1] << 16; |
531 word |= pc[0] << 24; | 533 word |= ptr[0] << 24; |
532 return word; | 534 return word; |
533 #endif | 535 #endif |
534 } | 536 } |
535 | 537 |
536 | 538 |
537 static inline void Store16(byte* pc, uint16_t value) { | 539 static inline void Store16(byte* ptr, uint16_t value) { |
538 #ifdef CAN_READ_UNALIGNED | 540 #ifdef CAN_READ_UNALIGNED |
539 *reinterpret_cast<uint16_t*>(pc) = value; | 541 *reinterpret_cast<uint16_t*>(ptr) = value; |
540 #else | 542 #else |
541 pc[1] = value; | 543 ptr[1] = value; |
542 pc[0] = value >> 8; | 544 ptr[0] = value >> 8; |
543 #endif | 545 #endif |
544 } | 546 } |
545 | 547 |
546 | 548 |
547 static inline void Store32(byte* pc, uint32_t value) { | 549 static inline void Store32(byte* ptr, uint32_t value) { |
548 #ifdef CAN_READ_UNALIGNED | 550 #ifdef CAN_READ_UNALIGNED |
549 *reinterpret_cast<uint32_t*>(pc) = value; | 551 *reinterpret_cast<uint32_t*>(ptr) = value; |
550 #else | 552 #else |
551 pc[3] = value; | 553 ptr[3] = value; |
552 pc[2] = value >> 8; | 554 ptr[2] = value >> 8; |
553 pc[1] = value >> 16; | 555 ptr[1] = value >> 16; |
554 pc[0] = value >> 24; | 556 ptr[0] = value >> 24; |
555 #endif | 557 #endif |
556 } | 558 } |
557 | 559 |
558 | 560 |
559 | |
560 | |
561 | |
562 } } // namespace v8::internal | 561 } } // namespace v8::internal |
563 | 562 |
564 #endif // V8_UTILS_H_ | 563 #endif // V8_UTILS_H_ |
OLD | NEW |