Re: Rules about type of comparison of gcc vector types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 14 Jul 2025, Imple Lee via Gcc-help wrote:

> I'm writing code about gcc vector types, which, in C, looks like this.
> 
> ```C
> typedef int v4si __attribute__ ((vector_size (16)));
> ```
> 
> The relevant documentation is as follows.
> 
> > The result of the comparison is a vector of the same width and number of elements as the comparison operands with a signed integral element type.
> 
> However, on architectures where different integral types have the same
> width, e.g. `long` and `long long` are both 64-bit on x86-64 linux, it
> is unclear which type will be used (on x86-64 linux, the type of both
> `vector of long == vector of long` and `vector of long long == vector
> of long long` are both `vector of long`). Are there any more specific
> rules in such cases? Since I want to support many different
> architectures, experimenting on all of them to find the rule seems
> kind of tedious...

Unfortunately, Clang and GCC implement different rules here, so perhaps
it would be best to avoid a dependency on that, if possible?..

For GCC, element type for the resulting vector is chosen in
c_common_type_for_size, which starts by picking a suitable type in sequence
int, signed char, short, long, long long. Hence, 'long' is never chosen on
ILP32 platforms, and 'long long' won't be picked on LP64.

https://gcc.gnu.org/cgit/gcc/tree/gcc/c-family/c-common.cc#n2339

HTH
Alexander



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux