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

Issue 694003002: Don't use one-bit bit fields for enums -- they misbehave and are inefficient in VC++ (Closed)

Created:
6 years, 1 month ago by brucedawson
Modified:
5 years, 10 months ago
CC:
v8-dev
Project:
v8
Visibility:
Public.

Description

Don't use one-bit bit fields for enums -- they misbehave in VC++, unless you force the enum's type to be unsigned. enum bit fields may also waste space. The bug is that direct comparisons of STORE_TO_INITIALIZED_ENTRY with store_mode_ would always fail, so this is a behavior-altering change. One-bit bit fields in VC++ default to being signed so their only possible values are zero and *negative* one. /analyze warned that such a bit field was being compared to one which can never succeed. Also, the bit field in particular was falling afoul of the VC++ bit field layout rules and the two one-bit bit fields were actually taking up 64-bits. Fixed by removing some bit field specifiers and specifying the enum's type as being unsigned char. This saves four bytes in both places the enum was used, and the lack of bit fields means that access to the variables will be faster, and the sign problem will be avoided. In some cases it would be nice to use unsigned-char enums together with bit fields but gcc warns on that. Luckily that combination is not needed for this fix. Here is the /analyze warning which I confirmed in a test app is a real bug: v8\src\hydrogen-instructions.h(6845) : warning C6299: Explicitly comparing a bit field to a Boolean type will yield unexpected results. BUG=427616 LOG=n

Patch Set 1 #

Patch Set 2 : Marked the enum's type as unsigned char to save space and removed some bit fields. #

Patch Set 3 : Comment fix. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+8 lines, -7 lines) Patch
M src/hydrogen-instructions.h View 1 2 3 chunks +8 lines, -7 lines 0 comments Download

Messages

Total messages: 13 (3 generated)
brucedawson
6 years, 1 month ago (2014-10-31 18:38:51 UTC) #2
cpu_(ooo_6.6-7.5)
there are quite a few more of those in the file... not compiled for windows?
6 years, 1 month ago (2014-11-03 17:23:37 UTC) #4
brucedawson
On 2014/11/03 17:23:37, cpu wrote: > there are quite a few more of those in ...
6 years, 1 month ago (2014-11-03 22:14:42 UTC) #5
brucedawson
I have an update that further improves things with VC++ by squishing the enum into ...
6 years, 1 month ago (2014-11-03 22:21:31 UTC) #6
Jakob Kummerow
On 2014/11/03 22:21:31, brucedawson wrote: > I have an update that further improves things with ...
6 years, 1 month ago (2014-11-04 09:12:14 UTC) #7
Hannes Payer (out of office)
On 2014/11/04 09:12:14, Jakob wrote: > On 2014/11/03 22:21:31, brucedawson wrote: > > I have ...
6 years, 1 month ago (2014-11-04 09:14:08 UTC) #8
Hannes Payer (out of office)
On 2014/11/04 09:14:08, Hannes Payer (OOO) wrote: > On 2014/11/04 09:12:14, Jakob wrote: > > ...
6 years, 1 month ago (2014-11-04 09:44:14 UTC) #9
brucedawson
Okay, updates made. It's a shame that gcc and VC++ both make combining of enums ...
6 years, 1 month ago (2014-11-04 18:48:02 UTC) #10
cpu_(ooo_6.6-7.5)
removing myself from review.
6 years, 1 month ago (2014-11-04 21:26:20 UTC) #12
Jakob Kummerow
6 years, 1 month ago (2014-11-04 21:37:33 UTC) #13
Triggered by this, and by the fact that we have many more places where we pack
member fields, I've created a patch that migrates all of them to V8's own
BitField. That's more verbose to write, but allows us full control over every
bit, and is compiler independent: https://codereview.chromium.org/700963002/

Powered by Google App Engine
This is Rietveld 408576698