xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/vector.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-apple-darwin9 -O1 -target-cpu pentium4 -target-feature +sse4.1 -g -emit-llvm %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc typedef short __v4hi __attribute__ ((__vector_size__ (8)));
3*f4a2713aSLionel Sambuc 
test1()4*f4a2713aSLionel Sambuc void test1() {
5*f4a2713aSLionel Sambuc   __v4hi A = (__v4hi)0LL;
6*f4a2713aSLionel Sambuc }
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc __v4hi x = {1,2,3};
9*f4a2713aSLionel Sambuc __v4hi y = {1,2,3,4};
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc typedef int vty __attribute((vector_size(16)));
test2()12*f4a2713aSLionel Sambuc int test2() { vty b; return b[2LL]; }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc // PR4339
15*f4a2713aSLionel Sambuc typedef float vec4 __attribute__((vector_size(16)));
16*f4a2713aSLionel Sambuc 
test3(vec4 * a,char b,float c)17*f4a2713aSLionel Sambuc void test3 ( vec4* a, char b, float c ) {
18*f4a2713aSLionel Sambuc   (*a)[b] = c;
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc // Don't include mm_malloc.h, it's system specific.
24*f4a2713aSLionel Sambuc #define __MM_MALLOC_H
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc #include <mmintrin.h>
27*f4a2713aSLionel Sambuc 
test4(int argc,char * argv[])28*f4a2713aSLionel Sambuc int test4(int argc, char *argv[]) {
29*f4a2713aSLionel Sambuc   int array[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
30*f4a2713aSLionel Sambuc   __m64 *p = (__m64 *)array;
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc   __m64 accum = _mm_setzero_si64();
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc   for (int i=0; i<8; ++i)
35*f4a2713aSLionel Sambuc      accum = _mm_add_pi32(p[i], accum);
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   __m64 accum2 = _mm_unpackhi_pi32(accum, accum);
38*f4a2713aSLionel Sambuc   accum = _mm_add_pi32(accum, accum2);
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc   int result = _mm_cvtsi64_si32(accum);
41*f4a2713aSLionel Sambuc   _mm_empty();
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc   return result;
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc #include <smmintrin.h>
47*f4a2713aSLionel Sambuc 
test_epi8(__m128i x)48*f4a2713aSLionel Sambuc unsigned long test_epi8(__m128i x) { return _mm_extract_epi8(x, 4); }
49*f4a2713aSLionel Sambuc // CHECK: @test_epi8
50*f4a2713aSLionel Sambuc // CHECK: extractelement <16 x i8> {{.*}}, i32 4
51*f4a2713aSLionel Sambuc // CHECK: zext i8 {{.*}} to i32
52*f4a2713aSLionel Sambuc 
test_epi16(__m128i x)53*f4a2713aSLionel Sambuc unsigned long test_epi16(__m128i x) { return _mm_extract_epi16(x, 3); }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc // CHECK: @test_epi16
56*f4a2713aSLionel Sambuc // CHECK: extractelement <8 x i16> {{.*}}, i32 3
57*f4a2713aSLionel Sambuc // CHECK: zext i16 {{.*}} to i32
58*f4a2713aSLionel Sambuc 
extractinttypes()59*f4a2713aSLionel Sambuc void extractinttypes() {
60*f4a2713aSLionel Sambuc   extern int check_extract_result_int;
61*f4a2713aSLionel Sambuc   extern __typeof(_mm_extract_epi8(_mm_setzero_si128(), 3)) check_result_int;
62*f4a2713aSLionel Sambuc   extern __typeof(_mm_extract_epi16(_mm_setzero_si128(), 3)) check_result_int;
63*f4a2713aSLionel Sambuc   extern __typeof(_mm_extract_epi32(_mm_setzero_si128(), 3)) check_result_int;
64*f4a2713aSLionel Sambuc }
65