intel / ARM_NEON_2_x86_SSE

The platform independent header allowing to compile any C/C++ code containing ARM NEON intrinsic functions for x86 target systems using SIMD up to AVX2 intrinsic functions
Other
430 stars 149 forks source link

warning: implicit conversion from 'int' to 'char' changes value from 128 to -128 #27

Closed guillaume-michel closed 5 years ago

guillaume-michel commented 5 years ago

While compiling with clang I get this warning:

NEON_2_SSE.h:5456:30: warning: implicit conversion from 'int' to 'char' changes value from 128 to -128 [-Wconstant-conversion] c128 = _mm_set1_epi8(128);

official function signature:

__m128i _mm_set1_epi8 (char a);

and (signed) char range is [-128; 127].

I understand why clang complains but I don't know if it is a problem or not.

Can you please clarify the issue for me?

Best regards.

Zvictoria commented 5 years ago

Hi Michel. The honest answer is: I don't know but 99.9999% sure it is fine. ... And so far no one from LLVM side complained on the incorrect results... I don't work with LLVM compiler and the ones I use accept this value without conversion. The truth is -these functions are sign unaware. So unsigned char (and that's what 128 is actually) works fine for them - it should be 0x80 ie only the first bit in a char set to 1. So if you check it in any debugger and report -I'd appreciate it.

guillaume-michel commented 5 years ago

in C, value like 128 is definitely an int (signed integer). When given to function that expects char, it is casted to char -128 by the compiler which is 0x80. So if it is the value you expect, it is fine and you can close the issue. Thanks for your reply.

rosbif commented 4 years ago

Replacing 128 with 0x80 avoids the warning.