qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 7/8] target/ppc: Optimize emulation of vclzh and


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH 7/8] target/ppc: Optimize emulation of vclzh and vclzb instructions
Date: Thu, 6 Jun 2019 15:38:12 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

On 6/6/19 5:15 AM, Stefan Brankovic wrote:
> Optimize Altivec instruction vclzh (Vector Count Leading Zeros Halfword).
> This instruction counts the number of leading zeros of each halfword element
> in source register and places result in the appropriate halfword element of
> destination register.
For halfword, you're generating 32 operations.  A loop over the halfwords,
similar to the word loop I suggested for the last patch, does not reduce this
total, since one has to adjust the clz32 result.

For byte, you're generating 64 operations.

These expansions are so big that without host vector support it's probably best
to leave them out-of-line.

I can imagine a byte clz expansion like

        t0 = input >> 4;
        t1 = input << 4;
        cmp = input == 0 ? -1 : 0;
        input = cmp ? t1 : input;
        output = cmp & 4;

        t0 = input >> 6;
        t1 = input << 2;
        cmp = input == 0 ? -1 : 0;
        input = cmp ? t1 : input;
        t0 = cmp & 2;
        output += t0;

        t1 = input << 1;
        cmp = input >= 0 ? -1 : 0;
        output -= cmp;

        cmp = input == 0 ? -1 : 0;
        output -= cmp;

which would expand to 20 x86_64 vector instructions.  A halfword expansion
would require one more round and thus 25 instructions.

I'll also note that ARM, Power8, and S390 all support this as a native vector
operation; only x86_64 would require the above expansion.  It probably makes
sense to add this operation to tcg.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]