From: Xi Ruoyao <xry111@xry111.site>
To: chenxiaolong <chenxiaolong@loongson.cn>,
Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, i@xen0n.name, xuchenghua@loongson.cn,
chenglulu@loongson.cn
Subject: Re: [PATCH v3] LoongArch:Implement 128-bit floating point functions in gcc.
Date: Fri, 18 Aug 2023 15:19:33 +0800 [thread overview]
Message-ID: <58f3cb8a1d246f2090b62fe8b4492c0ecef92a98.camel@xry111.site> (raw)
In-Reply-To: <61f3e8be6c5ab594f8701908b94e27acfb0d7b70.camel@xry111.site>
On Fri, 2023-08-18 at 15:05 +0800, Xi Ruoyao via Gcc-patches wrote:
> On Fri, 2023-08-18 at 14:58 +0800, Xi Ruoyao via Gcc-patches wrote:
> > On Fri, 2023-08-18 at 14:39 +0800, chenxiaolong wrote:
> > > 在 2023-08-17四的 15:08 +0000,Joseph Myers写道:
> > > > On Thu, 17 Aug 2023, Xi Ruoyao via Gcc-patches wrote:
> > > >
> > > > > So I guess we just need
> > > > >
> > > > > builtin_define ("__builtin_fabsq=__builtin_fabsf128");
> > > > > builtin_define ("__builtin_nanq=__builtin_nanf128");
> > > > >
> > > > > etc. to map the "q" builtins to "f128" builtins if we really need
> > > > > the
> > > > > "q" builtins.
> > > > >
> > > > > Joseph: the problem here is many customers of LoongArch CPUs wish
> > > > > to
> > > > > compile their old code with minimal change. Is it acceptable to
> > > > > add
> > > > > these builtin_define's like rs6000-c.cc? Note "a new architecture"
> > > > > does
> > > > > not mean we'll only compile post-C2x-era programs onto it.
> > > >
> > > > The powerpc support for __float128 started in GCC 6, predating the
> > > > support
> > > > for _FloatN type names, built-in functions etc. in GCC 7 - that's
> > > > why
> > > > there's such backwards compatibility support there. That name only
> > > > exists
> > > > on a few architectures.
> > > >
> > > > If people really want to compile code using the old __float128 names
> > > > for
> > > > LoongArch I suppose you could have such #defines, but it would be
> > > > better
> > > > for people to make their code use the standard names (as supported
> > > > from
> > > > GCC 7 onwards, though only from GCC 13 in C++) and then put
> > > > backwards
> > > > compatibility in their code for using the __float128 names if they
> > > > want to
> > > > support the type with older GCC (GCC 6 or before for C; GCC 12 or
> > > > before
> > > > for C++) on x86_64 / i386 / powerpc / ia64. Such backwards
> > > > compatibility
> > > > in user code is more likely to be relevant for C++ than for C, given
> > > > how
> > > > the C++ support was added to GCC much more recently. (Note: I
> > > > haven't
> > > > checked when other compilers added support for the _Float128 name or
> > > > associated built-in functions, whether for C or for C++, which might
> > > > also
> > > > affect when user code wants such compatibility.)
> > > >
> > > Thank you for your valuable comments. On the LoongArch architecture,
> > > the "__float128" type is associated with float128_type_node and the "q"
> > > suffix function is mapped to the "f128" function. This allows
> > > compatibility with both "__float128" and "_Float128" types in the GCC
> > > compiler. The new code is modified as follows:
> > > Add the following to the loongarch-builtins.c file:
> > > +lang_hooks.types.register_builtin_type (float128_type_node,
> > > "__float128");
> > > Add the following to the loongarch-c.c file:
> > > +builtin_define ("__builtin_fabsq=__builtin_fabsf128");
> > > +builtin_define ("__builtin_copysignq=__builtin_copysignf128");
> > > +builtin_define ("__builtin_nanq=__builtin_nanf128");
> > > +builtin_define ("__builtin_nansq=__builtin_nansf128");
> > > +builtin_define ("__builtin_infq=__builtin_inff128");
> > > +builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
> > >
> > > The regression tests of the six functions were added without problems.
> > > However, the implementation of the __builtin_nansq() function does not
> > > get the result we want. The questions are as follows:
> > > x86_64:
> > > _Float128 ret=__builtin_nansf128("NAN");
> > >
> > > compiled to (with gcc test.c -O2 ):
> > > .cfi_offset 1, -8
> > > bl %plt(__builtin_nansf128)
> > > ..
> > > LoongArch:
> > > _Float128 ret=__builtin_nansf128("NAN");
> > > compiled to (with gcc test.c -O2 ):
> > > .cfi_offset 1, -8
> > > bl %plt(__builtin_nansf128)
> >
> > It seems wrong. It should be "bl %plt(nansf128)" instead, without the
> > __builtin_ prefix so the implementation in libm (from Glibc) will be
> > used instead. AFAIK __builtin_nan and __builtin_nans are rarely called
> > with a non-empty tagp so it's not worthy to inline the implementation
> > for non-empty tagp here.
> >
> > The same issue happens on x86_64:
> >
> > call __builtin_nansf128@PLT
> >
> > __builtin_nanf128 compiles correct:
> >
> > call nanf128@PLT
> >
> > I'll see if there is a ticket in https://gcc.gnu.org/bugzilla. If not
> > I'll create one.
https://gcc.gnu.org/PR111058
> Alright, Glibc does not have a "nansf128" function yet. Actually there
> is even no "nans" function for the plain double type. So even a plain
> __builtin_nans("114") won't work too.
>
> If we'll fix this, we need to do it in a generic, target-independent way
> (i. e. fix it all at once for all targets).
>
> So for now, and for LoongArch specific code, the proper thing to do is
> aliasing float128_type_node as __float128 and the six
> __builtin_define's.
>
> Please commit them to trunk if regression test passes. You need to also
> add LoongArch as a target supporting __float128 in extend.texi.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
next prev parent reply other threads:[~2023-08-18 7:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 10:39 chenxiaolong
2023-08-15 10:48 ` Xi Ruoyao
2023-08-17 6:56 ` chenxiaolong
2023-08-15 20:03 ` Joseph Myers
2023-08-16 10:08 ` chenxiaolong
2023-08-16 13:16 ` Joseph Myers
2023-08-17 3:44 ` Xi Ruoyao
2023-08-17 15:08 ` Joseph Myers
2023-08-18 6:39 ` chenxiaolong
2023-08-18 6:58 ` Xi Ruoyao
2023-08-18 7:05 ` Xi Ruoyao
2023-08-18 7:19 ` Xi Ruoyao [this message]
2023-08-18 7:52 ` chenxiaolong
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=58f3cb8a1d246f2090b62fe8b4492c0ecef92a98.camel@xry111.site \
--to=xry111@xry111.site \
--cc=chenglulu@loongson.cn \
--cc=chenxiaolong@loongson.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=i@xen0n.name \
--cc=joseph@codesourcery.com \
--cc=xuchenghua@loongson.cn \
/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).