X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <3C620456.967C433F@yahoo.com> From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp,comp.lang.c Subject: Re: gcc 2.953 output - is this a bug? References: <3C61E6BB DOT 7F9AD526 AT yahoo DOT com> <87d6zim2vy DOT fsf AT pfaff DOT stanford DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 45 Date: Thu, 07 Feb 2002 04:51:47 GMT NNTP-Posting-Host: 12.90.167.91 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1013057507 12.90.167.91 (Thu, 07 Feb 2002 04:51:47 GMT) NNTP-Posting-Date: Thu, 07 Feb 2002 04:51:47 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Ben Pfaff wrote: > > CBFalconer writes: > > > Please look at the following disassembly: > > > > h = h * 37UL + (unsigned char) *string++; > > 585: 8d 04 d2 lea (%edx,%edx,8),%eax <<*** > > 588: 8d 04 82 lea (%edx,%eax,4),%eax <<*** > > > > look at the lines marked "<<***". I fail to see how this > > implements h * 37UL. > > Why, you mean it's not perfectly obvious? :-) > Here's a translation back to C of these lines: > eax = edx + 8 * edx > eax = edx + 4 * eax > Here's an equivalent for the first line: > eax = 9 * edx > which, performing a substitution on eax, means that the second > line becomes equivalent to > eax = edx + 4 * (9 * edx) > and from there it should be evident. > > (GCC is more clever than I thought.) Thanks. If I had a handy x86 manual I *might* have eventually figured it out. Incidentally, I found that gcc generated better code for: h = h * 31UL + *string++; than for: h = (h << 5) - h; h += *string++; the latter used an additional temporary. Which proves something or other. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net) Available for consulting/temporary embedded and systems. (Remove "XXXX" from reply address. yahoo works unmodified) mailto:uce AT ftc DOT gov (for spambots to harvest)