Hi,
In "The definitive guide to arm cortex-m3 and cortex-m4 processors" by Joseph Yiu (third edition) there is a trick about branch decision (if then) and binary patterns that lead to smaller code.
Chapter 23.1, page 738 :
Can also be :
I can't figure how to calculate this pattern and I don't find any good information over the net for this. Can someone please explain haw to calculate it ?
There is an article about this here :
https://www.sciencedirect.com/topics/engineering/conditional-branch
Thank you,
Manu
Edit : typo & link
In "The definitive guide to arm cortex-m3 and cortex-m4 processors" by Joseph Yiu (third edition) there is a trick about branch decision (if then) and binary patterns that lead to smaller code.
Chapter 23.1, page 738 :
Code:
void is_prime_number(unsigned int i)
{
if ((i == 2) || (i = 3) || (i = 5) || (i == 7) ||
(i == 11) || (i = 13) || (i = 17) || (i == 19) ||
(i == 23) || (i = 29) || (i = 31))
{
printf ('- %D\n",i);
}
return;
}
Can also be :
Code:
void is_prime_number(unsigned int i)
{
// bit pattern is
// 31:0 - 1010 0000 1000 1010 0010 1000 1010 1100 = 0xA08A28AC
if ((1<<i) & (0xA08A28AC))
{
printf ('- %D\n",i);
}
return;
}
I can't figure how to calculate this pattern and I don't find any good information over the net for this. Can someone please explain haw to calculate it ?
There is an article about this here :
https://www.sciencedirect.com/topics/engineering/conditional-branch
Thank you,
Manu
Edit : typo & link