[PATCH]: Expand finite() as inline i386 asm

Richard Guenther richard.guenther@gmail.com
Thu Jan 25 15:48:00 GMT 2007


On 1/25/07, Uros Bizjak <ubizjak@gmail.com> wrote:
> Hello!
>
> Attached patch expands call to finite(), finitef() and finitel() as
> inline i386 asm (and produces the same code as is present in libm for
> those functions).
>
> Following testcase:
> --cut here--
> int test(double a)
> {
>         return finite(a + 2.0);
> }
> --cut here--
>
> produces (gcc -O2 -fomit-frame-pointer):
> test:
>         subl    $12, %esp
>         movl    $-1048577, %eax
>         flds    .LC0
>         faddl   16(%esp)
>         fstpl   (%esp)
>         movl    4(%esp), %edx
>         addl    $12, %esp
>         subl    %edx, %eax
>         xorl    %edx, %eax
>         shrl    $31, %eax
>         ret
>
> The patch also works for -mfpmath=sse:
> test:
>         subl    $12, %esp
>         movl    $-1048577, %eax
>         movsd   .LC0, %xmm0
>         addsd   16(%esp), %xmm0
>         movsd   %xmm0, (%esp)
>         movl    4(%esp), %edx
>         addl    $12, %esp
>         subl    %edx, %eax
>         xorl    %edx, %eax
>         shrl    $31, %eax
>         ret
>
> Regarding the implementation, by representing "finite" optab as a
> conversion optab, existing infrastructure that handles conversion
> optabs could be used with minimum middle-end changes.

A conversion optab has a non-neglible size overhead and in this case
we only have one target mode (SImode), so I'd rather have you use
a regular unoptab.

> It could be
> argued, that function named "expand_builtin_int_roundingfn_2" is not
> exactly the best name for the function that also handles finite (and
> eventually ilogb) optab - perhaps it could be renamed to a better name
> like "expand_builtin_intermodefn".

Just don't use that function and implement expand_builtin_classify ().

I think the testcase will fail on targets not providing a library fallback
for finite{,f,l} as it seems to conform to BSD (the C99 variant is called
isfinite ()).

Richard.

> Patch was bootstrapped and regression tested on i686-pc-linux-gnu for
> all default languages. OK for mainline?
>
> 2007-01-25  Uros Bizjak  <ubizjak@gmail.com>
>
>         * optabs.h (enum convert_optab_index): Add new COI_finite.
>         (finite_optab): Define corresponding macro.
>         * optabs.c (init_optabs): Initialize finite_optab.
>         * genopinit.c (optabs): Implement finite_optab using finite?f?i2
>         patterns.
>         * builtins.c (expand_builtin_int_roundingfn_2): Handle
>         BUILT_IN_FINITE{,F,L} using finite_optab.  Add check_errno boolean
>         and clear it for BUILT_IN_FINITE{,F,L}.  Do not expand optab when
>         check_errno and flag_errno_math are both set.
>         (expand_builtin): Expand BUILT_IN_FINITE{,F,L} using
>         expand_builtin_int_roundingfn_2.
>
>         * config/i386/i386.md (finite<mode>si2) New expander to implement
>         finite, finitef and finitel built-in functions as inline asm.
>
> testsuite/ChangeLog:
>
> 2007-01-25  Uros Bizjak  <ubizjak@gmail.com>
>
>         * gcc.dg/builtins-63.c: New test.
>
> Uros.
>
>
>



More information about the Gcc-patches mailing list