+ const __m512i* rawData = reinterpret_cast<const __m512i*>(dataIn.dataExpanded);
+ /// Re-order and vertical max abs
+ const auto maxAbsVert = maxAbsVertical4RB(rawData[0], rawData[1], rawData[2]);
+ /// Horizontal max abs
+ const auto maxAbsHorz = horizontalMax4x16(maxAbsVert);
+ /// Calculate exponent
+ const auto maxAbs = BlockFloatCompander::maskUpperWord(maxAbsHorz);
+ return BlockFloatCompander::expLzCnt(maxAbs, totShiftBits);
+ }
+
+
+ /// Compute exponent value for 1 RB from the maximum absolute value.
+ /// This works with horizontal max abs only, and needs to include a
+ /// step to select the final exponent from the 4 lanes.
+ uint8_t
+ computeExponent_1RB(const BlockFloatCompander::ExpandedData& dataIn, const __m512i totShiftBits)
+ {
+ const __m512i* rawData = reinterpret_cast<const __m512i*>(dataIn.dataExpanded);
+ /// Abs
+ const auto rawDataAbs = _mm512_abs_epi16(rawData[0]);
+ /// No need to do a full horizontal max operation here, just do a max IQ step,
+ /// compute the exponents and then use a reduce max over all exponent values. This
+ /// is the fastest way to handle a single RB.
+ const auto rawAbsIQSwap = _mm512_rol_epi32(rawDataAbs, BlockFloatCompander::k_numBitsIQ);
+ const auto maxAbsIQ = _mm512_max_epi16(rawDataAbs, rawAbsIQSwap);
+ /// Calculate exponent
+ const auto maxAbsIQ32 = BlockFloatCompander::maskUpperWord(maxAbsIQ);
+ const auto exps = BlockFloatCompander::expLzCnt(maxAbsIQ32, totShiftBits);
+ /// At this point we have exponent values for the maximum of each IQ pair.
+ /// Run a reduce max step to compute the maximum exponent value in the first
+ /// three lanes - this will give the desired exponent for this RB.
+ constexpr uint16_t k_expMsk = 0x0FFF;
+ return (uint8_t)_mm512_mask_reduce_max_epi32(k_expMsk, exps);
+ }
+
+
+ /// Apply compression to 1 RB
+ template<BlockFloatCompander::PackFunction networkBytePack>
+ void
+ applyCompressionN_1RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const int numREOffset, const uint8_t thisExp, const int thisRBExpAddr, const uint16_t rbWriteMask)
+ {
+ /// Get AVX512 pointer aligned to desired RB
+ const __m512i* rawDataIn = reinterpret_cast<const __m512i*>(dataIn.dataExpanded + numREOffset);
+ /// Apply the exponent shift
+ const auto compData = _mm512_srai_epi16(*rawDataIn, thisExp);
+ /// Pack compressed data network byte order
+ const auto compDataBytePacked = networkBytePack(compData);
+ /// Store exponent first
+ dataOut->dataCompressed[thisRBExpAddr] = thisExp;
+ /// Now have 1 RB worth of bytes separated into 3 chunks (1 per lane)
+ /// Use three offset stores to join
+ _mm_mask_storeu_epi8(dataOut->dataCompressed + thisRBExpAddr + 1, rbWriteMask, _mm512_extracti64x2_epi64(compDataBytePacked, 0));
+ _mm_mask_storeu_epi8(dataOut->dataCompressed + thisRBExpAddr + 1 + dataIn.iqWidth, rbWriteMask, _mm512_extracti64x2_epi64(compDataBytePacked, 1));
+ _mm_mask_storeu_epi8(dataOut->dataCompressed + thisRBExpAddr + 1 + (2 * dataIn.iqWidth), rbWriteMask, _mm512_extracti64x2_epi64(compDataBytePacked, 2));
+ }
+
+
+ /// Apply 9, 10, or 12bit compression to 16 RB
+ template<BlockFloatCompander::PackFunction networkBytePack>
+ void
+ compressN_16RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const __m512i totShiftBits, const int totNumBytesPerRB, const uint16_t rbWriteMask)
+ {
+ const auto exponents = computeExponent_16RB(dataIn, totShiftBits);
+#pragma unroll(16)
+ for (int n = 0; n < 16; ++n)
+ {
+ applyCompressionN_1RB<networkBytePack>(dataIn, dataOut, n * k_numREReal, ((uint8_t*)&exponents)[n * 4], n * totNumBytesPerRB, rbWriteMask);
+ }
+ }
+
+
+ /// Apply 9, 10, or 12bit compression to 4 RB
+ template<BlockFloatCompander::PackFunction networkBytePack>
+ void
+ compressN_4RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const __m512i totShiftBits, const int totNumBytesPerRB, const uint16_t rbWriteMask)
+ {
+ const auto exponents = computeExponent_4RB(dataIn, totShiftBits);
+#pragma unroll(4)
+ for (int n = 0; n < 4; ++n)
+ {
+ applyCompressionN_1RB<networkBytePack>(dataIn, dataOut, n * k_numREReal, ((uint8_t*)&exponents)[n * 16], n * totNumBytesPerRB, rbWriteMask);
+ }
+ }
+
+
+ /// Apply 9, 10, or 12bit compression to 1 RB
+ template<BlockFloatCompander::PackFunction networkBytePack>
+ void
+ compressN_1RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const __m512i totShiftBits, const int totNumBytesPerRB, const uint16_t rbWriteMask)
+ {
+ const auto thisExponent = computeExponent_1RB(dataIn, totShiftBits);
+ applyCompressionN_1RB<networkBytePack>(dataIn, dataOut, 0, thisExponent, 0, rbWriteMask);
+ }
+
+
+ /// Calls compression function specific to the number of RB to be executed. For 9, 10, or 12bit iqWidth.
+ template<BlockFloatCompander::PackFunction networkBytePack>
+ void
+ compressByAllocN(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const __m512i totShiftBits, const int totNumBytesPerRB, const uint16_t rbWriteMask)
+ {
+ switch (dataIn.numBlocks)
+ {
+ case 16:
+ compressN_16RB<networkBytePack>(dataIn, dataOut, totShiftBits, totNumBytesPerRB, rbWriteMask);
+ break;
+
+ case 4:
+ compressN_4RB<networkBytePack>(dataIn, dataOut, totShiftBits, totNumBytesPerRB, rbWriteMask);
+ break;
+
+ case 1:
+ compressN_1RB<networkBytePack>(dataIn, dataOut, totShiftBits, totNumBytesPerRB, rbWriteMask);
+ break;
+ }
+ }
+
+
+ /// Apply compression to 1 RB
+ void
+ applyCompression8_1RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut,
+ const int numREOffset, const uint8_t thisExp, const int thisRBExpAddr)
+ {
+ /// Get AVX512 pointer aligned to desired RB
+ const __m512i* rawDataIn = reinterpret_cast<const __m512i*>(dataIn.dataExpanded + numREOffset);
+ /// Apply the exponent shift
+ const auto compData = _mm512_srai_epi16(*rawDataIn, thisExp);
+ /// Store exponent first
+ dataOut->dataCompressed[thisRBExpAddr] = thisExp;
+ /// Now have 1 RB worth of bytes separated into 3 chunks (1 per lane)
+ /// Use three offset stores to join
+ constexpr uint32_t k_rbMask = 0x00FFFFFF; // Write mask for 1RB (24 values)
+ _mm256_mask_storeu_epi8(dataOut->dataCompressed + thisRBExpAddr + 1, k_rbMask, _mm512_cvtepi16_epi8(compData));
+ }
+
+
+ /// 8bit RB compression loop for 16 RB
+ void
+ compress8_16RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut, const __m512i totShiftBits)
+ {
+ const auto exponents = computeExponent_16RB(dataIn, totShiftBits);
+#pragma unroll(16)
+ for (int n = 0; n < 16; ++n)
+ {
+ applyCompression8_1RB(dataIn, dataOut, n * k_numREReal, ((uint8_t*)&exponents)[n * 4], n * (k_numREReal + 1));
+ }
+ }
+
+
+ /// 8bit RB compression loop for 4 RB
+ void
+ compress8_4RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut, const __m512i totShiftBits)
+ {
+ const auto exponents = computeExponent_4RB(dataIn, totShiftBits);
+#pragma unroll(4)
+ for (int n = 0; n < 4; ++n)
+ {
+ applyCompression8_1RB(dataIn, dataOut, n * k_numREReal, ((uint8_t*)&exponents)[n * 16], n * (k_numREReal + 1));
+ }
+ }
+
+
+ /// 8bit RB compression loop for 4 RB
+ void
+ compress8_1RB(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut, const __m512i totShiftBits)
+ {
+ const auto thisExponent = computeExponent_1RB(dataIn, totShiftBits);
+ applyCompression8_1RB(dataIn, dataOut, 0, thisExponent, 0);
+ }
+
+
+ /// Calls compression function specific to the number of RB to be executed. For 8 bit iqWidth.
+ void
+ compressByAlloc8(const BlockFloatCompander::ExpandedData& dataIn, BlockFloatCompander::CompressedData* dataOut, const __m512i totShiftBits)
+ {
+ switch (dataIn.numBlocks)
+ {
+ case 16:
+ compress8_16RB(dataIn, dataOut, totShiftBits);
+ break;
+
+ case 4:
+ compress8_4RB(dataIn, dataOut, totShiftBits);
+ break;