Skip to content

cpu: stm32: convert preprocessor if to compiler if statement#7502

Merged
jnohlgard merged 1 commit intoRIOT-OS:masterfrom
kaspar030:stmclk_remove_ifdef
Sep 20, 2017
Merged

cpu: stm32: convert preprocessor if to compiler if statement#7502
jnohlgard merged 1 commit intoRIOT-OS:masterfrom
kaspar030:stmclk_remove_ifdef

Conversation

@kaspar030
Copy link
Copy Markdown
Contributor

As CLOCK_HS[EI] are always defined as either 0 or 1, we can use conventional compiler if instead of preprocessor #if, and rely on the optimizer to drop the dead code.

@kaspar030 kaspar030 added Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR labels Aug 23, 2017
@smlng
Copy link
Copy Markdown
Member

smlng commented Aug 24, 2017

and rely on the optimizer to drop the dead code.

doesn't work 😉 increases binary size by 8B compared to master, tested with BOARD=nucleo-f411 and tests/periph_spi.

However, this approach also opens a more general discussion on how to handle that in RIOT overall: macros vs. real code.

#if CLOCK_HSE
if ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) {
RCC->CR &= ~(RCC_CR_HSION);
if (CLOCK_HSE) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC some compilers, e.g. clang, may complain about tautological compare if CLOCK_HSE is 0 rendering this if always false and hence obsolete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though I know, we don't use clang for ARM (currently/yet) but newer GCC might also be not happy?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try it with

make TOOLCHAIN=llvm

@kaspar030 kaspar030 force-pushed the stmclk_remove_ifdef branch from 4370e36 to ead7ae1 Compare August 29, 2017 16:35
@kaspar030
Copy link
Copy Markdown
Contributor Author

doesn't work increases binary size by 8B compared to master, tested with BOARD=nucleo-f411 and tests/periph_spi.

Same size here, with arch linux gcc version 7.1.0... Did you compile with RIOT_VERSION_OVERRIDE=foo?

@kaspar030
Copy link
Copy Markdown
Contributor Author

make TOOLCHAIN=llvm

Doesn't complain!

@kaspar030
Copy link
Copy Markdown
Contributor Author

(I messed up the latest rebase)

@kaspar030
Copy link
Copy Markdown
Contributor Author

(I messed up the latest rebase)

fixed

RCC->REG_LSE |= BIT_LSEON;
while (!(RCC->REG_LSE & BIT_LSERDY)) {}
stmclk_dbp_lock();
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this two lines:
}
else {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

RCC->REG_LSE &= ~(BIT_LSEON);
while (!(RCC->REG_LSE & BIT_LSERDY)) {}
stmclk_dbp_lock();
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jnohlgard
Copy link
Copy Markdown
Member

Looks fine to me, apart from the minor nit on the else statements. Feel free to squash immediately.

@kaspar030
Copy link
Copy Markdown
Contributor Author

Looks fine to me, apart from the minor nit on the else statements. Feel free to squash immediately.

Fixed & squashed.

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on samr21-xpro, no changes in build size. ACK

@jnohlgard jnohlgard merged commit b720c30 into RIOT-OS:master Sep 20, 2017
@kaspar030 kaspar030 deleted the stmclk_remove_ifdef branch September 20, 2017 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants