Hello! Attached patch implements __builtin_nanq and __builtin_nansq __float128 functions.
2016-06-10 Uros Bizjak <ubiz...@gmail.com> PR target/71241 * config/i386/i386.i386-builtin-types.def (CONST_STRING): New primitive type. (FLOAT128_FTYPE_CONST_STRING): New function type. * config/i386/i386.c (enum ix86_builtins) [IX86_BUILTIN_NANQ]: New. [IX86_BUILTIN_NANSQ]: Ditto. (ix86_fold_builtin): Handle IX86_BUILTIN_NANQ and IX86_BUILTIN_NANSQ. (ix86_init_builtin_types) Declare const_string_type_node. Add __builtin_nanq and __builtin_nansq builtin functions. (ix86_expand_builtin): Handle IX86_BUILTIN_NANQ and IX86_BUILTIN_NANSQ. * doc/extend.texi (x86 Built-in Functions): Document __builtin_nanq and __builtin_nansq. Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Joseph, does it look OK to you? Richi, I hope I got tree stuff implemented correctly. Uros.
Index: config/i386/i386-builtin-types.def =================================================================== --- config/i386/i386-builtin-types.def (revision 237270) +++ config/i386/i386-builtin-types.def (working copy) @@ -73,6 +73,7 @@ DEF_PRIMITIVE_TYPE (FLOAT, float_type_node) DEF_PRIMITIVE_TYPE (DOUBLE, double_type_node) DEF_PRIMITIVE_TYPE (FLOAT80, float80_type_node) DEF_PRIMITIVE_TYPE (FLOAT128, float128_type_node) +DEF_PRIMITIVE_TYPE (CONST_STRING, const_string_type_node) # MMX vectors DEF_VECTOR_TYPE (V2SF, FLOAT) @@ -191,6 +192,7 @@ DEF_FUNCTION_TYPE (PVOID) DEF_FUNCTION_TYPE (FLOAT, FLOAT) DEF_FUNCTION_TYPE (FLOAT128, FLOAT128) +DEF_FUNCTION_TYPE (FLOAT128, CONST_STRING) DEF_FUNCTION_TYPE (INT, INT) DEF_FUNCTION_TYPE (INT, V16QI) DEF_FUNCTION_TYPE (INT, V2DF) Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 237270) +++ config/i386/i386.c (working copy) @@ -32718,6 +32718,8 @@ enum ix86_builtins /* TFmode support builtins. */ IX86_BUILTIN_INFQ, IX86_BUILTIN_HUGE_VALQ, + IX86_BUILTIN_NANQ, + IX86_BUILTIN_NANSQ, IX86_BUILTIN_FABSQ, IX86_BUILTIN_COPYSIGNQ, @@ -38105,11 +38107,28 @@ ix86_fold_builtin (tree fndecl, int n_args, { enum ix86_builtins fn_code = (enum ix86_builtins) DECL_FUNCTION_CODE (fndecl); - if (fn_code == IX86_BUILTIN_CPU_IS - || fn_code == IX86_BUILTIN_CPU_SUPPORTS) + switch (fn_code) { + case IX86_BUILTIN_CPU_IS: + case IX86_BUILTIN_CPU_SUPPORTS: gcc_assert (n_args == 1); - return fold_builtin_cpu (fndecl, args); + return fold_builtin_cpu (fndecl, args); + + case IX86_BUILTIN_NANQ: + case IX86_BUILTIN_NANSQ: + { + tree type = TREE_TYPE (TREE_TYPE (fndecl)); + const char *str = c_getstr (*args); + int quiet = fn_code == IX86_BUILTIN_NANQ; + REAL_VALUE_TYPE real; + + if (str && real_nan (&real, str, quiet, TYPE_MODE (type))) + return build_real (type, real); + return NULL_TREE; + } + + default: + break; } } @@ -38210,7 +38229,7 @@ ix86_init_builtins_va_builtins_abi (void) static void ix86_init_builtin_types (void) { - tree float128_type_node, float80_type_node; + tree float128_type_node, float80_type_node, const_string_type_node; /* The __float80 type. */ float80_type_node = long_double_type_node; @@ -38230,6 +38249,10 @@ ix86_init_builtin_types (void) layout_type (float128_type_node); lang_hooks.types.register_builtin_type (float128_type_node, "__float128"); + const_string_type_node + = build_pointer_type (build_qualified_type + (char_type_node, TYPE_QUAL_CONST)); + /* This macro is built by i386-builtin-types.awk. */ DEFINE_BUILTIN_PRIMITIVE_TYPES; } @@ -38250,6 +38273,18 @@ ix86_init_builtins (void) def_builtin_const (0, "__builtin_huge_valq", FLOAT128_FTYPE_VOID, IX86_BUILTIN_HUGE_VALQ); + t = ix86_get_builtin_func_type (FLOAT128_FTYPE_CONST_STRING); + t = add_builtin_function ("__builtin_nanq", t, IX86_BUILTIN_NANQ, + BUILT_IN_MD, "nanq", NULL_TREE); + TREE_READONLY (t) = 1; + ix86_builtins[(int) IX86_BUILTIN_NANQ] = t; + + t = ix86_get_builtin_func_type (FLOAT128_FTYPE_CONST_STRING); + t = add_builtin_function ("__builtin_nansq", t, IX86_BUILTIN_NANSQ, + BUILT_IN_MD, "nansq", NULL_TREE); + TREE_READONLY (t) = 1; + ix86_builtins[(int) IX86_BUILTIN_NANSQ] = t; + /* We will expand them to normal call if SSE isn't available since they are used by libgcc. */ t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128); @@ -41463,6 +41498,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx sub return target; } + case IX86_BUILTIN_NANQ: + case IX86_BUILTIN_NANSQ: + return expand_call (exp, target, ignore); + case IX86_BUILTIN_RDPMC: case IX86_BUILTIN_RDTSC: case IX86_BUILTIN_RDTSCP: Index: doc/extend.texi =================================================================== --- doc/extend.texi (revision 237270) +++ doc/extend.texi (working copy) @@ -18476,6 +18476,14 @@ Similar to @code{__builtin_inf}, except the return @item __float128 __builtin_huge_valq (void) Similar to @code{__builtin_huge_val}, except the return type is @code{__float128}. @findex __builtin_huge_valq + +@item __float128 __builtin_nanq (void) +Similar to @code{__builtin_nan}, except the return type is @code{__float128}. +@findex __builtin_nanq + +@item __float128 __builtin_nansq (void) +Similar to @code{__builtin_nans}, except the return type is @code{__float128}. +@findex __builtin_nansq @end table The following built-in functions are always available and can be used to