summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/BitUtilsTest.cpp
AgeCommit message (Collapse)Author
2024-05-03Replace Common::BitCast with std::bit_castPokechu22
2022-12-11Replace BitUtils with C++20: RotateLeft/RotateRightJosJuice
Now that we've flipped the C++20 switch, let's start making use of the nice new <bit> header. I'm planning on handling this move away from BitUtils.h incrementally in a series of PRs. There may be a few functions remaining in BitUtils.h by the end that C++20 doesn't have any equivalents for.
2021-07-05treewide: convert GPLv2+ license info to SPDX tagsPierre Bourdon
SPDX standardizes how source code conveys its copyright and licensing information. See https://spdx.github.io/spdx-spec/1-rationale/ . SPDX tags are adopted in many large projects, including things like the Linux kernel.
2018-06-12UnitTests: Fix MSVC compilationspycrab
2018-05-10BitUtils: Add C++14/C++17 compatible equivalent of std::bit_cast from C++2aLioncash
Given bit conversions between types are quite common in emulation (particularly when it comes to floating-point among other things) it makes sense to provide a utility function that keeps all the boilerplate contained; especially considering it makes it harder to accidentally misuse std::memcpy (such as accidentally transposing arguments, etc). Another benefit of this function is that it doesn't require separating declarations from assignments, allowing variables to be declared const. This makes the scenario of of uninitialized variables being used less likely to occur.
2018-03-31UnitTests: Add basic tests for RotateRight() and RotateLeft()Lioncash
2017-08-13BitUtilsTest: update to pass clang-formatMichael M
2017-06-22Add function testing whether a bitmask is valid.Niels Boehm
This one verifies bitmasks where low bits are set to 1 (hence the name). Any stray 0 among the lower ones or any stray 1 among the higher zeros renders the mask invalid. The edge cases of all zeros and all ones are considered valid masks. It uses an efficient implementation. It's the counterpart of https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
2017-03-24BitUtilsTest: compare ints of the same signedness (fixes warnings)Michael Maltese
Fixes warnings like: ``` dolphin/Source/UnitTests/Common/BitUtilsTest.cpp:5: ../Externals/gtest/googletest/include/gtest/gtest.h:1392:11: warning: comparison of integers of different signs: 'const unsigned long' and 'const int' [-Wsign-compare] if (lhs == rhs) { ~~~ ^ ~~~ ../Externals/gtest/googletest/include/gtest/gtest.h:1421:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<unsigned long, int>' requested here return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); ^ dolphin/Source/UnitTests/Common/BitUtilsTest.cpp:12:3: note: in instantiation of function template specialization 'testing::internal::EqHelper<false>::Compare<unsigned long, int>' requested here EXPECT_EQ(Common::BitSize<s8>(), 8); ^ ../Externals/gtest/googletest/include/gtest/gtest.h:1924:63: note: expanded from macro 'EXPECT_EQ' EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \ ```
2017-01-14Common: Add bit utility headerLioncash
This attempts to make some bit arithmetic more self-documenting and also make it easier during review to identify potential off-by-one errors by making it possible to just specify which bits are being extracted. Functions both support the case where bits being extracted can vary and fixed bit extraction. In the case the bits are fixed, compile-time asserts are present to prevent accidental API usage at compile-time. e.g. Instead of shifting and masking to get bits 10 to 15, Common::ExtractBits<10, 15>(value) can just be done instead.