Skip to content

Commit 647f87a

Browse files
committed
Added notes on CMSIS optimization for FloatArray
1 parent 33ca2e1 commit 647f87a

2 files changed

Lines changed: 51 additions & 16 deletions

File tree

LibSource/FloatArray.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string.h>
55

66
void FloatArray::getMin(float* value, int* index){
7+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
78
#ifdef ARM_CORTEX
89
unsigned long idx;
910
arm_min_f32(data, size, value, &idx);
@@ -24,19 +25,22 @@ void FloatArray::getMin(float* value, int* index){
2425
float FloatArray::getMinValue(){
2526
float value;
2627
int index;
28+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
2729
getMin(&value, &index);
2830
return value;
2931
}
3032

3133
int FloatArray::getMinIndex(){
3234
float value;
3335
int index;
36+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
3437
getMin(&value, &index);
3538
return index;
3639
}
3740

3841
void FloatArray::getMax(float* value, int* index){
3942
ASSERT(size>0, "Wrong size");
43+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
4044
#ifdef ARM_CORTEX
4145
unsigned long idx;
4246
arm_max_f32(data, size, value, &idx);
@@ -57,20 +61,23 @@ void FloatArray::getMax(float* value, int* index){
5761
float FloatArray::getMaxValue(){
5862
float value;
5963
int index;
64+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
6065
getMax(&value, &index);
6166
return value;
6267
}
6368

6469
int FloatArray::getMaxIndex(){
6570
float value;
6671
int index;
72+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
6773
getMax(&value, &index);
6874
return index;
6975
}
7076

7177
void FloatArray::rectify(FloatArray& destination){ //this is actually "copy data with rectifify"
7278
int minSize= min(size,destination.getSize()); //TODO: shall we take this out and allow it to segfault?
73-
#ifdef ARM_CORTEX
79+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
80+
#ifdef ARM_CORTEX
7481
arm_abs_f32( (float*)data, (float*)destination, size);
7582
#else
7683
for(int n=0; n<minSize; n++){
@@ -80,6 +87,7 @@ void FloatArray::rectify(FloatArray& destination){ //this is actually "copy data
8087
}
8188

8289
void FloatArray::rectify(){//in place
90+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
8391
rectify(*this);
8492
}
8593

@@ -104,7 +112,7 @@ void FloatArray::reverse(){//in place
104112
void FloatArray::reciprocal(FloatArray& destination){
105113
float* data = getData();
106114
for(int n=0; n<getSize(); n++)
107-
destination[n] = 1/data[n];
115+
destination[n] = 1.0f/data[n];
108116
}
109117

110118
void FloatArray::reciprocal(){//in place
@@ -113,6 +121,7 @@ void FloatArray::reciprocal(){//in place
113121

114122
float FloatArray::getRms(){
115123
float result;
124+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
116125
#ifdef ARM_CORTEX
117126
arm_rms_f32 (data, size, &result);
118127
#else
@@ -128,6 +137,7 @@ float FloatArray::getRms(){
128137

129138
float FloatArray::getMean(){
130139
float result;
140+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
131141
#ifdef ARM_CORTEX
132142
arm_mean_f32 (data, size, &result);
133143
#else
@@ -142,6 +152,7 @@ float FloatArray::getMean(){
142152

143153
float FloatArray::getPower(){
144154
float result;
155+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
145156
#ifdef ARM_CORTEX
146157
arm_power_f32 (data, size, &result);
147158
#else
@@ -156,6 +167,7 @@ float FloatArray::getPower(){
156167

157168
float FloatArray::getStandardDeviation(){
158169
float result;
170+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
159171
#ifdef ARM_CORTEX
160172
arm_std_f32 (data, size, &result);
161173
#else
@@ -166,6 +178,7 @@ float FloatArray::getStandardDeviation(){
166178

167179
float FloatArray::getVariance(){
168180
float result;
181+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
169182
#ifdef ARM_CORTEX
170183
arm_var_f32(data, size, &result);
171184
#else
@@ -179,6 +192,7 @@ float FloatArray::getVariance(){
179192
return result;
180193
}
181194
void FloatArray::scale(float factor, FloatArray destination){//supports in-place
195+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
182196
#ifdef ARM_CORTEX
183197
arm_scale_f32(data, factor, destination, size);
184198
#else
@@ -189,6 +203,7 @@ void FloatArray::scale(float factor, FloatArray destination){//supports in-place
189203
}
190204

191205
void FloatArray::scale(float factor){
206+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
192207
scale(factor, *this);
193208
}
194209
void FloatArray::clip(){
@@ -216,15 +231,18 @@ FloatArray FloatArray::subArray(int offset, int length){
216231
}
217232

218233
void FloatArray::copyTo(FloatArray destination){
234+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
219235
copyTo(destination, min(size, destination.getSize()));
220236
}
221237

222238
void FloatArray::copyFrom(FloatArray source){
239+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
223240
copyFrom(source, min(size, source.getSize()));
224241
}
225242

226243
void FloatArray::copyTo(float* other, int length){
227244
ASSERT(size >= length, "Array too small");
245+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
228246
#ifdef ARM_CORTEX
229247
arm_copy_f32(data, other, length);
230248
#else
@@ -234,6 +252,7 @@ void FloatArray::copyTo(float* other, int length){
234252

235253
void FloatArray::copyFrom(float* other, int length){
236254
ASSERT(size >= length, "Array too small");
255+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
237256
#ifdef ARM_CORTEX
238257
arm_copy_f32(other, data, length);
239258
#else
@@ -244,6 +263,7 @@ void FloatArray::copyFrom(float* other, int length){
244263
void FloatArray::insert(FloatArray source, int sourceOffset, int destinationOffset, int samples){
245264
ASSERT(size >= destinationOffset+samples, "Array too small");
246265
ASSERT(source.size >= sourceOffset+samples, "Array too small");
266+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
247267
#ifdef ARM_CORTEX
248268
arm_copy_f32(source.data+sourceOffset, data+destinationOffset, samples);
249269
#else
@@ -252,6 +272,7 @@ void FloatArray::insert(FloatArray source, int sourceOffset, int destinationOffs
252272
}
253273

254274
void FloatArray::insert(FloatArray source, int destinationOffset, int samples){
275+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
255276
insert(source, 0, destinationOffset, samples);
256277
}
257278

@@ -261,6 +282,7 @@ void FloatArray::move(int fromIndex, int toIndex, int samples){
261282
}
262283

263284
void FloatArray::setAll(float value){
285+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
264286
#ifdef ARM_CORTEX
265287
arm_fill_f32(value, data, size);
266288
#else
@@ -272,6 +294,7 @@ void FloatArray::setAll(float value){
272294

273295
void FloatArray::add(FloatArray operand2, FloatArray destination){ //allows in-place
274296
ASSERT(operand2.size == size && destination.size==size, "Arrays must be same size");
297+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
275298
#ifdef ARM_CORTEX
276299
/* despite not explicitely documented in the CMSIS documentation,
277300
this has been tested to behave properly even when pSrcA==pDst
@@ -286,18 +309,20 @@ void FloatArray::add(FloatArray operand2, FloatArray destination){ //allows in-p
286309
}
287310

288311
void FloatArray::add(FloatArray operand2){ //in-place
312+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
289313
add(operand2, *this);
290314
}
291315

292316
void FloatArray::add(float scalar){
293317
for(int n=0; n<size; n++){
294-
data[n]+=scalar;
318+
data[n]+=scalar;
295319
}
296320
}
297321

298322
void FloatArray::subtract(FloatArray operand2, FloatArray destination){ //allows in-place
299323
ASSERT(operand2.size == size && destination.size==size, "Arrays must be same size");
300-
#ifdef ARM_CORTEX
324+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
325+
#ifdef ARM_CORTEX
301326
/* despite not explicitely documented in the CMSIS documentation,
302327
this has been tested to behave properly even when pSrcA==pDst
303328
void arm_sub_f32 (float32_t *pSrcA, float32_t *pSrcB, float32_t *pDst, uint32_t blockSize)
@@ -311,6 +336,7 @@ void FloatArray::subtract(FloatArray operand2, FloatArray destination){ //allows
311336
}
312337

313338
void FloatArray::subtract(FloatArray operand2){ //in-place
339+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
314340
subtract(operand2, *this);
315341
}
316342

@@ -322,7 +348,8 @@ void FloatArray::subtract(float scalar){
322348

323349
void FloatArray::multiply(FloatArray operand2, FloatArray destination){ //allows in-place
324350
ASSERT(operand2.size == size && destination.size==size, "Arrays must be same size");
325-
#ifdef ARM_CORTEX
351+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
352+
#ifdef ARM_CORTEX
326353
/* despite not explicitely documented in the CMSIS documentation,
327354
this has been tested to behave properly even when pSrcA==pDst
328355
void arm_mult_f32 (float32_t *pSrcA, float32_t *pSrcB, float32_t *pDst, uint32_t blockSize)
@@ -337,6 +364,7 @@ void FloatArray::multiply(FloatArray operand2, FloatArray destination){ //allows
337364
}
338365

339366
void FloatArray::multiply(FloatArray operand2){ //in-place
367+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
340368
multiply(operand2, *this);
341369
}
342370

@@ -347,7 +375,8 @@ void FloatArray::multiply(float scalar){
347375
}
348376

349377
void FloatArray::negate(FloatArray& destination){//allows in-place
350-
#ifdef ARM_CORTEX
378+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
379+
#ifdef ARM_CORTEX
351380
arm_negate_f32(data, destination.getData(), size);
352381
#else
353382
for(int n=0; n<size; n++){
@@ -356,6 +385,7 @@ void FloatArray::negate(FloatArray& destination){//allows in-place
356385
#endif /* ARM_CORTEX */
357386
}
358387
void FloatArray::negate(){
388+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
359389
negate(*this);
360390
}
361391

@@ -375,6 +405,7 @@ void FloatArray::noise(float min, float max){
375405

376406
void FloatArray::convolve(FloatArray operand2, FloatArray destination){
377407
ASSERT(destination.size >= size + operand2.size -1, "Destination array too small");
408+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
378409
#ifdef ARM_CORTEX
379410
arm_conv_f32(data, size, operand2.data, operand2.size, destination);
380411
#else
@@ -393,6 +424,7 @@ void FloatArray::convolve(FloatArray operand2, FloatArray destination){
393424

394425
void FloatArray::convolve(FloatArray operand2, FloatArray destination, int offset, int samples){
395426
ASSERT(destination.size >= size + operand2.size -1, "Destination array too small"); //TODO: change this condition to the actual size being written(will be samples+ tail)
427+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
396428
#ifdef ARM_CORTEX
397429
//TODO: I suspect a bug in arm_conv_partial_f32
398430
//it seems that destination[n] is left unchanged for n<offset
@@ -420,10 +452,12 @@ void FloatArray::convolve(FloatArray operand2, FloatArray destination, int offse
420452

421453
void FloatArray::correlate(FloatArray operand2, FloatArray destination){
422454
destination.setAll(0);
455+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
423456
correlateInitialized(operand2, destination);
424457
}
425458
void FloatArray::correlateInitialized(FloatArray operand2, FloatArray destination){
426459
ASSERT(destination.size >= size+operand2.size-1, "Destination array too small"); //TODO: change CMSIS docs, which state a different size
460+
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
427461
#ifdef ARM_CORTEX
428462
arm_correlate_f32(data, size, operand2.data, operand2.size, destination);
429463
#else

LibSource/FloatArray.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ class FloatArray {
3636
* Get the minimum value in the array and its index
3737
* @param[out] value will be set to the minimum value after the call
3838
* @param[out] index will be set to the index of the minimum value after the call
39+
*
3940
*/
4041
void getMin(float* value, int* index);
4142

4243
/**
4344
* Get the maximum value in the array and its index
4445
* @param[out] value will be set to the maximum value after the call
4546
* @param[out] index will be set to the index of the maximum value after the call
46-
*/
47+
*/
4748
void getMax(float* value, int* index);
4849

4950
/**
5051
* Get the minimum value in the array
5152
* @return the minimum value contained in the array
52-
*/
53+
*/
5354
float getMinValue();
5455

5556
/**
@@ -282,7 +283,7 @@ class FloatArray {
282283
* @param[out] destination the destination array.
283284
* @param[in] offset first output sample to compute
284285
* @param[in] samples number of samples to compute
285-
* @note **destination[n]** is left unchanged for n<offset and the result is stored from destination[offset] onwards
286+
* @remarks **destination[n]** is left unchanged for n<offset and the result is stored from destination[offset] onwards
286287
* that is, in the same position where they would be if a full convolution was performed.
287288
*/
288289
void convolve(FloatArray operand2, FloatArray destination, int offset, int samples);
@@ -300,7 +301,7 @@ class FloatArray {
300301
* Sets **destination** to the correlation of *this* array and **operand2**.
301302
* @param[in] operand2 the second operand for the correlation
302303
* @param[out] destination array. It must have a minimum size of 2*max(srcALen, srcBLen)-1
303-
* @note It is the same as correlate(), but destination must have been initialized to 0 in advance.
304+
* @remarks It is the same as correlate(), but destination must have been initialized to 0 in advance.
304305
*/
305306
void correlateInitialized(FloatArray operand2, FloatArray destination);
306307

@@ -317,10 +318,10 @@ class FloatArray {
317318
* @param[in] offset the first element of the subset.
318319
* @param[in] length the number of elments in the new FloatArray.
319320
* @return the newly created FloatArray.
320-
* @note no memory is allocated by this method. The memory is still shared with the original array.
321+
* @remarks no memory is allocated by this method. The memory is still shared with the original array.
321322
* The memory should not be de-allocated elsewhere (e.g.: by calling FloatArray::destroy() on the original FloatArray)
322323
* as long as the FloatArray returned by this method is still in use.
323-
* @note Calling FloatArray::destroy() on a FloatArray instance created wit this method will cause an exception.
324+
* @remarks Calling FloatArray::destroy() on a FloatArray instance created wit this method will cause an exception.
324325
*/
325326
FloatArray subArray(int offset, int length);
326327

@@ -377,7 +378,7 @@ class FloatArray {
377378
* @param[in] fromIndex the first element to copy
378379
* @param[in] toIndex the destination of the first element
379380
* @param[in] length the number of elements to copy
380-
* @note this method uses *memmove()* so that the source memory and the destination memory can overlap. As a consequence it might have slow performances.
381+
* @remarks this method uses *memmove()* so that the source memory and the destination memory can overlap. As a consequence it might have slow performances.
381382
*/
382383
void move(int fromIndex, int toIndex, int length);
383384

@@ -446,15 +447,15 @@ class FloatArray {
446447
* Allocates size*sizeof(float) bytes of memory and returns a FloatArray that points to it.
447448
* @param size the size of the new FloatArray.
448449
* @return a FloatArray which **data** point to the newly allocated memory and **size** is initialized to the proper value.
449-
* @note a FloatArray created with this method has to be destroyed invoking the FloatArray::destroy() method.
450+
* @remarks a FloatArray created with this method has to be destroyed invoking the FloatArray::destroy() method.
450451
*/
451452
static FloatArray create(int size);
452453

453454
/**
454455
* Destroys a FloatArray created with the create() method.
455456
* @param array the FloatArray to be destroyed.
456-
* @note the FloatArray object passed as an argument should not be used again after invoking this method.
457-
* @note a FloatArray object that has not been created by the FloatArray::create() method might cause an exception if passed as an argument to this method.
457+
* @remarks the FloatArray object passed as an argument should not be used again after invoking this method.
458+
* @remarks a FloatArray object that has not been created by the FloatArray::create() method might cause an exception if passed as an argument to this method.
458459
*/
459460
static void destroy(FloatArray array);
460461
};

0 commit comments

Comments
 (0)