[Dwarf-discuss] ISSUE: CPU vector types.

Pedro Alves pedro@palves.net
Tue Apr 4 10:09:07 GMT 2023


On 2023-04-04 12:22 a.m., Kyle Huey wrote:
> On Mon, Apr 3, 2023 at 12:42 PM Pedro Alves via Dwarf-discuss <dwarf-discuss@lists.dwarfstd.org <mailto:dwarf-discuss@lists.dwarfstd.org>> wrote:
> 
>     Hi Ben,
> 
>     On 2023-03-24 6:19 p.m., Ben Woodard via Dwarf-discuss wrote:
> 
>     > I will admit that in its current state it is a work in progress. My original intent was to simply
>     > codify the existing behavior as implemented by GCC and LLVM (and probably other compilers) moving it
>     > from a vendor attribute to something that was in the standard.
> 
>     In light of the recent discussion, I was thinking how it would help if the
>     proposal was laid out in terms of vector types instead of hardware registers.
> 
> 
> I think the proposed language here is a bit too C/C++ centric.

This is introducing the need for the attribute.  The audience is the committee, not DWARF spec readers,
because none of this text would end up in the spec.  It is just setting the ground.  It is true that other
languages have vector types as well, but I'd think that even if only C/C++ had them, that would
not be reason to not support the types.  But we can certainly tweak the language to cover other languages.

>  
> 
>     Please see comments inline below.
> 
>     > Vector registers
>     >
>     > It has been the long standing existing practice to treat hardware
>     > vector registers as arrays of a fundamental base type. To deliniate
>     > these hardware register arrays from arrays in the language source they
>     > have been given the DW_AT_GNU_vector attribute. This proposal simply
>     > standardizes the existing behavior.
> 
>     I'd suggest replacing the above with something like this:
> 
>     ~~~~~~~~~~~~
>     Vector types
> 
>     As an extension to C and C++, GCC supports defining vector data types.
> 
> 
> DW_AT_GNU_vector is used for languages beyond C/C++ today.
>  
> 
>     On some targets, operations on these vector types make use of SIMD
>     vector registers and instructions.
> 
>     Vector types are similar to arrays, and you can index and initialize
>     them similarly, but they have some important differences.  For
>     example:
> 
> 
> These statements are not true in general for non C/C++ languages, and DW_TAG_array_type represents a variety of array types across many languages.

Sure, but as clearly stated above, this text is comparing C arrays and vectors, so you have to read it in that
context.

>  
> 
>     - Arrays automatically decay to pointers.  Vector types do not.
> 
> 
> Array decay is only a C/C++ "feature" as far as I know.

Certainly.

> 
>     - You can pass vector types by value to functions, and likewise
>       functions can return vector types by value.  You can not do either
>       with C arrays.
> 
> 
> Arrays in other languages can be passed and returned by value at the language level (e.g. Ada) and sometimes even at the machine level (e.g. Rust).
>  
> 
>     - Vector types can be used with a subset of normal C operations: +, -,
>       *, /, unary minus, ^, |, &, ~, %.  For example, addition is defined as
>       the addition of the corresponding elements of the operands.
> 
> 
> The implicit statement here that non-vector arrays cannot be used with any normal operations is also not true in general (e.g. in Fortran 90 A = B + C works).

No really, the implicit statement here is that non-vector arrays cannot be used with any normal operations _in C_.  If we
tweaked the intro before this list to be language-agnostic, then certainly this list will not be generic enough.

>  
> 
>     A debugger that supports expression evaluation will want to be able to
>     support these vector operations on vector objects too.
> 
> 
> Supporting expression evaluation requires very deep knowledge of the semantics of the program's language, to the point where I think saying much beyond "vector types may have different semantics than standard array types" in the DWARF spec isn't worth the effort.

This is intro language to justify why we need to distinguish arrays from vectors, and it used one language practically
everyone is familiar for that.  None of it would be proposed as wording in the DWARF spec.  Even if it weren't needed for
any other language, it is needed for C/C++, and that should be sufficient justification, IMO.

Pedro Alves


More information about the Dwarf-discuss mailing list