Commit 4959a752 by Richard Sandiford Committed by Richard Sandiford

Add internal bitcount functions

This patch adds internal function equivalents of all the INT_FN functions.
Unlike the math functions, these functions never set errno and the internal
functions should be exactly equivalent to the built-in ones.  The reason
for defining the internal functions is so that we can extend the
functionality to other modes, in particular vector modes.

Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/
	* internal-fn.def (DEF_INTERNAL_INT_FN): New macro.
	(CLRSB, CLZ, CTZ, FFS, PARITY, POPCOUNT): New functions.
	* builtins.c (associated_internal_fn): Handle them.

From-SVN: r230475
parent 686ee971
2015-11-17 Richard Sandiford <richard.sandiford@arm.com> 2015-11-17 Richard Sandiford <richard.sandiford@arm.com>
* internal-fn.def (DEF_INTERNAL_INT_FN): New macro.
(CLRSB, CLZ, CTZ, FFS, PARITY, POPCOUNT): New functions.
* builtins.c (associated_internal_fn): Handle them.
2015-11-17 Richard Sandiford <richard.sandiford@arm.com>
* builtins.h (associated_internal_fn): Declare. * builtins.h (associated_internal_fn): Declare.
(replacement_internal_fn): Likewise. (replacement_internal_fn): Likewise.
* builtins.c: Include internal-fn.h * builtins.c: Include internal-fn.h
...@@ -1916,6 +1916,8 @@ associated_internal_fn (tree fndecl) ...@@ -1916,6 +1916,8 @@ associated_internal_fn (tree fndecl)
{ {
#define DEF_INTERNAL_FLT_FN(NAME, FLAGS, OPTAB, TYPE) \ #define DEF_INTERNAL_FLT_FN(NAME, FLAGS, OPTAB, TYPE) \
CASE_FLT_FN (BUILT_IN_##NAME): return IFN_##NAME; CASE_FLT_FN (BUILT_IN_##NAME): return IFN_##NAME;
#define DEF_INTERNAL_INT_FN(NAME, FLAGS, OPTAB, TYPE) \
CASE_INT_FN (BUILT_IN_##NAME): return IFN_##NAME;
#include "internal-fn.def" #include "internal-fn.def"
CASE_FLT_FN (BUILT_IN_POW10): CASE_FLT_FN (BUILT_IN_POW10):
......
...@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
DEF_INTERNAL_FN (NAME, FLAGS, FNSPEC) DEF_INTERNAL_FN (NAME, FLAGS, FNSPEC)
DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE) DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE)
DEF_INTERNAL_FLT_FN (NAME, FLAGS, OPTAB, TYPE) DEF_INTERNAL_FLT_FN (NAME, FLAGS, OPTAB, TYPE)
DEF_INTERNAL_INT_FN (NAME, FLAGS, OPTAB, TYPE)
where NAME is the name of the function, FLAGS is a set of where NAME is the name of the function, FLAGS is a set of
ECF_* flags and FNSPEC is a string describing functions fnspec. ECF_* flags and FNSPEC is a string describing functions fnspec.
...@@ -53,6 +54,10 @@ along with GCC; see the file COPYING3. If not see ...@@ -53,6 +54,10 @@ along with GCC; see the file COPYING3. If not see
function BUILT_IN_<NAME>{F,,L}. Unlike some built-in functions, function BUILT_IN_<NAME>{F,,L}. Unlike some built-in functions,
these internal functions never set errno. these internal functions never set errno.
DEF_INTERNAL_INT_FN is like DEF_INTERNAL_OPTAB_FN, but in addition
says that the function extends the C-level BUILT_IN_<NAME>{,L,LL,IMAX}
group of functions to any integral mode (including vector modes).
Each entry must have a corresponding expander of the form: Each entry must have a corresponding expander of the form:
void expand_NAME (gimple_call stmt) void expand_NAME (gimple_call stmt)
...@@ -75,6 +80,11 @@ along with GCC; see the file COPYING3. If not see ...@@ -75,6 +80,11 @@ along with GCC; see the file COPYING3. If not see
DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE) DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE)
#endif #endif
#ifndef DEF_INTERNAL_INT_FN
#define DEF_INTERNAL_INT_FN(NAME, FLAGS, OPTAB, TYPE) \
DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE)
#endif
DEF_INTERNAL_OPTAB_FN (MASK_LOAD, ECF_PURE, maskload, mask_load) DEF_INTERNAL_OPTAB_FN (MASK_LOAD, ECF_PURE, maskload, mask_load)
DEF_INTERNAL_OPTAB_FN (LOAD_LANES, ECF_CONST, vec_load_lanes, load_lanes) DEF_INTERNAL_OPTAB_FN (LOAD_LANES, ECF_CONST, vec_load_lanes, load_lanes)
...@@ -119,6 +129,14 @@ DEF_INTERNAL_FLT_FN (SCALB, ECF_CONST, scalb, binary) ...@@ -119,6 +129,14 @@ DEF_INTERNAL_FLT_FN (SCALB, ECF_CONST, scalb, binary)
/* FP scales. */ /* FP scales. */
DEF_INTERNAL_FLT_FN (LDEXP, ECF_CONST, ldexp, binary) DEF_INTERNAL_FLT_FN (LDEXP, ECF_CONST, ldexp, binary)
/* Unary integer ops. */
DEF_INTERNAL_INT_FN (CLRSB, ECF_CONST, clrsb, unary)
DEF_INTERNAL_INT_FN (CLZ, ECF_CONST, clz, unary)
DEF_INTERNAL_INT_FN (CTZ, ECF_CONST, ctz, unary)
DEF_INTERNAL_INT_FN (FFS, ECF_CONST, ffs, unary)
DEF_INTERNAL_INT_FN (PARITY, ECF_CONST, parity, unary)
DEF_INTERNAL_INT_FN (POPCOUNT, ECF_CONST, popcount, unary)
DEF_INTERNAL_FN (GOMP_SIMD_LANE, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (GOMP_SIMD_LANE, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, NULL)
DEF_INTERNAL_FN (GOMP_SIMD_VF, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (GOMP_SIMD_VF, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
DEF_INTERNAL_FN (GOMP_SIMD_LAST_LANE, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (GOMP_SIMD_LAST_LANE, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
...@@ -163,6 +181,7 @@ DEF_INTERNAL_FN (GOACC_LOOP, ECF_PURE | ECF_NOTHROW, NULL) ...@@ -163,6 +181,7 @@ DEF_INTERNAL_FN (GOACC_LOOP, ECF_PURE | ECF_NOTHROW, NULL)
/* OpenACC reduction abstraction. See internal-fn.h for usage. */ /* OpenACC reduction abstraction. See internal-fn.h for usage. */
DEF_INTERNAL_FN (GOACC_REDUCTION, ECF_NOTHROW | ECF_LEAF, NULL) DEF_INTERNAL_FN (GOACC_REDUCTION, ECF_NOTHROW | ECF_LEAF, NULL)
#undef DEF_INTERNAL_INT_FN
#undef DEF_INTERNAL_FLT_FN #undef DEF_INTERNAL_FLT_FN
#undef DEF_INTERNAL_OPTAB_FN #undef DEF_INTERNAL_OPTAB_FN
#undef DEF_INTERNAL_FN #undef DEF_INTERNAL_FN
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment