[llvm-dev] [RISC-V V] How to read each bit of vbool8_t individually

Shao-Ce Sun via llvm-dev
Sat, 10 Jul 2021 02:33:38 -0000

Thanks for your help, and here is the code:


#include <stdio.h&gt;
#include <riscv_vector.h&gt;


#define N 5


int main(int argc, char **argv)
{
&nbsp; signed char A[N] = {1, 2, 3, 4, 5};
&nbsp; vint8m1_t B = vle8_v_i8m1(A, N);
&nbsp; vbool8_t C = vmseq_vx_i8m1_b8(B, 3, N);
&nbsp; int i;
&nbsp; for (i = 0; i < N; ++i)
&nbsp; {
&nbsp; &nbsp; if (C[i])
&nbsp; &nbsp; &nbsp; printf("INDEX:%d", i);
&nbsp; }
}







------------------&nbsp;Original&nbsp;------------------
From:
"Craig Topper"
<craig.topper at gmail.com&gt;;
Date:&nbsp;Fri, Jul 9, 2021 11:41 AM
To:&nbsp;"Shao-Ce Sun"<llvm at foxmail.com&gt;;
Cc:&nbsp;"via llvm-dev"<llvm-dev at lists.llvm.org&gt;;
Subject:&nbsp;Re: [llvm-dev] [RISC-V V] How to read each bit of vbool8_t
individually



There aren't really any instructions for doing this in the ISA. Solutions I
can think of are rounding vl to the next multiple of 8 and storing it to a
uint8_t using vse8. Then reading it back by looping over the array and looking
at all 8 bits of each uint8_t. Or you could use vmerge to turn into a vuint8m1_t
vector of 1 and 0.


Perhaps if you shared your use case I might be able to come up with something
else.

~Craig




On Thu, Jul 8, 2021 at 7:23 PM Shao-Ce Sun via llvm-dev <llvm-dev at
lists.llvm.org&gt; wrote:

Hi All,
&nbsp; I have a question about RISC-V V, that is how to read each bit of
vbool8_t individually, for example:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbool8_t A;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bool B[8] = A;
Thanks!

_______________________________________________
 LLVM Developers mailing list
 llvm-dev at lists.llvm.org
 https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20210710/eb2f0df3/attachment-0001.html>