[PATCH, take 2] implement drem() and fmod() as built-in x87 intrinsic

Uros Bizjak uros@kss-loka.si
Wed May 5 10:45:00 GMT 2004


Roger Sayle wrote:

>In your current patch you create a forward conditional "ordered" jump
>over a backward unconditional jump.  A better approach is just generate a
>single backward conditional "unordered" jump.  gen_rtx_UNORDERED and
>and gen_rtx_LABEL_REF (VOIDmode, label1).  This should reduce the amount
>of initial RTL.
>
>The final fmoddf3 expanders should look like:  
>
  Roger,

  I have (hopefully) addressed all your suggestions, and new patch is 
attached to this message. This patch now implements both drem and fmod 
instructions. Patch is tested by bootstrapping gcc on i686-linux-gnu, 
and attached builtins-40.c testcase was compiled.

  BTW: I had to recode fprem{,1} instructions as two input, two output 
instruction, otherwise this testcase failed:

--cut here--
#define OP1 37865432.1234e300
#define OP2 0.234786234

int main() {
        float xf = OP1;
        float yf = OP2;

        double x = OP1;
        double y = OP2;

        long double xl = OP1;
        long double yl = OP2;
        printf("%f, %f, %Lf\n", fmodf(xf,yf), fmod(x,y), fmodl(xl,yl));
        printf("%f, %f, %Lf\n", dremf(xf,yf), drem(x,y), dreml(xl,yl));
        return 0;
}
--cut here--

Input register for x86_fnstsw_1 pattern was changed to (reg:CCFP 18) and 
everything works as expected now.

OK for mainline CVS?

2004-05-05  Uros Bizjak  <uros@kss-loka.si>

    * optabs.h (enum optab_index): Add new OTI_fmod and OTI_drem.
    (fmod_optab): Define corresponding macros.
    * optabs.c (init_optabs): Initialize fmod_optab and drem_optab.
    * genopinit.c (optabs): Implement fmod_optab and drem_optab
    using fmod?f3 and drem?f3 patterns.
    * builtins.c (expand_builtin_mathfn_2): Handle BUILT_IN_FMOD{,F,L}
    using fmod_optab and BUILT_IN_DREM{,F,L} using drem_optab.
    (expand_builtin): Expand BUILT_IN_FMOD{,F,L} and
    BUILT_IN_DREM{,F,L} using expand_builtin_mathfn_2 if
    flag_unsafe_math_optimizations is set.

    * reg-stack.c (subst_stack_regs_pat): Handle UNSPEC_FPREM_F,
    UNSPEC_FPREM_U, UNSPEC_FPREM1_F and UNSPEC_FPREM1_U.

    * config/i386/i386.c (ix86_emit_fp_unordered_jump): New function.
    * config/i386/i386-protos.h (ix86_emit_fp_unordered_jump):
    Prototype here.
    * config/i386/i386.md (UNSPEC_FPREM_F, UNSPEC_FPREM_U,
    UNSPEC_FPREM1_F, UNSPEC_FPREM1_U): New unspecs to represent x87's
    fprem and fprem1 instructions.
    (*x86_fnstsw_1): Change input parameter to (reg:CCFP 18).
    Rename insn definition to x86_fnstsw_1.
    (fpremxf4, fprem1xf4): New patterns to implement fprem and fprem1
    x87 instructions.
    (fmodsf3, fmoddf3, fmodxf3): New expanders to implement fmodf, fmod
    and fmodl built-ins as inline x87 intrinsics.
    (dremsf3, dremdf3, dremxf3): New expanders to implement dremf, drem
    and dreml built-ins as inline x87 intrinsics.

testsuite:

    * testsuite/gcc.dg/builtins-40.c: New test.

    Uros.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dremfmod.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040505/6598a9bb/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: builtins-40.c
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040505/6598a9bb/attachment.c>


More information about the Gcc-patches mailing list