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 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
62 inline void l1pf_pattern_pack_slim(const T objs[N], ap_uint<NB> data[]) {
63 #ifdef __SYNTHESIS__
64 #pragma HLS inline
65 #pragma HLS inline region recursive
66 #endif
67  assert(T::BITWIDTH_SLIM <= NB);
68  for (unsigned int i = 0; i < N; ++i) {
69 #ifdef __SYNTHESIS__
70 #pragma HLS unroll
71 #endif
72  data[i + OFFS] = objs[i].pack_slim();
73  }
74 }
75 
76 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
77 inline void l1pf_pattern_unpack_slim(const ap_uint<NB> data[], T objs[N]) {
78 #ifdef __SYNTHESIS__
79 #pragma HLS inline
80 #pragma HLS inline region recursive
81 #endif
82  assert(T::BITWIDTH_SLIM <= NB);
83  for (unsigned int i = 0; i < N; ++i) {
84 #ifdef __SYNTHESIS__
85 #pragma HLS unroll
86 #endif
87  objs[i] = T::unpack(data[i + OFFS]);
88  }
89 }
90 
91 #endif
Definition: start.py:1
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)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
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
void l1pf_pattern_pack_slim(const T objs[N], ap_uint< NB > data[])
Definition: bit_encoding.h:62
#define N
Definition: blowfish.cc:9
void l1pf_pattern_unpack_slim(const ap_uint< NB > data[], T objs[N])
Definition: bit_encoding.h:77
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
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