-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mgill
committed
Sep 4, 2020
1 parent
a84495e
commit 40148c5
Showing
49 changed files
with
2,377 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
Copyright(c) 2015-2020 Parker Hannifin Corp. All rights reserved. | ||
MIT Licensed. See the included LICENSE.txt for a copy of the full MIT License. | ||
*******************************************************************************/ | ||
#include "stdafx.h" | ||
|
||
#include "Bitfield.h" | ||
|
||
namespace mscl | ||
{ | ||
uint64 Bitfield::get(uint64 mask, bool shiftToLsb) const | ||
{ | ||
uint64 getVal = m_value & mask; | ||
|
||
if (!shiftToLsb) | ||
{ | ||
return getVal; | ||
} | ||
|
||
return getVal >> shiftCount(mask); | ||
} | ||
|
||
void Bitfield::set(uint64 mask, uint64 value, bool shiftRequired) | ||
{ | ||
clear(mask); | ||
|
||
// if value was 0, just need to clear | ||
if (value == 0) | ||
{ | ||
return; | ||
} | ||
|
||
// bitshift value to put it in the right spot in the bitfield | ||
uint64 setVal = value; | ||
|
||
if (shiftRequired) | ||
{ | ||
setVal = setVal << shiftCount(mask); | ||
} | ||
|
||
// or the set value into the complete value now that it's in the correct place | ||
m_value = m_value | setVal; | ||
} | ||
|
||
void Bitfield::clear(uint64 mask) | ||
{ | ||
uint64 clearMap = 0xFFFFFFFFFFFFFFFF ^ mask; | ||
m_value = m_value & clearMap; | ||
} | ||
|
||
uint8 Bitfield::shiftCount(uint64 mask) | ||
{ | ||
// shift until all zeros removed from right-hand side of map (least significant bit is 1) | ||
uint64 shiftMap = mask; | ||
uint8 count = 0; | ||
while (shiftMap % 2 != 1) | ||
{ | ||
shiftMap = shiftMap >> 1; | ||
count++; | ||
} | ||
|
||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/******************************************************************************* | ||
Copyright(c) 2015-2020 Parker Hannifin Corp. All rights reserved. | ||
MIT Licensed. See the included LICENSE.txt for a copy of the full MIT License. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "mscl/Types.h" | ||
|
||
namespace mscl | ||
{ | ||
class Bitfield | ||
{ | ||
public: | ||
//Constructor: Bitfield | ||
// Constructs Bitfield object with value 0 | ||
Bitfield() {}; | ||
|
||
//Constructor: Bitfield | ||
// Constructs Bitfield object with indicated value | ||
// | ||
//Parameters: | ||
// val - uint64 bitfield value | ||
Bitfield(uint64 val) : | ||
m_value(val) | ||
{}; | ||
|
||
//Destructor: ~Bitfield | ||
// Default destructor for the Bitfield object | ||
virtual ~Bitfield() {}; | ||
|
||
private: | ||
//Variable: m_value | ||
// The bitfield value | ||
uint64 m_value; | ||
|
||
public: | ||
//Function: value | ||
// Gets or sets the entire underlying bitfield value | ||
uint64 value() const { return m_value; } | ||
void value(uint64 val) { m_value = val; } | ||
|
||
//Function: get | ||
// Gets the value of only the bits masked by the indicated mask. | ||
// | ||
//Parameters: | ||
// mask - uint64 indicating which bits to evaluate | ||
// shiftToLsb - true: return the masked bits shifted all the way to the right, false: return the masked bits in their original position | ||
// | ||
//Returns: | ||
// uint64 - the masked value | ||
uint64 get(uint64 mask, bool shiftToLsb = true) const; | ||
|
||
//Function: set | ||
// Sets the provided value to the position indicated by the indicated mask | ||
// | ||
//Parameters: | ||
// mask - uint64 indicating the position to place the value | ||
// value - uint64 value to set | ||
// shiftRequired - true: provided value needs to be shifted to the masked position before being set, false: provided value already in the correct position within the bitfield | ||
void set(uint64 mask, uint64 value, bool shiftRequired = true); | ||
|
||
protected: | ||
//Function: clear | ||
// Sets all bits under the indicated mask to 0. | ||
// | ||
//Parameters: | ||
// mask - uint64 mask indicating the position of the bits to clear | ||
void clear(uint64 mask); | ||
|
||
private: | ||
//Function shiftCount | ||
// Calculate the number of bits to shift the mask value so that the least significant bit is 1 (mask shifted all the way to the right). | ||
// | ||
//Parameters: | ||
// mask - uint64 mask to calculate shift count for | ||
static uint8 shiftCount(uint64 mask); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.