Commit 6715d47b by Janne Blomqvist

Enable BUILT_IN_IROUND.

2012-03-15  Janne Blomqvist  <jb@gcc.gnu.org>

	* f95-lang.c (gfc_init_builtin_functions): Initialize
	BUILT_IN_IROUND.
	* mathbuiltins.def: Add IROUND.
	* trans-intrinsic.c (build_round_expr): Use BUILT_IN_IROUND if
	type size matches.
	(gfc_build_intrinsic_lib_fndecls): Build iround functions.

From-SVN: r185442
parent 28eccf2d
2012-03-15 Janne Blomqvist <jb@gcc.gnu.org>
* f95-lang.c (gfc_init_builtin_functions): Initialize
BUILT_IN_IROUND.
* mathbuiltins.def: Add IROUND.
* trans-intrinsic.c (build_round_expr): Use BUILT_IN_IROUND if
type size matches.
(gfc_build_intrinsic_lib_fndecls): Build iround functions.
2012-03-12 Richard Guenther <rguenther@suse.de> 2012-03-12 Richard Guenther <rguenther@suse.de>
* f95-lang.c (builtin_type_for_size): Use gfc_type_for_size. * f95-lang.c (builtin_type_for_size): Use gfc_type_for_size.
......
...@@ -773,7 +773,11 @@ gfc_init_builtin_functions (void) ...@@ -773,7 +773,11 @@ gfc_init_builtin_functions (void)
gfc_define_builtin ("__builtin_fmodf", mfunc_float[1], gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST); BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST);
/* lround{f,,l} and llround{f,,l} */ /* iround{f,,l}, lround{f,,l} and llround{f,,l} */
ftype = build_function_type_list (integer_type_node,
float_type_node, NULL_TREE);
gfc_define_builtin("__builtin_iroundf", ftype, BUILT_IN_IROUNDF,
"iroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
ftype = build_function_type_list (long_integer_type_node, ftype = build_function_type_list (long_integer_type_node,
float_type_node, NULL_TREE); float_type_node, NULL_TREE);
gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF, gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF,
...@@ -783,6 +787,10 @@ gfc_init_builtin_functions (void) ...@@ -783,6 +787,10 @@ gfc_init_builtin_functions (void)
gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF, gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF,
"llroundf", ATTR_CONST_NOTHROW_LEAF_LIST); "llroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
ftype = build_function_type_list (integer_type_node,
double_type_node, NULL_TREE);
gfc_define_builtin("__builtin_iround", ftype, BUILT_IN_IROUND,
"iround", ATTR_CONST_NOTHROW_LEAF_LIST);
ftype = build_function_type_list (long_integer_type_node, ftype = build_function_type_list (long_integer_type_node,
double_type_node, NULL_TREE); double_type_node, NULL_TREE);
gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND, gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND,
...@@ -792,6 +800,10 @@ gfc_init_builtin_functions (void) ...@@ -792,6 +800,10 @@ gfc_init_builtin_functions (void)
gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND, gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND,
"llround", ATTR_CONST_NOTHROW_LEAF_LIST); "llround", ATTR_CONST_NOTHROW_LEAF_LIST);
ftype = build_function_type_list (integer_type_node,
long_double_type_node, NULL_TREE);
gfc_define_builtin("__builtin_iroundl", ftype, BUILT_IN_IROUNDL,
"iroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
ftype = build_function_type_list (long_integer_type_node, ftype = build_function_type_list (long_integer_type_node,
long_double_type_node, NULL_TREE); long_double_type_node, NULL_TREE);
gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL, gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL,
......
...@@ -64,6 +64,7 @@ OTHER_BUILTIN (FMOD, "fmod", 2, true) ...@@ -64,6 +64,7 @@ OTHER_BUILTIN (FMOD, "fmod", 2, true)
OTHER_BUILTIN (FREXP, "frexp", frexp, false) OTHER_BUILTIN (FREXP, "frexp", frexp, false)
OTHER_BUILTIN (LLROUND, "llround", llround, true) OTHER_BUILTIN (LLROUND, "llround", llround, true)
OTHER_BUILTIN (LROUND, "lround", lround, true) OTHER_BUILTIN (LROUND, "lround", lround, true)
OTHER_BUILTIN (IROUND, "iround", iround, true)
OTHER_BUILTIN (NEXTAFTER, "nextafter", 2, true) OTHER_BUILTIN (NEXTAFTER, "nextafter", 2, true)
OTHER_BUILTIN (POW, "pow", 1, true) OTHER_BUILTIN (POW, "pow", 1, true)
OTHER_BUILTIN (ROUND, "round", 1, true) OTHER_BUILTIN (ROUND, "round", 1, true)
......
...@@ -376,28 +376,24 @@ build_round_expr (tree arg, tree restype) ...@@ -376,28 +376,24 @@ build_round_expr (tree arg, tree restype)
{ {
tree argtype; tree argtype;
tree fn; tree fn;
bool longlong;
int argprec, resprec; int argprec, resprec;
argtype = TREE_TYPE (arg); argtype = TREE_TYPE (arg);
argprec = TYPE_PRECISION (argtype); argprec = TYPE_PRECISION (argtype);
resprec = TYPE_PRECISION (restype); resprec = TYPE_PRECISION (restype);
/* Depending on the type of the result, choose the long int intrinsic /* Depending on the type of the result, choose the int intrinsic
(lround family) or long long intrinsic (llround). We might also (iround, available only as a builtin), long int intrinsic (lround
need to convert the result afterwards. */ family) or long long intrinsic (llround). We might also need to
if (resprec <= LONG_TYPE_SIZE) convert the result afterwards. */
longlong = false; if (resprec <= INT_TYPE_SIZE)
fn = builtin_decl_for_precision (BUILT_IN_IROUND, argprec);
else if (resprec <= LONG_TYPE_SIZE)
fn = builtin_decl_for_precision (BUILT_IN_LROUND, argprec);
else if (resprec <= LONG_LONG_TYPE_SIZE) else if (resprec <= LONG_LONG_TYPE_SIZE)
longlong = true;
else
gcc_unreachable ();
/* Now, depending on the argument type, we choose between intrinsics. */
if (longlong)
fn = builtin_decl_for_precision (BUILT_IN_LLROUND, argprec); fn = builtin_decl_for_precision (BUILT_IN_LLROUND, argprec);
else else
fn = builtin_decl_for_precision (BUILT_IN_LROUND, argprec); gcc_unreachable ();
return fold_convert (restype, build_call_expr_loc (input_location, return fold_convert (restype, build_call_expr_loc (input_location,
fn, 1, arg)); fn, 1, arg));
...@@ -623,7 +619,7 @@ gfc_build_intrinsic_lib_fndecls (void) ...@@ -623,7 +619,7 @@ gfc_build_intrinsic_lib_fndecls (void)
q-suffixed functions. */ q-suffixed functions. */
tree type, complex_type, func_1, func_2, func_cabs, func_frexp; tree type, complex_type, func_1, func_2, func_cabs, func_frexp;
tree func_lround, func_llround, func_scalbn, func_cpow; tree func_iround, func_lround, func_llround, func_scalbn, func_cpow;
memset (quad_decls, 0, sizeof(tree) * (END_BUILTINS + 1)); memset (quad_decls, 0, sizeof(tree) * (END_BUILTINS + 1));
...@@ -631,6 +627,9 @@ gfc_build_intrinsic_lib_fndecls (void) ...@@ -631,6 +627,9 @@ gfc_build_intrinsic_lib_fndecls (void)
complex_type = complex_float128_type_node; complex_type = complex_float128_type_node;
/* type (*) (type) */ /* type (*) (type) */
func_1 = build_function_type_list (type, type, NULL_TREE); func_1 = build_function_type_list (type, type, NULL_TREE);
/* int (*) (type) */
func_iround = build_function_type_list (integer_type_node,
type, NULL_TREE);
/* long (*) (type) */ /* long (*) (type) */
func_lround = build_function_type_list (long_integer_type_node, func_lround = build_function_type_list (long_integer_type_node,
type, NULL_TREE); type, NULL_TREE);
......
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