Skip to content

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Sep 11, 2020

This allows to save space. (around 4k).
Thanks to @PeeJay in this comment:
stm32duino/STM32LowPower#13 (comment)

Note that I've added a check to 0 value because __builtin_clz with 0 produce an undefined result:
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

Built-in Function: int __builtin_clz (unsigned int x)

Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined. 
This allows to save space. Thanks to @PeeJay. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm added the enhancement New feature or request label Sep 11, 2020
@fpistm fpistm added this to the 1.1.0 milestone Sep 11, 2020
@PeeJay
Copy link

PeeJay commented Sep 12, 2020

You beat me to it! :)
I noticed my M0+ core doesn't actually have the clz instruction, so the compiler implements it instead in 84 bytes.

@fpistm fpistm merged commit df63712 into stm32duino:master Sep 14, 2020
@fpistm fpistm deleted the log2 branch September 14, 2020 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

2 participants