Aded CMSIS5 DSP and NN folder. Needs some work

Committer:
robert_lp
Date:
Thu Apr 12 01:31:58 2018 +0000
Revision:
0:eedb7d567a5d
CMSIS5 Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robert_lp 0:eedb7d567a5d 1 /* ----------------------------------------------------------------------
robert_lp 0:eedb7d567a5d 2 * Project: CMSIS DSP Library
robert_lp 0:eedb7d567a5d 3 * Title: arm_min_f32.c
robert_lp 0:eedb7d567a5d 4 * Description: Minimum value of a floating-point vector
robert_lp 0:eedb7d567a5d 5 *
robert_lp 0:eedb7d567a5d 6 * $Date: 27. January 2017
robert_lp 0:eedb7d567a5d 7 * $Revision: V.1.5.1
robert_lp 0:eedb7d567a5d 8 *
robert_lp 0:eedb7d567a5d 9 * Target Processor: Cortex-M cores
robert_lp 0:eedb7d567a5d 10 * -------------------------------------------------------------------- */
robert_lp 0:eedb7d567a5d 11 /*
robert_lp 0:eedb7d567a5d 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
robert_lp 0:eedb7d567a5d 13 *
robert_lp 0:eedb7d567a5d 14 * SPDX-License-Identifier: Apache-2.0
robert_lp 0:eedb7d567a5d 15 *
robert_lp 0:eedb7d567a5d 16 * Licensed under the Apache License, Version 2.0 (the License); you may
robert_lp 0:eedb7d567a5d 17 * not use this file except in compliance with the License.
robert_lp 0:eedb7d567a5d 18 * You may obtain a copy of the License at
robert_lp 0:eedb7d567a5d 19 *
robert_lp 0:eedb7d567a5d 20 * www.apache.org/licenses/LICENSE-2.0
robert_lp 0:eedb7d567a5d 21 *
robert_lp 0:eedb7d567a5d 22 * Unless required by applicable law or agreed to in writing, software
robert_lp 0:eedb7d567a5d 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
robert_lp 0:eedb7d567a5d 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
robert_lp 0:eedb7d567a5d 25 * See the License for the specific language governing permissions and
robert_lp 0:eedb7d567a5d 26 * limitations under the License.
robert_lp 0:eedb7d567a5d 27 */
robert_lp 0:eedb7d567a5d 28
robert_lp 0:eedb7d567a5d 29 #include "arm_math.h"
robert_lp 0:eedb7d567a5d 30
robert_lp 0:eedb7d567a5d 31 /**
robert_lp 0:eedb7d567a5d 32 * @ingroup groupStats
robert_lp 0:eedb7d567a5d 33 */
robert_lp 0:eedb7d567a5d 34
robert_lp 0:eedb7d567a5d 35 /**
robert_lp 0:eedb7d567a5d 36 * @defgroup Min Minimum
robert_lp 0:eedb7d567a5d 37 *
robert_lp 0:eedb7d567a5d 38 * Computes the minimum value of an array of data.
robert_lp 0:eedb7d567a5d 39 * The function returns both the minimum value and its position within the array.
robert_lp 0:eedb7d567a5d 40 * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
robert_lp 0:eedb7d567a5d 41 */
robert_lp 0:eedb7d567a5d 42
robert_lp 0:eedb7d567a5d 43 /**
robert_lp 0:eedb7d567a5d 44 * @addtogroup Min
robert_lp 0:eedb7d567a5d 45 * @{
robert_lp 0:eedb7d567a5d 46 */
robert_lp 0:eedb7d567a5d 47
robert_lp 0:eedb7d567a5d 48
robert_lp 0:eedb7d567a5d 49 /**
robert_lp 0:eedb7d567a5d 50 * @brief Minimum value of a floating-point vector.
robert_lp 0:eedb7d567a5d 51 * @param[in] *pSrc points to the input vector
robert_lp 0:eedb7d567a5d 52 * @param[in] blockSize length of the input vector
robert_lp 0:eedb7d567a5d 53 * @param[out] *pResult minimum value returned here
robert_lp 0:eedb7d567a5d 54 * @param[out] *pIndex index of minimum value returned here
robert_lp 0:eedb7d567a5d 55 * @return none.
robert_lp 0:eedb7d567a5d 56 */
robert_lp 0:eedb7d567a5d 57
robert_lp 0:eedb7d567a5d 58 void arm_min_f32(
robert_lp 0:eedb7d567a5d 59 float32_t * pSrc,
robert_lp 0:eedb7d567a5d 60 uint32_t blockSize,
robert_lp 0:eedb7d567a5d 61 float32_t * pResult,
robert_lp 0:eedb7d567a5d 62 uint32_t * pIndex)
robert_lp 0:eedb7d567a5d 63 {
robert_lp 0:eedb7d567a5d 64 #if defined (ARM_MATH_DSP)
robert_lp 0:eedb7d567a5d 65 /* Run the below code for Cortex-M4 and Cortex-M3 */
robert_lp 0:eedb7d567a5d 66
robert_lp 0:eedb7d567a5d 67 float32_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
robert_lp 0:eedb7d567a5d 68 uint32_t blkCnt, outIndex, count; /* loop counter */
robert_lp 0:eedb7d567a5d 69
robert_lp 0:eedb7d567a5d 70 /* Initialise the count value. */
robert_lp 0:eedb7d567a5d 71 count = 0U;
robert_lp 0:eedb7d567a5d 72 /* Initialise the index value to zero. */
robert_lp 0:eedb7d567a5d 73 outIndex = 0U;
robert_lp 0:eedb7d567a5d 74 /* Load first input value that act as reference value for comparision */
robert_lp 0:eedb7d567a5d 75 out = *pSrc++;
robert_lp 0:eedb7d567a5d 76
robert_lp 0:eedb7d567a5d 77 /* Loop unrolling */
robert_lp 0:eedb7d567a5d 78 blkCnt = (blockSize - 1U) >> 2U;
robert_lp 0:eedb7d567a5d 79
robert_lp 0:eedb7d567a5d 80 while (blkCnt > 0U)
robert_lp 0:eedb7d567a5d 81 {
robert_lp 0:eedb7d567a5d 82 /* Initialize minVal to the next consecutive values one by one */
robert_lp 0:eedb7d567a5d 83 minVal1 = *pSrc++;
robert_lp 0:eedb7d567a5d 84 minVal2 = *pSrc++;
robert_lp 0:eedb7d567a5d 85
robert_lp 0:eedb7d567a5d 86 /* compare for the minimum value */
robert_lp 0:eedb7d567a5d 87 if (out > minVal1)
robert_lp 0:eedb7d567a5d 88 {
robert_lp 0:eedb7d567a5d 89 /* Update the minimum value and its index */
robert_lp 0:eedb7d567a5d 90 out = minVal1;
robert_lp 0:eedb7d567a5d 91 outIndex = count + 1U;
robert_lp 0:eedb7d567a5d 92 }
robert_lp 0:eedb7d567a5d 93
robert_lp 0:eedb7d567a5d 94 /* compare for the minimum value */
robert_lp 0:eedb7d567a5d 95 if (out > minVal2)
robert_lp 0:eedb7d567a5d 96 {
robert_lp 0:eedb7d567a5d 97 /* Update the minimum value and its index */
robert_lp 0:eedb7d567a5d 98 out = minVal2;
robert_lp 0:eedb7d567a5d 99 outIndex = count + 2U;
robert_lp 0:eedb7d567a5d 100 }
robert_lp 0:eedb7d567a5d 101
robert_lp 0:eedb7d567a5d 102 /* Initialize minVal to the next consecutive values one by one */
robert_lp 0:eedb7d567a5d 103 minVal1 = *pSrc++;
robert_lp 0:eedb7d567a5d 104 minVal2 = *pSrc++;
robert_lp 0:eedb7d567a5d 105
robert_lp 0:eedb7d567a5d 106 /* compare for the minimum value */
robert_lp 0:eedb7d567a5d 107 if (out > minVal1)
robert_lp 0:eedb7d567a5d 108 {
robert_lp 0:eedb7d567a5d 109 /* Update the minimum value and its index */
robert_lp 0:eedb7d567a5d 110 out = minVal1;
robert_lp 0:eedb7d567a5d 111 outIndex = count + 3U;
robert_lp 0:eedb7d567a5d 112 }
robert_lp 0:eedb7d567a5d 113
robert_lp 0:eedb7d567a5d 114 /* compare for the minimum value */
robert_lp 0:eedb7d567a5d 115 if (out > minVal2)
robert_lp 0:eedb7d567a5d 116 {
robert_lp 0:eedb7d567a5d 117 /* Update the minimum value and its index */
robert_lp 0:eedb7d567a5d 118 out = minVal2;
robert_lp 0:eedb7d567a5d 119 outIndex = count + 4U;
robert_lp 0:eedb7d567a5d 120 }
robert_lp 0:eedb7d567a5d 121
robert_lp 0:eedb7d567a5d 122 count += 4U;
robert_lp 0:eedb7d567a5d 123
robert_lp 0:eedb7d567a5d 124 /* Decrement the loop counter */
robert_lp 0:eedb7d567a5d 125 blkCnt--;
robert_lp 0:eedb7d567a5d 126 }
robert_lp 0:eedb7d567a5d 127
robert_lp 0:eedb7d567a5d 128 /* if (blockSize - 1U) is not multiple of 4 */
robert_lp 0:eedb7d567a5d 129 blkCnt = (blockSize - 1U) % 4U;
robert_lp 0:eedb7d567a5d 130
robert_lp 0:eedb7d567a5d 131 #else
robert_lp 0:eedb7d567a5d 132 /* Run the below code for Cortex-M0 */
robert_lp 0:eedb7d567a5d 133
robert_lp 0:eedb7d567a5d 134 float32_t minVal1, out; /* Temporary variables to store the output value. */
robert_lp 0:eedb7d567a5d 135 uint32_t blkCnt, outIndex; /* loop counter */
robert_lp 0:eedb7d567a5d 136
robert_lp 0:eedb7d567a5d 137 /* Initialise the index value to zero. */
robert_lp 0:eedb7d567a5d 138 outIndex = 0U;
robert_lp 0:eedb7d567a5d 139 /* Load first input value that act as reference value for comparision */
robert_lp 0:eedb7d567a5d 140 out = *pSrc++;
robert_lp 0:eedb7d567a5d 141
robert_lp 0:eedb7d567a5d 142 blkCnt = (blockSize - 1U);
robert_lp 0:eedb7d567a5d 143
robert_lp 0:eedb7d567a5d 144 #endif /* #if defined (ARM_MATH_DSP) */
robert_lp 0:eedb7d567a5d 145
robert_lp 0:eedb7d567a5d 146 while (blkCnt > 0U)
robert_lp 0:eedb7d567a5d 147 {
robert_lp 0:eedb7d567a5d 148 /* Initialize minVal to the next consecutive values one by one */
robert_lp 0:eedb7d567a5d 149 minVal1 = *pSrc++;
robert_lp 0:eedb7d567a5d 150
robert_lp 0:eedb7d567a5d 151 /* compare for the minimum value */
robert_lp 0:eedb7d567a5d 152 if (out > minVal1)
robert_lp 0:eedb7d567a5d 153 {
robert_lp 0:eedb7d567a5d 154 /* Update the minimum value and it's index */
robert_lp 0:eedb7d567a5d 155 out = minVal1;
robert_lp 0:eedb7d567a5d 156 outIndex = blockSize - blkCnt;
robert_lp 0:eedb7d567a5d 157 }
robert_lp 0:eedb7d567a5d 158
robert_lp 0:eedb7d567a5d 159 /* Decrement the loop counter */
robert_lp 0:eedb7d567a5d 160 blkCnt--;
robert_lp 0:eedb7d567a5d 161 }
robert_lp 0:eedb7d567a5d 162
robert_lp 0:eedb7d567a5d 163 /* Store the minimum value and it's index into destination pointers */
robert_lp 0:eedb7d567a5d 164 *pResult = out;
robert_lp 0:eedb7d567a5d 165 *pIndex = outIndex;
robert_lp 0:eedb7d567a5d 166 }
robert_lp 0:eedb7d567a5d 167
robert_lp 0:eedb7d567a5d 168 /**
robert_lp 0:eedb7d567a5d 169 * @} end of Min group
robert_lp 0:eedb7d567a5d 170 */
robert_lp 0:eedb7d567a5d 171