- /// Selects first 32 bit value in each src lane and packs into laneNum of dest
- __m512i
- slidePermute(const __m512i src, const __m512i dest, const int laneNum)
- {
- const auto k_selectVals = _mm512_set_epi32(28, 24, 20, 16, 28, 24, 20, 16,
- 28, 24, 20, 16, 28, 24, 20, 16);
- constexpr uint16_t k_laneMsk[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 };
- return _mm512_mask_permutex2var_epi32(dest, k_laneMsk[laneNum], k_selectVals, src);
- }
-
-
- /// Compute exponent value for a set of 16 RB from the maximum absolute value.
- /// Max Abs operates in a loop, executing 4 RB per iteration. The results are
- /// packed into the final output register.
- __m512i
- computeExponent_16RB(const BlockFloatCompander::ExpandedData& dataIn, const __m512i totShiftBits)
- {
- __m512i maxAbs = __m512i();
- const __m512i* rawData = reinterpret_cast<const __m512i*>(dataIn.dataExpanded);
- /// Max Abs loop operates on 4RB at a time
-#pragma unroll(4)
- for (int n = 0; n < 4; ++n)
- {
- /// Re-order and vertical max abs
- auto maxAbsVert = maxAbsVertical4RB(rawData[3 * n + 0], rawData[3 * n + 1], rawData[3 * n + 2]);
- /// Horizontal max abs
- auto maxAbsHorz = horizontalMax4x16(maxAbsVert);
- /// Pack these 4 values into maxAbs
- maxAbs = slidePermute(maxAbsHorz, maxAbs, n);
- }
- /// Calculate exponent
- const auto maxAbs32 = BlockFloatCompander::maskUpperWord(maxAbs);
- return BlockFloatCompander::expLzCnt(maxAbs32, totShiftBits);
- }
-
-
- /// Compute exponent value for a set of 4 RB from the maximum absolute value.
- /// Note that we do not need to perform any packing of result as we are only
- /// computing 4 RB. The appropriate offset is taken later when extracting the
- /// exponent.
- __m512i
- computeExponent_4RB(const BlockFloatCompander::ExpandedData& dataIn, const __m512i totShiftBits)
- {
- 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));
- }
- }