On Fri, Dec 19, 2008 at 8:35 PM, Yonik Seeley <ysee...@gmail.com> wrote:

> On Fri, Dec 19, 2008 at 7:10 PM, Mike Klaas <mike.kl...@gmail.com> wrote:
> >
> > On 19-Dec-08, at 8:27 AM, Kay Kay (JIRA) wrote:
> >>            int newCapacity = (oldCapacity * 3)/2 + 1;
> >>
> >> +1 seems to be move away from 0, and keep incrementing the count. ( Hmm
> ..
> >> That piece of code - in Java 6 ArrayList can definitely make use of
> bitwise
> >> operators for the div-by-2 operation !!).
> >
> > Let's not go crazy here guys.  This relatively trivial calculation is
> only
> > called log(n) times, and certainly uses bit ops after the jit gets its
> hands
> > on it.
>
> Log(n) point is well taken.
>
> The translation from "/2" to ">>1" can only really take place when the
> compiler knows it's unsigned.  This might be a simple enough case for
> the compiler to figure it out, but who knows... it took forever (late
> Java6) to generate native rotate instructions.
>
> Oh, and Kay, the simplest way to strength-reduce x*3/2 is (x+x/2) or
> (x+(x>>1))


I agree.  If we are doing any numeric calculations with the numbers
predetermined - we might as well help the compiler generate the most
efficient code, instead of human readable ease . (That can always go in the
comments ).



>
> -Yonik
>

Reply via email to