Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions UnitTests/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
1 change: 1 addition & 0 deletions Vorb.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@
<None Include="include/typesArray.inl" />
<None Include="include/typesColor.inl" />
<None Include="include\AssetLoader.inl" />
<None Include="include\Bitfields.inl" />
<None Include="include\math\MatrixMath.hpp" />
<None Include="include\Matrix.inl" />
<None Include="include\Quaternion.inl" />
Expand Down
3 changes: 3 additions & 0 deletions Vorb.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@
<None Include="include\IntersectionUtils.hpp">
<Filter>Utils</Filter>
</None>
<None Include="include\Bitfields.inl">
<Filter>Utils</Filter>
</None>
<None Include="include\Matrix.inl">
<Filter>Core</Filter>
</None>
Expand Down
88 changes: 88 additions & 0 deletions include/Bitfields.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*! \file typesArray.inl
* @brief Bitfield implementation for different access methodologies.
*/

#define VORB_BITS_PER_BYTE 8

namespace vorb {
/*! @brief
*/
template<typename T, size_t BITOFF, size_t BITSIZE>
class UncheckedBitfield {
static_assert(std::is_integral<T>::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));
};
};
};
}