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

Make the mode an integer constant expression in cmp_mask #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uidops
Copy link

@uidops uidops commented Sep 5, 2022

I ran into a problem when I was compiling with Clang + SSE4.2
This code is invalid in clang compiler

const int mode = SIDD_UWORD_OPS | SIDD_CMP_EQUAL_EACH | SIDD_BIT_MASK;
return _mm_cmpistrm(a, b, mode);

Because _mm_cmpistrm takes mode as an integer constant expression, not a const qualified int.
For instance assume this code:

#include <smmintrin.h>

#define SIDD_UWORD_OPS _SIDD_UWORD_OPS
#define SIDD_CMP_EQUAL_EACH _SIDD_CMP_EQUAL_EACH
#define SIDD_BIT_MASK _SIDD_BIT_MASK

static inline __m128i cmp_mask(__m128i a, __m128i b) {
    const int mode = SIDD_UWORD_OPS | SIDD_CMP_EQUAL_EACH | SIDD_BIT_MASK;
    return _mm_cmpistrm(a, b, mode);
}

int main(void) {
    return 0;
}
$ clang -msse4.2 a.c -o a
a.c:11:9: error: argument to '__builtin_ia32_pcmpistrm128' must be a constant integer
        return _mm_cmpistrm(a, b, mode);
               ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.6/include/smmintrin.h:1629:13: note: expanded from macro '_mm_cmpistrm'
  ((__m128i)__builtin_ia32_pcmpistrm128((__v16qi)(__m128i)(A), \
            ^
1 error generated.

I think other compilers like GCC have no problem if we use

return _mm_cmpistrm(a, b, SIDD_UWORD_OPS | SIDD_CMP_EQUAL_EACH | SIDD_BIT_MASK);

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

Successfully merging this pull request may close these issues.

1 participant