From: Scott Dattalo <scott@da...>  20001117 13:51:09

On Thu, 16 Nov 2000, Stephen Williams wrote: > > scott@... said: > > BTW, this looks like it could be a huge savings in the '51 code as > > well. For example, multiplication between a char and an int will > > promote the char to an int and then proceed to multiply the two ints. > > ... which is the right thing to do unless the result is assigned to > something smaller then an int. The C standard is clear that this promotion > is supposed to happen and you have to be careful that the result of any > optimization (subsequently cast into its context) behaves is if it were > an int*int operation. Watch out for overflow. True. Fortunately, SDCC does most of the work to ensure that mispromotion does NOT occur. It's fairly simple to detect and optimize for the cases: x .op.= y; // e.g. x += y even when x and y are different types. If y is smaller than x then it needs to be promoted. If y is unsigned, then the promotion consists of zeroes; if y is signed then the promotion depends on y's sign/MS bit. It's also easy to optimize the very similar case: x = y .op. z; // e.g. x = y + z; If x and y are the same type (or if the operator is associative and x and z are the same type) then you can optimize like so: x = y; // x and y are the same type x .op.= z; I do this already for addition (when x, y and z are the same types). The only problem is that my gen.c is growing like a fungus in a Lousiana swamp! Scott 