ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::BitField< Lo, Hi, AuxValue, Value > Class Template Reference

#include <BitSpec.h>

Collaboration diagram for GlobalSim::BitField< Lo, Hi, AuxValue, Value >:

Public Types

using value_type = Value
using bits_type = std::bitset<width>
using encoder_type = bits_type (*)(Value)
using decoder_type = Value (*)(bits_type)

Public Member Functions

constexpr BitField (std::string_view name, std::string_view auxvar, std::string_view description, encoder_type encoder=nullptr, decoder_type decoder=nullptr)
constexpr std::string_view name () const
constexpr std::string_view description () const
Value value (const SG::AuxElement &obj) const
Value value (const SG::AuxElement &obj, bool truncate) const
AuxValue & store (SG::AuxElement &obj, Value value) const
bits_type encode (Value value) const
bits_type bits (const SG::AuxElement &obj) const
Value decode (bits_type bits) const
template<std::size_t N>
bits_type extract (const std::bitset< N > &packed) const
template<std::size_t N>
Value decodeFrom (const std::bitset< N > &packed) const
template<std::size_t N>
void decodeAndAssignFrom (const std::bitset< N > &packed, SG::AuxElement &obj) const
template<std::size_t N>
void pack (std::bitset< N > &result, const SG::AuxElement &obj) const

Public Attributes

AuxSpec auxspec

Static Public Attributes

static constexpr unsigned lo = Lo
static constexpr unsigned hi = Hi
static constexpr unsigned width = Hi - Lo + 1

Private Attributes

std::string_view m_name
std::string_view m_description
encoder_type m_encoder
decoder_type m_decoder
SG::ConstAccessor< AuxValue > m_acc
SG::Accessor< AuxValue > m_wacc

Detailed Description

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
class GlobalSim::BitField< Lo, Hi, AuxValue, Value >

Definition at line 122 of file BitSpec.h.

Member Typedef Documentation

◆ bits_type

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
using GlobalSim::BitField< Lo, Hi, AuxValue, Value >::bits_type = std::bitset<width>

Definition at line 142 of file BitSpec.h.

◆ decoder_type

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
using GlobalSim::BitField< Lo, Hi, AuxValue, Value >::decoder_type = Value (*)(bits_type)

Definition at line 145 of file BitSpec.h.

◆ encoder_type

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
using GlobalSim::BitField< Lo, Hi, AuxValue, Value >::encoder_type = bits_type (*)(Value)

Definition at line 144 of file BitSpec.h.

◆ value_type

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
using GlobalSim::BitField< Lo, Hi, AuxValue, Value >::value_type = Value

Definition at line 141 of file BitSpec.h.

Constructor & Destructor Documentation

◆ BitField()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
GlobalSim::BitField< Lo, Hi, AuxValue, Value >::BitField ( std::string_view name,
std::string_view auxvar,
std::string_view description,
encoder_type encoder = nullptr,
decoder_type decoder = nullptr )
inlineconstexpr

Definition at line 147 of file BitSpec.h.

154 m_name(name),
159
160 }
SG::Accessor< AuxValue > m_wacc
Definition BitSpec.h:306
SG::ConstAccessor< AuxValue > m_acc
Definition BitSpec.h:305
constexpr std::string_view description() const
Definition BitSpec.h:168
std::string_view m_name
Definition BitSpec.h:299
constexpr std::string_view name() const
Definition BitSpec.h:166
std::string_view m_description
Definition BitSpec.h:300
decoder_type m_decoder
Definition BitSpec.h:303
encoder_type m_encoder
Definition BitSpec.h:302

Member Function Documentation

◆ bits()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
bits_type GlobalSim::BitField< Lo, Hi, AuxValue, Value >::bits ( const SG::AuxElement & obj) const
inline

Definition at line 233 of file BitSpec.h.

233 {
234 return encode(value(obj));
235 }
Value value(const SG::AuxElement &obj) const
Definition BitSpec.h:174
bits_type encode(Value value) const
Definition BitSpec.h:216

◆ decode()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
Value GlobalSim::BitField< Lo, Hi, AuxValue, Value >::decode ( bits_type bits) const
inline

Definition at line 241 of file BitSpec.h.

241 {
242 if (m_decoder)
243 return m_decoder(bits);
244
245 return static_cast<Value>(bits.to_ullong());
246 }
bits_type bits(const SG::AuxElement &obj) const
Definition BitSpec.h:233

◆ decodeAndAssignFrom()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
template<std::size_t N>
void GlobalSim::BitField< Lo, Hi, AuxValue, Value >::decodeAndAssignFrom ( const std::bitset< N > & packed,
SG::AuxElement & obj ) const
inline

Definition at line 274 of file BitSpec.h.

274 {
276 }
bits_type extract(const std::bitset< N > &packed) const
Definition BitSpec.h:253
AuxValue & store(SG::AuxElement &obj, Value value) const
Definition BitSpec.h:196
Value decode(bits_type bits) const
Definition BitSpec.h:241

◆ decodeFrom()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
template<std::size_t N>
Value GlobalSim::BitField< Lo, Hi, AuxValue, Value >::decodeFrom ( const std::bitset< N > & packed) const
inline

Definition at line 269 of file BitSpec.h.

269 {
270 return decode(extract(packed));
271 }

◆ description()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
std::string_view GlobalSim::BitField< Lo, Hi, AuxValue, Value >::description ( ) const
inlineconstexpr

Definition at line 168 of file BitSpec.h.

168{ return m_description; }

◆ encode()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
bits_type GlobalSim::BitField< Lo, Hi, AuxValue, Value >::encode ( Value value) const
inline

Definition at line 216 of file BitSpec.h.

216 {
217 if (m_encoder)
218 return m_encoder(value);
219
220 // Default behaviour: integral conversion.
221
222 // should we check for out-of-range given size of bitset?
223
224 return bits_type{
225 static_cast<unsigned long long>(value)
226 };
227 }
std::bitset< width > bits_type
Definition BitSpec.h:142

◆ extract()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
template<std::size_t N>
bits_type GlobalSim::BitField< Lo, Hi, AuxValue, Value >::extract ( const std::bitset< N > & packed) const
inline

Definition at line 253 of file BitSpec.h.

253 {
254 static_assert(Hi < N, "BitField extends beyond the specification width");
255
257
258 for (unsigned i = 0; i < width; ++i)
259 result[i] = packed[Lo + i];
260
261 return result;
262 }
static constexpr unsigned width
Definition BitSpec.h:130

◆ name()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
std::string_view GlobalSim::BitField< Lo, Hi, AuxValue, Value >::name ( ) const
inlineconstexpr

Definition at line 166 of file BitSpec.h.

166{ return m_name; }

◆ pack()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
template<std::size_t N>
void GlobalSim::BitField< Lo, Hi, AuxValue, Value >::pack ( std::bitset< N > & result,
const SG::AuxElement & obj ) const
inline

Definition at line 283 of file BitSpec.h.

285 {
286 static_assert(
287 Hi < N,
288 "BitField extends beyond the specification width");
289
290 const bits_type field_bits = bits(obj);
291
292 for (unsigned i = 0; i < width; ++i)
293 result[Lo + i] = field_bits[i];
294 }

◆ store()

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
AuxValue & GlobalSim::BitField< Lo, Hi, AuxValue, Value >::store ( SG::AuxElement & obj,
Value value ) const
inline

Definition at line 196 of file BitSpec.h.

196 {
197 if constexpr (std::is_integral_v<AuxValue>)
198 { // ensures have bitwise operators, has_mask is not constexpr so must hide this from invalid AuxValue types
199 // leaving this commented as may revery to constexpr again at some point
200 // if constexpr (has_mask) {
201 // auto& val = m_wacc(obj);
202 // val = (val & ~Mask) | ((value << shift) & Mask);
203 if (auxspec.has_mask) {
204 auto &val = m_wacc(obj);
205 return (val = (val & ~auxspec.mask) | ((value << auxspec.shift) & auxspec.mask));
206 }
207 }
208 return (m_wacc(obj) = value);
209
210 }

◆ value() [1/2]

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
Value GlobalSim::BitField< Lo, Hi, AuxValue, Value >::value ( const SG::AuxElement & obj) const
inline

Definition at line 174 of file BitSpec.h.

174 {
175
176 if constexpr (std::is_integral_v<AuxValue>)
177 { // ensures have bitwise operators
178
179 /*if constexpr(has_mask) {
180 return (m_acc(obj) & Mask) >> shift;*/
181 if (auxspec.has_mask) {
182 return (m_acc(obj) & auxspec.mask) >> auxspec.shift;
183 }
184 }
185
186 return m_acc(obj);
187
188 }

◆ value() [2/2]

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
Value GlobalSim::BitField< Lo, Hi, AuxValue, Value >::value ( const SG::AuxElement & obj,
bool truncate ) const
inline

Definition at line 191 of file BitSpec.h.

191 {
192 if(!truncate) return value(obj);
193 return decode(encode(value(obj)));
194 }

Member Data Documentation

◆ auxspec

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
AuxSpec GlobalSim::BitField< Lo, Hi, AuxValue, Value >::auxspec

Definition at line 296 of file BitSpec.h.

◆ hi

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
unsigned GlobalSim::BitField< Lo, Hi, AuxValue, Value >::hi = Hi
staticconstexpr

Definition at line 129 of file BitSpec.h.

◆ lo

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
unsigned GlobalSim::BitField< Lo, Hi, AuxValue, Value >::lo = Lo
staticconstexpr

Definition at line 128 of file BitSpec.h.

◆ m_acc

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
SG::ConstAccessor<AuxValue> GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_acc
private

Definition at line 305 of file BitSpec.h.

◆ m_decoder

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
decoder_type GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_decoder
private

Definition at line 303 of file BitSpec.h.

◆ m_description

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
std::string_view GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_description
private

Definition at line 300 of file BitSpec.h.

◆ m_encoder

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
encoder_type GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_encoder
private

Definition at line 302 of file BitSpec.h.

◆ m_name

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
std::string_view GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_name
private

Definition at line 299 of file BitSpec.h.

◆ m_wacc

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
SG::Accessor<AuxValue> GlobalSim::BitField< Lo, Hi, AuxValue, Value >::m_wacc
private

Definition at line 306 of file BitSpec.h.

◆ width

template<unsigned Lo, unsigned Hi, typename AuxValue, typename Value = AuxValue>
unsigned GlobalSim::BitField< Lo, Hi, AuxValue, Value >::width = Hi - Lo + 1
staticconstexpr

Definition at line 130 of file BitSpec.h.


The documentation for this class was generated from the following file: