Re: Are Decimal operations are fully implemented/tested ?

2012-09-17 Thread Vincent Lefevre
On 2012-09-14 16:17:43 +, Joseph S. Myers wrote:
 On Fri, 14 Sep 2012, Vincent Lefevre wrote:
 
  round-to-odd would be a good solution if it were provided directly
  in hardware. Otherwise a direct implementation would probably be
  more efficient (in particular when the implementation of the usual
  operation is done in software, like for decimal arithmetic).
 
 It's the case for a lot of libm operations that the best implementation 
 for software floating point is not the same as for hardware floating point 
 (anything implemented using Dekker's algorithms or similar precision 
 extension techniques would probably better use higher precision more 
 directly on integers, for example).

The main difference is that most processors have hardware FP, so
that FP expansions are better in general to implement libm math
functions (a hardware FMA is very useful for that too, but most
processors will have one in the near future), while round-to-odd
is not provided in hardware, not in IEEE 754-2008, and probably
won't be provided in hardware at least before a distant future.
So, there is work to do in software...

Then, between implementing round-to-odd and implementing a direct
formatOf operation, I don't think there is much difference concerning
the work to do (I would even say that round-to-odd could require more
work).

 It's also the case that there hasn't been any actual interest in
 optimal software implementations for these cases in glibc (I guess
 people concerned about floating-point performance are generally
 using hardware floating point).

If people really need decimal (e.g. for financial applications),
they would use it instead of hardware binary FP.

-- 
Vincent Lefèvre vinc...@vinc17.net - Web: http://www.vinc17.net/
100% accessible validated (X)HTML - Blog: http://www.vinc17.net/blog/
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Re: Are Decimal operations are fully implemented/tested ?

2012-09-17 Thread Joseph S. Myers
On Mon, 17 Sep 2012, Vincent Lefevre wrote:

 Then, between implementing round-to-odd and implementing a direct
 formatOf operation, I don't think there is much difference concerning
 the work to do (I would even say that round-to-odd could require more
 work).

The difference would probably be that round-to-odd involves a temporary 
(and probably expensive) change to the rounding mode to round towards zero 
- whereas other approaches (one of which might be using Dekker's / Knuth's 
algorithms to compute an exact sum or product, then using the low part of 
that to adjust the high part before rounding to the desired format) could 
be done without such a change.

(With direct software floating-point implementations on a processor that 
has hardware floating point, you also need to ensure that the final result 
is rounded according to the current rounding direction and that 
appropriate exceptions are raised - maybe through using the software 
floating point to produce directly the adjusted value in a wider format, 
then the hardware floating point to round that to the narrower format.)

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: Are Decimal operations are fully implemented/tested ?

2012-09-14 Thread Vincent Lefevre
On 2012-09-13 16:46:04 +, Joseph S. Myers wrote:
 On Thu, 13 Sep 2012, Vincent Lefevre wrote:
  But if you want an example, I don't think that the formatOf
  arithmetic operations (IEEE 754-2008 §5.4.1 -- that's a shall)
  are implemented by GCC, either for binary or for decimal, say
  add two _Decimal128 numbers and round to _Decimal64 directly
  (with a single rounding).
 
 For binary floating point, the draft C bindings (I'm looking at WG14 
 N1605, which is just a draft of the first part of what's supposed to end 
 up as a five-part document) defines such operations as library operations 
 (e.g. float fadd(double x, double y);) rather than compiler ones (although 
 of course the compiler might have corresponding built-in functions).  

Note however that efficiency is important. If one had to choose to
spend time on compiling/implementing these operations, the focus
should be on the compiler first (actually, that's particularly
true for binary on IA-64, where these operations are part of the
instruction set and implemented in hardware on the Itanium).

Also if the (software) implementation of _Decimal64 operations and
_Decimal128 operations is done by GCC, it would be better to have
the implementation of the corresponding formatOf operations done
by GCC too (keep similar code at the same place).

 (Implementing fadd itself probably isn't hard; given exception and 
 rounding mode support you should be able to do it with round-to-odd as 
 described by Boldo and Melquiond

round-to-odd would be a good solution if it were provided directly
in hardware. Otherwise a direct implementation would probably be
more efficient (in particular when the implementation of the usual
operation is done in software, like for decimal arithmetic).

Note: What makes round-to-odd work is that one gets a good enough
approximation to the exact result, and the sign of the error w.r.t.
a format with less precision is encoded in the result itself;
and all this information is kept in a single floating-point number.
But if you need to implement a formatOf operation and round-to-odd
isn't directly available, it may be better to get the approximation
and the error (or just its sign) in some more usual way, and work
with them without packing them in a single floating-point number.

 - and some processors (ia64?) may have direct support for it.

In binary only (because it doesn't have decimal support at all).

 But there are lots of new functions, that's just one.)

-- 
Vincent Lefèvre vinc...@vinc17.net - Web: http://www.vinc17.net/
100% accessible validated (X)HTML - Blog: http://www.vinc17.net/blog/
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Re: Are Decimal operations are fully implemented/tested ?

2012-09-14 Thread Joseph S. Myers
On Fri, 14 Sep 2012, Vincent Lefevre wrote:

 round-to-odd would be a good solution if it were provided directly
 in hardware. Otherwise a direct implementation would probably be
 more efficient (in particular when the implementation of the usual
 operation is done in software, like for decimal arithmetic).

It's the case for a lot of libm operations that the best implementation 
for software floating point is not the same as for hardware floating point 
(anything implemented using Dekker's algorithms or similar precision 
extension techniques would probably better use higher precision more 
directly on integers, for example).  It's also the case that there hasn't 
been any actual interest in optimal software implementations for these 
cases in glibc (I guess people concerned about floating-point performance 
are generally using hardware floating point).

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: Are Decimal operations are fully implemented/tested ?

2012-09-13 Thread Vincent Lefevre
On 2012-09-12 15:55:16 +0300, Hesham Moustafa wrote:
 If exist, what are the known bugs in the current implementation of
 Decimal / IEEE 754-2008 standard ?

I don't know any reported bug of the decimal implementation (though
PR 37845 about the FP_CONTRACT pragma, which affects binary on some
machines, might also affect decimal in some distant future if it is
still not fixed).

But if you want an example, I don't think that the formatOf
arithmetic operations (IEEE 754-2008 §5.4.1 -- that's a shall)
are implemented by GCC, either for binary or for decimal, say
add two _Decimal128 numbers and round to _Decimal64 directly
(with a single rounding).

-- 
Vincent Lefèvre vinc...@vinc17.net - Web: http://www.vinc17.net/
100% accessible validated (X)HTML - Blog: http://www.vinc17.net/blog/
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Re: Are Decimal operations are fully implemented/tested ?

2012-09-13 Thread Joseph S. Myers
On Thu, 13 Sep 2012, Vincent Lefevre wrote:

 But if you want an example, I don't think that the formatOf
 arithmetic operations (IEEE 754-2008 §5.4.1 -- that's a shall)
 are implemented by GCC, either for binary or for decimal, say
 add two _Decimal128 numbers and round to _Decimal64 directly
 (with a single rounding).

For binary floating point, the draft C bindings (I'm looking at WG14 
N1605, which is just a draft of the first part of what's supposed to end 
up as a five-part document) defines such operations as library operations 
(e.g. float fadd(double x, double y);) rather than compiler ones (although 
of course the compiler might have corresponding built-in functions).  
N1582 indicates that names such as _Float32 f32addf64(_Float64 x, _Float64 
y); would be used for the functions with specific IEEE types - so I guess 
d64addd128 for the example you give.

The draft C bindings for IEEE 754-2008 are at a sufficiently early stage 
that before putting anything in mainline glibc it would be important to 
look carefully at how likely any incompatible changes would be (more 
likely for some functions than for others, I expect).  Of course they will 
only go in (for either GCC or glibc) if someone contributes 
implementations, and they would be a sufficiently large project that they 
aren't particularly likely to be done as a spare-time project.

(Implementing fadd itself probably isn't hard; given exception and 
rounding mode support you should be able to do it with round-to-odd as 
described by Boldo and Melquiond - and some processors (ia64?) may have 
direct support for it.  But there are lots of new functions, that's just 
one.)

-- 
Joseph S. Myers
jos...@codesourcery.com

Re: Are Decimal operations are fully implemented/tested ?

2012-09-12 Thread Vincent Lefevre
On 2012-09-12 11:29:41 +0300, Hesham Moustafa wrote:
 I want to inquire about the state of decimal floating point operations
 at gcc low-level library.
 Does gcc fully implement IEEE 754-2008 standard ?

No. Even for binary-only it doesn't (though it almost does). Also
note that some parts of IEEE 754-2008 are (should be) implemented
on the C library side (e.g. glibc).

-- 
Vincent Lefèvre vinc...@vinc17.net - Web: http://www.vinc17.net/
100% accessible validated (X)HTML - Blog: http://www.vinc17.net/blog/
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Re: Are Decimal operations are fully implemented/tested ?

2012-09-12 Thread Hesham Moustafa
On Wed, Sep 12, 2012 at 1:29 PM, Vincent Lefevre vincent+...@vinc17.org wrote:
 On 2012-09-12 11:29:41 +0300, Hesham Moustafa wrote:
 I want to inquire about the state of decimal floating point operations
 at gcc low-level library.
 Does gcc fully implement IEEE 754-2008 standard ?

 No. Even for binary-only it doesn't (though it almost does). Also
 note that some parts of IEEE 754-2008 are (should be) implemented
 on the C library side (e.g. glibc).

If exist, what are the known bugs in the current implementation of
Decimal / IEEE 754-2008 standard ?
 --
 Vincent Lefèvre vinc...@vinc17.net - Web: http://www.vinc17.net/
 100% accessible validated (X)HTML - Blog: http://www.vinc17.net/blog/
 Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)