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