7084058e0c0c135e1782eaa4ea8916e4c7f63ac3
[o-du/phy.git] / fhi_lib / lib / api / xran_compression.hpp
1 /******************************************************************************\r
2 *\r
3 *   Copyright (c) 2019 Intel.\r
4 *\r
5 *   Licensed under the Apache License, Version 2.0 (the "License");\r
6 *   you may not use this file except in compliance with the License.\r
7 *   You may obtain a copy of the License at\r
8 *\r
9 *       http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 *   Unless required by applicable law or agreed to in writing, software\r
12 *   distributed under the License is distributed on an "AS IS" BASIS,\r
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 *   See the License for the specific language governing permissions and\r
15 *   limitations under the License.\r
16 *\r
17 *******************************************************************************/\r
18 \r
19 #pragma once\r
20 #include <stdint.h>\r
21 \r
22 // This configuration file sets global constants and macros which are\r
23 // of general use throughout the project.\r
24 \r
25 // All current IA processors of interest align their cache lines on\r
26 // this boundary. If the cache alignment for future processors changes\r
27 // then the most restrictive alignment should be set.\r
28 constexpr unsigned k_cacheByteAlignment = 64;\r
29 \r
30 // Force the data to which this macro is applied to be aligned on a cache line.\r
31 // For example:\r
32 //\r
33 // CACHE_ALIGNED float data[64];\r
34 #define CACHE_ALIGNED alignas(k_cacheByteAlignment)\r
35 \r
36 // Hint to the compiler that the data to which this macro is applied\r
37 // can be assumed to be aligned to a cache line. This allows the\r
38 // compiler to generate improved code by using aligned reads and\r
39 // writes.\r
40 #define ASSUME_CACHE_ALIGNED(data) __assume_aligned(data, k_cacheByteAlignment);\r
41 \r
42 /// Intel compiler frequently complains about templates not being declared in an external\r
43 /// header. Templates are used throughout this project's source files to define local type-specific\r
44 /// versions of functions. Defining every one of these in a header is unnecessary, so the warnings\r
45 /// about this are turned off globally.\r
46 #pragma warning(disable:1418)\r
47 #pragma warning(disable:1419)\r
48 \r
49 \r
50 namespace BlockFloatCompander\r
51 {\r
52   /// Compute 32 RB at a time\r
53   static constexpr int k_numBitsIQ = 16;\r
54   static constexpr int k_numRB = 16;\r
55   static constexpr int k_numRE = 12;\r
56   static constexpr int k_numREReal = k_numRE * 2;\r
57   static constexpr int k_numSampsExpanded = k_numRB * k_numREReal;\r
58   static constexpr int k_numSampsCompressed = (k_numSampsExpanded * 2) + k_numRB;\r
59 \r
60   struct CompressedData\r
61   {\r
62     /// Compressed data\r
63     CACHE_ALIGNED uint8_t dataCompressedDataOut[k_numSampsCompressed];\r
64     CACHE_ALIGNED uint8_t *dataCompressed;\r
65     /// Size of mantissa including sign bit\r
66     int iqWidth;\r
67   };\r
68 \r
69   struct ExpandedData\r
70   {\r
71     /// Expanded data or input data to compressor\r
72     CACHE_ALIGNED int16_t dataExpandedIn[k_numSampsExpanded];\r
73     CACHE_ALIGNED int16_t *dataExpanded;\r
74 \r
75     /// Size of mantissa including sign bit\r
76     int iqWidth;\r
77   };\r
78 \r
79   void BlockFloatCompress_Basic(const ExpandedData& dataIn, CompressedData* dataOut);\r
80   void BlockFloatCompress_8b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
81   void BlockFloatCompress_9b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
82   void BlockFloatCompress_10b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
83   void BlockFloatCompress_12b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
84 \r
85   void BlockFloatExpand_Basic(const CompressedData& dataIn, ExpandedData* dataOut);\r
86   void BlockFloatExpand_8b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
87   void BlockFloatExpand_9b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
88   void BlockFloatExpand_10b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
89   void BlockFloatExpand_12b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
90 }\r
91 \r
92 namespace BlockFloatCompanderBFW\r
93 {\r
94   /// Compute 32 RB at a time\r
95   static constexpr int k_numBitsIQ = 16;\r
96   static constexpr int k_numRB = 1;\r
97   static constexpr int k_numRE = 32;\r
98   static constexpr int k_numREReal = k_numRE * 2;\r
99   static constexpr int k_numSampsExpanded = k_numRB * k_numREReal;\r
100   static constexpr int k_numSampsCompressed = (k_numSampsExpanded * 2) + k_numRB;\r
101 \r
102   struct CompressedData\r
103   {\r
104     /// Compressed data\r
105     CACHE_ALIGNED uint8_t dataCompressedDataOut[k_numSampsCompressed];\r
106     CACHE_ALIGNED uint8_t *dataCompressed;\r
107     /// Size of mantissa including sign bit\r
108     int iqWidth;\r
109   };\r
110 \r
111   struct ExpandedData\r
112   {\r
113     /// Expanded data or input data to compressor\r
114     CACHE_ALIGNED int16_t dataExpandedIn[k_numSampsExpanded];\r
115     CACHE_ALIGNED int16_t *dataExpanded;\r
116 \r
117     /// Size of mantissa including sign bit\r
118     int iqWidth;\r
119   };\r
120 \r
121   void BlockFloatCompress_Basic(const ExpandedData& dataIn, CompressedData* dataOut);\r
122 /*  void BlockFloatCompress_8b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
123   void BlockFloatCompress_9b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
124   void BlockFloatCompress_10b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut);\r
125   void BlockFloatCompress_12b_AVX512(const ExpandedData& dataIn, CompressedData* dataOut); */\r
126 \r
127   void BlockFloatExpand_Basic(const CompressedData& dataIn, ExpandedData* dataOut);\r
128 /*  void BlockFloatExpand_8b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
129   void BlockFloatExpand_9b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
130   void BlockFloatExpand_10b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);\r
131   void BlockFloatExpand_12b_AVX512(const CompressedData& dataIn, ExpandedData* dataOut);*/\r
132 }\r
133 \r