I see the library code seems mostly done in 1999. The code works, but it feels me a little dump after some checking.
For example, the "_divuint"
do
{// reste: x <-0;**c= MSB_SET(x);
x <<=1;
reste <<=1;if(c)
reste |=1;**if(reste >= y){
reste -= y;// x <-(result =1)
x |=1;}}
will it be equal to
do
{// reste: x <-0;**reste <<=1;if(MSB_SET(x))
reste |=1;
x<<=1;**if(reste >= y){
reste -= y;// x <-(result =1)
x |=1;}}// which saves a variable and some lines of codes
also the _mod operation
**while (!MSB_SET(b))
{
b <<= 1;
if (b > a)
{
b >>=1;
break;
}
count++;
}**
do
{
if (a >= b)
a -= b;
b >>= 1;
}
while (count--);
why not write as
**while (!MSB_SET(b) && b<=a)
{
b <<= 1;
count++;
}
** do
{
if (a >= b)
a -= b;
b >>= 1;
}
// this also saves a right shift of b
Though several bytes of code will not effect the correctness, shorter code let embedded systems enters sleep mode earlier and saves energy, which also saves our earth.
Just ..free discussion.
Chingson
Last edit: Maarten Brock 2018-08-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In "_divuxxx", assignment of "c" is hard to be optimized. Also, in "__moduxxx", shift left (<<) is also hard to be optimized. Yes, we will get shorter code, at least for PIC series.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see the library code seems mostly done in 1999. The code works, but it feels me a little dump after some checking.
For example, the "_divuint"
will it be equal to
also the _mod operation
why not write as
Though several bytes of code will not effect the correctness, shorter code let embedded systems enters sleep mode earlier and saves energy, which also saves our earth.
Just ..free discussion.
Chingson
Last edit: Maarten Brock 2018-08-14
But is the generated asm also shorter and/or faster? Shorter C does not automatically mean better asm. For which target are you compiling?
In "_divuxxx", assignment of "c" is hard to be optimized. Also, in "__moduxxx", shift left (<<) is also hard to be optimized. Yes, we will get shorter code, at least for PIC series.