libsimdpp icon indicating copy to clipboard operation
libsimdpp copied to clipboard

Comparing packed floats and test_bits_any

Open enuren opened this issue 7 years ago • 1 comments

My humble apologies if this turns out to be an error on my end. I am fumbling my way through the documentation, though I have experience with AVX intrinsics.

I am working with simdpp::float32<8> types with the architecture

#define SIMDPP_ARCH_X86_AVX2 1

I am trying to achieve a test that must hold for all elements in the vectors. I have no reduce_and, reduce_or or simdpp::test_bits_any for mask types. I presume they are not implemented due to compatibility reasons?

A workaround that seems to work for AVX2 is:

simdpp::float32<8> v1 = simdpp::splat(1); simdpp::float32<8> v2 = simdpp::splat(2); if (simdpp::test_bits_any(simdpp::bit_cast<simdpp::float32<8>>(v1 < v2))) { cout << "yes" << endl; }

It generates:

vcmplt_oqps %ymm1,%ymm0,%ymm0 vptest %ymm0,%ymm0 jne b3a <main+0x9a> For the comparison.

Am I missing a function that tests if a comparison is true or false for all elements in a vector, or could that be an enhancement request? all_true and all_false could be reasonable names. Implementation could be inspired by this question on stackoverflow.com.

A separate issue I wondered if you had considered is the operator[] as a supplement (syntactic sugar) to insert and extract?

Thank you for your work!

enuren avatar Apr 06 '18 15:04 enuren

I also have this issue, what is the correct way to test bits of a mask?

For example, given a call to simdpp::mask_float32<4> m = cmp_eq(a, b) how can I check that:

  1. All of m's bits are set
  2. None of m's bits are set
  3. Some of m's bits are set

I think I'm missing something but I haven't stumbled across the API that lets me do this.

englercj avatar Jul 18 '18 16:07 englercj