[Patch, fortran] Use BUILT_IN_IROUND

Janne Blomqvist blomqvist.janne@gmail.com
Thu Mar 15 19:02:00 GMT 2012


Hi,

since some time GCC has BUILT_IN_IROUND{F,,L}, similar to lround() and
llround() but the result is returned as an integer. As there is no
corresponding libc function, this builtin is expanded to lround{f,l}
except when -ffast-math is used, in which case it enables slightly
shorter and faster code to be generated inline. Attached patch enables
this builtin in the gfortran frontend. For the testcase

function my_nint(x)
  implicit none
  real :: x
  integer :: my_nint
  my_nint = nint(x)
end function my_nint

compiled with "-O2 -ffast-math" on x86-64, the difference between the
assembler output of trunk and trunk+patch:

--- iround.trunk.O2fastmath.s   2012-03-15 20:12:40.045069324 +0200
+++ iround.s    2012-03-15 20:24:19.501320278 +0200
@@ -12,7 +12,7 @@ my_nint_:
        movss   .LC0(%rip), %xmm0
        orps    %xmm1, %xmm0
        addss   %xmm2, %xmm0
-       cvttss2siq      %xmm0, %rax
+       cvttss2si       %xmm0, %eax
        ret
        .cfi_endproc
 .LFE0:

Comparing the size of the object files, in the patched version the
text section is one byte shorter.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

(As an aside, there were some recent problems with __builtin_iround(),
see PR 52592, but they seem to be fixed now so I think this should be
safe)

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.


-- 
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iround.diff
Type: text/x-patch
Size: 5125 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120315/4337d3c0/attachment.bin>


More information about the Gcc-patches mailing list