Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add compile-time blend masks #130

Open
eriksjolund opened this issue Dec 17, 2018 · 0 comments
Open

Feature request: Add compile-time blend masks #130

eriksjolund opened this issue Dec 17, 2018 · 0 comments

Comments

@eriksjolund
Copy link

The intrinsics blend functions

  • __m256i _mm256_blendv_epi8(__m256i v1, __m256i v2, __m256i mask)
  • __m256i _mm256_blend_epi16(__m256i a, __m256i b, const int imm8)
  • __m256i _mm256_blend_epi32(__m256i a, __m256i b, const int imm8)

have different performance characteristics. Among them the function _mm256_blend_epi32() is the fastest but its mask needs to be encoded into an const int imm8 at compile-time. That hinders its use in the blend implementation of the current libsimdpp if I understand correctly (see also #56)

For masks that are already known at compile-time, I think it would be good to represent them in a new fashion. For instance the blend mask could be represented as a tuple from the library boost::hana

    auto mask = hana::make_tuple(
      hana::true_c,  hana::true_c,
      hana::true_c,  hana::true_c, 
      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 

      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 
      hana::true_c,  hana::true_c, 
      hana::true_c,  hana::true_c, 

      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 

      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c, 
      hana::false_c, hana::false_c
    );

The immediate mask for _mm256_blend_epi32() could then be computed at compile-time.
I made an proof-of-concept implementation of this in

https://github.com/eriksjolund/compile-time-simd-blend-mask

@eriksjolund eriksjolund changed the title Feature reqeust: Add compile-time blend masks Feature request: Add compile-time blend masks Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant