Unnecessary 64-bit calculations result in 700+ bytes increase in firmware size #163
Labels
enhancement
New feature or request
hal
HAL-LL driver-related issue or pull-request.
rcc
Reset and Clock Controller
Function
uint32_t HAL_RCC_GetSysClockFreq(void)
calculates expressionPLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
using 64-bit multiplication and division.STM32CubeF4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
Lines 905 to 920 in d5af563
This forces the compiler (in particular gcc) to link to an external
__aeabi_uldivmod
function that performs a 64-bit division.But to calculate the expression
a * b / c
, wherea
,b
andc
areuint32_t
and the result is also 32 bits, it is possible without expanding to 64 bits.Let
a = m * c + n
,b = p * c + q
. ThenDefine the auxiliary function:
Expressions in lines 911, 916 are converted to the following
How this change affects the size of the binary.
For example, create an empty Makefile project in CubeMX for MCU STM32F407 and compile it by arm-gnu-toolchain-12.2.
Using the
muldiv
function:The difference in binary size is 776 bytes.
The text was updated successfully, but these errors were encountered: