From: Sandeep D. <sa...@wi...> - 2002-03-02 17:04:50
|
Doing it for unsigned only is the way to go .... Sandeep > -----Original Message----- > From: sdc...@li... > [mailto:sdc...@li...]On Behalf Of Johan Knol > Sent: Saturday, March 02, 2002 3:52 AM > To: sdc...@li... > Subject: [sdcc-devel] Re: [ sdcc-Bugs-524685 ] Division by power of 2 > fails with neg nu > > > Now this is a nice one :). In fact this is two bugs in one. > > First the _literal_ shift. The "(SPEC_USIGN(let) ? (unsigned long) > operandLitValue (left) : (long) operandLitValue (left))" in > SDCCicode.c:operandOperation() doesn't work because the type > of the ternary > operation is always the type of the second operand (it > seems), so the shift > will allways be done unsigned. This is fixed in > SDCCicode.c:130 for RIGHT_OP > but will probably also be needed for the other ops. Now at > least "-18 >> 2" > is 0xfffffffb instead of 0x3ffffffb. > > Second the divide. -18 >> 2 = -5 whereas -18 / 4 = -4. > Perhaps we could > say -18 / 4 = (-18 >> 2) + (MSBit >> size-1) but I wonder if > that would be > more efficient that doing just the divide. If not, this > optimation should > only be done for unsigned. > > Please comment. > > Johan > > > ----- Original Message ----- > From: <no...@so...> > To: <no...@so...> > Sent: Saturday, March 02, 2002 6:21 AM > Subject: [sdcc-devel] [ sdcc-Bugs-524685 ] Division by power > of 2 fails with > neg nu > > > > Bugs item #524685, was opened at 2002-03-01 21:21 > > You can respond by visiting: > > > http://sourceforge.net/tracker/?func=detail&atid=100599&aid=52 4685&group_id= 599 > > Category: C-Front End > Group: None > Status: Open > Resolution: None > Priority: 5 > Submitted By: Michael Hope (michaelh) > Assigned to: Nobody/Anonymous (nobody) > Summary: Division by power of 2 fails with neg nu > > Initial Comment: > See the regression tests under this number. > > The front end optimises division by a constant power of two as in: > > volatile int left; > > left = -18; > ASSERT(left/4 == (-18/4)); > > However, if left is negative then shifting and division are not equivalent. > > The optimisation still holds if left is unsigned. > > > ---------------------------------------------------------------------- > > You can respond by visiting: > http://sourceforge.net/tracker/?func=detail&atid=100599&aid=524685&group_id= 599 > > _______________________________________________ > sdcc-devel mailing list > sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-devel > > _______________________________________________ sdcc-devel mailing list sdc...@li... https://lists.sourceforge.net/lists/listinfo/sdcc-devel |