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

Issue 606063: Make class BitField able to use 32 bits of a uint32.... (Closed)

Created:
10 years, 10 months ago by fschneider
Modified:
9 years, 6 months ago
CC:
v8-dev
Visibility:
Public.

Description

Make class BitField able to use 32 bits of a uint32. Although algorithmically correct, the compiler would not allow to instantiate a BitField that uses all 32 bits without warnings about a too large shift count. As a consequence we were limited to 31 bit values when using BitField. This happened when instantiating a bitfield BitField<T, shift, size> with [shift=0, size=32] or [shift=31, size=1] or more general any [shift=X, size=32-X] As side-effect of the new implementation the compiler now warns if we ever try instantiating a bitfield with size 0. Committed: http://code.google.com/p/v8/source/detail?r=3910

Patch Set 1 #

Patch Set 2 : '' #

Total comments: 14

Patch Set 3 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+10 lines, -8 lines) Patch
M src/codegen.h View 1 2 1 chunk +3 lines, -3 lines 0 comments Download
M src/frame-element.h View 1 chunk +1 line, -1 line 0 comments Download
M src/objects.h View 1 chunk +1 line, -1 line 0 comments Download
M src/register-allocator.h View 1 chunk +1 line, -1 line 0 comments Download
M src/utils.h View 1 2 2 chunks +4 lines, -2 lines 0 comments Download

Messages

Total messages: 3 (0 generated)
fschneider
Small code review for you :)
10 years, 10 months ago (2010-02-16 19:01:27 UTC) #1
Kevin Millikin (Chromium)
Nice. I've got some questions: http://codereview.chromium.org/606063/diff/3002/2004 File src/codegen.h (right): http://codereview.chromium.org/606063/diff/3002/2004#newcode521 src/codegen.h:521: // Minor key encoding ...
10 years, 10 months ago (2010-02-17 10:16:33 UTC) #2
fschneider
10 years, 10 months ago (2010-02-17 12:00:31 UTC) #3
http://codereview.chromium.org/606063/diff/3002/2004
File src/codegen.h (right):

http://codereview.chromium.org/606063/diff/3002/2004#newcode521
src/codegen.h:521: // Minor key encoding in 32 bits AAAAAAAAAAAAAAAAAAAAAFI
A(rgs)F(lag)I(nloop).
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> I think these comments should go.  It's impossible to count the A's, and the
bit
> field declarations are self-documenting and authoritative (and nobody cares
> about the specific bit positions if they use the accessors anyway).
> 
> I think a simple
> 
> // Minor key is encoded in 32 bits.
> 
> is better.

Done.

http://codereview.chromium.org/606063/diff/3002/2004#newcode522
src/codegen.h:522: class InLoopBits: public BitField<InLoopFlag, 0, 1> {};
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> I also like to put "// Type, start, size." or similar on the first declaration
> in the group or before it.  It's usually obvious, but it saves having to
> remember the order of the two ints and whether size or end position is
encoded.

Done.

http://codereview.chromium.org/606063/diff/3002/2004#newcode524
src/codegen.h:524: class ArgcBits: public BitField<int, 2, 30> {};
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> 32 - 2?  Might be useful to document that this is not a 30 bit field but "the
> rest".

Done.

http://codereview.chromium.org/606063/diff/3002/2005
File src/runtime.cc (right):

http://codereview.chromium.org/606063/diff/3002/2005#newcode1508
src/runtime.cc:1508: static const int kStringBuilderConcatHelperPositionBits =
21;
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> 32 - 11?

I'm changing this back since the value is actually converted to a smi later.

http://codereview.chromium.org/606063/diff/3002/2005#newcode1517
src/runtime.cc:1517: typedef BitField<int, 11, 21>
StringBuilderSubstringPosition;
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> 32 - 11?
 Same here.

http://codereview.chromium.org/606063/diff/3002/2007
File src/utils.h (right):

http://codereview.chromium.org/606063/diff/3002/2007#newcode162
src/utils.h:162: return (((1U << (size + shift - 1)) << 1) - (1U << shift));
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> This code assumes size and shift are not both zero (reasonable).  If that's
the
> case then shift can't be 32 and you could write:
> 
> ((1U << shift) << size) - (1U << shift)
> 
> ?

Done. There is one (not too useful) border case [shift=0, size=32] that would
still give a warning. But that's ok since we should not use a bitfield in that
case anyway.

http://codereview.chromium.org/606063/diff/3002/2007#newcode175
src/utils.h:175: return static_cast<T>((value >> shift) & (((1U << (size - 1))
<< 1) - 1));
On 2010/02/17 10:16:33, Kevin Millikin wrote:
> Hairy.  Is it worse to write:
> 
> (value & mask()) >> shift
> 
> ?

Done. Good idea to reuse mask().

Powered by Google App Engine
This is Rietveld 408576698