* GSoC 2018 - Adding functions in math.h
@ 2018-03-11 21:15 Tejas Joshi
2018-03-12 16:41 ` Joseph Myers
0 siblings, 1 reply; 3+ messages in thread
From: Tejas Joshi @ 2018-03-11 21:15 UTC (permalink / raw)
To: gcc
> * roundeven is similar to existing functions round / ceil / floor / trunc.
> So you'd define built-in functions (roundeven / roundevenf / roundevenl
> and _FloatN and _FloatNx variants) similar to those for the older rounding
> functions, in builtins.def.
Hello,
Thanks to all for your inputs to get me through. As mentioned above, I
have added the function roundeven in match.pd
and its declaration in builtins.def for the testcase 0. Following is
the patch for the same.
For inlining functions, is it the same kind of specialized expansion from
GIMPLE to RTL which is already there for some math functions in bultins.c?
If I get more clear with it, I'd get to go for the proposal.
Thank you.
Regards,
-Tejas
Patch:
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 17f825da367..70640a53347 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -563,6 +563,7 @@ DEF_C99_BUILTIN (BUILT_IN_RINTL, "rintl",
BT_FN_LONGDOUBLE_LONGDOUBLE, AT
DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_RINT, "rint", RINT_TYPE,
ATTR_CONST_NOTHROW_LEAF_LIST)
#undef RINT_TYPE
DEF_C99_BUILTIN (BUILT_IN_ROUND, "round", BT_FN_DOUBLE_DOUBLE,
ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_C11_BUILTIN (BUILT_IN_ROUNDEVEN, "roundeven",
BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_ROUNDF, "roundf", BT_FN_FLOAT_FLOAT,
ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_ROUNDL, "roundl",
BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
#define ROUND_TYPE(F) BT_FN_##F##_##F
diff --git a/gcc/match.pd b/gcc/match.pd
index 5ba1304af4e..fd77349ed55 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4686,3 +4686,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
|| wi::geu_p (wi::to_wide (@rpos),
wi::to_wide (@ipos) + isize))
(BIT_FIELD_REF @0 @rsize @rpos)))))
+(simplify
+ (BUILT_IN_ROUNDEVEN real_zerop@0)
+ { build_zero_cst (TREE_TYPE(@0)); })
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GSoC 2018 - Adding functions in math.h
2018-03-11 21:15 GSoC 2018 - Adding functions in math.h Tejas Joshi
@ 2018-03-12 16:41 ` Joseph Myers
0 siblings, 0 replies; 3+ messages in thread
From: Joseph Myers @ 2018-03-12 16:41 UTC (permalink / raw)
To: Tejas Joshi; +Cc: gcc
On Mon, 12 Mar 2018, Tejas Joshi wrote:
> Hello,
> Thanks to all for your inputs to get me through. As mentioned above, I
> have added the function roundeven in match.pd
> and its declaration in builtins.def for the testcase 0. Following is
> the patch for the same.
The existing rounding functions are handled in match.pd through several
pieces of code, such as (just one example of many):
/* trunc(trunc(x)) -> trunc(x), etc. */
(for fns (TRUNC_ALL FLOOR_ALL CEIL_ALL ROUND_ALL NEARBYINT_ALL RINT_ALL)
(simplify
(fns (fns @0))
(fns @0)))
/* f(x) -> x if x is integer valued and f does nothing for such values. */
(for fns (TRUNC_ALL FLOOR_ALL CEIL_ALL ROUND_ALL NEARBYINT_ALL RINT_ALL)
(simplify
(fns integer_valued_real_p@0)
@0))
This is one example of what would need extending to handle roundeven
functions for all types, and it's more general than what you did for zero
arguments (and it points to integer_valued_real_p; once you investigate
that, you'll see that integer_valued_real_call_p should be updated so it
knows that roundeven always returns an integer value). internal-fn.def
would need extending to handle roundeven similarly to:
DEF_INTERNAL_FLT_FLOATN_FN (CEIL, ECF_CONST, ceil, unary)
(read the comments in that file for details of what this handles regarding
setting up optabs and built-in function support).
builtins.def should not define roundeven with DEF_C11_BUILTIN, because
it's not a C11 function. Rather, all of roundeven, roundevenf and
roundevenl should be defined with DEF_EXT_LIB_BUILTIN, and
DEF_EXT_LIB_FLOATN_NX_BUILTINS needs to be used (similar to ceil etc.) to
define the _FloatN and _FloatNx variants.
> For inlining functions, is it the same kind of specialized expansion from
> GIMPLE to RTL which is already there for some math functions in bultins.c?
internal-fn.def sets up various pieces for functions such as this that
correspond directly to optabs for RTL expansion. You still need to write
the documentation of what the machine description patterns should look
like. And you need to check places in builtins.c and elsewhere that
reference the existing functions to consider if they should handle
roundeven similarly; for example, mathfn_built_in_2 probably should.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* GSoC 2018 - Adding functions in math.h
@ 2018-03-11 21:00 Tejas Joshi
0 siblings, 0 replies; 3+ messages in thread
From: Tejas Joshi @ 2018-03-11 21:00 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 748 bytes --]
> * roundeven is similar to existing functions round / ceil / floor / trunc.
> So you'd define built-in functions (roundeven / roundevenf / roundevenl
> and _FloatN and _FloatNx variants) similar to those for the older rounding
> functions, in builtins.def.
Hello,
Thanks to all for your inputs to get me through. As mentioned above, I
have added the function roundeven in match.pd
and its declaration in builtins.def for the testcase 0. Following is the
attachment patch for the same.
For inlining functions, is it the same kind of specialized expansion from
GIMPLE to RTL which is already there for some math functions in bultins.c?
If I get more clear with it, I'd get to go for the proposal.
Thank you.
Regards,
-Tejas
Patch Attachment:
[-- Attachment #2: roundeven.diff --]
[-- Type: text/x-patch, Size: 1191 bytes --]
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 17f825da367..70640a53347 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -563,6 +563,7 @@ DEF_C99_BUILTIN (BUILT_IN_RINTL, "rintl", BT_FN_LONGDOUBLE_LONGDOUBLE, AT
DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_RINT, "rint", RINT_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
#undef RINT_TYPE
DEF_C99_BUILTIN (BUILT_IN_ROUND, "round", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_C11_BUILTIN (BUILT_IN_ROUNDEVEN, "roundeven", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_ROUNDF, "roundf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_ROUNDL, "roundl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
#define ROUND_TYPE(F) BT_FN_##F##_##F
diff --git a/gcc/match.pd b/gcc/match.pd
index 5ba1304af4e..fd77349ed55 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4686,3 +4686,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
|| wi::geu_p (wi::to_wide (@rpos),
wi::to_wide (@ipos) + isize))
(BIT_FIELD_REF @0 @rsize @rpos)))))
+(simplify
+ (BUILT_IN_ROUNDEVEN real_zerop@0)
+ { build_zero_cst (TREE_TYPE(@0)); })
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-12 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-11 21:15 GSoC 2018 - Adding functions in math.h Tejas Joshi
2018-03-12 16:41 ` Joseph Myers
-- strict thread matches above, loose matches on Subject: below --
2018-03-11 21:00 Tejas Joshi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).