mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 08:15:26 +03:00
Replace ABS(float) with fabsf(float)
Disregarding loads and stores, fabfs() compiles to a single vabs.f32 instruction, which completes in 1 cycle. ABS(float), however, compiles to vcmpe.f32, a branch and vneg.f32, which needs 2 cycles + branching. The compiler is not able to perform this transformation because (f < 0 ? -f : f) doesn't always yield the absolute value for floats (e.g. ABS(-0) will yield -0).
This commit is contained in:
parent
b0d285d66d
commit
0f4e74cd04
10 changed files with 14 additions and 14 deletions
|
@ -1106,8 +1106,8 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n
|
|||
// If we have valid pos sensor OR we are configured to ignore GPS loss
|
||||
if ((posControl.flags.estPosStatus >= EST_USABLE) || !checkForPositionSensorTimeout() || navConfig()->general.flags.rth_climb_ignore_emerg) {
|
||||
const float rthAltitudeMargin = STATE(FIXED_WING) ?
|
||||
MAX(FW_RTH_CLIMB_MARGIN_MIN_CM, (FW_RTH_CLIMB_MARGIN_PERCENT/100.0) * ABS(posControl.homeWaypointAbove.pos.z - posControl.homePosition.pos.z)) : // Airplane
|
||||
MAX(MR_RTH_CLIMB_MARGIN_MIN_CM, (MR_RTH_CLIMB_MARGIN_PERCENT/100.0) * ABS(posControl.homeWaypointAbove.pos.z - posControl.homePosition.pos.z)); // Copters
|
||||
MAX(FW_RTH_CLIMB_MARGIN_MIN_CM, (FW_RTH_CLIMB_MARGIN_PERCENT/100.0) * fabsf(posControl.homeWaypointAbove.pos.z - posControl.homePosition.pos.z)) : // Airplane
|
||||
MAX(MR_RTH_CLIMB_MARGIN_MIN_CM, (MR_RTH_CLIMB_MARGIN_PERCENT/100.0) * fabsf(posControl.homeWaypointAbove.pos.z - posControl.homePosition.pos.z)); // Copters
|
||||
|
||||
if (((navGetCurrentActualPositionAndVelocity()->pos.z - posControl.homeWaypointAbove.pos.z) > -rthAltitudeMargin) || (!navConfig()->general.flags.rth_climb_first)) {
|
||||
// Delayed initialization for RTH sanity check on airplanes - allow to finish climb first as it can take some distance
|
||||
|
@ -1667,7 +1667,7 @@ float navPidApply3(pidController_t *pid, const float setpoint, const float measu
|
|||
|
||||
if (pidFlags & PID_SHRINK_INTEGRATOR) {
|
||||
// Only allow integrator to shrink
|
||||
if (ABS(newIntegrator) < ABS(pid->integrator)) {
|
||||
if (fabsf(newIntegrator) < fabsf(pid->integrator)) {
|
||||
pid->integrator = newIntegrator;
|
||||
}
|
||||
}
|
||||
|
@ -3311,7 +3311,7 @@ void onNewGPSData(void)
|
|||
GPS_home.alt = gpsSol.llh.alt;
|
||||
GPS_distanceToHome = 0;
|
||||
GPS_directionToHome = 0;
|
||||
GPS_scaleLonDown = cos_approx((ABS((float)gpsSol.llh.lat) / 10000000.0f) * 0.0174532925f);
|
||||
GPS_scaleLonDown = cos_approx((fabsf((float)gpsSol.llh.lat) / 10000000.0f) * 0.0174532925f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue