]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix _mm_popcnt* intrinsics.
authorSebastian Pop <sebastian.pop@amd.com>
Mon, 7 Dec 2009 22:22:54 +0000 (22:22 +0000)
committerSebastian Pop <spop@gcc.gnu.org>
Mon, 7 Dec 2009 22:22:54 +0000 (22:22 +0000)
* config.gcc (i[34567]86-*-*, x86_64-*-*): Add popcntintrin.h.
* config/i386/abmintrin.h (_mm_popcnt_u32, _mm_popcnt_u64): Moved...
* config/i386/i386-c.c (__POPCNT__): Defined.
* config/i386/popcntintrin.h: ...here.  New file.
* config/i386/smmintrin.h (_mm_popcnt_u32, _mm_popcnt_u64): Moved...
Include popcntintrin.h.
* config/i386/x86intrin.h: Include popcntintrin.h when __POPCNT__
is defined.

From-SVN: r155058

gcc/ChangeLog
gcc/config.gcc
gcc/config/i386/abmintrin.h
gcc/config/i386/i386-c.c
gcc/config/i386/popcntintrin.h [new file with mode: 0644]
gcc/config/i386/smmintrin.h
gcc/config/i386/x86intrin.h

index a7694cba329e3e079dd9ae9a2000ca954600c9e5..e0892eef6901a8e7ddd164ced5653cb385a60c36 100644 (file)
@@ -1,3 +1,14 @@
+2009-12-07  Sebastian Pop  <sebastian.pop@amd.com>
+
+       * config.gcc (i[34567]86-*-*, x86_64-*-*): Add popcntintrin.h.
+       * config/i386/abmintrin.h (_mm_popcnt_u32, _mm_popcnt_u64): Moved...
+       * config/i386/i386-c.c (__POPCNT__): Defined.
+       * config/i386/popcntintrin.h: ...here.  New file.
+       * config/i386/smmintrin.h (_mm_popcnt_u32, _mm_popcnt_u64): Moved...
+       Include popcntintrin.h.
+       * config/i386/x86intrin.h: Include popcntintrin.h when __POPCNT__
+       is defined.
+
 2009-12-07  Sebastian Pop  <sebastian.pop@amd.com>
 
        * config/i386/i386-protos.h (ix86_expand_fma4_multiple_memory):
index ca9441ff3acceae4df4488e2bae0b26d67583010..9c0075b23cf4ed37e1e52d3372ed840d889d026d 100644 (file)
@@ -288,7 +288,7 @@ i[34567]86-*-*)
                       pmmintrin.h tmmintrin.h ammintrin.h smmintrin.h
                       nmmintrin.h bmmintrin.h fma4intrin.h wmmintrin.h
                       immintrin.h x86intrin.h avxintrin.h xopintrin.h
-                      ia32intrin.h cross-stdarg.h lwpintrin.h"
+                      ia32intrin.h cross-stdarg.h lwpintrin.h popcntintrin.h"
        ;;
 x86_64-*-*)
        cpu_type=i386
@@ -298,7 +298,7 @@ x86_64-*-*)
                       pmmintrin.h tmmintrin.h ammintrin.h smmintrin.h
                       nmmintrin.h bmmintrin.h fma4intrin.h wmmintrin.h
                       immintrin.h x86intrin.h avxintrin.h xopintrin.h
-                      ia32intrin.h cross-stdarg.h lwpintrin.h"
+                      ia32intrin.h cross-stdarg.h lwpintrin.h popcntintrin.h"
        need_64bit_hwint=yes
        ;;
 ia64-*-*)
index b85bdb773480e705fc3e1dc5977df708159eb317..9d87f5745864a54d05f219a6b5455855fe5d6c4f 100644 (file)
@@ -52,19 +52,4 @@ __lzcnt64 (unsigned long __X)
 }
 #endif
 
-/* Calculate a number of bits set to 1.  */
-extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_popcnt_u32 (unsigned int __X)
-{
-  return __builtin_popcount (__X);
-}
-
-#ifdef __x86_64__
-extern __inline long long  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_popcnt_u64 (unsigned long long __X)
-{
-  return __builtin_popcountll (__X);
-}
-#endif
-
 #endif /* _ABMINTRIN_H_INCLUDED */
index cba9ceb19ae102a9e59ed68f9d58d0e73a431653..35eab492b6cdda37ac4d501c187333cb79f67bd3 100644 (file)
@@ -238,6 +238,8 @@ ix86_target_macros_internal (int isa_flag,
     def_or_undef (parse_in, "__LWP__");
   if (isa_flag & OPTION_MASK_ISA_ABM)
     def_or_undef (parse_in, "__ABM__");
+  if (isa_flag & OPTION_MASK_ISA_POPCNT)
+    def_or_undef (parse_in, "__POPCNT__");
   if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE))
     def_or_undef (parse_in, "__SSE_MATH__");
   if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2))
diff --git a/gcc/config/i386/popcntintrin.h b/gcc/config/i386/popcntintrin.h
new file mode 100644 (file)
index 0000000..8d4d657
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __POPCNT__
+# error "POPCNT instruction set not enabled"
+#endif /* __POPCNT__ */
+
+#ifndef _POPCNTINTRIN_H_INCLUDED
+#define _POPCNTINTRIN_H_INCLUDED
+
+/* Calculate a number of bits set to 1.  */
+extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_popcnt_u32 (unsigned int __X)
+{
+  return __builtin_popcount (__X);
+}
+
+#ifdef __x86_64__
+extern __inline long long  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_popcnt_u64 (unsigned long long __X)
+{
+  return __builtin_popcountll (__X);
+}
+#endif
+
+#endif /* _POPCNTINTRIN_H_INCLUDED */
index 8fbb35c9b7a2ff4f908ff64fb75e62e1a73447e9..170fae589b90e3e8284f4f90665809edeaaaf935 100644 (file)
@@ -793,19 +793,8 @@ _mm_cmpgt_epi64 (__m128i __X, __m128i __Y)
   return (__m128i) __builtin_ia32_pcmpgtq ((__v2di)__X, (__v2di)__Y);
 }
 
-/* Calculate a number of bits set to 1.  */
-extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_popcnt_u32 (unsigned int __X)
-{
-  return __builtin_popcount (__X);
-}
-
-#ifdef __x86_64__
-extern __inline long long  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_popcnt_u64 (unsigned long long __X)
-{
-  return __builtin_popcountll (__X);
-}
+#ifdef __POPCNT__
+#include <popcntintrin.h>
 #endif
 
 /* Accumulate CRC32 (polynomial 0x11EDC6F41) value.  */
index 63252bf95c86802a29074ddcc118db95cc743657..29d44dc870692940bd75b4178515f9de50c21456 100644 (file)
@@ -81,4 +81,8 @@
 #include <abmintrin.h>
 #endif
 
+#ifdef __POPCNT__
+#include <popcntintrin.h>
+#endif
+
 #endif /* _X86INTRIN_H_INCLUDED */