Compare commits

...

3 commits

Author SHA1 Message Date
Michael Hope 2c11b7089a build: enable -ffast-math.
By default, GCC implements strict IEEE 754 confirmance and chooses
bitwise accuracy over speed.  -ffast-math relaxes this and lets GCC do
optimisations like re-writing a / constant as a * (1 / constant).

Saves 144 bytes of flash and should be a speedup.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-20 06:31:22 +02:00
Michael Hope 7cd6798eb1 serial_cli: use the reentrant version of strtok().
Newlib's strtok() allocates memory and causes malloc() to be linked
in.  Use the reentrant version instead.

Saves 336 bytes.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-20 05:33:15 +02:00
Michael Hope 6dcd91ada6 various: use float instead of double.
Add 'f' suffixes to some constants so they don't get silently promoted
to double.  Use roundf() instead of round().

Saves 208 bytes of flash.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-20 05:10:24 +02:00
6 changed files with 10 additions and 8 deletions

View file

@ -564,6 +564,7 @@ CFLAGS = $(ARCH_FLAGS) \
$(DEBUG_FLAGS) \
-std=gnu99 \
-Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
-ffast-math \
-ffunction-sections \
-fdata-sections \
$(DEVICE_FLAGS) \

View file

@ -184,10 +184,10 @@ static void autotuneLogAngleTargets(float currentAngle)
eventData.targetAngleAtPeak = (int) targetAngleAtPeak;
// currentAngle is integer decidegrees divided by 10, so just reverse that process to get an integer again:
eventData.currentAngle = round(currentAngle * 10);
eventData.currentAngle = roundf(currentAngle * 10);
// the peak angles are only ever set to currentAngle, so they get the same treatment:
eventData.firstPeakAngle = round(firstPeakAngle * 10);
eventData.secondPeakAngle = round(secondPeakAngle * 10);
eventData.firstPeakAngle = roundf(firstPeakAngle * 10);
eventData.secondPeakAngle = roundf(secondPeakAngle * 10);
blackboxLogEvent(FLIGHT_LOG_EVENT_AUTOTUNE_TARGETS, (flightLogEventData_t*)&eventData);
}

View file

@ -1296,13 +1296,14 @@ static void cliMotor(char *cmdline)
int motor_value = 0;
int index = 0;
char *pch = NULL;
char *saveptr;
if (isEmpty(cmdline)) {
cliPrint("Usage:\r\nmotor index [value] - show [or set] motor value\r\n");
return;
}
pch = strtok(cmdline, " ");
pch = strtok_r(cmdline, " ", &saveptr);
while (pch != NULL) {
switch (index) {
case 0:
@ -1313,7 +1314,7 @@ static void cliMotor(char *cmdline)
break;
}
index++;
pch = strtok(NULL, " ");
pch = strtok_r(NULL, " ", &saveptr);
}
if (motor_index < 0 || motor_index >= MAX_SUPPORTED_MOTORS) {

View file

@ -114,7 +114,7 @@ uint8_t sumhFrameStatus(void)
for (channelIndex = 0; channelIndex < SUMH_MAX_CHANNEL_COUNT; channelIndex++) {
sumhChannels[channelIndex] = (((uint32_t)(sumhFrame[(channelIndex << 1) + 3]) << 8)
+ sumhFrame[(channelIndex << 1) + 4]) / 6.4 - 375;
+ sumhFrame[(channelIndex << 1) + 4]) / 6.4f - 375;
}
return SERIAL_RX_FRAME_COMPLETE;
}

View file

@ -154,5 +154,5 @@ uint8_t calculateBatteryCapacityRemainingPercentage(void)
{
uint16_t batteryCapacity = batteryConfig->batteryCapacity;
return constrain((batteryCapacity - constrain(mAhDrawn, 0, 0xFFFF)) * 100.0 / batteryCapacity , 0, 100);
return constrain((batteryCapacity - constrain(mAhDrawn, 0, 0xFFFF)) * 100.0f / batteryCapacity , 0, 100);
}

View file

@ -230,7 +230,7 @@ static void sendSatalliteSignalQualityAsTemperature2(void)
if (telemetryConfig->frsky_unit == FRSKY_UNIT_METRICS) {
serialize16(satellite);
} else {
float tmp = (satellite - 32) / 1.8;
float tmp = (satellite - 32) / 1.8f;
//Round the value
tmp += (tmp < 0) ? -0.5f : 0.5f;
serialize16(tmp);