This is the mail archive of the
mailing list for the glibc project.
[RFC] Decimal Floating Point C Library Implementation
- From: "Ryan S. Arnold" <rsa at us dot ibm dot com>
- To: libc-alpha <libc-alpha at sourceware dot org>
- Cc: Roland McGrath <roland at redhat dot com>, sjmunroe <munroesj at us dot ibm dot com>
- Date: Fri, 03 Nov 2006 14:44:24 -0600
- Subject: [RFC] Decimal Floating Point C Library Implementation
Here is a first pass (preview) implementation of the Decimal
Floating Point C runtime Library.
The DFP C library is an implementation of the Draft Technical Report
ISO/IEC WDTR 24732, which extends the C programming language to
support decimal floating point arithmetic. The current draft is
ISO/IEC JTC1 SC22 WG14 N1176:
In its current form the DFP C library is implemented as a GLIBC
add-on with no platform-specific code and should build for any
platform that has the required decimal floating support in GCC
(powerpc*-linux, x86-linux, x86_64-linux).
Decimal float support is in mainline GCC, to become GCC 4.2.0, and
in the ibm/gcc-4_1-branch of the GCC Subversion repository. Decimal
float support is not enabled by default; configure GCC with
The eventual location of the DFP C library, in an existing project
or a new separate project, is yet to be decided. It is our intent
to contribute this code to FSF once we have an agreement with the
community on how to proceed. We post this preview here to expose it
to the community for review and to solicit input on how best to
address the remaining technical issues and the best way to proceed.
The following reasons indicate why 'dfp' is currently implemented as
a GLIBC add-on:
o Unmaintained printf hooks need official maintenance to enable new
DFP format codes (%H, %D, %DD).
o Restrictions on printf callback format codes, e.g. '%H' is not
o Lack of scanf callback mechanism to support DFP format codes, i.e.
(%DF, %DD, %DL):
o The ISO C TR defines DFP prototypes and constants in the
o Math function prototypes belong in math.h
o DFP constants belong in float.h
o DFP constants not provided in float.h belong in math.h
o DFP rounding modes and prototypes belong in fenv.h
o DFP strtod prototypes belong in stdlib.h
o The current math.h doesn't provide a callback mechanism for
polymorphic classification functions that are extended for decimal
floating point types support (e.g. fpclassify()). The libdfp
add-on currently uses __builtin_types_compatible_p() support in
gcc to provide this polymorphism in math.h.
o The runtime and applications need access to the FP exceptions,
masks, and rounding modes. Currently the fe* access functions
are in libm and the soft-fp status storage for the exceptions,
masks and rounding modes are in libc. The DFP spec uses the same
exceptions and masks as binary floating point but adds separate
decimal rounding modes. The question is should DFP follow this
pattern for the new Decimal rounting modes.
o PowerPC needs to support both software and hardware DFP. POWER6
uses the same bits in the FPSCR for exceptions and masks as BFP,
but has an 'extended to 64-bit' FPSCR for the DPF rounding modes.
This complicates the question above, since processors with binary
FPUs but no DPF unit (970, POWER4, POWER5, POWER5+) can use the
existing FPSCR for decimal exceptions raised by the runtime, but
still need separate storage for the decimal round mode."
In the GLIBC base directory unpack the DFP archive 'dfp.tgz'. This
will populate a 'dfp' add-on directory. Add 'dfp' to the GLIBC
--enable-add-ons configuration right before nptl:
The GLIBC DFP add-on overrides some of the base GLIBC files (e.g.
vfprintf, vfscanf, math.h, mathcalls.h, fenv.h). This release of
the DFP add-on overrides files checked out of GLIBC cvs-head as of
Linking against libdfp:
In order to pick up all DFP functionality the following is
-D__STDC_WANT_DEC_FP__=1 -std=gnu99 -ldfp
Thanks for your time,
Ryan S. Arnold
IBM Linux Technology Center