diff --git a/lib_com/options.h b/lib_com/options.h index c7af60bf39339b008620426570457ee1ac44f0b3..b146e8df7b795993a13e1955ed251e1b0ed5eaf3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,6 +153,7 @@ #define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ #define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ #define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ +#define FIX_520_REMOVE_MEMMOVE_JBM /* VA: issue 520: Remove memmove() from JBM code */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index e68b3e170e2e71260d37eb05aeebec5e37984789..a1a7ad76f624437262a04581674309177b9663ea 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -53,7 +53,7 @@ * @param[in,out] size size of elements buffer * @param[in] capacity maximum number of elements to buffer * @param[in] newElement element to insert in buffer if great enough */ -static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, uint16_t *size, uint16_t capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ); +static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, uint16_t *size, const uint16_t capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ); /** circular buffer (FIFO) with fixed capacity */ struct JB4_CIRCULARBUFFER @@ -70,7 +70,8 @@ struct JB4_CIRCULARBUFFER /* Creates a circular buffer (FIFO) */ -ivas_error JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) +ivas_error JB4_CIRCULARBUFFER_Create( + JB4_CIRCULARBUFFER_HANDLE *ph ) { JB4_CIRCULARBUFFER_HANDLE h; @@ -433,10 +434,13 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, uint16_t *size, - uint16_t capacity, + const uint16_t capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ) { uint16_t i; +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + uint16_t j; +#endif /* insert newElement if elements buffer is not yet full */ if ( *size < capacity ) @@ -446,7 +450,14 @@ static void JB4_CIRCULARBUFFER_calcPercentile( if ( newElement <= elements[i] ) { /* insert newElement at index i */ +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + for ( j = *size; j > i; --j ) + { + elements[j] = elements[j - 1]; + } +#else memmove( elements + i + 1, elements + i, ( *size - i ) * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */ +#endif elements[i] = newElement; ++*size; return; @@ -470,7 +481,14 @@ static void JB4_CIRCULARBUFFER_calcPercentile( if ( newElement >= elements[i] ) { /* insert newElement at index i */ +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + for ( j = 0; j < i; j++ ) + { + elements[j] = elements[1 + j]; + } +#else memmove( elements, elements + 1, i * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); +#endif elements[i] = newElement; return; } diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index 925e35dfff2c23e7b28ad59f400d836f6cda0939..99f6c3ae2dd2372e270857a1353624745c4c37bf 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -151,6 +151,9 @@ int16_t JB4_INPUTBUFFER_Enque( uint16_t canMoveRight; uint16_t canMoveLeft; bool replace; +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + uint16_t j; +#endif *replacedElement = NULL; size = JB4_INPUTBUFFER_Size( h ); @@ -210,12 +213,14 @@ int16_t JB4_INPUTBUFFER_Enque( } } +#ifdef DEBUGGING assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) != 0 ); if ( low > 0 ) assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low - 1 ), &replace ) > 0 ); assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) < 0 ); if ( (uint16_t) ( low + 1 ) < size ) assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low + 1 ), &replace ) < 0 ); +#endif insertPos = ( h->readPos + low ) % h->capacity; if ( h->readPos < h->writePos ) @@ -234,7 +239,14 @@ int16_t JB4_INPUTBUFFER_Enque( if ( canMoveRight ) { /* move higher elements to the right and insert at insertPos */ +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + for ( j = h->writePos; j > insertPos; --j ) + { + h->data[j] = h->data[j - 1]; + } +#else memmove( h->data + insertPos + 1, h->data + insertPos, ( h->writePos - insertPos ) * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */ +#endif h->data[insertPos] = element; ++h->writePos; if ( h->writePos == h->capacity ) @@ -245,7 +257,14 @@ int16_t JB4_INPUTBUFFER_Enque( else { /* move lower elements to the left and insert before insertPos */ - memmove( h->data + h->readPos - 1, h->data + h->readPos, low * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */ +#ifdef FIX_520_REMOVE_MEMMOVE_JBM + for ( j = 0; j < low; j++ ) + { + h->data[h->readPos - 1 + j] = h->data[h->readPos + j]; + } +#else + memmove( h->data + h->readPos - 1, h->data + h->readPos, low * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); /* IVAS_fmToDo: avoid use of memmove() */ +#endif h->data[insertPos - 1] = element; --h->readPos; assert( (int16_t) h->readPos >= 0 );