From 29f9a25346d1e8aa6aceaaa2e89a4cf7b4ff0924 Mon Sep 17 00:00:00 2001 From: czaloj Date: Fri, 17 Jul 2015 16:01:36 -0700 Subject: [PATCH 1/3] Add multiline macro --- UnitTests/macros.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UnitTests/macros.h b/UnitTests/macros.h index 4c375df75..4f927489d 100644 --- a/UnitTests/macros.h +++ b/UnitTests/macros.h @@ -22,4 +22,13 @@ bool UnitTestsFuncs::UT_##B##N() #define UNIT_TEST_BATCH General_ +#define DO_2X(EX) EX; EX +#define DO_4X(EX) DO_2X(EX); DO_2X(EX) +#define DO_8X(EX) DO_4X(EX); DO_4X(EX) +#define DO_16X(EX) DO_8X(EX); DO_8X(EX) +#define DO_32X(EX) DO_16X(EX); DO_16X(EX) +#define DO_64X(EX) DO_32X(EX); DO_32X(EX) +#define DO_128X(EX) DO_64X(EX); DO_64X(EX) +#define DO_256X(EX) DO_128X(EX); DO_128X(EX) + #endif // macros_h__ From d39a4ba2a6c0b189585e3e91ae58109584b9b0cd Mon Sep 17 00:00:00 2001 From: czaloj Date: Fri, 17 Jul 2015 16:37:07 -0700 Subject: [PATCH 2/3] Begin bitfield implementation --- Vorb.vcxproj | 1 + Vorb.vcxproj.filters | 3 ++ include/Bitfields.inl | 88 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 include/Bitfields.inl diff --git a/Vorb.vcxproj b/Vorb.vcxproj index 6805a04b9..595d41f6d 100644 --- a/Vorb.vcxproj +++ b/Vorb.vcxproj @@ -490,6 +490,7 @@ + diff --git a/Vorb.vcxproj.filters b/Vorb.vcxproj.filters index b7e4113fd..29be9e244 100644 --- a/Vorb.vcxproj.filters +++ b/Vorb.vcxproj.filters @@ -815,6 +815,9 @@ Utils + + Utils + diff --git a/include/Bitfields.inl b/include/Bitfields.inl new file mode 100644 index 000000000..0d0479af8 --- /dev/null +++ b/include/Bitfields.inl @@ -0,0 +1,88 @@ +/*! \file typesArray.inl + * @brief Bitfield implementation for different access methodologies. + */ + +#define VORB_BITS_PER_BYTE 8 + +namespace vorb { + /*! @brief + */ + template + class UncheckedBitfield { + static_assert(std::is_integral::value, "Bitfield may only represent integral types"); + static_assert(BITOFF < sizeof(T) * VORB_BITS_PER_BYTE, "Starting offset must be contained within the type"); + static_assert((BITOFF + BITSIZE) <= sizeof(T) * VORB_BITS_PER_BYTE, "Bitfield must be contained within the type"); + public: + UncheckedBitfield& operator = (T v) { + // Reduced by an extra masking operation for overflowss + value = (value & ~(((1 << BITSIZE) - 1) << BITOFF)) | (v << BITOFF); + return *this; + } + + UncheckedBitfield& operator += (T v) { + // Allows for overflows + value += (v << BITOFF); + return *this; + } + UncheckedBitfield& operator -= (T v) { + // Allows for overflows + value += (v << BITOFF); + return *this; + } + UncheckedBitfield& operator *= (T v) { + field *= v; + return *this; + } + UncheckedBitfield& operator /= (T v) { + field /= v; + return *this; + } + UncheckedBitfield& operator |= (T v) { + value |= (v << BITOFF); + return *this; + } + UncheckedBitfield& operator &= (T v) { + value &= (v << BITOFF) | ~(((1 << BITSIZE) - 1) << BITOFF); + return *this; + } + UncheckedBitfield& operator ^= (T v) { + value ^= (v << BITOFF); + return *this; + } + + T operator + (T v) { + return field + v; + } + T operator - (T v) { + return field - v; + } + T operator * (T v) { + return field * v; + } + T operator / (T v) { + return field / v; + } + T operator | (T v) { + return field | v; + } + T operator & (T v) { + return field & v; + } + T operator ^ (T v) { + return field ^ v; + } + + operator T() const { + return field; + } + + union { + T value; + struct { + T : BITOFF; + T field : BITSIZE; + T : ((sizeof(T) * VORB_BITS_PER_BYTE) - (BITOFF + BITSIZE)); + }; + }; + }; +} From 152befce71004752410f7e0772903dde4bb7b74c Mon Sep 17 00:00:00 2001 From: czaloj Date: Fri, 17 Jul 2015 16:38:37 -0700 Subject: [PATCH 3/3] Fix small error --- include/Bitfields.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Bitfields.inl b/include/Bitfields.inl index 0d0479af8..753e4148e 100644 --- a/include/Bitfields.inl +++ b/include/Bitfields.inl @@ -26,7 +26,7 @@ namespace vorb { } UncheckedBitfield& operator -= (T v) { // Allows for overflows - value += (v << BITOFF); + value -= (v << BITOFF); return *this; } UncheckedBitfield& operator *= (T v) {