[RFC PATCH v1 1/1] PPC64: Implement POWER Architecture Vector Function ABI.

Jakub Jelinek jakub@redhat.com
Thu Aug 20 20:04:53 GMT 2020


On Thu, Aug 20, 2020 at 07:31:50PM +0000, GT wrote:
> I'm still trying to understand why we need attribute((target("vsx"))).
> 
> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
> 
> The documentation for target(string) states that the purpose is to allow a function to be
> compiled with different target options than were specified on the command line. Why would we
> want the vector version of say sinf to be compiled for a different target than the scalar sinf?

The scalar sinf (well, better let's talk about some arbitrary user function,
sinf or at least the vector versions thereof will be often implemented in
assembly) can be compiled with whatever ISA options the user chooses.
But, the SIMD ABI says that the 'b' char variants are VSX only, need to pass
arguments in certain registers that might not be even available without that
ISA, similarly for returns, and per the ABI the callers will ensure such
functions are only used from code which assumes that ISA.

Have a look at the x86_64 case, we have several different variants there,
e.g. SSE2 that passes in registers that are only available in SSE1 and
later, then AVX variants which use AVX registers, AVX2 variants which use
the same registers but different in he way how integral vectors are passed,
and finally AVX512F variants that use AVX512F registers.
So, on the caller side among the other desirability checks (if the function
is declare simd at all, what vectorization factor is available, whether it
is inbranch or notinbranch or both, whether arguments are vectors or uniform
or linear etc.), the compiler also checks the ISA.  And in loops that aren't
even SSE2 (-mno-sse, -msse1) just won't use any of the simd variants and
will use always scalar version, in code that isn't -mavx or later will only
use SSE2 (or scalar), in code that isn't -mavx2 will only use AVX or SSE2 or
scalar, etc.  Either one wouldn't be even able to pass the arguments or read
the return values without those, or if it would, the ABI still says one can
assume such ISA level.
This is all implemented by:
1) having the target hook used during the vectorization decision
(simd_clone_usable) decide based on the current ISA level
2) on the side of generation of the functions, it checks if the ISA is
already available (e.g. from command line), if it is, nothing needs to be
done, otherwise target attribute is added.

	Jakub



More information about the Gcc-patches mailing list