Unfortunately, there is a lot of code that used signed where unsigend would be appropriate. While we can recommend the use of unsigne din the manual, SDCC still has to deal with signed operations efficiently.
SDCC currently optimizes / by powers of 2, but not %. Unfortunately, % by 2^n is a bit more complex than / by 2^n.
The best I found for m-bit x %= 2^n so far is:
x &= ((2^n - 1) | (2^(m - 1));
if (x < 0)
{
x--;
x |= -2^n;
x++;
}
This would be very fast for the common case of nonnegative numbers, and still be much faster than calling the support routine for negative numbers. In programs that need the support routine anyway (which we don't know at compile time), it would lead to an increase in code size. I don't know if the optimization should be done even when optimizing for code size.
Philipp