Speeding up floating point number reading

Daniel Kraft d@domob.eu
Mon Dec 29 15:40:00 GMT 2008


Hi all,

as promised on PR 38654, I gave floating point reading a look.  I used 
the attached program for testing with -O3 -static.  It takes around 31s 
on my system with an unpatched gfortran 4.4.

First, I tried to replace the strtod call in 
libgfortran/io/read.c:convert_real with a custom made parser according 
to the one I implemented for FreeWRL, and even got execution time to 
around 29s (a bit surprising, I though strtod must be well optimized).

However, I then looked further, and discovered that read_f, the caller 
of convert_real, is already doing most of the work!  And then, it prints 
the number back to a string just to parse it again using convert_real... 
With the simple (experimental and rough) patch attached, the final 
floating point value can be calculated with little additional effort in 
read_f, without ever calling convert_real.  This cuts the execution time 
in half to 15.5s!

The only weak point is that I'm not sure if we may experience rounding 
errors in parsing the float due to all the *10 and + operations, and 
that could be something strtod takes care of.  On the other hand, I 
think this is rather unlikely.  What do you think about this one?

I'm going to work out a real patch, that handles all kinds, not just 
double, and in addition cleans up all now-useless stuff.  Comments welcome!

Yours,
Daniel

-- 
Done:  Arc-Bar-Cav-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri-Ran
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch1.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081229/9fd5a462/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081229/9fd5a462/attachment.f90>


More information about the Fortran mailing list