From: SourceForge.net <no...@so...> - 2004-01-22 22:24:59
|
Feature Requests item #603246, was opened at 2002-09-01 20:53 Message generated for change (Comment added) made by frief You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=350599&aid=603246&group_id=599 Category: None Group: None Status: Open Priority: 5 Submitted By: Wim Lewis (wiml) Assigned to: Nobody/Anonymous (nobody) Summary: Inefficient multiply by a constant Initial Comment: The following C code: xdata at 0x7FC6 char FOO; char fun(unsigned char tmp) { tmp = 2 * (tmp-1); return ((xdata char *)(&FOO))[tmp]; } is compiled inefficiently by the version of SDCC I got from CVS on 1-September-2002. My older copy of SDCC (2.2.1, which I'm trying to upgrade from) generates reasonably efficient code involving a decrement and an add. The new version (2.3.2-devel) generates much more elaborate code using an actual MUL instruction, instead of optimizing the MUL to an ADD. ---------------------------------------------------------------------- >Comment By: Frieder Ferlemann (frief) Date: 2004-01-22 22:24 Message: Logged In: YES user_id=589052 Hi Maarten, > , although more optimizations are always possible. what you're probably alluding to is the sequence with the redundant xch xch pair: ; genLeftShift ; genLeftShiftLiteral ; genlshTwo mov a,r4 xch a,r3 add a,acc xch a,r3 rlc a mov r4,a There is a peephole optimization to catch a similar case (peephole 252 for variables in direct data). Unfortunately it doesn't catch this one... While another peephole could be defined this is probably not the proper level to do it: there would have to be one for xdata, idata, and yes, some people would even want to left shift a long int too:) > , although more optimizations are always possible. Yeah, there is another one. And it would make sense to find a peephole optimization for it :^) This is it: mov r4,#0x00 ; genLeftShift ; genLeftShiftLiteral ; genlshTwo mov a,r4 ---------------------------------------------------------------------- Comment By: Maarten Brock (maartenbrock) Date: 2004-01-22 18:54 Message: Logged In: YES user_id=888171 Dear developers, Tried this with SDCC 2.3.7 (2004-01-21) and it uses no MUL, only ADD A,ACC and RLC A along with the necessary MOV's. Produced code looks perfectly ok to me, although more optimizations are always possible. I think this RFE can be closed. Maarten ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=350599&aid=603246&group_id=599 |