On Tue, Feb 24, 2009 at 06:15:37AM -0800, Bingfeng Mei wrote: > Hello, > For the targets that support vectors, we can write the following code: > > typedef short V4H __attribute__ ((vector_size (8))); > > V4H tst(V4H a, V4H b){ > return a + b; > } > > Other operators such as -, *, |, &, ^ etc are also supported. However, > vector shift > is not supported by frontend, including both scalar and vector second > operands. > > V4H tst(V4H a, V4H b){ > return a << 3; > } > > V4H tst(V4H a, V4H b){ > return a << b; > } > > Currently, we have to use intrinsics to support such shift. Isn't syntax of > vector > shift intuitive enough to be supported natively? Someone may argue it breaks > the > C language. But vector is a GCC extension anyway. Support for vector > add/sub/etc > already break C syntax. Any thought? Sorry if this issue had been raised in > past.
Note, internally there are two different types of vector shift. Some machines support a vector shift by a scalar, some machines support a vector shift by a vector. One future machine (x86_64 with -msse5) can support both types of vector shifts. The auto vectorizer now can deal with both types: for (i = 0; i < n; i++) a[i] = b[i] << c will generate a vector shift by a scalar on machines with that support, and splat the scalar into a vector for the second set of machines. If the machine only has vector shift by a scalar, the auto vectorizer will not generate a vector shift for: for (i = 0; i < n; i++) a[i] = b[i] << c[i] Internally, the compiler uses the standard shift names for vector shift by a scalar (i.e. ashl<type>, ashr<type>, lshl<type>), and a v prefix for the vector by vector shifts (i.e. vashl<type>, vashr<type>, vlshl<type>). The rotate patterns are also similar. -- Michael Meissner, IBM 4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA meiss...@linux.vnet.ibm.com