Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitfield cleanup #204

Merged
merged 5 commits into from Mar 25, 2014
Merged

Bitfield cleanup #204

merged 5 commits into from Mar 25, 2014

Conversation

neobrain
Copy link
Member

This branch adds my BitField class (BSD-licensed) to the Dolphin code base and converts a small number of structures to it. In the long term we should target a full conversion of the source code, but at this stage I don't think the advantage justified the effort, especially since the monotonous task might be prone to stupid errors.

Cf. PR #157 for details.

@neobrain
Copy link
Member Author

Fixed Windows build + spacing.

@Sonicadvance1
Copy link
Contributor

I can't find any glaring issues and it looks like a nice addition. LGTM

// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@neobrain
Copy link
Member Author

Fixed license header copy-paste derp.


BitField& operator = (T val)
{
storage = (storage & ~GetMask()) | ((val<<position) & GetMask());

This comment was marked as off-topic.

…ianness-independent way.

The underlying storage type of a bitfield can be any intrinsic integer type,
but also any enumeration.

Custom storage types are supported if the following things are defined on the storage type:
- casting 0 to the storage type
- bit shift operators (in both directions)
- bitwise & operator
- bitwise ~ operator
- std::make_unsigned specialization
@neobrain
Copy link
Member Author

Fixed spacing and improved documentation a tiny bit (it said "u32" for the storage before, now it says T in general).

// Now make sure the value is indeed correct
EXPECT_EQ(val, object.full_u64);
EXPECT_EQ(*(s64*)&val, object.full_s64);
EXPECT_EQ((val>>9) & 0x7, object.regular_field_unsigned);

This comment was marked as off-topic.

@delroth
Copy link
Member

delroth commented Mar 25, 2014

Other than these few style comments, LGTM.

Please migrate the rest of Dolphin to this new class too :p Would be cool if we could start forbidding new bitfields.

delroth added a commit that referenced this pull request Mar 25, 2014
@delroth delroth merged commit b4337a2 into dolphin-emu:master Mar 25, 2014
Joern-P pushed a commit to Joern-P/dolphin that referenced this pull request Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants