On Mon, 14 Jul 2025, Alexander Monakov via Gcc-help wrote:
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
Note that the type used as the result of a comparison is made *opaque*,
which relaxes the checks in case of a conversion. So you should be able to
assign it to a vector of long and a vector of long long without either
giving an error.
(I think it would make sense to check if the input already has a suitable
type before querying c_common_type_for_size, or some other similar
heuristic, I doubt that would break any code not written specifically to
demonstrate the difference)
--
Marc Glisse