# harmony-dev mailing list archives

##### Site index · List index
Message view
Top
From "Aleksey Shipilev" <aleksey.shipi...@gmail.com>
Subject Re: FW: [general][performance] Stefan Krause's Harmony performance evaluation
Date Mon, 07 Jul 2008 10:50:29 GMT
```Hi, Xiaoming!

Yep, signed integer division is much tougher than we expected :(

The answer on (1) question is:

Baseline: q = a / (1 << d);
Optimized: q = (a + [(1 << d) - 1] & (a >> 31)) >> d;

There's additional increment [(1 << d) - 1] which contributes to
correct rounding, which is added when a is negative, checked by ANDing
with sign-extended (a >> 31). But anyway, the mask would be computed
in the compile time, so the calculation would be complicated only with
should be faster than division.

The answer on (2) question is:

Don't deal with negative divisors so far, generate conventional
division for them.

Thanks,
Aleksey.

On Mon, Jul 7, 2008 at 10:48 AM, xiaoming gu <xiaoming.gu@gmail.com> wrote:
> Hi, all. I have two problems now.
>
> 1. Round-up problem with division and shift right that "The division
> operator rounds towards 0, but the right
> shift operator (>>) rounds towards negative infinity." For example -5/4=-1
> but -5>>2=-2.
>
> 2. When the divisor is negative, how to deal with the shift operation? It's
> meaningless to do shift with a
> number of negative bits.
>
>
> Xiaoming
>
> On Mon, Jul 7, 2008 at 11:57 AM, Xiao-Feng Li <xiaofeng.li@gmail.com> wrote:
>
>> On Mon, Jul 7, 2008 at 11:31 AM, xiaoming gu <xiaoming.gu@gmail.com>
>> wrote:
>> > With testing, I find SAR is the "signed shift right" to replace div. So
>> the
>>
>> So I assume you will correct it in your patch. :)
>>
>> Thanks,
>> xiaofeng
>>
>> > Xiaoming
>> >
>> > On Mon, Jul 7, 2008 at 8:24 AM, xiaoming gu <xiaoming.gu@gmail.com>
>> wrote:
>> >
>> >> Hi, everyone. Which one is signed shift right, SAR or SHR? It seems
>> there
>> >> are some conflicts between
>> >> the definitions (in Enc_defs.h) and the usages (in
>> >> Ia32InstCodeSelector.cpp). Thanks.
>> >>
>> >> Xiaoming
>> >>
>> >>
>> >> On Sun, Jul 6, 2008 at 4:47 PM, Egor Pasko <egor.pasko@gmail.com>
>> wrote:
>> >>
>> >>> On the 0x479 day of Apache Harmony xiaoming gu wrote:
>> >>> > Aleksey, one question. Is there any easy way to know which binary
>> >>> > instructions are generated at runtime? Thanks.
>> >>>
>> >>> Use command line options [1].
>> >>>
>> >>> I suggest this set:
>> >>>
>> >>> -Xem:server_static -XX:jit.p.filter=.main
>> >>> -XX:jit.p.arg.log=ct,irdump,dotdump
>> >>>
>> >>>
>> >>> [1] http://harmony.apache.org/cmd_options.html
>> >>>
>> >>>
>> >>> > Xiaoming
>> >>> >
>> >>> > On Fri, Jul 4, 2008 at 6:17 PM, xiaoming gu <xiaoming.gu@gmail.com>
>> >>> wrote:
>> >>> >
>> >>> > > Got it. I'll take the 1st way and the left work is pretty
clear.
>> >>> Thanks.
>> >>> > >
>> >>> > > Xiaoming
>> >>> > >
>> >>> > >
>> >>> > > On Fri, Jul 4, 2008 at 6:11 PM, Aleksey Shipilev <
>> >>> > > aleksey.shipilev@gmail.com> wrote:
>> >>> > >
>> >>> > >> On Fri, Jul 4, 2008 at 2:04 PM, Aleksey Shipilev
>> >>> > >> <aleksey.shipilev@gmail.com> wrote:
>> >>> > >> > do "shl reg,<value>"
>> >>> > >> Of course, it's "SHIFT RIGHT", so "shr reg, <value>".
>> >>> > >>
>> >>> > >> Thanks,
>> >>> > >> Aleksey.
>> >>> > >>
>> >>> > >
>> >>> > >
>> >>>
>> >>> --
>> >>>
>> >>>
>> >>
>> >
>>
>>
>>
>> --
>> http://xiao-feng.blogspot.com
>>
>

```
Mime
View raw message