CMS 3D CMS Logo

bit_encoding.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_L1TPARTICLEFLOW_ENCODING_H
2 #define DATAFORMATS_L1TPARTICLEFLOW_ENCODING_H
3 
4 #include <cassert>
6 
7 template <typename U, typename T>
8 inline void pack_into_bits(U& u, unsigned int& start, const T& data) {
9  const unsigned int w = T::width;
10  u(start + w - 1, start) = data(w - 1, 0);
11  start += w;
12 }
13 
14 template <typename U, typename T>
15 inline void unpack_from_bits(const U& u, unsigned int& start, T& data) {
16  const unsigned int w = T::width;
17  data(w - 1, 0) = u(start + w - 1, start);
18  start += w;
19 }
20 
21 template <typename U>
22 inline void pack_bool_into_bits(U& u, unsigned int& start, bool data) {
23  u[start++] = data;
24 }
25 
26 template <typename U>
27 inline void unpack_bool_from_bits(const U& u, unsigned int& start, bool& data) {
28  data = u[start++];
29 }
30 
31 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
32 inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {
33 #ifdef __SYNTHESIS__
34 #pragma HLS inline
35 #pragma HLS inline region recursive
36 #endif
37  assert(T::BITWIDTH <= NB);
38  for (unsigned int i = 0; i < N; ++i) {
39 #ifdef __SYNTHESIS__
40 #pragma HLS unroll
41 #endif
42  data[i + OFFS] = objs[i].pack();
43  }
44 }
45 
46 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
47 inline void l1pf_pattern_unpack(const ap_uint<NB> data[], T objs[N]) {
48 #ifdef __SYNTHESIS__
49 #pragma HLS inline
50 #pragma HLS inline region recursive
51 #endif
52  assert(T::BITWIDTH <= NB);
53  for (unsigned int i = 0; i < N; ++i) {
54 #ifdef __SYNTHESIS__
55 #pragma HLS unroll
56 #endif
57  objs[i] = T::unpack(data[i + OFFS]);
58  }
59 }
60 
61 #endif
Definition: start.py:1
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
T w() const
void l1pf_pattern_unpack(const ap_uint< NB > data[], T objs[N])
Definition: bit_encoding.h:47
void unpack_bool_from_bits(const U &u, unsigned int &start, bool &data)
Definition: bit_encoding.h:27
assert(be >=bs)
void pack_into_bits(U &u, unsigned int &start, const T &data)
Definition: bit_encoding.h:8
void l1pf_pattern_pack(const T objs[N], ap_uint< NB > data[])
Definition: bit_encoding.h:32
#define N
Definition: blowfish.cc:9
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void unpack_from_bits(const U &u, unsigned int &start, T &data)
Definition: bit_encoding.h:15
long double T
void pack_bool_into_bits(U &u, unsigned int &start, bool data)
Definition: bit_encoding.h:22