From: Joseph Myers <joseph@codesourcery.com>
To: Tejas Joshi <tejasjoshi9673@gmail.com>
Cc: <gcc@gcc.gnu.org>
Subject: Re: GSoC
Date: Thu, 01 Mar 2018 18:34:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.20.1803011755560.17797@digraph.polyomino.org.uk> (raw)
In-Reply-To: <CACMrGjDfqAQJbwFZ42zpsEqWNsmWSoK6pGr-Lpg9uXj+Nd7zww@mail.gmail.com>
On Thu, 1 Mar 2018, Tejas Joshi wrote:
> "GCC supports built-in functions for math.h and complex.h functions in
> the C99/C11 standards (both folding calls for constant arguments, and
> expanding inline when the processor supports appropriate
> functionality). More such functions have been added in ISO/IEC TS
> 18661, supporting features of IEEE 754-2008. It would be useful to
> have built-in functions for those, both folding for constant
> arguments, and expanding inline where appropriate (e.g. for roundeven
> and the functions rounding result to narrower type, on some
> processors; roundeven can be inlined on x86 for SSE4.1 and later, and
> the narrowing functions on IA64 and POWER8, for example)".
>
> The above Project Idea is made available on 'Summer of Code' wiki of
> GNU GCC Website. I wanted to have some more details about above idea
> regarding to what is expected for implementation and expected output
> for the same.
See <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1778.pdf> for a
near-final draft of TS 18661-1 that says what various of the functions
mentioned should do. In most cases you'd be folding for constant
arguments and generating appropriate instructions for non-constant
arguments if the target processor has such instructions - for non-constant
arguments where the processor doesn't have relevant instructions, the
implementation would be left to libm (e.g. glibc 2.25 has most of these
functions) as it would be too big to expand inline in that case.
Here are some examples:
* roundeven is similar to existing functions round / ceil / floor / trunc.
So you'd define built-in functions (roundeven / roundevenf / roundevenl
and _FloatN and _FloatNx variants) similar to those for the older rounding
functions, in builtins.def. You'd look at all the places through the
compiler that are needed to handle those functions - where the existing
ones get folded for constant arguments, where they end up getting
converted to appropriate RTL using corresponding .md patterns for
processors supporting expanding them inline for non-constant arguments,
and update all those places to handle these functions. Documentation of
built-in functions (extend.texi) and instruction patterns (md.texi) would
need updating. Testcases would need adding to verify appropriate folding
for constant arguments.
You'd also implement the new instruction patterns for at least one target
- for example, for x86 (roundss and roundsd SSE4.1 instructions, immediate
operand 8). There would then be architecture-specific tests needed for
the testsuite to verify the appropriate code generation (both scanning
assembler output and execution tests). Some other architectures also have
appropriate instructions, but once things have been illustrated by doing
it for one architecture, the target maintainers for other architectures
might well do those updates.
Doing roundeven would be a good starting point for becoming familiar with
the relevant parts of the compiler, because there are existing built-in
functions that are very similar and so serve as a guide to what you need
to change. There are lots of other functions for which built-in functions
are also useful, some of which bring their own complications - this
project is open-ended, and the number of functions implemented can depend
on how long it takes to do each one.
* The narrowing functions, e.g. fadd, faddl, daddl, are a bit different
from most other built-in math.h functions because the return type is
different from the argument types. You could start by adding them to
builtins.def similarly to roundeven (with new macros to handle adding such
functions for relevant pairs of _FloatN, _FloatNx types). These functions
could be folded for constant arguments only if the result is exact, or if
-fno-rounding-math -fno-trapping-math (and -fno-math-errno if the result
involves overflow / underflow).
Probably more interesting than folding them for constant arguments is
expanding them inline for non-constant arguments (provided
-fno-math-errno). Given -fno-math-errno, those functions can always be
expanded inline if the argument and result types have the same
floating-point format - for example, f32xaddf64 on all GCC configurations
that support _Float32x and _Float64. So you want that to expand to a
normal ADD operation (on GIMPLE and then RTL) just as if the user had
written normal floating-point addition.
But when the functions are genuinely narrowing - fadd taking double
arguments and returning float, for example - you can only expand inline
for non-constant arguments when the target architecture has appropriate
support. There are various existing standard instruction patterns with
arguments and results of different modes - for example, mulsidi3, a
widening multiplication of SImode (32-bit) operands producing a DImode
(64-bit) result. So you might add support for e.g. adddfsf3, a narrowing
addition of DFmode operands producing an SFmode result. Then that pattern
would need implementing for some suitable target, say POWER8 (rs6000
port), where the instructions for float arithmetic work with double
arguments and have the required narrowing semantics.
* The fromfp / fromfpx / ufromfp / ufromfpx functions (round to integers
of a specified number of bits, in a specified rounding mode, with
specified handling of inexact results) are a case with some other
complications. Typically I'd expect them to be expanded inline only (for
constant arguments or) for constant values of the number of bits and
rounding mode, if the target machine has an appropriate instruction. A
target hook would need adding for a target to specify the FP_INT_* values
used in libm, since that's an ABI that's defined by libm, not by GCC.
Then you'd need instruction patterns that might only be supported in
certain cases.
For example, AArch64 has FCVT instructions to convert floating-point
values to 32-bit or 64-bit integers, signed and unsigned, with a rounding
mode specified in the instruction. Those instructions set "inexact" for
non-integer arguments, so are appropriate for fromfpx / ufromfpx, but for
the functions that don't set "inexact" (fromfp / ufromfp) you might use an
appropriate FRINT instruction to round to integer in the floating-point
type, without setting "inexact", followed by an FCVT instruction to
convert that to an integer type.
* Classification and comparison macros also naturally have corresponding
type-generic built-in functions which are a bit different from the
examples discussed above. For example, there ought to be
__builtin_iseqsig, see
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77928> for details.
__builtin_issignaling, which would need to work by examining the bits of
the representation of the argument passed (except on architectures with
RISC-V that have instructions that help), would also be useful. (Some
such functions, see e.g. bug 77925, were implemented by Tamar Christina
but that patch had to be reverted because it caused problems which haven't
yet been resolved. However, I don't think anyone has implemented
__builtin_iseqsig or __builtin_issignaling for GCC.)
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2018-03-01 18:34 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-01 17:28 GSoC Tejas Joshi
2018-03-01 18:34 ` Joseph Myers [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-03-23 7:23 GSoC koushiki khobare
2024-03-25 16:48 ` GSoC Martin Jambor
2024-03-06 1:56 GSoC Abhinav Gupta
2024-03-07 13:02 ` GSoC Martin Jambor
[not found] ` <CANMwAi-zb1W8Ajss3WVVd5XP-X=_q=Ezf=WRNT4L1mi=JEzzsw@mail.gmail.com>
2024-03-13 13:54 ` GSoC Martin Jambor
2024-03-14 22:24 ` GSoC Thomas Schwinge
2024-03-30 17:40 ` GSoC Abhinav Gupta
2024-03-30 22:47 ` GSoC Martin Jambor
2024-02-26 22:15 GSOC Pratush Rai
2024-03-01 13:54 ` GSOC Martin Jambor
2022-06-09 9:04 GSoC Tim Lange
2022-06-09 14:38 ` GSoC David Malcolm
2022-04-10 18:57 Gsoc 20-cs Kunal Rajnish
2022-04-14 16:26 ` Gsoc Martin Jambor
2022-03-12 15:39 GSoC Γιωργος Μελλιος
2022-03-12 16:00 ` GSoC David Edelsohn
2021-03-20 12:23 GSOC Manish Sahani
2021-03-23 15:09 ` GSOC Jonathan Wakely
2021-03-23 18:20 ` GSOC Martin Jambor
2021-03-19 8:03 GSoC Isitha Subasinghe
2021-03-19 13:24 ` GSoC Philip Herron
2021-03-22 16:12 ` GSoC David Malcolm
2021-03-23 13:35 ` GSoC Martin Jambor
2021-03-12 9:26 GSoC ΓΙΩΡΓΟΣ ΛΙΑΚΟΠΟΥΛΟΣ
2021-03-12 10:50 ` GSoC Philip Herron
2021-02-07 10:47 GSoC Ravi Kumar
2021-02-09 14:20 ` GSoC Martin Jambor
2020-03-31 17:09 GSoC Yerassyl Sagynov
2020-03-15 14:14 GSOC shivam tiwari
2020-03-15 13:19 GSOC shivam tiwari
2020-03-15 18:58 ` GSOC Segher Boessenkool
2020-03-15 21:18 ` GSOC Martin Jambor
2020-03-16 13:13 ` GSOC Giuliano Belinassi
2020-02-21 8:18 GSoC shivam tiwari
2020-02-21 9:31 ` GSoC Richard Biener
2019-04-07 18:14 GSoC utkarsh shrivastava
2019-04-07 18:12 GSoC utkarsh shrivastava
2019-04-07 9:09 GSOC ashwina kumar
2019-04-08 9:23 ` GSOC Richard Biener
2019-04-08 11:27 ` GSOC Martin Jambor
2019-04-04 11:11 GSoC Muhammad Shehzad
2019-04-04 12:38 ` GSoC Martin Jambor
2019-03-26 14:12 Gsoc FuN traveller
2019-03-26 18:34 ` Gsoc Martin Jambor
2019-03-27 1:31 ` Gsoc FuN traveller
2019-03-25 23:51 GSOC nick
2019-03-26 13:32 ` GSOC David Malcolm
2019-03-26 13:41 ` GSOC Richard Biener
2019-03-26 13:59 ` GSOC nick
2019-03-27 13:55 ` GSOC Giuliano Belinassi
2019-03-27 14:43 ` GSOC nick
2019-03-28 8:44 ` GSOC Richard Biener
2019-03-28 8:42 ` GSOC Richard Biener
2019-03-28 20:20 ` GSOC Giuliano Belinassi
2019-03-29 8:48 ` GSOC Richard Biener
2019-05-06 18:47 ` GSOC Giuliano Belinassi
2019-05-07 13:18 ` GSOC Richard Biener
2019-05-12 18:31 ` GSOC Giuliano Belinassi
2019-05-13 12:18 ` GSOC Richard Biener
2019-05-13 22:32 ` GSOC Giuliano Belinassi
2019-03-25 19:22 Gsoc FuN traveller
2019-03-23 16:26 GSoC youssef Elmasry
2019-03-26 18:10 ` GSoC Martin Jambor
2019-03-15 4:20 GSOC nick
2019-03-14 20:01 GSoC Matias Barrientos
2019-03-27 8:31 ` GSoC Martin Jambor
2019-03-10 18:54 GSoC Martin Emil
2019-03-26 0:05 ` GSoC Martin Jambor
2019-03-26 0:15 ` GSoC Jakub Jelinek
2019-03-01 20:08 GSoC Ahmed Ashraf
2019-03-01 22:04 ` GSoC Dmitry Mikushin
2018-11-27 16:36 GSOC Siddhartha Sen
2018-03-25 16:04 GSoC Basil George
2018-03-15 4:25 GSoC Gaurav Ahuja
2018-03-15 11:24 ` GSoC Martin Jambor
[not found] <CAF3k35YMd2jxTkHx0i-7CXp0fJHUeTNeovqeXGVYLiuuNzPN-Q@mail.gmail.com>
2018-03-14 16:34 ` GSOC Martin Jambor
2018-03-15 8:43 ` GSOC Richard Biener
2018-03-14 9:49 GSoC Maria Kalikas
[not found] <CALsyVYzd+67-McGFX-xPRDTE=J=YJ+ZoEzsLfg596fOK783WAw@mail.gmail.com>
[not found] ` <CALsyVYz41bkXd4+ivrebu0DTQm9DugShjDbAaBdo71xBTo6_=w@mail.gmail.com>
[not found] ` <CALsyVYwNDgicbnAnSGxqGQPL299PxZiy+iBzt3VVpT=e3Eq=uw@mail.gmail.com>
[not found] ` <CALsyVYy26POK5GcHtEkTdp+02pe6jyqRx9n8DqRzG8brRuNq=g@mail.gmail.com>
[not found] ` <CALsyVYzYiFaL85VBOHaXcYhizEwc4JweD4y9ktZK8WGg87-XhQ@mail.gmail.com>
[not found] ` <CALsyVYzvf-YM7Oe_zwYLpg=sDuAuufuVgi+iv88KS+6Q20YRwA@mail.gmail.com>
[not found] ` <CALsyVYzJqP7wOJ=k=rKdtEgc3XpfeLy-EZp_UHL9JCQ-ZF2Qrw@mail.gmail.com>
[not found] ` <CALsyVYxtrhJHVS-0y+jc8RcbPyOBUCRf+2f=8sqmANGGSugJdQ@mail.gmail.com>
[not found] ` <CALsyVYwVbM2vpTZng7mHzaPU8m366xnjCO3YYwihJCzwoW+VsQ@mail.gmail.com>
[not found] ` <CALsyVYyR0DY20AcMgcZEdpzh3JVLPDGhJLPp=frz0orX9vSQEQ@mail.gmail.com>
[not found] ` <CALsyVYxfzACgWawTCtKfMOq8Oubw52xKFRVTFy7=LWzZnA=u2w@mail.gmail.com>
[not found] ` <CALsyVYzLapO10POzqA9QFCZW+dxx4HnSCMJ_uoxsewn=54ESHg@mail.gmail.com>
[not found] ` <CALsyVYzSmoNgztsk=mJCamj7N8qp5WdF+gPsd2SNj6hoAdNFkg@mail.gmail.com>
[not found] ` <CALsyVYyuLf3oPwb=5r1jLOfiiQ9ODZZKGMSVgKBaVHyK-20bFg@mail.gmail.com>
[not found] ` <CALsyVYw1hv2c_9_DyS_AK8x1XJmKY0Hgb-CfwoXWbb=5Pr-R_A@mail.gmail.com>
[not found] ` <CALsyVYyVbVaBb6Bxfo8tBORKWuzF84QhPEN7k7waBUDm+mBbZA@mail.gmail.com>
[not found] ` <CALsyVYxqko-1VTgQ4UBeDaAxfQs3+hQgrB+z_0N7UsnGEM-Krw@mail.gmail.com>
[not found] ` <CALsyVYxa5GpG99+D6a-U1iAdut1Xv=SseoKP3UptHFNHDdim5Q@mail.gmail.com>
[not found] ` <CALsyVYzp2xBLYJHziOGa5nCk3-D8KsW9sZ7Tm6nay3BLCKu2-Q@mail.gmail.com>
[not found] ` <CALsyVYyvE0tD1RfPR8D_ZEP6vNdO0gEBMGffvOJbG_LQ3NmM_w@mail.gmail.com>
2018-03-13 14:53 ` GSoC Ko Phyo
2018-02-26 16:35 GSoC Dushyant Pratap Singh
2018-02-27 13:16 ` GSoC Richard Biener
2018-02-21 16:05 GSoC Thejazeto Lhousa
2018-02-24 10:56 ` GSoC Thomas Schwinge
2018-02-24 13:24 ` GSoC Thejazeto Lhousa
2018-02-24 16:27 ` GSoC Martin Jambor
2018-02-27 8:01 ` GSoC Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1803011755560.17797@digraph.polyomino.org.uk \
--to=joseph@codesourcery.com \
--cc=gcc@gcc.gnu.org \
--cc=tejasjoshi9673@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).