Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:50:14

0001 #ifndef DATAFORMATS_L1TPARTICLEFLOW_ENCODING_H
0002 #define DATAFORMATS_L1TPARTICLEFLOW_ENCODING_H
0003 
0004 #include <cassert>
0005 #include "DataFormats/L1TParticleFlow/interface/datatypes.h"
0006 
0007 template <typename U, typename T>
0008 inline void pack_into_bits(U& u, unsigned int& start, const T& data) {
0009   const unsigned int w = T::width;
0010   u(start + w - 1, start) = data(w - 1, 0);
0011   start += w;
0012 }
0013 
0014 template <typename U, typename T>
0015 inline void unpack_from_bits(const U& u, unsigned int& start, T& data) {
0016   const unsigned int w = T::width;
0017   data(w - 1, 0) = u(start + w - 1, start);
0018   start += w;
0019 }
0020 
0021 template <typename U>
0022 inline void pack_bool_into_bits(U& u, unsigned int& start, bool data) {
0023   u[start++] = data;
0024 }
0025 
0026 template <typename U>
0027 inline void unpack_bool_from_bits(const U& u, unsigned int& start, bool& data) {
0028   data = u[start++];
0029 }
0030 
0031 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
0032 inline void l1pf_pattern_pack(const T objs[N], ap_uint<NB> data[]) {
0033 #ifdef __SYNTHESIS__
0034 #pragma HLS inline
0035 #pragma HLS inline region recursive
0036 #endif
0037   assert(T::BITWIDTH <= NB);
0038   for (unsigned int i = 0; i < N; ++i) {
0039 #ifdef __SYNTHESIS__
0040 #pragma HLS unroll
0041 #endif
0042     data[i + OFFS] = objs[i].pack();
0043   }
0044 }
0045 
0046 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
0047 inline void l1pf_pattern_unpack(const ap_uint<NB> data[], T objs[N]) {
0048 #ifdef __SYNTHESIS__
0049 #pragma HLS inline
0050 #pragma HLS inline region recursive
0051 #endif
0052   assert(T::BITWIDTH <= NB);
0053   for (unsigned int i = 0; i < N; ++i) {
0054 #ifdef __SYNTHESIS__
0055 #pragma HLS unroll
0056 #endif
0057     objs[i] = T::unpack(data[i + OFFS]);
0058   }
0059 }
0060 
0061 #endif