public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Missing POWER9 built-in functions
@ 2023-04-20  6:53 Matthew R. Wilson
  2023-04-20  7:16 ` Xi Ruoyao
  2023-04-20  7:18 ` Kewen.Lin
  0 siblings, 2 replies; 5+ messages in thread
From: Matthew R. Wilson @ 2023-04-20  6:53 UTC (permalink / raw)
  To: gcc-help

Hello,

I'm looking into writing some code for a POWER9 processor in which I
want to explicitly use the VSX scalar instructions for quad-precision
floating point arithmetic.

In the GCC documentation, section 6.60.22.5, the relevant built-in
functions are listed (see
<https://gcc.gnu.org/onlinedocs/gcc/Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0.html#Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0>)

However, it looks like only the ..._round_to_odd versions of the
functions exist. But in the Power ISA 3.0, there are both the "normal"
version of the instruction (that use the rounding mode configured in the
floating-point control register, as all of the other floating point
instructions do) and the "round to odd" versions of the instructions.

(See, for example, the VSX Scalar Add Quad-Precision instruction on page
520 of the Power ISA Version 3.0 B PDF at
<https://wiki.raptorcs.com/w/images/c/cb/PowerISA_public.v3.0B.pdf>)

That is, two instructions exist: xsaddqp and xdaddqpo, with the latter
being the round-to-odd version of the instruction. I have verified that
using the GCC __builtin_addf128_round_to_odd function does produce code
that uses xsaddqpo, but it would be more typical to want to generate
code that uses xsaddqp. It seems like an equivalent __builtin_addf128
function is missing (for add and all of the other quad-precision VSX
scalar arithmetic instructions that have both xxx and xxxo
instructions).

Is there a particular reason this is the case, or is it indeed just an
oversight? If there isn't a known reason to exclude those, I can open a
bug in the bug tracker.

Thanks,
Matthew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Missing POWER9 built-in functions
  2023-04-20  6:53 Missing POWER9 built-in functions Matthew R. Wilson
@ 2023-04-20  7:16 ` Xi Ruoyao
  2023-04-20  7:52   ` Matthew R. Wilson
  2023-04-20  7:18 ` Kewen.Lin
  1 sibling, 1 reply; 5+ messages in thread
From: Xi Ruoyao @ 2023-04-20  7:16 UTC (permalink / raw)
  To: Matthew R. Wilson; +Cc: gcc-help

On Wed, 2023-04-19 at 23:53 -0700, Matthew R. Wilson wrote:
> Hello,
> 
> I'm looking into writing some code for a POWER9 processor in which I
> want to explicitly use the VSX scalar instructions for quad-precision
> floating point arithmetic.
> 
> In the GCC documentation, section 6.60.22.5, the relevant built-in
> functions are listed (see
> <https://gcc.gnu.org/onlinedocs/gcc/Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0.html#Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0>)
> 
> However, it looks like only the ..._round_to_odd versions of the
> functions exist. But in the Power ISA 3.0, there are both the "normal"
> version of the instruction (that use the rounding mode configured in the
> floating-point control register, as all of the other floating point
> instructions do) and the "round to odd" versions of the instructions.
> 
> (See, for example, the VSX Scalar Add Quad-Precision instruction on page
> 520 of the Power ISA Version 3.0 B PDF at
> <https://wiki.raptorcs.com/w/images/c/cb/PowerISA_public.v3.0B.pdf>)
> 
> That is, two instructions exist: xsaddqp and xdaddqpo, with the latter
> being the round-to-odd version of the instruction. I have verified that
> using the GCC __builtin_addf128_round_to_odd function does produce code
> that uses xsaddqpo, but it would be more typical to want to generate
> code that uses xsaddqp. It seems like an equivalent __builtin_addf128
> function is missing (for add and all of the other quad-precision VSX
> scalar arithmetic instructions that have both xxx and xxxo
> instructions).
> 
> Is there a particular reason this is the case, or is it indeed just an
> oversight?

Because you can simply say "a + b":

https://godbolt.org/z/6a73xv11b


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Missing POWER9 built-in functions
  2023-04-20  6:53 Missing POWER9 built-in functions Matthew R. Wilson
  2023-04-20  7:16 ` Xi Ruoyao
@ 2023-04-20  7:18 ` Kewen.Lin
  1 sibling, 0 replies; 5+ messages in thread
From: Kewen.Lin @ 2023-04-20  7:18 UTC (permalink / raw)
  To: Matthew R. Wilson; +Cc: gcc-help

Hi,

on 2023/4/20 14:53, Matthew R. Wilson wrote:
> Hello,
> 
> I'm looking into writing some code for a POWER9 processor in which I
> want to explicitly use the VSX scalar instructions for quad-precision
> floating point arithmetic.
> 
> In the GCC documentation, section 6.60.22.5, the relevant built-in
> functions are listed (see
> <https://gcc.gnu.org/onlinedocs/gcc/Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0.html#Basic-PowerPC-Built-in-Functions-Available-on-ISA-3_002e0>)
> 
> However, it looks like only the ..._round_to_odd versions of the
> functions exist. But in the Power ISA 3.0, there are both the "normal"
> version of the instruction (that use the rounding mode configured in the
> floating-point control register, as all of the other floating point
> instructions do) and the "round to odd" versions of the instructions.
> 
> (See, for example, the VSX Scalar Add Quad-Precision instruction on page
> 520 of the Power ISA Version 3.0 B PDF at
> <https://wiki.raptorcs.com/w/images/c/cb/PowerISA_public.v3.0B.pdf>)
> 
> That is, two instructions exist: xsaddqp and xdaddqpo, with the latter
> being the round-to-odd version of the instruction. I have verified that
> using the GCC __builtin_addf128_round_to_odd function does produce code
> that uses xsaddqpo, but it would be more typical to want to generate
> code that uses xsaddqp. It seems like an equivalent __builtin_addf128
> function is missing (for add and all of the other quad-precision VSX
> scalar arithmetic instructions that have both xxx and xxxo
> instructions).

There is no this kind of bif, I think it's because users can just use
the normal arithmetic operators, like "+" for "addition".

For:

_Float128 foo (_Float128 a, _Float128 b) {
  return a + b;
}

It gets desired xsaddqp with -mcpu=power9 -O2:

foo:
        xsaddqp 2,2,3
        blr

BR,
Kewen

> 
> Is there a particular reason this is the case, or is it indeed just an
> oversight? If there isn't a known reason to exclude those, I can open a
> bug in the bug tracker.
> 
> Thanks,
> Matthew
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Missing POWER9 built-in functions
  2023-04-20  7:16 ` Xi Ruoyao
@ 2023-04-20  7:52   ` Matthew R. Wilson
  2023-04-20  8:22     ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew R. Wilson @ 2023-04-20  7:52 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-help

On 04.20.2023 15:16, Xi Ruoyao wrote:
>On Wed, 2023-04-19 at 23:53 -0700, Matthew R. Wilson wrote:
>> However, it looks like only the ..._round_to_odd versions of the
>> functions exist. But in the Power ISA 3.0, there are both the "normal"
>> version of the instruction (that use the rounding mode configured in the
>> floating-point control register, as all of the other floating point
>> instructions do) and the "round to odd" versions of the instructions.
>>
>> Is there a particular reason this is the case, or is it indeed just an
>> oversight?
>
>Because you can simply say "a + b":
>
>https://godbolt.org/z/6a73xv11b

Well, that is indeed a good reason!

I have gcc-generated .s files built with -mcpu=power9 -mfloat128 and
they generated `bl __gcc_qadd` to perform the addition, which is why I
started going down the path of looking into the built-in functions.

But sure enough, I just tried it with my local GCC and it does directly
generate the xsaddqp instructions now. So I'm not sure what went wrong
with the compiler flags or whatever else with the earlier tests I have.

My mistake. Thank you!

-Matthew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Missing POWER9 built-in functions
  2023-04-20  7:52   ` Matthew R. Wilson
@ 2023-04-20  8:22     ` Segher Boessenkool
  0 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2023-04-20  8:22 UTC (permalink / raw)
  To: Matthew R. Wilson; +Cc: Xi Ruoyao, gcc-help

On Thu, Apr 20, 2023 at 12:52:48AM -0700, Matthew R. Wilson wrote:
> I have gcc-generated .s files built with -mcpu=power9 -mfloat128 and
> they generated `bl __gcc_qadd` to perform the addition, which is why I
> started going down the path of looking into the built-in functions.
> 
> But sure enough, I just tried it with my local GCC and it does directly
> generate the xsaddqp instructions now. So I'm not sure what went wrong
> with the compiler flags or whatever else with the earlier tests I have.

You used "long double" and you didn't use "-mabi=ieeelongdouble".  You
can instead use "__ieee128" for the types, which will always work (for
some version of "always"...  You need to compile for at least a power8).


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-20  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20  6:53 Missing POWER9 built-in functions Matthew R. Wilson
2023-04-20  7:16 ` Xi Ruoyao
2023-04-20  7:52   ` Matthew R. Wilson
2023-04-20  8:22     ` Segher Boessenkool
2023-04-20  7:18 ` Kewen.Lin

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).