On May 20, 2018 11:01:54 AM GMT+02:00, Allan Sandfeld Jensen
wrote:
>A little over a year back we had a regression in a point release of gcc
>
>because the builtin __builtin_clzs got removed from i386, in part
>because it
>is was wrongly named for a target specific builtin, but we were using
>it in Qt
>since it existed in multiple compilers. I got the patch removing it
>partially
>reverted and the problem solved, but in the meantime I had worked on a
>patch
>to make it a generic builtin instead. I have rebased it and added it
>below,
>should I clean it up futher, finish the other builtins add tests and
>propose
>it, or is this not something we want?
Can't users simply do clz((unsigned short) s) - 16? GCC should be able to
handle this for instruction selection
With The addition of some folding patterns using the corresponding internal
function.
Richard.
>diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
>index 5365befd351..74a84e653e4 100644
>--- a/gcc/builtin-types.def
>+++ b/gcc/builtin-types.def
>@@ -232,6 +232,8 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_LONG, BT_INT,
>BT_LONG)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_ULONG, BT_INT, BT_ULONG)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_LONGLONG, BT_INT, BT_LONGLONG)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_ULONGLONG, BT_INT, BT_ULONGLONG)
>+DEF_FUNCTION_TYPE_1 (BT_FN_INT_INT16, BT_INT, BT_INT16)
>+DEF_FUNCTION_TYPE_1 (BT_FN_INT_UINT16, BT_INT, BT_UINT16)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_INTMAX, BT_INT, BT_INTMAX)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_UINTMAX, BT_INT, BT_UINTMAX)
> DEF_FUNCTION_TYPE_1 (BT_FN_INT_PTR, BT_INT, BT_PTR)
>diff --git a/gcc/builtins.c b/gcc/builtins.c
>index 9a2bf8c7d38..a8ad00e8016 100644
>--- a/gcc/builtins.c
>+++ b/gcc/builtins.c
>@@ -10689,14 +10689,17 @@ is_inexpensive_builtin (tree decl)
> case BUILT_IN_CLZIMAX:
> case BUILT_IN_CLZL:
> case BUILT_IN_CLZLL:
>+ case BUILT_IN_CLZS:
> case BUILT_IN_CTZ:
> case BUILT_IN_CTZIMAX:
> case BUILT_IN_CTZL:
> case BUILT_IN_CTZLL:
>+ case BUILT_IN_CTZS:
> case BUILT_IN_FFS:
> case BUILT_IN_FFSIMAX:
> case BUILT_IN_FFSL:
> case BUILT_IN_FFSLL:
>+ case BUILT_IN_FFSS:
> case BUILT_IN_IMAXABS:
> case BUILT_IN_FINITE:
> case BUILT_IN_FINITEF:
>@@ -10734,10 +10737,12 @@ is_inexpensive_builtin (tree decl)
> case BUILT_IN_POPCOUNTL:
> case BUILT_IN_POPCOUNTLL:
> case BUILT_IN_POPCOUNTIMAX:
>+ case BUILT_IN_POPCOUNTS:
> case BUILT_IN_POPCOUNT:
> case BUILT_IN_PARITYL:
> case BUILT_IN_PARITYLL:
> case BUILT_IN_PARITYIMAX:
>+ case BUILT_IN_PARITYS:
> case BUILT_IN_PARITY:
> case BUILT_IN_LABS:
> case BUILT_IN_LLABS:
>diff --git a/gcc/builtins.def b/gcc/builtins.def
>index 449d08d682f..618ee798767 100644
>--- a/gcc/builtins.def
>+++ b/gcc/builtins.def
>@@ -848,15 +848,18 @@ DEF_GCC_BUILTIN(BUILT_IN_CLZ, "clz",
>BT_FN_INT_UINT, ATTR_CONST_NOTHROW_
>DEF_GCC_BUILTIN(BUILT_IN_CLZIMAX, "clzimax", BT_FN_INT_UINTMAX,
>
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CLZL, "clzl", BT_FN_INT_ULONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CLZLL, "clzll", BT_FN_INT_ULONGLONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>+DEF_GCC_BUILTIN(BUILT_IN_CLZS, "clzs", BT_FN_INT_UINT16,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>DEF_GCC_BUILTIN(BUILT_IN_CONSTANT_P, "constant_p",
>BT_FN_INT_VAR,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CTZ, "ctz", BT_FN_INT_UINT,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>DEF_GCC_BUILTIN(BUILT_IN_CTZIMAX, "ctzimax", BT_FN_INT_UINTMAX,
>
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CTZL, "ctzl", BT_FN_INT_ULONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CTZLL, "ctzll", BT_FN_INT_ULONGLONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>+DEF_GCC_BUILTIN(BUILT_IN_CTZS, "ctzs", BT_FN_INT_UINT16,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CLRSB, "clrsb", BT_FN_INT_INT,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>DEF_GCC_BUILTIN(BUILT_IN_CLRSBIMAX, "clrsbimax",
>BT_FN_INT_INTMAX,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_GCC_BUILTIN(BUILT_IN_CLRSBL, "clrsbl", BT_FN_INT_LONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>DEF_GCC_BUILTIN(BUILT_IN_CLRSBLL, "clrsbll",
>BT_FN_INT_LONGLONG,
>ATTR_CONST_NOTHROW_LEAF_LIST)
>+DEF_GCC_BUILTIN(BUILT_IN_CLRSBS, "clrsbs", BT_FN_INT_INT16,
>ATTR_CONST_NOTHROW_LEAF_LIST)
> DEF_EXT_LIB_BUILTIN(BUILT_IN_DCGETTEXT, "dcgettext",
>BT_FN_STRING_CONST_STRING_CONST_STRING_INT, ATTR_FORMAT_ARG_2)
> DEF_EXT_LIB_BUILTIN(BUILT_IN_DGETTEXT, "dgettext",
>BT_FN_STRING_CONST_STRING_CONST_STRING, ATTR_FORMAT_ARG_2)
> DEF_GCC_BUILTIN(BUILT_IN_DWARF_CFA, "dwarf_cfa", BT_FN_PTR,
>ATTR_NULL)
>@@ -878,6 +881,7 @@ DEF_EXT_LIB_BUILTIN(BUILT_IN_FFS, "ffs",
>BT_FN_INT_INT, ATTR_CONST_NOTHROW_L
>DEF_EXT_LIB_BUILTIN(BUILT_IN_FFSIMAX, "ffsimax", BT_FN_INT_INTM