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

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

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.

Thanks for your help, and here is the code:

#include <stdio.h>
#include <riscv_vector.h>

#define N 5

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

------------------ Original ------------------

I think this might work

#include <stdio.h>
#include <riscv_vector.h>

#define N 5

int main(int argc, char **argv)
{
signed char A[N] = {1, 2, 3, 4, 5};
vint8m1_t B = vle8_v_i8m1(A, N);
vbool8_t C = vmseq_vx_i8m1_b8(B, 3, N);

long i;
while ((i = vfirst_m_b8(C, N)) >= 0) {
printf(“INDEX:%ld”, i);
C = vmandnot_mm_b8(C, vmsof_m_b8(C, N), N);
}
return 0;
}