Wrong parameter type for _mm256_insert_epi64 in avxintrin.h

Uros Bizjak ubizjak@gmail.com
Sun Dec 4 11:49:00 GMT 2011


Hello!

> Attached is a patch which fixes bug target/51393:
>
>   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51393
>
> Also attached, avx_bug.c is a minimal example to reproduce the bug
> (requires an AVX-capable CPU):
>
>   $ gcc -O3 -mavx avx_bug.c
>   $ ./a.out 0x80000000
>   in  = 0x0000000080000000
>   out = 0xffffffff80000000
>
> The correct output should be:
>
>   $ ./a.out 0x80000000
>   in  = 0x0000000080000000
>   out = 0x0000000080000000
>
> As explained in the bug report, it's just a matter of the second
> parameter of _mm256_insert_epi64 being declared as int where it should
> be long long (avxintrin.h:762). A simple typo, trivially fixed by the
> attached patch.

OK.

Attached patch (with a testcase) was committed to mainline SVN with
following ChangeLog entry:

2011-12-04  Jérémie Detrey  <Jeremie.Detrey@loria.fr>

	PR target/51393
	* config/i386/avxintrin.h (_mm256_insert_epi64): Declare second
	parameter as long long.

testsuite/ChangeLog:

2011-12-04  Uros Bizjak  <ubizjak@gmail.com>
	    Jérémie Detrey  <Jeremie.Detrey@loria.fr>

	PR target/51393
	* gcc.target/i386/pr51393.c: New test.

Patch was tested on x86_64-pc-linux-gnu {,-m32}. Patch was committed
to mainline, will be committed to release branches.

Thanks,
Uros.
-------------- next part --------------
Index: config/i386/avxintrin.h
===================================================================
--- config/i386/avxintrin.h	(revision 181984)
+++ config/i386/avxintrin.h	(working copy)
@@ -759,7 +759,7 @@
 
 #ifdef __x86_64__
 extern __inline __m256i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm256_insert_epi64 (__m256i __X, int __D, int const __N)
+_mm256_insert_epi64 (__m256i __X, long long __D, int const __N)
 {
   __m128i __Y = _mm256_extractf128_si256 (__X, __N >> 1);
   __Y = _mm_insert_epi64 (__Y, __D, __N % 2);
Index: testsuite/gcc.target/i386/pr51393.c
===================================================================
--- testsuite/gcc.target/i386/pr51393.c	(revision 0)
+++ testsuite/gcc.target/i386/pr51393.c	(revision 0)
@@ -0,0 +1,21 @@
+/* { dg-do run { target { ! { ia32 } } } } */
+/* { dg-require-effective-target avx } */
+/* { dg-options "-O -mavx" } */
+
+#include "avx-check.h"
+#include <immintrin.h>
+
+static void
+__attribute__((noinline))
+avx_test (void)
+{
+  long long in = 0x800000000ll;
+  long long out;
+
+  __m256i zero = _mm256_setzero_si256();
+  __m256i tmp  = _mm256_insert_epi64 (zero, in, 0);
+  out = _mm256_extract_epi64(tmp, 0);
+
+  if (in != out)
+    abort ();
+}


More information about the Gcc-patches mailing list