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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // A uint32_t mask of bit field. To use all bits of a uint32 in a | 206 // A uint32_t mask of bit field. To use all bits of a uint32 in a |
207 // bitfield without compiler warnings we have to compute 2^32 without | 207 // bitfield without compiler warnings we have to compute 2^32 without |
208 // using a shift count of 32. | 208 // using a shift count of 32. |
209 static const uint32_t kMask = ((1U << shift) << size) - (1U << shift); | 209 static const uint32_t kMask = ((1U << shift) << size) - (1U << shift); |
210 | 210 |
211 // Value for the field with all bits set. | 211 // Value for the field with all bits set. |
212 static const T kMax = static_cast<T>((1U << size) - 1); | 212 static const T kMax = static_cast<T>((1U << size) - 1); |
213 | 213 |
214 // Tells whether the provided value fits into the bit field. | 214 // Tells whether the provided value fits into the bit field. |
215 static bool is_valid(T value) { | 215 static bool is_valid(T value) { |
216 return (static_cast<uint32_t>(value) & ~kMax) == 0; | 216 return (static_cast<uint32_t>(value) & ~static_cast<uint32_t>(kMax)) == 0; |
217 } | 217 } |
218 | 218 |
219 // Returns a uint32_t with the bit field value encoded. | 219 // Returns a uint32_t with the bit field value encoded. |
220 static uint32_t encode(T value) { | 220 static uint32_t encode(T value) { |
221 ASSERT(is_valid(value)); | 221 ASSERT(is_valid(value)); |
222 return static_cast<uint32_t>(value) << shift; | 222 return static_cast<uint32_t>(value) << shift; |
223 } | 223 } |
224 | 224 |
225 // Returns a uint32_t with the bit field value updated. | 225 // Returns a uint32_t with the bit field value updated. |
226 static uint32_t update(uint32_t previous, T value) { | 226 static uint32_t update(uint32_t previous, T value) { |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 911 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
912 return 1 << element; | 912 return 1 << element; |
913 } | 913 } |
914 | 914 |
915 T bits_; | 915 T bits_; |
916 }; | 916 }; |
917 | 917 |
918 } } // namespace v8::internal | 918 } } // namespace v8::internal |
919 | 919 |
920 #endif // V8_UTILS_H_ | 920 #endif // V8_UTILS_H_ |
OLD | NEW |