mirror of https://github.com/YosysHQ/abc.git
misc: Prevent Vec_IntRemove from loading nSize in every iteration
This seemly benign loop ``` for ( i++; i < p->nSize; i++ ) p->pArray[i-1] = p->pArray[i]; ``` will actually load `p->nSize` in every loop iteration (rather than memorizing the value) due to some unfortunate pointer aliasing properties in C/C++. As Vec_IntRemove is quite ubiquitous, this extra memory load actually causes visible performance impact and prevents further optimizations on the loop. This patch fixes this by factoring `p->nSize` out of the loop.
This commit is contained in:
parent
f4d870e109
commit
9e02a87c1d
|
|
@ -1069,28 +1069,28 @@ static inline int Vec_IntFind( Vec_Int_t * p, int Entry )
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
static inline int Vec_IntRemove( Vec_Int_t * p, int Entry )
|
static inline int Vec_IntRemove( Vec_Int_t * p, int Entry )
|
||||||
{
|
{
|
||||||
int i;
|
int i, Size = p->nSize;
|
||||||
for ( i = 0; i < p->nSize; i++ )
|
for ( i = 0; i < Size; i++ )
|
||||||
if ( p->pArray[i] == Entry )
|
if ( p->pArray[i] == Entry )
|
||||||
break;
|
break;
|
||||||
if ( i == p->nSize )
|
if ( i == Size )
|
||||||
return 0;
|
return 0;
|
||||||
assert( i < p->nSize );
|
assert( i < Size );
|
||||||
for ( i++; i < p->nSize; i++ )
|
for ( i++; i < Size; i++ )
|
||||||
p->pArray[i-1] = p->pArray[i];
|
p->pArray[i-1] = p->pArray[i];
|
||||||
p->nSize--;
|
p->nSize--;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
static inline int Vec_IntRemove1( Vec_Int_t * p, int Entry )
|
static inline int Vec_IntRemove1( Vec_Int_t * p, int Entry )
|
||||||
{
|
{
|
||||||
int i;
|
int i, Size = p->nSize;
|
||||||
for ( i = 1; i < p->nSize; i++ )
|
for ( i = 1; i < Size; i++ )
|
||||||
if ( p->pArray[i] == Entry )
|
if ( p->pArray[i] == Entry )
|
||||||
break;
|
break;
|
||||||
if ( i >= p->nSize )
|
if ( i >= Size )
|
||||||
return 0;
|
return 0;
|
||||||
assert( i < p->nSize );
|
assert( i < Size );
|
||||||
for ( i++; i < p->nSize; i++ )
|
for ( i++; i < Size; i++ )
|
||||||
p->pArray[i-1] = p->pArray[i];
|
p->pArray[i-1] = p->pArray[i];
|
||||||
p->nSize--;
|
p->nSize--;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue