Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:39:23

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 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
0062 inline void l1pf_pattern_pack_slim(const T objs[N], ap_uint<NB> data[]) {
0063 #ifdef __SYNTHESIS__
0064 #pragma HLS inline
0065 #pragma HLS inline region recursive
0066 #endif
0067   assert(T::BITWIDTH_SLIM <= NB);
0068   for (unsigned int i = 0; i < N; ++i) {
0069 #ifdef __SYNTHESIS__
0070 #pragma HLS unroll
0071 #endif
0072     data[i + OFFS] = objs[i].pack_slim();
0073   }
0074 }
0075 
0076 template <unsigned int N, unsigned int OFFS = 0, typename T, int NB>
0077 inline void l1pf_pattern_unpack_slim(const ap_uint<NB> data[], T objs[N]) {
0078 #ifdef __SYNTHESIS__
0079 #pragma HLS inline
0080 #pragma HLS inline region recursive
0081 #endif
0082   assert(T::BITWIDTH_SLIM <= NB);
0083   for (unsigned int i = 0; i < N; ++i) {
0084 #ifdef __SYNTHESIS__
0085 #pragma HLS unroll
0086 #endif
0087     objs[i] = T::unpack(data[i + OFFS]);
0088   }
0089 }
0090 
0091 #endif