Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #126448

Re: What happened to short float?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c, comp.std.c
Subject Re: What happened to short float?
Date 2018-02-08 10:13 -0800
Organization None to speak of
Message-ID <lntvurxsbk.fsf@kst-u.example.com> (permalink)
References (2 earlier) <p52ngk$evf$1@dont-email.me> <fdr6e4Fp1fcU1@mid.individual.net> <20180208012936.09fa549ce0fe0785da7cf560@gmail.com> <lnk1voz46u.fsf@kst-u.example.com> <20180208095429.606364963470edfaf0cc3206@gmail.com>

Cross-posted to 2 groups.

Show all headers | View raw


GOTHIER Nathan <nathan.gothier@gmail.com> writes:
> On Wed, 07 Feb 2018 16:59:53 -0800
> Keith Thompson <kst-u@mib.org> wrote:
>> Wouldn't you need extra code to convert between 16-bit and 32-bit
>> formats?  For normal values you'd need to do some bit-twiddling.
>> Special values like infinities, NaNs, subnormals, and so forth might
>> require some extra work (I haven't looked into the details).
>
> No. Supporting the short float type for computing purpose doesn't mean
> you have to implement the half floating point format.
>
> Since the IEEE 754 standard requires only the implementation of the
> single precision float format, any compliant hardware could implement
> the short float type as a single precision float. Hardware with a full
> specific half float support could provide more performance.
>
>> > typedef char half_t[2];
>> 
>> (I'd use uint16_t, or at least unsigned char[2] rather than char[2].)
>
> I agree, the object should be stored at least as unsigned char[2].

If a compiler supports short float as a 16-bit type, it's going to be a
distinct type.  I don't see the point of a typedef.  A short float would
be stored in 16 bits; it would not be an array of unsigned char any more
than short int is.

>> Sure, if you have a CPU instruction that does the conversion, it's
>> easy.
>
> Not really. The F16C instruction set for example only provides the
> conversion to half precision float but not the arithmetic.

If there are CPU instructions for arithmetic on 32-bit floating-point
but not for 16-bit floating-point, then arithmetic on 16-bit short
float would be performed by converting to 32-bit float, performing
the operation, and then converting back to 16-bit short float.
The same can be done with float and double, depending on what the
hardware directly supports.

> Consequently, the implementation should distinguish the storage format
> from the computing format such as:
>
> typedef unsigned char half_t[2];
> typedef float sflt_t;
>
> sflt_t *htosf(half_t *x);
> half_t *sftoh(sflt_t *x);

The standard already permits floating-point operations to be done using
a wider type.  This would be no different.

>> If you don't, it's not prohitively difficult, but it's not quite as
>> obvious that it's worth the effort.
>
> As already said, there's no need to implement the half precision
> format. The short float type should only provide hardware acceleration
> when available.

I don't understand the scenario you're suggesting.  How could the
short float type provide hardware acceleration if the format isn't
implemented?

I see the following possibilities:

1. short float and float are both 32 bits.  Using short float rather
than float doesn't provide any advantage in speed or storage for
the particular platform.

2. short float is 16 bits, float is 32 bits.  The hardware doesn't
provide 16-bit floating-point arithmetic operations.  Arithmetic
operations on short float values are performed by converting to a
wider floating-point type and back again.

3. short float is 16 bits, float is 32 bits.  The hardware provides
16-bit and 32-bit hardware floating-point arithmetic instructions.
short float arithmetic operates directly on 16-bit values (and,
we hope, is faster than 32-bit arithmetic).

(In response to the question that started this thread, I have no idea
what, if anything, has been done with the proposal.  Since the next
edition of the C standard is several years away, there's probably
no particular urgency.  There could be more information in the WG14
meeting notes, but I haven't checked.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What happened to short float? Philipp Klaus Krause <pkk@spth.de> - 2018-01-17 17:21 +0100
  Re: What happened to short float? "James R. Kuyper" <jameskuyper@verizon.net> - 2018-01-17 11:42 -0500
    Re: What happened to short float? jacobnavia <jacob@jacob.remcomp.fr> - 2018-02-02 23:08 +0100
      Re: What happened to short float? Jakob Bohm <jb-usenet@wisemo.com> - 2018-02-05 07:57 +0100
        Re: What happened to short float? jameskuyper@verizon.net - 2018-02-05 05:31 -0800
      Re: What happened to short float? Tim Prince <tprince@intelretiree.com> - 2018-02-05 08:55 -0500
        Re: What happened to short float? jacobnavia <jacob@jacob.remcomp.fr> - 2018-02-05 15:46 +0100
        Re: What happened to short float? GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-02-08 01:29 +0100
          Re: What happened to short float? Keith Thompson <kst-u@mib.org> - 2018-02-07 16:59 -0800
            Re: What happened to short float? Philipp Klaus Krause <pkk@spth.de> - 2018-02-08 09:08 +0100
              Re: What happened to short float? Keith Thompson <kst-u@mib.org> - 2018-02-08 09:27 -0800
            Re: What happened to short float? GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-02-08 09:54 +0100
              Re: What happened to short float? Keith Thompson <kst-u@mib.org> - 2018-02-08 10:13 -0800
            Re: What happened to short float? jameskuyper@verizon.net - 2018-02-08 06:36 -0800
              Re: What happened to short float? GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-02-08 17:04 +0100
                Re: What happened to short float? jameskuyper@verizon.net - 2018-02-08 08:56 -0800
                Re: What happened to short float? scott@slp53.sl.home (Scott Lurndal) - 2018-02-08 17:23 +0000
                Re: What happened to short float? GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-02-08 18:52 +0100
                Re: What happened to short float? jameskuyper@verizon.net - 2018-02-08 11:27 -0800
                Re: What happened to short float? GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-02-08 22:58 +0100
              Re: What happened to short float? Keith Thompson <kst-u@mib.org> - 2018-02-08 10:18 -0800
          Re: What happened to short float? Jakob Bohm <jb-usenet@wisemo.com> - 2018-02-08 18:59 +0100
            Re: What happened to short float? Robert Wessel <robertwessel2@yahoo.com> - 2018-02-08 16:22 -0600
              Re: What happened to short float? Jakob Bohm <jb-usenet@wisemo.com> - 2018-02-09 15:01 +0100
  Re: What happened to short float? Chad <cdalten@gmail.com> - 2018-01-17 09:12 -0800
  Re: What happened to short float? scott@slp53.sl.home (Scott Lurndal) - 2018-01-17 17:31 +0000
  Re: What happened to short float? jacobnavia <jacob@jacob.remcomp.fr> - 2018-01-17 19:52 +0100
    Re: What happened to short float? Philipp Klaus Krause <pkk@spth.de> - 2018-01-18 13:18 +0100
      Re: What happened to short float? bartc <bc@freeuk.com> - 2018-01-18 12:40 +0000

csiph-web