This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [ARM] Enable __fp16 as a function parameter and return type.
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Matthew Wahab <matthew dot wahab at foss dot arm dot com>
- Cc: Ramana Radhakrishnan <ramana dot gcc at googlemail dot com>, Tejas Belagod <tejas dot belagod at foss dot arm dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Ramana Radhakrishnan <Ramana dot Radhakrishnan at arm dot com>
- Date: Wed, 18 May 2016 15:54:52 +0000
- Subject: Re: [ARM] Enable __fp16 as a function parameter and return type.
- Authentication-results: sourceware.org; auth=none
- References: <5721D5C1 dot 3080000 at foss dot arm dot com> <alpine dot DEB dot 2 dot 20 dot 1604281528210 dot 13527 at digraph dot polyomino dot org dot uk> <5733499E dot 7050001 at foss dot arm dot com> <alpine dot DEB dot 2 dot 20 dot 1605111536270 dot 27272 at digraph dot polyomino dot org dot uk> <5739C827 dot 9060109 at foss dot arm dot com> <CAJA7tRa8unSc=U9dntMJ4UW_UGABnecnOMW6MSpD0Gch87xnwA at mail dot gmail dot com> <573C7D41 dot 8070502 at foss dot arm dot com>
On Wed, 18 May 2016, Matthew Wahab wrote:
> On 18/05/16 09:41, Ramana Radhakrishnan wrote:
> > On Mon, May 16, 2016 at 2:16 PM, Tejas Belagod
> > <tejas.belagod@foss.arm.com> wrote:
> >
> > >
> > > We do have plans to fix pre-ACLE behavior of fp16 to conform to current
> > > ACLE
> > > spec, but can't say when exactly.
> >
> > Matthew, could you please take a look at this while you are in this area ?
>
> Ok.
FWIW, the obvious (to me) approach to doing the conversion without double
rounding issues while properly respecting exceptions and rounding modes
would be to set a sticky bit in the double value and ensure its precision
is no more than that of float before converting to float. Something like
(example for little-endian, untested):
union { double d; struct { uint32_t lo, hi; } r; } x;
__fp16 ret;
if (x.r.lo) x.r.hi |= 1;
x.r.lo = 0;
ret = (__fp16) (float) x.d;
By using floating point for the final conversion, you ensure it respects
the rounding mode and produces the proper exceptions.
--
Joseph S. Myers
joseph@codesourcery.com