Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
camilo committed Jan 15, 2024
1 parent 9546f1d commit 2c6a2ee
Show file tree
Hide file tree
Showing 22 changed files with 324 additions and 321 deletions.
2 changes: 1 addition & 1 deletion check/sa_check.ewt
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
<group name="CERT-EXP" enabled="true">
<check name="CERT-EXP19-C" enabled="true" />
<check name="CERT-EXP30-C_a" enabled="true" />
<check name="CERT-EXP30-C_b" enabled="true" />
<check name="CERT-EXP30-C_b" enabled="false" />
<check name="CERT-EXP32-C" enabled="true" />
<check name="CERT-EXP33-C_a" enabled="true" />
<check name="CERT-EXP33-C_b" enabled="true" />
Expand Down
2 changes: 1 addition & 1 deletion src/bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool bitfield::writeFloat( const size_t index,

if ( nullptr != field ) {
uint32_t fval = 0U;

(void)memcpy( &fval, &value, sizeof(float) );
write_uint32( index, fval );
retValue = true;
Expand Down
8 changes: 4 additions & 4 deletions src/ffmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ static float getAbnormal( const int i )
static const uint32_t u_ab[ 2 ] = { 0x7F800000U, 0x7FBFFFFFU };
static float f_ab[ 2 ] = { 0.0F, 0.0F };
static bool init = true;

if ( init ) {
cast_reinterpret( f_ab, u_ab );
init = false;
}
return f_ab[ i ];

return f_ab[ i ];
}
/*============================================================================*/
float ffmath::getInf( void )
Expand Down Expand Up @@ -533,7 +533,7 @@ float ffmath::hypot( float x, float y )
( classification::FFP_INFINITE == yClass ) ) ? ffmath::getInf()
: ffmath::getNan();
}

return retVal;
}
/*============================================================================*/
Expand Down
14 changes: 7 additions & 7 deletions src/fis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool fis::instance::setDeFuzzMethod( fis::deFuzzMethod m ) noexcept

if ( m < FIS_NUM_DEFUZZ ) {
/*cppcheck-suppress knownConditionTrueFalse */
if ( ( ( Mamdani == xType ) && ( m <= som ) ) ||
if ( ( ( Mamdani == xType ) && ( m <= som ) ) ||
( ( Sugeno == xType ) && ( m >= wtaver ) && ( m <= wtsum ) ) ||
( ( Tsukamoto == xType ) && ( wtaver == m ) ) ) {
deFuzz = method[ m ];
Expand All @@ -85,9 +85,9 @@ bool fis::instance::setup( const fis::type t,
{
bool retValue = false;

if ( ( t <= Tsukamoto ) &&
( nullptr != inputs ) && ( ni > 0U ) &&
( nullptr != outputs) && ( no > 0U ) &&
if ( ( t <= Tsukamoto ) &&
( nullptr != inputs ) && ( ni > 0U ) &&
( nullptr != outputs) && ( no > 0U ) &&
( nullptr != mf_inputs) && ( nmi > 0U ) &&
( nullptr != mf_outputs) && ( nmo > 0U ) &&
( nullptr != r ) && ( n > 0U )
Expand Down Expand Up @@ -288,7 +288,7 @@ fis::fuzzyOperator fis::instance::getFuzzOperator( void ) noexcept
case Q_FIS_OR:
oper = orOp;
break;
default:
default:
oper = &Sum;
break;
}
Expand All @@ -308,7 +308,7 @@ size_t fis::instance::inferenceAntecedent( size_t i ) noexcept
/*cstat +CERT-INT30-C_a*/
op = getFuzzOperator();
rStrength = op( rStrength, parseFuzzValue( inMF, MFInIndex ) );

if ( ( inIndex < 0 ) || ( static_cast<size_t>( inIndex ) > nInputs ) ) {
i = INFERENCE_ERROR;
}
Expand Down Expand Up @@ -381,7 +381,7 @@ size_t fis::instance::inferenceConsequent( size_t i ) noexcept
fis::output &o = xOutput[ outIndex ];
fis::mf &m = outMF[ MFOutIndex ];
/*cstat +CERT-STR34-C*/

if ( Mamdani == xType ) {
real_t v;
v = m.evalMF( o );
Expand Down
2 changes: 1 addition & 1 deletion src/fisCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ real_t fis::core::GBellMF( const fis::ioBase * const in,
a = p[ 0 ];
b = p[ 1 ];
c = p[ 2 ];

return ( 1.0_re/( 1.0_re + ffmath::pow( ffmath::absf( ( x - c )/a ) , 2.0_re*b ) ) );
}
/*============================================================================*/
Expand Down
6 changes: 3 additions & 3 deletions src/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void generic::sort( void * const pbase,
while ( stack < top ) {
uint8_t *left_ptr, *right_ptr;
uint8_t *mid = &lo[ size*( ( static_cast<size_t>( hi - lo )/size ) >> 1U ) ];

if ( cmp( mid, lo, arg ) < 0 ) {
generic::swap( mid, lo, size );
}
Expand Down Expand Up @@ -179,7 +179,7 @@ void generic::reverse( void * const pbase,
if ( ( nullptr != pbase ) && ( size > 0U ) && ( end > init ) ) {
size_t s = size*init, e = size*end;
uint8_t * const v = static_cast<uint8_t*>( pbase );

while( s < e ) {
generic::swap( &v[ s ], &v[ e ], size );
s += size;
Expand Down Expand Up @@ -297,7 +297,7 @@ int generic::forEach( void *pbase,

if ( ( nullptr != pbase ) && ( nullptr != f ) && ( n > 0U ) ) {
uint8_t * const pb = static_cast<uint8_t *>( pbase );

if ( 1 != f( -1, nullptr, arg ) ) {
size_t i;
uint8_t *element;
Expand Down
Loading

0 comments on commit 2c6a2ee

Please sign in to comment.