Mail Archives: djgpp/2002/02/06/21:45:04.1
CBFalconer <cbfalconer AT yahoo DOT com> 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.)
[snippage]
--
"It would be a much better example of undefined behavior
if the behavior were undefined."
--Michael Rubenstein
- Raw text -