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 jos...@codesourcery.com