Update to odulow per maintenance bronze
[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 #include <immintrin.h>
22
23 // This configuration file sets global constants and macros which are
24 // of general use throughout the project.
25
26 // All current IA processors of interest align their cache lines on
27 // this boundary. If the cache alignment for future processors changes
28 // then the most restrictive alignment should be set.
29 constexpr unsigned k_cacheByteAlignment = 64;
30
31 // Force the data to which this macro is applied to be aligned on a cache line.
32 // For example:
33 //
34 // CACHE_ALIGNED float data[64];
35 #define CACHE_ALIGNED alignas(k_cacheByteAlignment)
36
37 // Hint to the compiler that the data to which this macro is applied
38 // can be assumed to be aligned to a cache line. This allows the
39 // compiler to generate improved code by using aligned reads and
40 // writes.
41 #define ASSUME_CACHE_ALIGNED(data)
42 // __assume_aligned(data, k_cacheByteAlignment);
43
44 /// Intel compiler frequently complains about templates not being declared in an external
45 /// header. Templates are used throughout this project's source files to define local type-specific
46 /// versions of functions. Defining every one of these in a header is unnecessary, so the warnings
47 /// about this are turned off globally.
48 #pragma warning(disable:1418)
49 #pragma warning(disable:1419)
50
51
52 namespace BlockFloatCompander
53 {
54   /// Compute 32 RB at a time
55   static constexpr int k_numBitsIQ = 16;
56   static constexpr int k_numBitsIQPair = 2 * k_numBitsIQ;
57   static constexpr int k_maxNumBlocks = 16;
58   static constexpr int k_maxNumElements = 128;
59   static constexpr int k_numSampsExpanded = k_maxNumBlocks * k_maxNumElements;
60   static constexpr int k_numSampsCompressed = (k_numSampsExpanded * 2) + k_maxNumBlocks;
61
62   struct CompressedData
63   {
64     /// Compressed data
65     CACHE_ALIGNED uint8_t dataCompressedDataOut[k_numSampsCompressed];
66     CACHE_ALIGNED uint8_t *dataCompressed;
67     /// Size of mantissa including sign bit
68     int iqWidth;
69
70     /// Number of BFP blocks in message
71     int numBlocks;
72
73     /// Number of data elements per compression block (only required for reference function)
74     int numDataElements;
75   };
76
77   struct ExpandedData
78   {
79     /// Expanded data or input data to compressor
80     CACHE_ALIGNED int16_t dataExpandedIn[k_numSampsExpanded];
81     CACHE_ALIGNED int16_t *dataExpanded;
82
83     /// Size of mantissa including sign bit
84     int iqWidth;
85
86     /// Number of BFP blocks in message
87     int numBlocks;
88
89     /// Number of data elements per compression block (only required for reference function)
90     int numDataElements;
91   };
92
93   /// Reference compression and expansion functions
94   void BFPCompressRef(const ExpandedData& dataIn, CompressedData* dataOut);
95   void BFPExpandRef(const CompressedData& dataIn, ExpandedData* dataOut);
96
97   /// User-Plane specific compression and expansion functions
98   void BFPCompressUserPlaneAvx512(const ExpandedData& dataIn, CompressedData* dataOut);
99   void BFPExpandUserPlaneAvx512(const CompressedData& dataIn, ExpandedData* dataOut);
100
101   /// Control-Plane specific compression and expansion functions for 8 antennas
102   void BFPCompressCtrlPlane8Avx512(const ExpandedData& dataIn, CompressedData* dataOut);
103   void BFPExpandCtrlPlane8Avx512(const CompressedData& dataIn, ExpandedData* dataOut);
104
105   /// Control-Plane specific compression and expansion functions for 16 antennas
106   void BFPCompressCtrlPlane16Avx512(const ExpandedData& dataIn, CompressedData* dataOut);
107   void BFPExpandCtrlPlane16Avx512(const CompressedData& dataIn, ExpandedData* dataOut);
108
109   /// Control-Plane specific compression and expansion functions for 32 antennas
110   void BFPCompressCtrlPlane32Avx512(const ExpandedData& dataIn, CompressedData* dataOut);
111   void BFPExpandCtrlPlane32Avx512(const CompressedData& dataIn, ExpandedData* dataOut);
112
113   /// Control-Plane specific compression and expansion functions for 64 antennas
114   void BFPCompressCtrlPlane64Avx512(const ExpandedData& dataIn, CompressedData* dataOut);
115   void BFPExpandCtrlPlane64Avx512(const CompressedData& dataIn, ExpandedData* dataOut);
116 }
117