x86: Cast to unsigned short first for _mm_extract_pi16

_mm_extract_pi16 is intrinsic for pextrw, which should be zero-extended,
not sign-extended.

gcc/

	PR target/98495
	* config/i386/xmmintrin.h (_mm_extract_pi16): Cast to unsigned
	short first.

gcc/testsuite/

	PR target/98495
	* gcc.target/i386/pr98495-1.c: New test.
	* gcc.target/i386/pr98495-2.c: New test.
	* gcc.target/i386/pr98495-3.c: New test.
	* gcc.target/i386/pr98495-4.c: New test.
	* gcc.target/i386/pr98495-5.c: New test.
This commit is contained in:
H.J. Lu 2021-01-01 05:30:34 -08:00
parent b679559385
commit af60b0ec79
6 changed files with 48 additions and 2 deletions

View File

@ -1022,7 +1022,7 @@ _mm_move_ss (__m128 __A, __m128 __B)
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_extract_pi16 (__m64 const __A, int const __N)
{
return __builtin_ia32_vec_ext_v4hi ((__v4hi)__A, __N);
return (unsigned short) __builtin_ia32_vec_ext_v4hi ((__v4hi)__A, __N);
}
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
@ -1032,7 +1032,7 @@ _m_pextrw (__m64 const __A, int const __N)
}
#else
#define _mm_extract_pi16(A, N) \
((int) __builtin_ia32_vec_ext_v4hi ((__v4hi)(__m64)(A), (int)(N)))
((int) (unsigned short) __builtin_ia32_vec_ext_v4hi ((__v4hi)(__m64)(A), (int)(N)))
#define _m_pextrw(A, N) _mm_extract_pi16(A, N)
#endif

View File

@ -0,0 +1,10 @@
/* { dg-do compile } */
/* { dg-options "-O2 -mmmx -msse2 -mtune=generic" } */
/* { dg-final { scan-assembler-not "movswl" } } */
/* { dg-final { scan-assembler-not "movzwl" } } */
/* { dg-final { scan-assembler-not "cwtl" } } */
/* { dg-final { scan-assembler "pextrw" } } */
#include <xmmintrin.h>
unsigned int foo16(__m64 x) { return _mm_extract_pi16(x, 3); }

View File

@ -0,0 +1,11 @@
/* { dg-do compile { target { ! ia32 } } } */
/* { dg-options "-O2 -mmmx -msse2 -mtune=generic" } */
/* { dg-final { scan-assembler-not "movswl" } } */
/* { dg-final { scan-assembler-not "movzwl" } } */
/* { dg-final { scan-assembler-not "cwtl" } } */
/* { dg-final { scan-assembler-not "cltq" } } */
/* { dg-final { scan-assembler "pextrw" } } */
#include <xmmintrin.h>
unsigned long long int foo16(__m64 x) { return _mm_extract_pi16(x, 3); }

View File

@ -0,0 +1,8 @@
/* { dg-do compile } */
/* { dg-options "-O2 -mmmx -msse2 -mtune=generic" } */
/* { dg-final { scan-assembler "(movswl|cwtl)" } } */
/* { dg-final { scan-assembler "pextrw" } } */
#include <xmmintrin.h>
int foo16(__m64 x) { return (short) _mm_extract_pi16(x, 3); }

View File

@ -0,0 +1,8 @@
/* { dg-do compile { target { ! ia32 } } } */
/* { dg-options "-O2 -mmmx -msse2 -mtune=generic" } */
/* { dg-final { scan-assembler "movswq" } } */
/* { dg-final { scan-assembler "pextrw" } } */
#include <xmmintrin.h>
long long int foo16(__m64 x) { return (short) _mm_extract_pi16(x, 3); }

View File

@ -0,0 +1,9 @@
/* { dg-do compile } */
/* { dg-options "-O0 -mmmx -msse2 -mtune=generic" } */
/* { dg-final { scan-assembler-not "movswl" } } */
/* { dg-final { scan-assembler-not "cwtl" } } */
/* { dg-final { scan-assembler "pextrw" } } */
#include <xmmintrin.h>
unsigned int foo16(__m64 x) { return _mm_extract_pi16(x, 3); }