| #include "edge-impulse-sdk/dsp/config.hpp" |
| #if EIDSP_LOAD_CMSIS_DSP_SOURCES |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "edge-impulse-sdk/CMSIS/DSP/Include/dsp/statistics_functions.h" |
| #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE) |
| #include <limits.h> |
| #endif |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) |
| void arm_max_f32( |
| const float32_t * pSrc, |
| uint32_t blockSize, |
| float32_t * pResult, |
| uint32_t * pIndex) |
| { |
| uint32_t blkCnt; |
| f32x4_t vecSrc; |
| f32x4_t curExtremValVec = vdupq_n_f32(F32_MIN); |
| float32_t maxValue = F32_MIN; |
| uint32_t idx = blockSize; |
| uint32x4_t indexVec; |
| uint32x4_t curExtremIdxVec; |
| uint32_t curIdx = 0; |
| mve_pred16_t p0; |
| float32_t tmp; |
|
|
|
|
| indexVec = vidupq_wb_u32(&curIdx, 1); |
| curExtremIdxVec = vdupq_n_u32(0); |
|
|
| |
| blkCnt = blockSize >> 2U; |
| while (blkCnt > 0U) |
| { |
| vecSrc = vldrwq_f32(pSrc); |
| |
| |
| |
| |
| p0 = vcmpgeq(vecSrc, curExtremValVec); |
| curExtremValVec = vpselq(vecSrc, curExtremValVec, p0); |
| curExtremIdxVec = vpselq(indexVec, curExtremIdxVec, p0); |
|
|
| indexVec = vidupq_wb_u32(&curIdx, 1); |
|
|
| pSrc += 4; |
| |
| blkCnt--; |
| } |
|
|
|
|
| |
| |
| |
| maxValue = vmaxnmvq(maxValue, curExtremValVec); |
| |
| |
| |
| p0 = vcmpgeq(curExtremValVec, maxValue); |
| indexVec = vpselq(curExtremIdxVec, vdupq_n_u32(blockSize), p0); |
| |
| |
| |
| idx = vminvq(idx, indexVec); |
|
|
| |
| blkCnt = blockSize & 0x3; |
|
|
| while (blkCnt > 0U) |
| { |
| |
| tmp = *pSrc++; |
|
|
| |
| if (maxValue < tmp) |
| { |
| |
| maxValue = tmp; |
| idx = blockSize - blkCnt; |
| } |
|
|
| |
| blkCnt--; |
| } |
|
|
| |
| |
| |
| *pIndex = idx; |
| *pResult = maxValue; |
| } |
|
|
| #else |
| #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE) |
| void arm_max_f32( |
| const float32_t * pSrc, |
| uint32_t blockSize, |
| float32_t * pResult, |
| uint32_t * pIndex) |
| { |
| float32_t maxVal1, out; |
| uint32_t blkCnt, outIndex; |
|
|
| float32x4_t outV, srcV; |
| float32x2_t outV2; |
|
|
| uint32x4_t idxV; |
| uint32x4_t maxIdx; |
| static const uint32_t indexInit[4]={4,5,6,7}; |
| static const uint32_t countVInit[4]={0,1,2,3}; |
|
|
| uint32x4_t index; |
| uint32x4_t delta; |
| uint32x4_t countV; |
| uint32x2_t countV2; |
|
|
| maxIdx = vdupq_n_u32(UINT_MAX); |
| delta = vdupq_n_u32(4); |
| index = vld1q_u32(indexInit); |
| countV = vld1q_u32(countVInit); |
|
|
|
|
| |
| outIndex = 0U; |
|
|
| |
| if (blockSize <= 3) |
| { |
| out = *pSrc++; |
|
|
| blkCnt = blockSize - 1; |
|
|
| while (blkCnt > 0U) |
| { |
| |
| maxVal1 = *pSrc++; |
| |
| |
| if (out < maxVal1) |
| { |
| |
| out = maxVal1; |
| outIndex = blockSize - blkCnt; |
| } |
| |
| |
| blkCnt--; |
| } |
| } |
| else |
| { |
| outV = vld1q_f32(pSrc); |
| pSrc += 4; |
| |
| |
| blkCnt = (blockSize - 4 ) >> 2U; |
| |
| while (blkCnt > 0U) |
| { |
| srcV = vld1q_f32(pSrc); |
| pSrc += 4; |
| |
| idxV = vcgtq_f32(srcV, outV); |
| outV = vbslq_f32(idxV, srcV, outV ); |
| countV = vbslq_u32(idxV, index,countV ); |
| |
| index = vaddq_u32(index,delta); |
| |
| |
| blkCnt--; |
| } |
| |
| outV2 = vpmax_f32(vget_low_f32(outV),vget_high_f32(outV)); |
| outV2 = vpmax_f32(outV2,outV2); |
| out = vget_lane_f32(outV2, 0); |
| |
| idxV = vceqq_f32(outV, vdupq_n_f32(out)); |
| countV = vbslq_u32(idxV, countV,maxIdx); |
| |
| countV2 = vpmin_u32(vget_low_u32(countV),vget_high_u32(countV)); |
| countV2 = vpmin_u32(countV2,countV2); |
| outIndex = vget_lane_u32(countV2,0); |
| |
| |
| blkCnt = (blockSize - 4 ) % 4U; |
| |
| while (blkCnt > 0U) |
| { |
| |
| maxVal1 = *pSrc++; |
| |
| |
| if (out < maxVal1) |
| { |
| |
| out = maxVal1; |
| outIndex = blockSize - blkCnt ; |
| } |
| |
| |
| blkCnt--; |
| } |
| |
| |
| } |
|
|
| |
| *pResult = out; |
| *pIndex = outIndex; |
| } |
| #else |
| void arm_max_f32( |
| const float32_t * pSrc, |
| uint32_t blockSize, |
| float32_t * pResult, |
| uint32_t * pIndex) |
| { |
| float32_t maxVal, out; |
| uint32_t blkCnt, outIndex; |
|
|
| #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE) |
| uint32_t index; |
| #endif |
|
|
| |
| outIndex = 0U; |
|
|
| |
| out = *pSrc++; |
|
|
| #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE) |
| |
| index = 0U; |
|
|
| |
| blkCnt = (blockSize - 1U) >> 2U; |
|
|
| while (blkCnt > 0U) |
| { |
| |
| maxVal = *pSrc++; |
|
|
| |
| if (out < maxVal) |
| { |
| |
| out = maxVal; |
| outIndex = index + 1U; |
| } |
|
|
| maxVal = *pSrc++; |
| if (out < maxVal) |
| { |
| out = maxVal; |
| outIndex = index + 2U; |
| } |
|
|
| maxVal = *pSrc++; |
| if (out < maxVal) |
| { |
| out = maxVal; |
| outIndex = index + 3U; |
| } |
|
|
| maxVal = *pSrc++; |
| if (out < maxVal) |
| { |
| out = maxVal; |
| outIndex = index + 4U; |
| } |
|
|
| index += 4U; |
|
|
| |
| blkCnt--; |
| } |
|
|
| |
| blkCnt = (blockSize - 1U) % 4U; |
|
|
| #else |
|
|
| |
| blkCnt = (blockSize - 1U); |
|
|
| #endif |
|
|
| while (blkCnt > 0U) |
| { |
| |
| maxVal = *pSrc++; |
|
|
| |
| if (out < maxVal) |
| { |
| |
| out = maxVal; |
| outIndex = blockSize - blkCnt; |
| } |
|
|
| |
| blkCnt--; |
| } |
|
|
| |
| *pResult = out; |
| *pIndex = outIndex; |
| } |
| #endif |
| #endif |
|
|
| |
| |
| |
|
|
| #endif |
|
|