2.3.3 Vector types

C Function: gcc_jit_type * gcc_jit_type_get_vector (gcc_jit_type *type, size_t num_units)

Given type “T”, get type:

T  __attribute__ ((vector_size (sizeof(T) * num_units))

T must be integral or floating point; num_units must be a power of two.

This can be used to construct a vector type in which operations are applied element-wise. The compiler will automatically use SIMD instructions where possible. See: ‘https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html

For example, assuming 4-byte ints, then:

typedef int v4si __attribute__ ((vector_size (16)));

can be obtained using:

gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt,
                                                   GCC_JIT_TYPE_INT);
gcc_jit_type *v4si_type = gcc_jit_type_get_vector (int_type, 4);

This API entrypoint was added in LIBGCCJIT_ABI_8; you can test for its presence using

#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_vector

Vector rvalues can be generated using gcc_jit_context_new_rvalue_from_vector().