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 <richard.hender...@linaro.org> 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~