This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, middle end]: Introduce BUILT_IN_I{CEIL_FLOOR_ROUND_RINT} FP-to-int conversion functions


On Thu, 11 Aug 2011, Uros Bizjak wrote:

> Hello!
> 
> Currently, conversion from floating point to integer on 64bit targets
> goes through DImode temporary, due to missing BUILT_IN_ICEIL (and
> other) builtins that can convert directly from FP to integer.
> 
> Attached patch introduces these builtins and improves i.e.:
> 
> int
> test (double a)
> {
>   return round (a);
> }
> 
> using -ffast-math -O2 from:
> 
> 	...
> 	cvttsd2siq	%xmm1, %rax
> 	ret
> 
> to
> 	...
> 	cvttsd2si	%xmm1, %eax
> 	ret

Please document those in doc/extend.texi and make sure they do not
leak into the global namespace as ifloor, etc., but are only available
as __builtin_ifloor, etc..  Please also add at least a testcase
that excercises expanding all of the variants - like by simply
writing wrappers with the non-__builtin_ name variant like

int ifloor (double f) { return __builtin_ifloor (f); }
int main () {}

all variants should link correctly.

I'm not sure about the naming - shouldn't we name those internal
builtins after the mode, thus sifloor or even SIfloor?  Is there
precedent for the 'i' prefix?

Thanks,
Richard.

> 2011-08-11  Uros Bizjak  <ubizjak@gmail.com>
> 
> 	* builtins.def (BUILT_IN_ICEIL{,F,L}, BUILT_IN_IFLOOR{,F,L},
> 	BUILT_IN_IRINT{,F,L}, BUILT_IN_IROUND{,F,L}: New builtin definitions.
> 	* convert.c (convert_to_integer): Convert to BUILT_IN_ICEIL,
> 	BUILT_IN_IFLOOR, BUILT_IN_IRINT or BUILT_INT_IROUND when converting
> 	to integer_type_node.
> 	* fold-const.c (tree_call_nonnegative_warnv_p): Handle BUILT_IN_ICEIL,
> 	BUILT_IN_IFLOOR, BUILT_IN_IRINT and BUILT_INT_IROUND.
> 	* builtins.c (expand_builtin_in): Ditto.
> 	(mathfn_built_in_1): Ditto.
> 	(expand_builtin_int_roundingfn): Handle BUILT_IN_ICEIL and
> 	BUILT_IN_IFLOOR.
> 	(expand_builtin_int_roundingfn_2): Handle BUILT_IN_IRINT and
> 	BUILT_IN_IROUND.
> 	(fold_fixed_mathfn): Canonicalize BUILT_IN_ICEIL, BUILTIN_IN_IFLOOR,
> 	BUILT_IN_IRINT and BUILT_IN_IROUND to BUILT_IN_LCEIL,
> 	BUILTIN_IN_LFLOOR, BUILT_IN_LRINT and BUILT_IN_LROUND on ILP32 targets.
> 
> Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.
> 
> OK for mainline?
> 
> Uros.
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]