This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] | |
For those not reading gcc-patches...
--- Begin Message ---Hello!
- From: "Uros Bizjak" <ubizjak at gmail dot com>
- Cc: "FX Coudert" <fxcoudert at gmail dot com>
- Date: Mon, 23 Oct 2006 12:32:19 +0200
- Subject: [RFC Patch]: Implement remainder() as built-in function [PR fortran/24518]
- Approved: news@gmane.org
- Archived-at: <http://permalink.gmane.org/gmane.comp.gcc.patches/125255>
- Envelope-to: gcc-patches@gmane.org
- Newsgroups: gmane.comp.gcc.patches
- Original-received: from sourceware.org ([209.132.176.174])by ciao.gmane.org with smtp (Exim 4.43)id 1Gbx6i-00062s-Jlfor gcc-patches@gmane.org; Mon, 23 Oct 2006 12:32:37 +0200
- Original-received: (qmail 10398 invoked by alias); 23 Oct 2006 10:32:29 -0000
- Original-received: (qmail 10384 invoked by uid 22791); 23 Oct 2006 10:32:25 -0000
- Original-received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.188) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 23 Oct 2006 10:32:22 +0000
- Original-received: by nf-out-0910.google.com with SMTP id l24so2446474nfc for <gcc-patches@gcc.gnu.org>; Mon, 23 Oct 2006 03:32:20 -0700 (PDT)
- Original-received: by 10.49.55.13 with SMTP id h13mr14163813nfk; Mon, 23 Oct 2006 03:32:19 -0700 (PDT)
- Original-received: by 10.48.210.2 with HTTP; Mon, 23 Oct 2006 03:32:19 -0700 (PDT)
- Original-to: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Original-x-from: gcc-patches-return-180356-gcc-patches=m.gmane.org@gcc.gnu.org Mon Oct 23 12:32:38 2006
- Xref: news.gmane.org gmane.comp.gcc.patches:125255
The motivation for this RFC patch is comment #4 to PR fortran/24518, where MOD and MODULO fortran calls are proposed to be implemented using __builtin_fmod() and __builtin_remainder().
Currently there are some obstacles in the implementation of fortran front-end support:
1) missing __builtin_remainder() optab description (solved by attached patch)
2) __builtin_fmod(), __builtin_drem() and __builtin_remainder() expansion currently depends on flag_unsafe_math_optimizations, but IMO there is no reason for that.
Attached patch expands these three builtin functions in all cases. Errno handling is implemented in the same way as sqrt?f2 support is handled. The return of intrinsic x87 function is checked for NaN, and in case NaN is detected, library function is called.
Following testcase: --cut here-- double test(double a, double b) { return remainder(a, b); } --cut here--
compiles to: test: pushl %ebp movl %esp, %ebp subl $8, %esp fldl 8(%ebp) fldl 16(%ebp) fld %st(1) fld %st(1) fxch %st(1) .L2: fprem1 fnstsw %ax sahf jp .L2 fstp %st(1) fstpl -8(%ebp) fldl -8(%ebp) fucom %st(0) fnstsw %ax sahf jp .L11 jne .L11 fstp %st(1) fstp %st(1) leave ret .p2align 4,,7 .L11: fstp %st(0) fstpl 16(%ebp) fstpl 8(%ebp) leave jmp remainder
When fno-math-errno is used, testcase compiles to:
test: pushl %ebp movl %esp, %ebp subl $8, %esp fldl 8(%ebp) fldl 16(%ebp) fxch %st(1) .L2: fprem1 fnstsw %ax sahf jp .L2 fstp %st(1) fstpl -8(%ebp) fldl -8(%ebp) leave ret
(fstpl/fldl pair at the end is in fact XFmode->DFmode fixup).
and using -ffast-math:
test: pushl %ebp movl %esp, %ebp fldl 8(%ebp) fldl 16(%ebp) fxch %st(1) .L2: fprem1 fnstsw %ax sahf jp .L2 fstp %st(1) popl %ebp ret
2006-10-23 Uros Bizjak <uros@kss-loka.si>
* optabs.h (enum optab_index): Add new OTI_remainder. (remainder_optab): Define corresponding macro. * optabs.c (init_optabs): Initialize remainder_optab. * genopinit.c (optabs): Implement remainder_optab using remainder?f3 patterns. * builtins.c (expand_builtin_mathfn_2): Handle BUILT_IN_REMAINDER{,F,L} using remainder_optab. (expand_builtin): Expand BUILT_IN_REMAINDER{,F,L} using expand_builtin_mathfn_2.
(expand_builtin) [BUILT_IN_FMOD], [BUILT_IN_DREM]: Do not depend on flag_unsafe_math_optimizations.
* config/i386/i386.md ("remaindersf3", "remainderdf3") ("remainderxf3"): New expanders to implement remainderf, remainder and remainderl built-ins as inline x87 intrinsics.
("fpremxf4", "fprem1xf4"): Do not depend on flag_unsafe_math_optimizations. ("fmodsf3", "fmoddf3", "fmodxf3"): Do not depend on flag_unsafe_math_optimizations. Use truncxf?f expander instead of truncxf?f_i387_noop. ("dremsf3", "dremdf3", "dremxf3"): Do not depend on flag_unsafe_math_optimizations. Use truncxf?f expander instead of truncxf?f_i387_noop.
Uros.Attachment: i386-remainder.diff
Description: Binary data
--- End Message ---
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |