qemu-riscv
[Top][All Lists]
Advanced

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

Re: [PATCH v5 50/60] target/riscv: vmfirst find-first-set mask bit


From: Richard Henderson
Subject: Re: [PATCH v5 50/60] target/riscv: vmfirst find-first-set mask bit
Date: Sat, 14 Mar 2020 18:36:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

On 3/12/20 7:58 AM, LIU Zhiwei wrote:
> +/* vmfirst find-first-set mask bit*/
> +target_ulong HELPER(vmfirst_m)(void *v0, void *vs2, CPURISCVState *env,
> +        uint32_t desc)
> +{
> +    uint32_t mlen = vext_mlen(desc);
> +    uint32_t vm = vext_vm(desc);
> +    uint32_t vl = env->vl;
> +    int i;
> +
> +    for (i = 0; i < vl; i++) {
> +        if (vm || vext_elem_mask(v0, mlen, i)) {
> +            if (vext_elem_mask(vs2, mlen, i)) {
> +               return i;
> +            }
> +        }
> +    }
> +    return -1LL;
> +}

This is ok as-is, so
Reviewed-by: Richard Henderson <address@hidden>

But you can do better.  With the mask, as discussed, the inner loop looks like

    j = mask;
    j &= ((uint64_t *)vs2)[i];
    j &= ((uint64_t *)v0)[i];
    if (j) {
        k = ctz64(j) + i * 64;
        return k >> log2_mlen;
    }


r~



reply via email to

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