Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: src/utils.h

Issue 606063: Make class BitField able to use 32 bits of a uint32.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/register-allocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 template<class T, int shift, int size> 150 template<class T, int shift, int size>
151 class BitField { 151 class BitField {
152 public: 152 public:
153 // Tells whether the provided value fits into the bit field. 153 // Tells whether the provided value fits into the bit field.
154 static bool is_valid(T value) { 154 static bool is_valid(T value) {
155 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0; 155 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0;
156 } 156 }
157 157
158 // Returns a uint32_t mask of bit field. 158 // Returns a uint32_t mask of bit field.
159 static uint32_t mask() { 159 static uint32_t mask() {
160 return (1U << (size + shift)) - (1U << shift); 160 // To use all bits of a uint32 in a bitfield without compiler warnings we
161 // have to compute 2^32 without using a shift count of 32.
162 return ((1U << shift) << size) - (1U << shift);
161 } 163 }
162 164
163 // Returns a uint32_t with the bit field value encoded. 165 // Returns a uint32_t with the bit field value encoded.
164 static uint32_t encode(T value) { 166 static uint32_t encode(T value) {
165 ASSERT(is_valid(value)); 167 ASSERT(is_valid(value));
166 return static_cast<uint32_t>(value) << shift; 168 return static_cast<uint32_t>(value) << shift;
167 } 169 }
168 170
169 // Extracts the bit field from the value. 171 // Extracts the bit field from the value.
170 static T decode(uint32_t value) { 172 static T decode(uint32_t value) {
171 return static_cast<T>((value >> shift) & ((1U << (size)) - 1)); 173 return static_cast<T>((value & mask()) >> shift);
172 } 174 }
173 }; 175 };
174 176
175 177
176 // ---------------------------------------------------------------------------- 178 // ----------------------------------------------------------------------------
177 // Support for compressed, machine-independent encoding 179 // Support for compressed, machine-independent encoding
178 // and decoding of integer values of arbitrary size. 180 // and decoding of integer values of arbitrary size.
179 181
180 // Encoding and decoding from/to a buffer at position p; 182 // Encoding and decoding from/to a buffer at position p;
181 // the result is the position after the encoded integer. 183 // the result is the position after the encoded integer.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 585 }
584 } 586 }
585 587
586 588
587 // Calculate 10^exponent. 589 // Calculate 10^exponent.
588 int TenToThe(int exponent); 590 int TenToThe(int exponent);
589 591
590 } } // namespace v8::internal 592 } } // namespace v8::internal
591 593
592 #endif // V8_UTILS_H_ 594 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/register-allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698