From ab0e4a354d3024397df0238a44dfeff5f37e5e49 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 2 Dec 2009 05:49:34 +0000 Subject: [PATCH] lzcount intrinsics. * config/i386/abmintrin.h (__lzcnt16): New. (__lzcnt): New. (__lzcnt64): New. * config/i386/i386-builtin-types.def (UINT16_FTYPE_UINT16): New. * config/i386/i386.c (IX86_BUILTIN_CLZS): New. (bdesc_special_args): Add __builtin_clzs. (ix86_expand_args_builtin): Handle UINT16_FTYPE_UINT16. From-SVN: r154895 --- gcc/ChangeLog | 10 ++++++++++ gcc/config/i386/abmintrin.h | 19 +++++++++++++++++++ gcc/config/i386/i386-builtin-types.def | 1 + gcc/config/i386/i386.c | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d04fb611187..a28fc61680f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2009-12-01 Sebastian Pop + + * config/i386/abmintrin.h (__lzcnt16): New. + (__lzcnt): New. + (__lzcnt64): New. + * config/i386/i386-builtin-types.def (UINT16_FTYPE_UINT16): New. + * config/i386/i386.c (IX86_BUILTIN_CLZS): New. + (bdesc_special_args): Add __builtin_clzs. + (ix86_expand_args_builtin): Handle UINT16_FTYPE_UINT16. + 2009-12-01 Sebastian Pop * config/i386/abmintrin.h (_mm_popcnt_u32): New. diff --git a/gcc/config/i386/abmintrin.h b/gcc/config/i386/abmintrin.h index 317bb98d5ea..b85bdb77348 100644 --- a/gcc/config/i386/abmintrin.h +++ b/gcc/config/i386/abmintrin.h @@ -32,6 +32,25 @@ #ifndef _ABMINTRIN_H_INCLUDED #define _ABMINTRIN_H_INCLUDED +extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +__lzcnt16 (unsigned short __X) +{ + return __builtin_clzs (__X); +} + +extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +__lzcnt (unsigned int __X) +{ + return __builtin_clz (__X); +} + +#ifdef __x86_64__ +extern __inline unsigned long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +__lzcnt64 (unsigned long __X) +{ + return __builtin_clzl (__X); +} +#endif /* Calculate a number of bits set to 1. */ extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) diff --git a/gcc/config/i386/i386-builtin-types.def b/gcc/config/i386/i386-builtin-types.def index 0843d4c9e36..e9e4d0c4c83 100644 --- a/gcc/config/i386/i386-builtin-types.def +++ b/gcc/config/i386/i386-builtin-types.def @@ -142,6 +142,7 @@ DEF_FUNCTION_TYPE (INT64, INT64) DEF_FUNCTION_TYPE (INT64, V2DF) DEF_FUNCTION_TYPE (INT64, V4SF) DEF_FUNCTION_TYPE (UINT64, INT) +DEF_FUNCTION_TYPE (UINT16, UINT16) DEF_FUNCTION_TYPE (UINT64, PUNSIGNED) DEF_FUNCTION_TYPE (V16QI, PCCHAR) DEF_FUNCTION_TYPE (V16QI, V16QI) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 21be89fed83..462f2d55648 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -21254,6 +21254,8 @@ enum ix86_builtins IX86_BUILTIN_LWPINS32, IX86_BUILTIN_LWPINS64, + IX86_BUILTIN_CLZS, + IX86_BUILTIN_MAX }; @@ -21535,6 +21537,8 @@ static const struct builtin_description bdesc_special_args[] = { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinssi3, "__builtin_ia32_lwpins32", IX86_BUILTIN_LWPINS64, UNKNOWN, (int) UCHAR_FTYPE_UINT_UINT_UINT }, { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinsdi3, "__builtin_ia32_lwpins64", IX86_BUILTIN_LWPINS64, UNKNOWN, (int) UCHAR_FTYPE_UINT64_UINT_UINT }, + { OPTION_MASK_ISA_ABM, CODE_FOR_clzhi2_abm, "__builtin_clzs", IX86_BUILTIN_CLZS, UNKNOWN, (int) UINT16_FTYPE_UINT16 }, + }; /* Builtins with variable number of arguments. */ @@ -23359,6 +23363,7 @@ ix86_expand_args_builtin (const struct builtin_description *d, case FLOAT_FTYPE_FLOAT: case INT_FTYPE_INT: case UINT64_FTYPE_INT: + case UINT16_FTYPE_UINT16: case INT64_FTYPE_INT64: case INT64_FTYPE_V4SF: case INT64_FTYPE_V2DF: