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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 #include <string.h> | 32 #include <string.h> |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
38 // General helper functions | 38 // General helper functions |
39 | 39 |
| 40 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) |
| 41 |
40 // Returns true iff x is a power of 2 (or zero). Cannot be used with the | 42 // Returns true iff x is a power of 2 (or zero). Cannot be used with the |
41 // maximally negative value of the type T (the -1 overflows). | 43 // maximally negative value of the type T (the -1 overflows). |
42 template <typename T> | 44 template <typename T> |
43 static inline bool IsPowerOf2(T x) { | 45 static inline bool IsPowerOf2(T x) { |
44 return (x & (x - 1)) == 0; | 46 return IS_POWER_OF_TWO(x); |
45 } | 47 } |
46 | 48 |
47 | 49 |
48 // The C++ standard leaves the semantics of '>>' undefined for | 50 // The C++ standard leaves the semantics of '>>' undefined for |
49 // negative signed operands. Most implementations do the right thing, | 51 // negative signed operands. Most implementations do the right thing, |
50 // though. | 52 // though. |
51 static inline int ArithmeticShiftRight(int x, int s) { | 53 static inline int ArithmeticShiftRight(int x, int s) { |
52 return x >> s; | 54 return x >> s; |
53 } | 55 } |
54 | 56 |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 | 701 |
700 Dest dest; | 702 Dest dest; |
701 memcpy(&dest, &source, sizeof(dest)); | 703 memcpy(&dest, &source, sizeof(dest)); |
702 return dest; | 704 return dest; |
703 } | 705 } |
704 | 706 |
705 } } // namespace v8::internal | 707 } } // namespace v8::internal |
706 | 708 |
707 | 709 |
708 #endif // V8_UTILS_H_ | 710 #endif // V8_UTILS_H_ |
OLD | NEW |