| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return static_cast<int>(length); | 197 return static_cast<int>(length); |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 // ---------------------------------------------------------------------------- | 201 // ---------------------------------------------------------------------------- |
| 202 // BitField is a help template for encoding and decode bitfield with | 202 // BitField is a help template for encoding and decode bitfield with |
| 203 // unsigned content. | 203 // unsigned content. |
| 204 template<class T, int shift, int size> | 204 template<class T, int shift, int size> |
| 205 class BitField { | 205 class BitField { |
| 206 public: | 206 public: |
| 207 typedef T ValueType; |
| 208 |
| 207 // Tells whether the provided value fits into the bit field. | 209 // Tells whether the provided value fits into the bit field. |
| 208 static bool is_valid(T value) { | 210 static bool is_valid(T value) { |
| 209 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0; | 211 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0; |
| 210 } | 212 } |
| 211 | 213 |
| 212 // Returns a uint32_t mask of bit field. | 214 // Returns a uint32_t mask of bit field. |
| 213 static uint32_t mask() { | 215 static uint32_t mask() { |
| 214 // To use all bits of a uint32 in a bitfield without compiler warnings we | 216 // To use all bits of a uint32 in a bitfield without compiler warnings we |
| 215 // have to compute 2^32 without using a shift count of 32. | 217 // have to compute 2^32 without using a shift count of 32. |
| 216 return ((1U << shift) << size) - (1U << shift); | 218 return ((1U << shift) << size) - (1U << shift); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 INLINE(Dest BitCast(const Source& source)); | 793 INLINE(Dest BitCast(const Source& source)); |
| 792 | 794 |
| 793 template <class Dest, class Source> | 795 template <class Dest, class Source> |
| 794 inline Dest BitCast(const Source& source) { | 796 inline Dest BitCast(const Source& source) { |
| 795 return BitCastHelper<Dest, Source>::cast(source); | 797 return BitCastHelper<Dest, Source>::cast(source); |
| 796 } | 798 } |
| 797 | 799 |
| 798 } } // namespace v8::internal | 800 } } // namespace v8::internal |
| 799 | 801 |
| 800 #endif // V8_UTILS_H_ | 802 #endif // V8_UTILS_H_ |
| OLD | NEW |