00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R DSP Library 00008 * Title: arm_max_q7.c 00009 * 00010 * Description: Maximum value of a Q7 vector. 00011 * 00012 * Target Processor: Cortex-R4/R5 00013 * 00014 * Version 1.0.0 2011/03/08 00015 * Alpha release. 00016 * 00017 * Version 1.0.1 2011/09/30 00018 * Beta release. 00019 * 00020 * Version 2.0.0 2011/12/15 00021 * Final release. 00022 * 00023 * ---------------------------------------------------------------------------- */ 00024 #include "arm_math.h" 00025 00049 void arm_max_q7( 00050 q7_t * pSrc, 00051 uint32_t blockSize, 00052 q7_t * pResult, 00053 uint32_t * pIndex) 00054 { 00055 q7_t maxVal1, maxVal2, maxVal3, maxVal4, out; /* Temporary variables to store the output value. */ 00056 uint32_t blkCnt, count, outIndex; /* loop counter */ 00057 00058 /* Initialise the count value. */ 00059 count = 0u; 00060 00061 /* Initialise the index value to zero. */ 00062 outIndex = 0u; 00063 00064 /* Load first input value that act as reference value for comparision */ 00065 out = *pSrc++; 00066 00067 /* Loop unrolling */ 00068 blkCnt = (blockSize - 1u) >> 2u; 00069 00070 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00071 ** a second loop below computes the remaining 1 to 3 samples. */ 00072 while(blkCnt > 0u) 00073 { 00074 /* Initialize maxVal to the next consecutive values one by one */ 00075 maxVal1 = pSrc[0]; 00076 maxVal2 = pSrc[1]; 00077 00078 /* compare for the maximum value */ 00079 if(out < maxVal1) 00080 { 00081 /* Update the maximum value and its index */ 00082 out = maxVal1; 00083 outIndex = count + 1u; 00084 } 00085 00086 maxVal3 = pSrc[2]; 00087 00088 /* compare for the maximum value */ 00089 if(out < maxVal2) 00090 { 00091 /* Update the maximum value and its index */ 00092 out = maxVal2; 00093 outIndex = count + 2u; 00094 } 00095 00096 maxVal4 = pSrc[3]; 00097 00098 /* compare for the maximum value */ 00099 if(out < maxVal3) 00100 { 00101 /* Update the maximum value and its index */ 00102 out = maxVal3; 00103 outIndex = count + 3u; 00104 } 00105 00106 /* compare for the maximum value */ 00107 if(out < maxVal4) 00108 { 00109 /* Update the maximum value and its index */ 00110 out = maxVal4; 00111 outIndex = count + 4u; 00112 } 00113 00114 count += 4u; 00115 pSrc += 4u; 00116 00117 /* Decrement the loop counter */ 00118 blkCnt--; 00119 00120 } 00121 00122 /* If the blockSize - 1 is not a multiple of 4, compute any remaining output samples here. 00123 ** No loop unrolling is used. */ 00124 blkCnt = (blockSize - 1u) % 0x04u; 00125 00126 while(blkCnt > 0u) 00127 { 00128 /* Initialize maxVal to the next consecutive values one by one */ 00129 maxVal1 = *pSrc++; 00130 00131 /* compare for the maximum value */ 00132 if(out < maxVal1) 00133 { 00134 /* Update the maximum value and its index */ 00135 out = maxVal1; 00136 outIndex = blockSize - blkCnt; 00137 } 00138 00139 /* Decrement the loop counter */ 00140 blkCnt--; 00141 } 00142 00143 /* Store the maximum value and its index into destination pointers */ 00144 *pResult = out; 00145 *pIndex = outIndex; 00146 } 00147