Re: Check mask all ones / all zeros

Andrew Waterman

On Wed, May 19, 2021 at 10:49 PM Roger Ferrer Ibanez <roger.ferrer@...> wrote:

Hi all,

I could not find any instruction that immediately computes this. Apologies if I missed the obvious here.

Two options came to mind:

  • vpopc.m and check whether the result is 0 (all zeros) or VLMAX(SEW, LMUL). I am under the impression that population count is not a fast operation (though I guess it depends on the actual VLEN)
I think this approach is sufficient, actually.

On the machines I've worked on so far, vpopc.m is no slower than vfirst.m.

For machines with very wide spatial vectors, you could imagine vpopc.m being slightly higher latency than vfirst.m (say, one extra clock cycle) because of the depth of the reduction tree.  But this shouldn't be a dominant effect: in a machine like that, surely the data movement latency will be a more prominent factor than the reduction latency, since the latter scales logarithmically.

PS. You probably already have the current vector length in a GPR, and that quantity is probably the more appropriate thing to compare against than VLMAX.  So you probably don't need to go to the trouble of materializing VLMAX.
  • vfirst.m, returns -1 it the mask is all zeros. For all ones we can do vmnot.m first and then vfirst.m. Might not be much faster than vpopc.m but (at expense of vmnot.m) does not need to compute VLMAX(SEW,LMUL).

Perhaps there are other alternatives?

Thoughts on whether it'd make sense to have a specific instruction for these checks? As in one instruction that returns one of three possible results (e.g. 1 for all ones, -1 for all zeros, 0 otherwise) in a GPR.

Thank you very much,

Roger Ferrer Ibáñez - roger.ferrer@...
Barcelona Supercomputing Center - Centro Nacional de Supercomputación

WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message. If you have received this communication in error, please notify the sender and destroy and delete any copies you may have received.

Join to automatically receive all group messages.