The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 1:24714b45cd1b 1 /* ----------------------------------------------------------------------
xorjoep 1:24714b45cd1b 2 * Project: CMSIS DSP Library
xorjoep 1:24714b45cd1b 3 * Title: arm_mat_trans_q15.c
xorjoep 1:24714b45cd1b 4 * Description: Q15 matrix transpose
xorjoep 1:24714b45cd1b 5 *
xorjoep 1:24714b45cd1b 6 * $Date: 27. January 2017
xorjoep 1:24714b45cd1b 7 * $Revision: V.1.5.1
xorjoep 1:24714b45cd1b 8 *
xorjoep 1:24714b45cd1b 9 * Target Processor: Cortex-M cores
xorjoep 1:24714b45cd1b 10 * -------------------------------------------------------------------- */
xorjoep 1:24714b45cd1b 11 /*
xorjoep 1:24714b45cd1b 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
xorjoep 1:24714b45cd1b 13 *
xorjoep 1:24714b45cd1b 14 * SPDX-License-Identifier: Apache-2.0
xorjoep 1:24714b45cd1b 15 *
xorjoep 1:24714b45cd1b 16 * Licensed under the Apache License, Version 2.0 (the License); you may
xorjoep 1:24714b45cd1b 17 * not use this file except in compliance with the License.
xorjoep 1:24714b45cd1b 18 * You may obtain a copy of the License at
xorjoep 1:24714b45cd1b 19 *
xorjoep 1:24714b45cd1b 20 * www.apache.org/licenses/LICENSE-2.0
xorjoep 1:24714b45cd1b 21 *
xorjoep 1:24714b45cd1b 22 * Unless required by applicable law or agreed to in writing, software
xorjoep 1:24714b45cd1b 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
xorjoep 1:24714b45cd1b 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
xorjoep 1:24714b45cd1b 25 * See the License for the specific language governing permissions and
xorjoep 1:24714b45cd1b 26 * limitations under the License.
xorjoep 1:24714b45cd1b 27 */
xorjoep 1:24714b45cd1b 28
xorjoep 1:24714b45cd1b 29 #include "arm_math.h"
xorjoep 1:24714b45cd1b 30
xorjoep 1:24714b45cd1b 31 /**
xorjoep 1:24714b45cd1b 32 * @ingroup groupMatrix
xorjoep 1:24714b45cd1b 33 */
xorjoep 1:24714b45cd1b 34
xorjoep 1:24714b45cd1b 35 /**
xorjoep 1:24714b45cd1b 36 * @addtogroup MatrixTrans
xorjoep 1:24714b45cd1b 37 * @{
xorjoep 1:24714b45cd1b 38 */
xorjoep 1:24714b45cd1b 39
xorjoep 1:24714b45cd1b 40 /*
xorjoep 1:24714b45cd1b 41 * @brief Q15 matrix transpose.
xorjoep 1:24714b45cd1b 42 * @param[in] *pSrc points to the input matrix
xorjoep 1:24714b45cd1b 43 * @param[out] *pDst points to the output matrix
xorjoep 1:24714b45cd1b 44 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
xorjoep 1:24714b45cd1b 45 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
xorjoep 1:24714b45cd1b 46 */
xorjoep 1:24714b45cd1b 47
xorjoep 1:24714b45cd1b 48 arm_status arm_mat_trans_q15(
xorjoep 1:24714b45cd1b 49 const arm_matrix_instance_q15 * pSrc,
xorjoep 1:24714b45cd1b 50 arm_matrix_instance_q15 * pDst)
xorjoep 1:24714b45cd1b 51 {
xorjoep 1:24714b45cd1b 52 q15_t *pSrcA = pSrc->pData; /* input data matrix pointer */
xorjoep 1:24714b45cd1b 53 q15_t *pOut = pDst->pData; /* output data matrix pointer */
xorjoep 1:24714b45cd1b 54 uint16_t nRows = pSrc->numRows; /* number of nRows */
xorjoep 1:24714b45cd1b 55 uint16_t nColumns = pSrc->numCols; /* number of nColumns */
xorjoep 1:24714b45cd1b 56 uint16_t col, row = nRows, i = 0U; /* row and column loop counters */
xorjoep 1:24714b45cd1b 57 arm_status status; /* status of matrix transpose */
xorjoep 1:24714b45cd1b 58
xorjoep 1:24714b45cd1b 59 #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 60
xorjoep 1:24714b45cd1b 61 /* Run the below code for Cortex-M4 and Cortex-M3 */
xorjoep 1:24714b45cd1b 62 #ifndef UNALIGNED_SUPPORT_DISABLE
xorjoep 1:24714b45cd1b 63
xorjoep 1:24714b45cd1b 64 q31_t in; /* variable to hold temporary output */
xorjoep 1:24714b45cd1b 65
xorjoep 1:24714b45cd1b 66 #else
xorjoep 1:24714b45cd1b 67
xorjoep 1:24714b45cd1b 68 q15_t in;
xorjoep 1:24714b45cd1b 69
xorjoep 1:24714b45cd1b 70 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
xorjoep 1:24714b45cd1b 71
xorjoep 1:24714b45cd1b 72 #ifdef ARM_MATH_MATRIX_CHECK
xorjoep 1:24714b45cd1b 73
xorjoep 1:24714b45cd1b 74
xorjoep 1:24714b45cd1b 75 /* Check for matrix mismatch condition */
xorjoep 1:24714b45cd1b 76 if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
xorjoep 1:24714b45cd1b 77 {
xorjoep 1:24714b45cd1b 78 /* Set status as ARM_MATH_SIZE_MISMATCH */
xorjoep 1:24714b45cd1b 79 status = ARM_MATH_SIZE_MISMATCH;
xorjoep 1:24714b45cd1b 80 }
xorjoep 1:24714b45cd1b 81 else
xorjoep 1:24714b45cd1b 82 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
xorjoep 1:24714b45cd1b 83
xorjoep 1:24714b45cd1b 84 {
xorjoep 1:24714b45cd1b 85 /* Matrix transpose by exchanging the rows with columns */
xorjoep 1:24714b45cd1b 86 /* row loop */
xorjoep 1:24714b45cd1b 87 do
xorjoep 1:24714b45cd1b 88 {
xorjoep 1:24714b45cd1b 89
xorjoep 1:24714b45cd1b 90 /* Apply loop unrolling and exchange the columns with row elements */
xorjoep 1:24714b45cd1b 91 col = nColumns >> 2U;
xorjoep 1:24714b45cd1b 92
xorjoep 1:24714b45cd1b 93 /* The pointer pOut is set to starting address of the column being processed */
xorjoep 1:24714b45cd1b 94 pOut = pDst->pData + i;
xorjoep 1:24714b45cd1b 95
xorjoep 1:24714b45cd1b 96 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
xorjoep 1:24714b45cd1b 97 ** a second loop below computes the remaining 1 to 3 samples. */
xorjoep 1:24714b45cd1b 98 while (col > 0U)
xorjoep 1:24714b45cd1b 99 {
xorjoep 1:24714b45cd1b 100 #ifndef UNALIGNED_SUPPORT_DISABLE
xorjoep 1:24714b45cd1b 101
xorjoep 1:24714b45cd1b 102 /* Read two elements from the row */
xorjoep 1:24714b45cd1b 103 in = *__SIMD32(pSrcA)++;
xorjoep 1:24714b45cd1b 104
xorjoep 1:24714b45cd1b 105 /* Unpack and store one element in the destination */
xorjoep 1:24714b45cd1b 106 #ifndef ARM_MATH_BIG_ENDIAN
xorjoep 1:24714b45cd1b 107
xorjoep 1:24714b45cd1b 108 *pOut = (q15_t) in;
xorjoep 1:24714b45cd1b 109
xorjoep 1:24714b45cd1b 110 #else
xorjoep 1:24714b45cd1b 111
xorjoep 1:24714b45cd1b 112 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
xorjoep 1:24714b45cd1b 113
xorjoep 1:24714b45cd1b 114 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
xorjoep 1:24714b45cd1b 115
xorjoep 1:24714b45cd1b 116 /* Update the pointer pOut to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 117 pOut += nRows;
xorjoep 1:24714b45cd1b 118
xorjoep 1:24714b45cd1b 119 /* Unpack and store the second element in the destination */
xorjoep 1:24714b45cd1b 120
xorjoep 1:24714b45cd1b 121 #ifndef ARM_MATH_BIG_ENDIAN
xorjoep 1:24714b45cd1b 122
xorjoep 1:24714b45cd1b 123 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
xorjoep 1:24714b45cd1b 124
xorjoep 1:24714b45cd1b 125 #else
xorjoep 1:24714b45cd1b 126
xorjoep 1:24714b45cd1b 127 *pOut = (q15_t) in;
xorjoep 1:24714b45cd1b 128
xorjoep 1:24714b45cd1b 129 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
xorjoep 1:24714b45cd1b 130
xorjoep 1:24714b45cd1b 131 /* Update the pointer pOut to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 132 pOut += nRows;
xorjoep 1:24714b45cd1b 133
xorjoep 1:24714b45cd1b 134 /* Read two elements from the row */
xorjoep 1:24714b45cd1b 135 #ifndef ARM_MATH_BIG_ENDIAN
xorjoep 1:24714b45cd1b 136
xorjoep 1:24714b45cd1b 137 in = *__SIMD32(pSrcA)++;
xorjoep 1:24714b45cd1b 138
xorjoep 1:24714b45cd1b 139 #else
xorjoep 1:24714b45cd1b 140
xorjoep 1:24714b45cd1b 141 in = *__SIMD32(pSrcA)++;
xorjoep 1:24714b45cd1b 142
xorjoep 1:24714b45cd1b 143 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
xorjoep 1:24714b45cd1b 144
xorjoep 1:24714b45cd1b 145 /* Unpack and store one element in the destination */
xorjoep 1:24714b45cd1b 146 #ifndef ARM_MATH_BIG_ENDIAN
xorjoep 1:24714b45cd1b 147
xorjoep 1:24714b45cd1b 148 *pOut = (q15_t) in;
xorjoep 1:24714b45cd1b 149
xorjoep 1:24714b45cd1b 150 #else
xorjoep 1:24714b45cd1b 151
xorjoep 1:24714b45cd1b 152 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
xorjoep 1:24714b45cd1b 153
xorjoep 1:24714b45cd1b 154 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
xorjoep 1:24714b45cd1b 155
xorjoep 1:24714b45cd1b 156 /* Update the pointer pOut to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 157 pOut += nRows;
xorjoep 1:24714b45cd1b 158
xorjoep 1:24714b45cd1b 159 /* Unpack and store the second element in the destination */
xorjoep 1:24714b45cd1b 160 #ifndef ARM_MATH_BIG_ENDIAN
xorjoep 1:24714b45cd1b 161
xorjoep 1:24714b45cd1b 162 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
xorjoep 1:24714b45cd1b 163
xorjoep 1:24714b45cd1b 164 #else
xorjoep 1:24714b45cd1b 165
xorjoep 1:24714b45cd1b 166 *pOut = (q15_t) in;
xorjoep 1:24714b45cd1b 167
xorjoep 1:24714b45cd1b 168 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
xorjoep 1:24714b45cd1b 169
xorjoep 1:24714b45cd1b 170 #else
xorjoep 1:24714b45cd1b 171 /* Read one element from the row */
xorjoep 1:24714b45cd1b 172 in = *pSrcA++;
xorjoep 1:24714b45cd1b 173
xorjoep 1:24714b45cd1b 174 /* Store one element in the destination */
xorjoep 1:24714b45cd1b 175 *pOut = in;
xorjoep 1:24714b45cd1b 176
xorjoep 1:24714b45cd1b 177 /* Update the pointer px to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 178 pOut += nRows;
xorjoep 1:24714b45cd1b 179
xorjoep 1:24714b45cd1b 180 /* Read one element from the row */
xorjoep 1:24714b45cd1b 181 in = *pSrcA++;
xorjoep 1:24714b45cd1b 182
xorjoep 1:24714b45cd1b 183 /* Store one element in the destination */
xorjoep 1:24714b45cd1b 184 *pOut = in;
xorjoep 1:24714b45cd1b 185
xorjoep 1:24714b45cd1b 186 /* Update the pointer px to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 187 pOut += nRows;
xorjoep 1:24714b45cd1b 188
xorjoep 1:24714b45cd1b 189 /* Read one element from the row */
xorjoep 1:24714b45cd1b 190 in = *pSrcA++;
xorjoep 1:24714b45cd1b 191
xorjoep 1:24714b45cd1b 192 /* Store one element in the destination */
xorjoep 1:24714b45cd1b 193 *pOut = in;
xorjoep 1:24714b45cd1b 194
xorjoep 1:24714b45cd1b 195 /* Update the pointer px to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 196 pOut += nRows;
xorjoep 1:24714b45cd1b 197
xorjoep 1:24714b45cd1b 198 /* Read one element from the row */
xorjoep 1:24714b45cd1b 199 in = *pSrcA++;
xorjoep 1:24714b45cd1b 200
xorjoep 1:24714b45cd1b 201 /* Store one element in the destination */
xorjoep 1:24714b45cd1b 202 *pOut = in;
xorjoep 1:24714b45cd1b 203
xorjoep 1:24714b45cd1b 204 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
xorjoep 1:24714b45cd1b 205
xorjoep 1:24714b45cd1b 206 /* Update the pointer pOut to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 207 pOut += nRows;
xorjoep 1:24714b45cd1b 208
xorjoep 1:24714b45cd1b 209 /* Decrement the column loop counter */
xorjoep 1:24714b45cd1b 210 col--;
xorjoep 1:24714b45cd1b 211 }
xorjoep 1:24714b45cd1b 212
xorjoep 1:24714b45cd1b 213 /* Perform matrix transpose for last 3 samples here. */
xorjoep 1:24714b45cd1b 214 col = nColumns % 0x4U;
xorjoep 1:24714b45cd1b 215
xorjoep 1:24714b45cd1b 216 #else
xorjoep 1:24714b45cd1b 217
xorjoep 1:24714b45cd1b 218 /* Run the below code for Cortex-M0 */
xorjoep 1:24714b45cd1b 219
xorjoep 1:24714b45cd1b 220 #ifdef ARM_MATH_MATRIX_CHECK
xorjoep 1:24714b45cd1b 221
xorjoep 1:24714b45cd1b 222 /* Check for matrix mismatch condition */
xorjoep 1:24714b45cd1b 223 if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
xorjoep 1:24714b45cd1b 224 {
xorjoep 1:24714b45cd1b 225 /* Set status as ARM_MATH_SIZE_MISMATCH */
xorjoep 1:24714b45cd1b 226 status = ARM_MATH_SIZE_MISMATCH;
xorjoep 1:24714b45cd1b 227 }
xorjoep 1:24714b45cd1b 228 else
xorjoep 1:24714b45cd1b 229 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
xorjoep 1:24714b45cd1b 230
xorjoep 1:24714b45cd1b 231 {
xorjoep 1:24714b45cd1b 232 /* Matrix transpose by exchanging the rows with columns */
xorjoep 1:24714b45cd1b 233 /* row loop */
xorjoep 1:24714b45cd1b 234 do
xorjoep 1:24714b45cd1b 235 {
xorjoep 1:24714b45cd1b 236 /* The pointer pOut is set to starting address of the column being processed */
xorjoep 1:24714b45cd1b 237 pOut = pDst->pData + i;
xorjoep 1:24714b45cd1b 238
xorjoep 1:24714b45cd1b 239 /* Initialize column loop counter */
xorjoep 1:24714b45cd1b 240 col = nColumns;
xorjoep 1:24714b45cd1b 241
xorjoep 1:24714b45cd1b 242 #endif /* #if defined (ARM_MATH_DSP) */
xorjoep 1:24714b45cd1b 243
xorjoep 1:24714b45cd1b 244 while (col > 0U)
xorjoep 1:24714b45cd1b 245 {
xorjoep 1:24714b45cd1b 246 /* Read and store the input element in the destination */
xorjoep 1:24714b45cd1b 247 *pOut = *pSrcA++;
xorjoep 1:24714b45cd1b 248
xorjoep 1:24714b45cd1b 249 /* Update the pointer pOut to point to the next row of the transposed matrix */
xorjoep 1:24714b45cd1b 250 pOut += nRows;
xorjoep 1:24714b45cd1b 251
xorjoep 1:24714b45cd1b 252 /* Decrement the column loop counter */
xorjoep 1:24714b45cd1b 253 col--;
xorjoep 1:24714b45cd1b 254 }
xorjoep 1:24714b45cd1b 255
xorjoep 1:24714b45cd1b 256 i++;
xorjoep 1:24714b45cd1b 257
xorjoep 1:24714b45cd1b 258 /* Decrement the row loop counter */
xorjoep 1:24714b45cd1b 259 row--;
xorjoep 1:24714b45cd1b 260
xorjoep 1:24714b45cd1b 261 } while (row > 0U);
xorjoep 1:24714b45cd1b 262
xorjoep 1:24714b45cd1b 263 /* set status as ARM_MATH_SUCCESS */
xorjoep 1:24714b45cd1b 264 status = ARM_MATH_SUCCESS;
xorjoep 1:24714b45cd1b 265 }
xorjoep 1:24714b45cd1b 266 /* Return to application */
xorjoep 1:24714b45cd1b 267 return (status);
xorjoep 1:24714b45cd1b 268 }
xorjoep 1:24714b45cd1b 269
xorjoep 1:24714b45cd1b 270 /**
xorjoep 1:24714b45cd1b 271 * @} end of MatrixTrans group
xorjoep 1:24714b45cd1b 272 */