17

I have medium size C99 program which uses long double type (80bit) for floating-point computation. I want to improve precision with new GCC 4.6 extension __float128. As I get, it is a software-emulated 128-bit precision math.

How should I convert my program from classic long double of 80-bit to quad floats of 128 bit with software emulation of full precision? What need I change? Compiler flags, sources?

My program have reading of full precision values with strtod, doing a lot of different operations on them (like +-*/ sin, cos, exp and other from <math.h>) and printf-ing of them.

PS: despite that float128 is declared only for Fortran (REAL*16), the libquadmath is written in C and it uses float128. I'm unsure will GCC convert operations on float128 to runtime library or not and I'm unsure how to migrate from long double to __float128 in my sources.

PPS: There is a documentation on "C" language gcc mode: http://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html

"GNU C compiler supports ... 128 bit (TFmode) floating types. Support for additional types includes the arithmetic operators: add, subtract, multiply, divide; unary arithmetic operators; relational operators; equality operators ... __float128 types are supported on i386, x86_64"

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
osgx
  • 90,338
  • 53
  • 357
  • 513
  • libquadmath is here http://gcc.gnu.org/onlinedocs/libquadmath/index.html#toc_Top and here is news about this http://gcc.gnu.org/gcc-4.6/changes.html "GCC now ships with the LGPL-licensed libquadmath library, which provides quad-precision mathematical functions for targets with a __float128 datatype. __float128 is available for targets on 32-bit x86, x86-64 and Itanium architectures. " – osgx Jun 23 '11 at 16:24
  • turn that basic operations are done by `glibc/soft-fp`, e.g `__subtf3()` http://koala.cs.pub.ro/lxr/#glibc+2.9/soft-fp/subtf3.c#L35 http://gcc.gnu.org/wiki/Software_floating_point – osgx Jun 24 '11 at 12:13
  • 1
    using libquadmath, you can use [strtoflt128](http://webcache.googleusercontent.com/search?q=cache:P0PwG_dRv4EJ:gcc.gnu.org/onlinedocs/libquadmath.ps.gz+&cd=1&hl=en&ct=clnk&client=ubuntu) as a `strtod` replacement. – Janus Troelsen Jul 29 '12 at 23:34

1 Answers1

32

How should I convert my program from classic long double of 80-bit to quad floats of 128 bit with software emulation of full precision? What need I change? Compiler flags, sources?

You need recent software, GCC version with support of __float128 type (4.6 and newer) and libquadmath (supported only on x86 and x86_64 targets; in IA64 and HPPA with newer GCC). You should add linker flag -lquadmath (the cannot find -lquadmath' will show that you have no libquadmath installed)

You should also know, that since 4.6 Gfortran will use __float128 type for DOUBLE PRECISION, if the option -fdefault-real-8 was given and there were no option -fdefault-double-8. This may be problem, since 128 long double is much slower than standard long double on many platforms due to software computation. (Thanks to post by glennglockwood http://glennklockwood.blogspot.com/2014/02/linux-perf-libquadmath-and-gfortrans.html)

osgx
  • 90,338
  • 53
  • 357
  • 513