Compare commits

...

6 commits

Author SHA1 Message Date
77f2ae63d5 libs: use the internal versions of sqrtf, powf, atan2f, and acosf.
Newlib calls the __ieee754_* versions and then sets errno based on any
domain errors, which causes the float -> double functions to be pulled
in.  Call them directly instead.

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

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-14 22:07:21 +02:00
17bbf7d442 autotune: switch from round to roundf.
Prevents a extra promotion to double.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-14 22:06:19 +02:00
ba9f272f1c build: use __ieee754_sqrtf instead of the Newlib sqrtf.
To be compliant, Newlib's sqrtf calls __ieee754_sqrtf and then sets
errno if there's an argument error.  This test also casts the value to
double causing more of the double support functions to be linked in.

Skip the extra tests and call __ieee754_sqrtf directly.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-14 20:47:48 +02:00
f53c9abd6e various: mark constants as float.
This patch fixes three cases where a constant is silently promoted to
double.  Saves 132 bytes.

Signed-off-by: Michael Hope <mlhx@google.com>
2015-05-14 20:38:11 +02:00
813d756ee8 build: build with -ffast-math
-ffast-math lets the compiler perform extra optimisations such a
 converting *float / constant) to the very similar but not bitwise exact
 (float * (1 / constant)).

This saves 136 bytes.

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

View file

@ -557,6 +557,11 @@ endif
DEBUG_FLAGS = -ggdb3
REMAP_FLAGS = -Wl,--defsym=sqrtf=__ieee754_sqrtf -Wl,-u,__ieee754_sqrtf \
-Wl,--defsym=powf=__ieee754_powf -Wl,-u,__ieee754_powf \
-Wl,--defsym=atan2f=__ieee754_atan2f -Wl,-u,__ieee754_atan2f \
-Wl,--defsym=acosf=__ieee754_acosf -Wl,-u,__ieee754_acosf
CFLAGS = $(ARCH_FLAGS) \
$(LTO_FLAGS) \
$(addprefix -D,$(OPTIONS)) \
@ -566,6 +571,7 @@ CFLAGS = $(ARCH_FLAGS) \
-Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
-ffunction-sections \
-fdata-sections \
-ffast-math \
$(DEVICE_FLAGS) \
-DUSE_STDPERIPH_DRIVER \
$(TARGET_FLAGS) \
@ -590,6 +596,7 @@ LDFLAGS = -lm \
$(DEBUG_FLAGS) \
-static \
-Wl,-gc-sections,-Map,$(TARGET_MAP) \
$(REMAP_FLAGS) \
-T$(LD_SCRIPT)
###############################################################################

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

@ -1293,13 +1293,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:
@ -1310,7 +1311,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

@ -142,6 +142,7 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea
}
mAhdrawnRaw += (amperage * lastUpdateAt) / 1000;
/* TODO(mlhx): causes divdi3 to be linked in. */
mAhDrawn = mAhdrawnRaw / (3600 * 100);
}
@ -154,5 +155,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);