summaryrefslogtreecommitdiffstats
path: root/import/hwpf
diff options
context:
space:
mode:
authorMatt K. Light <mklight@us.ibm.com>2015-06-29 13:13:26 -0500
committerJoshua Hunsberger <jahunsbe@us.ibm.com>2017-10-23 15:51:14 -0500
commit961d6b34b08cbc2e57f832499b99351b728fb4ab (patch)
treeddafb90d94932efe4fe1cd9b46bd38645d5f5271 /import/hwpf
parent9a213bcbd9d911fa591728a895ec3a3e38891487 (diff)
downloadtalos-hcode-961d6b34b08cbc2e57f832499b99351b728fb4ab.tar.gz
talos-hcode-961d6b34b08cbc2e57f832499b99351b728fb4ab.zip
made const extract methods
Change-Id: I556f0028fcfae3b3d3892897edf8c853d8873660 Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/18831 Tested-by: Jenkins Server Reviewed-by: Thi N. Tran <thi@us.ibm.com> Reviewed-by: Brian Silver <bsilver@us.ibm.com> Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'import/hwpf')
-rw-r--r--import/hwpf/fapi2/include/buffer.H220
1 files changed, 150 insertions, 70 deletions
diff --git a/import/hwpf/fapi2/include/buffer.H b/import/hwpf/fapi2/include/buffer.H
index 8d20b71c..6ee0f102 100644
--- a/import/hwpf/fapi2/include/buffer.H
+++ b/import/hwpf/fapi2/include/buffer.H
@@ -36,11 +36,11 @@
namespace fapi2
{
- /// @brief Class representing a FAPI buffer<T>
- /// @tparam T, the integral type of the buffer (uint16_t, uint64_t, etc.)
- template <typename T, typename TT = bufferTraits<T> >
- class buffer
- {
+/// @brief Class representing a FAPI buffer<T>
+/// @tparam T, the integral type of the buffer (uint16_t, uint64_t, etc.)
+template <typename T, typename TT = bufferTraits<T> >
+class buffer
+{
public:
/// Shortcut typedef to get to our traits class
typedef typename TT::bits_type bits_type;
@@ -52,40 +52,54 @@ namespace fapi2
///
inline buffer(T i_value = 0):
iv_data(i_value)
- {
- }
+ {
+ }
~buffer(void) = default;
-#if !defined(DOXYGEN) && defined(FAPI2_DEBUG)
+ #if !defined(DOXYGEN) && defined(FAPI2_DEBUG)
/// @brief Print the contents of the buffer to stdout
inline void print(void) const
- { TT::print(iv_data); }
-#endif
+ {
+ TT::print(iv_data);
+ }
+ #endif
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline operator T() const { return iv_data; }
+ inline operator T() const
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline operator T&() { return iv_data; }
+ inline operator T&()
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline T& operator()(void) { return iv_data; }
+ inline T& operator()(void)
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return Reference to the contents of the buffer
///
- inline const T& operator()(void) const { return iv_data; }
+ inline const T& operator()(void) const
+ {
+ return iv_data;
+ }
/// @name Buffer Manipulation Functions
///@{
@@ -118,11 +132,14 @@ namespace fapi2
// Create mask if part of this byte is not in the valid part of the buffer,
// Shift it left by the amount of unused bits,
// Clear the unused bits
- if (((i_offset + 1) == length) && (bit_length % bits_in_value)) {
- i_value &= parameterTraits<OT>::mask() << ((bits_in_value * length) - bit_length);
+ if (((i_offset + 1) == length) && (bit_length % bits_in_value))
+ {
+ i_value &= parameterTraits<OT>::mask() << ((bits_in_value * length) -
+ bit_length);
}
- parameterTraits<OT>::template write_element<typename TT::unit_type>(TT::get_address(iv_data), i_value, i_offset);
+ parameterTraits<OT>::template write_element<typename TT::unit_type>
+ (TT::get_address(iv_data), i_value, i_offset);
return FAPI2_RC_SUCCESS;
}
@@ -134,7 +151,9 @@ namespace fapi2
/// @return Length in bits
///
inline constexpr uint32_t getBitLength(void) const
- { return TT::bit_length(iv_data); }
+ {
+ return TT::bit_length(iv_data);
+ }
///
/// @brief Return the length of the buffer in OT units
@@ -167,7 +186,8 @@ namespace fapi2
// This would be a candidate for a fast_mask (see variable_buffer) but
// we'd need tables for all the integral types which maybe we need to
// do ...
- iv_data |= (T(~0) >> (TT::bits_per_unit() - C)) << (TT::bits_per_unit() - B - C);
+ iv_data |= (T(~0) >> (TT::bits_per_unit() - C)) << (TT::bits_per_unit() - B -
+ C);
return *this;
}
@@ -178,14 +198,16 @@ namespace fapi2
/// @note 0 is left-most
/// @return FAPI2_RC_SUCCESS if OK
///
- inline fapi2::ReturnCode setBit(const bits_type& i_bit, const bits_type& i_count = 1)
+ inline fapi2::ReturnCode setBit(const bits_type& i_bit,
+ const bits_type& i_count = 1)
{
if ((i_count + i_bit - 1) >= TT::bits_per_unit())
{
return FAPI2_RC_INVALID_PARAMETER;
}
- iv_data |= (T(~0) >> (TT::bits_per_unit() - i_count)) << (TT::bits_per_unit() - i_bit - i_count);
+ iv_data |= (T(~0) >> (TT::bits_per_unit() - i_count)) <<
+ (TT::bits_per_unit() - i_bit - i_count);
return FAPI2_RC_SUCCESS;
}
@@ -216,7 +238,8 @@ namespace fapi2
/// @note 0 is left-most
/// @return FAPI2_RC_SUCCESS if OK
///
- inline fapi2::ReturnCode clearBit(const bits_type& i_bit, const bits_type& i_count = 1)
+ inline fapi2::ReturnCode clearBit(const bits_type& i_bit,
+ const bits_type& i_count = 1)
{
if ((i_count + i_bit - 1) >= TT::bits_per_unit())
{
@@ -282,9 +305,9 @@ namespace fapi2
///
template< bits_type B, bits_type C = 1>
inline bool getBit(void) const
- {
- return buffer<T>().setBit<B, C>() & iv_data;
- }
+ {
+ return buffer<T>().setBit<B, C>() & iv_data;
+ }
///
/// @brief Set and entire buffer to X's
@@ -294,25 +317,31 @@ namespace fapi2
///
template< uint8_t X >
inline buffer& flush(void)
- {
- static_assert( (X == 1) || (X == 0), "bad argument to flush" );
- (0 == X) ? TT::clear(iv_data) : TT::set(iv_data);
- return *this;
- }
+ {
+ static_assert( (X == 1) || (X == 0), "bad argument to flush" );
+ (0 == X) ? TT::clear(iv_data) : TT::set(iv_data);
+ return *this;
+ }
///
/// @brief Invert entire buffer
/// @return buffer_base&, Useful for method chaining
///
inline buffer& invert(void)
- { TT::invert(iv_data); return *this; }
+ {
+ TT::invert(iv_data);
+ return *this;
+ }
///
/// @brief Bit reverse entire buffer
/// @return buffer_base&, Useful for method chaining
///
inline buffer& reverse(void)
- { TT::reverse(iv_data); return *this; }
+ {
+ TT::reverse(iv_data);
+ return *this;
+ }
///@}
@@ -324,7 +353,10 @@ namespace fapi2
/// @brief Get a pointer to the buffer bits
/// @return Pointer to the buffer itself
///
- inline T* pointer(void) { return &iv_data; }
+ inline T* pointer(void)
+ {
+ return &iv_data;
+ }
// Note: Many (all?) of these are not needed and the compiler complains
// as the cast to T yields a better operator. There are here mainly for
@@ -333,86 +365,86 @@ namespace fapi2
///
/// @brief operator>>()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator>>(bits_type i_shiftnum);
-#endif
+ #endif
///
/// @brief operator<<()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator<<(bits_type i_shiftnum);
-#endif
+ #endif
///
/// @brief operator+()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator+(const T& rhs);
-#endif
+ #endif
///
/// @brief operator+=()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator+=(const T& rhs);
-#endif
+ #endif
///
/// @brief operator|=()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator|=(const T& rhs);
-#endif
+ #endif
///
/// @brief operator&=()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator&=(const T& rhs);
-#endif
+ #endif
///
/// @brief operator|()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator|(const T& rhs);
-#endif
+ #endif
///
/// @brief operator&()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator&(const T& rhs);
-#endif
+ #endif
///
/// @brief operator^=()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator^=(const T& rhs);
-#endif
+ #endif
///
/// @brief operator~()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline buffer<T>& operator~(const T& rhs) const;
-#endif
+ #endif
///
/// @brief operator==()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline bool operator==(const T& rhs) const;
-#endif
+ #endif
///
/// @brief operator!=()
///
-#ifdef DOXYGEN
+ #ifdef DOXYGEN
inline bool operator!=(const T& rhs) const;
-#endif
+ #endif
///
/// @brief Copy part of a OT into the DataBuffer
@@ -444,15 +476,19 @@ namespace fapi2
uint64_t source = static_cast<uint64_t>(i_datain);
const uint64_t target = static_cast<uint64_t>(iv_data);
- const bits_type source_start = parameterTraits<uint64_t>::bit_length() - (source_length - SS);
- const bits_type target_start = parameterTraits<uint64_t>::bit_length() - (target_length - TS);
+ const bits_type source_start = parameterTraits<uint64_t>::bit_length() -
+ (source_length - SS);
+ const bits_type target_start = parameterTraits<uint64_t>::bit_length() -
+ (target_length - TS);
// Get mask value for Target buffer
// Note: Need "& 0UL" because bit shift left for Target buffer doesn't roll off
- uint64_t mask = ((~0UL << (parameterTraits<uint64_t>::bit_length() - L)) & ~0UL) >> target_start;
+ uint64_t mask = ((~0UL << (parameterTraits<uint64_t>::bit_length() - L)) & ~0UL)
+ >> target_start;
// Align the source to the target. Make things signed so we know which way to shift.
int32_t shift = source_start - target_start;
+
if (shift > 0)
{
source <<= shift;
@@ -514,15 +550,19 @@ namespace fapi2
uint64_t source = static_cast<uint64_t>(i_datain);
const uint64_t target = static_cast<uint64_t>(iv_data);
- const bits_type source_start = parameterTraits<uint64_t>::bit_length() - (source_length - i_sourceStart);
- const bits_type target_start = parameterTraits<uint64_t>::bit_length() - (target_length - i_targetStart);
+ const bits_type source_start = parameterTraits<uint64_t>::bit_length() -
+ (source_length - i_sourceStart);
+ const bits_type target_start = parameterTraits<uint64_t>::bit_length() -
+ (target_length - i_targetStart);
// Get mask value for Target buffer
// Note: Need "& 0UL" because bit shift left for Target buffer doesn't roll off
- uint64_t mask = ((~0UL << (parameterTraits<uint64_t>::bit_length() - i_len)) & ~0UL) >> target_start;
+ uint64_t mask = ((~0UL << (parameterTraits<uint64_t>::bit_length() - i_len)) &
+ ~0UL) >> target_start;
// Align the source to the target. Make things signed so we know which way to shift.
int32_t shift = source_start - target_start;
+
if (shift > 0)
{
source <<= shift;
@@ -573,7 +613,8 @@ namespace fapi2
/// @note Data is assumed to be aligned on the word boundary of L
///
template<typename OT>
- fapi2::ReturnCode insertFromRight(const OT i_datain, const bits_type i_targetStart,
+ fapi2::ReturnCode insertFromRight(const OT i_datain,
+ const bits_type i_targetStart,
const bits_type i_len)
{
// Error if input data don't make sense
@@ -595,7 +636,28 @@ namespace fapi2
return FAPI2_RC_INVALID_PARAMETER;
}
- return this->insert(i_datain, i_targetStart, i_len, parameterTraits<OT>::bit_length() - i_len);
+ return this->insert(i_datain, i_targetStart, i_len,
+ parameterTraits<OT>::bit_length() - i_len);
+ }
+
+ ///
+ /// @brief Copy data from this buffer into an OT
+ /// @tparam SS Start bit in source
+ /// @tparam L Length of bits to insert
+ /// @tparam TS Start bit to insert into (target start)
+ /// @tparam OT the type of the outgoing (target)
+ /// @param[out] o_out OT to copy into - data is placed left aligned
+ /// @return const buffer& Useful for method chaining
+ ///
+ template<bits_type SS, bits_type L, bits_type TS = 0, typename OT>
+ inline const buffer& extract(OT& o_out) const
+ {
+ // Extraction is just an insert into o_out
+
+ buffer<OT> out(o_out);
+ out.insert<TS, L, SS>(iv_data);
+ o_out = out;
+ return *this;
}
///
@@ -629,12 +691,14 @@ namespace fapi2
///
template<typename OT>
fapi2::ReturnCode extract(OT& o_out, const bits_type i_sourceStart,
- const bits_type i_len, const bits_type i_targetStart = 0)
+ const bits_type i_len, const bits_type i_targetStart = 0) const
{
// Extraction is just an insert into o_out
buffer<OT> out(o_out);
- if (out.insert(iv_data, i_targetStart, i_len, i_sourceStart) != FAPI2_RC_SUCCESS)
+
+ if (out.insert(iv_data, i_targetStart, i_len,
+ i_sourceStart) != FAPI2_RC_SUCCESS)
{
return FAPI2_RC_INVALID_PARAMETER;
}
@@ -649,6 +713,21 @@ namespace fapi2
/// @tparam L Length of bits to extract
/// @tparam OT the type of the outgoing (target)
/// @param[out] o_out OT to copy into - data is placed right aligned
+ /// @return const buffer& Useful for method chaining
+ ///
+ template<bits_type SS, bits_type L, typename OT>
+ inline const buffer& extractToRight(OT& o_out) const
+ {
+ extract<SS, L, parameterTraits<OT>::bit_length() - L>(o_out);
+ return *this;
+ }
+
+ ///
+ /// @brief Copy data from this buffer into an OT and right justify
+ /// @tparam SS Start bit to insert into (source start)
+ /// @tparam L Length of bits to extract
+ /// @tparam OT the type of the outgoing (target)
+ /// @param[out] o_out OT to copy into - data is placed right aligned
/// @return buffer& Useful for method chaining
///
template<bits_type SS, bits_type L, typename OT>
@@ -668,9 +747,10 @@ namespace fapi2
///
template<typename OT>
fapi2::ReturnCode extractToRight(OT& o_out, const bits_type i_sourceStart,
- const bits_type i_len)
+ const bits_type i_len) const
{
- return extract(o_out, i_sourceStart, i_len, parameterTraits<OT>::bit_length() - i_len);
+ return extract(o_out, i_sourceStart, i_len,
+ parameterTraits<OT>::bit_length() - i_len);
}
///@}
@@ -678,7 +758,7 @@ namespace fapi2
private:
/// The contents of the buffer
T iv_data;
- };
+};
}
#endif
OpenPOWER on IntegriCloud