Skip to content

x86 sse2 for loongarch: fix GCC build failure#1287

Merged
mr-c merged 1 commit intosimd-everywhere:masterfrom
jinboson:loongarch_fix_for_sse2
Mar 13, 2025
Merged

x86 sse2 for loongarch: fix GCC build failure#1287
mr-c merged 1 commit intosimd-everywhere:masterfrom
jinboson:loongarch_fix_for_sse2

Conversation

@jinboson
Copy link
Contributor

@jinboson jinboson commented Mar 6, 2025

It seems there is some problem for GCC in dealing with vector type on Ternary Operator, see below:

//test.c
#define SIMDE_ENABLE_NATIVE_ALIASES
#include "/home/jin/data/community/simde-loong64/simde/x86/sse2.h"
int main()
{
        __m128i a = {8};
        __m128i b = _mm_slli_si128(a, 3);
        return 0;
}

gcc -mlsx test.c,the compile output is:

In file included from test.c:2:
test.c: In function ‘main’:
/home/jin/data/community/simde-loong64/simde/x86/sse2.h:1347:22: error: type mismatch in conditional expression
   (((imm8)<=0) ? (a) : (((imm8)>15) ? simde_mm_setzero_si128() : simde__m128i_from_lsx_i8((v16i8)__lsx_vbsll_v(simde__m128i_to_private(a).lsx_i64, (imm8)))))
                      ^
/home/jin/data/community/simde-loong64/simde/x86/sse2.h:1406:35: note: in expansion of macro ‘simde_mm_bslli_si128’
   #define _mm_slli_si128(a, imm8) simde_mm_bslli_si128(a, imm8)
                                   ^~~~~~~~~~~~~~~~~~~~
test.c:6:14: note: in expansion of macro ‘_mm_slli_si128’
  __m128i b = _mm_slli_si128(a, 3);
              ^~~~~~~~~~~~~~

We can simplify the demo like bellow, which is tested on x86:

//1.c
#include <immintrin.h>
int main() {
        __m128i a, b;
        int i = 3;
        b = i > 0 ? a : a + a;
        return 0;
}

gcc 1.c, the compile output is:

> 
> > 1.c: In function ‘main’:
> > 1.c:5:23: error: type mismatch in conditional expression
> >     5 |         b = i > 0 ? a : a + a;
> >       |                       ^

I have reported the strange phenomenon to our compiler team, they are wroking on it.
But I think there is no harm in adding the simde__m128i type-cast for (a) to work round this problem.

@jinboson
Copy link
Contributor Author

jinboson commented Mar 6, 2025

Reproducing this failure requires a and b to be declared by __m128i, which is why the CI test didn't catch this before. So it's not the problem of CI.

@jinboson
Copy link
Contributor Author

@mr-c ping.

@mr-c mr-c merged commit 2af3dce into simd-everywhere:master Mar 13, 2025
112 checks passed
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.

2 participants