Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
Like this article? We recommend

GCC Vector Types

The additions to C for supporting vector operations in GCC are very simple. Vector types are defined with typedef, just as scalar types are. The only difference is an attribute that indicates the number of elements in the vector. The following example shows how to define a vector of four signed integers:

typedef int v4si __attribute__ (( vector_size(4*sizeof(int)) ));

The only constraint is that the size must be a power of two multiple of a scalar type. Once you’ve defined this type, you can operate on it as if it were a scalar type.

Sounds great? Well, everything good comes with a price, and in this case the price is compiler compatibility. If you write pure ISO C, you can easily move from GCC to any other standards-compliant C compiler, such as the Intel C++ Compiler (ICC) or XL C, that might give better performance on a particular architecture. Once you start using GCC extensions, you’re stuck with GCC. But if every platform you target is already supported by GCC, the code is not for distribution, or you’re already using GCC extensions elsewhere, this restriction may not matter to you.

  • + Share This
  • 🔖 Save To Your Account