in general, but I wonder if it will result in the optimal code for
arrays, which can look like

int mask = array.length - 1; // already there
if (mask < 0) goAway();

C2 generates uncommon trap in such cases and go to interpreter to throw exception. As result the hot path in compiled code is compact.

That's what I've meant with goAway. My point was the jump using already computed flags (which doesn't work as you explained below).
">

(original) (raw)

Hi Vladimir,

On Thu, Feb 13, 2014 at 12:45 AM, Vladimir Kozlov <vladimir.kozlov@oracle.com> wrote:
On 2/12/14 3:32 PM, Martin Grajcar wrote:
Hi John, Chris, and Vladimir,

I guess the Gist replacing

(x & array.length - 1) u< array.length
by
array.length != 0

can be easily changed to implement

(x & (m-1)) u< m, if and only if (m > 0)

Yes, that is what Kris did.

Yes, I was being too slow with my email.
in general, but I wonder if it will result in the optimal code for
arrays, which can look like

int mask = array.length - 1; // already there
if (mask < 0) goAway();

C2 generates uncommon trap in such cases and go to interpreter to throw exception. As result the hot path in compiled code is compact.

That's what I've meant with goAway. My point was the jump using already computed flags (which doesn't work as you explained below).

where the second line on i86 translates to simply jump if sign, i.e., a

conditional branch without any test as the flags has been already set.


C2 always generates test instruction before jump. It is one of shortfalls of C2.

So forget my above idea.
Note that modern x86 cpus fuse tst+jcc (and cmp+jcc) instructions into 1 micro-instruction. So there should be no performance penalty to have a separate test instruction.

I see, but can't other limits (number of bytes fetched, or instructions decoded, or whatever) pose a problem? Probably not worth the effort, I guess.

Regards,
Martin.