xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/sse-builtins.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -triple x86_64-apple-macosx10.8.0 -target-feature +sse4.1 -g -emit-llvm %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc #include <xmmintrin.h>
4*f4a2713aSLionel Sambuc #include <emmintrin.h>
5*f4a2713aSLionel Sambuc #include <smmintrin.h>
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc __m128 test_rsqrt_ss(__m128 x) {
8*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_rsqrt_ss
9*f4a2713aSLionel Sambuc   // CHECK: call <4 x float> @llvm.x86.sse.rsqrt.ss
10*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 0
11*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 1
12*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 2
13*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 3
14*f4a2713aSLionel Sambuc   return _mm_rsqrt_ss(x);
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc __m128 test_rcp_ss(__m128 x) {
18*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_rcp_ss
19*f4a2713aSLionel Sambuc   // CHECK: call <4 x float> @llvm.x86.sse.rcp.ss
20*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 0
21*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 1
22*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 2
23*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 3
24*f4a2713aSLionel Sambuc   return _mm_rcp_ss(x);
25*f4a2713aSLionel Sambuc }
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc __m128 test_sqrt_ss(__m128 x) {
28*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_sqrt_ss
29*f4a2713aSLionel Sambuc   // CHECK: call <4 x float> @llvm.x86.sse.sqrt.ss
30*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 0
31*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 1
32*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 2
33*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> {{.*}}, i32 3
34*f4a2713aSLionel Sambuc   return _mm_sqrt_ss(x);
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc __m128 test_loadl_pi(__m128 x, void* y) {
38*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadl_pi
39*f4a2713aSLionel Sambuc   // CHECK: load <2 x float>* {{.*}}, align 1{{$}}
40*f4a2713aSLionel Sambuc   // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1
41*f4a2713aSLionel Sambuc   // CHECK: shufflevector {{.*}} <4 x i32> <i32 4, i32 5, i32 2, i32 3>
42*f4a2713aSLionel Sambuc   return _mm_loadl_pi(x,y);
43*f4a2713aSLionel Sambuc }
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc __m128 test_loadh_pi(__m128 x, void* y) {
46*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadh_pi
47*f4a2713aSLionel Sambuc   // CHECK: load <2 x float>* {{.*}}, align 1{{$}}
48*f4a2713aSLionel Sambuc   // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1
49*f4a2713aSLionel Sambuc   // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1, i32 4, i32 5>
50*f4a2713aSLionel Sambuc   return _mm_loadh_pi(x,y);
51*f4a2713aSLionel Sambuc }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc __m128 test_load_ss(void* y) {
54*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_load_ss
55*f4a2713aSLionel Sambuc   // CHECK: load float* {{.*}}, align 1{{$}}
56*f4a2713aSLionel Sambuc   return _mm_load_ss(y);
57*f4a2713aSLionel Sambuc }
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc __m128 test_load1_ps(void* y) {
60*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_load1_ps
61*f4a2713aSLionel Sambuc   // CHECK: load float* {{.*}}, align 1{{$}}
62*f4a2713aSLionel Sambuc   return _mm_load1_ps(y);
63*f4a2713aSLionel Sambuc }
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc void test_store_ss(__m128 x, void* y) {
66*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_store_ss
67*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} float* {{.*}}, align 1,
68*f4a2713aSLionel Sambuc   _mm_store_ss(y, x);
69*f4a2713aSLionel Sambuc }
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc __m128d test_load1_pd(__m128 x, void* y) {
72*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_load1_pd
73*f4a2713aSLionel Sambuc   // CHECK: load double* {{.*}}, align 1{{$}}
74*f4a2713aSLionel Sambuc   return _mm_load1_pd(y);
75*f4a2713aSLionel Sambuc }
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc __m128d test_loadr_pd(__m128 x, void* y) {
78*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadr_pd
79*f4a2713aSLionel Sambuc   // CHECK: load <2 x double>* {{.*}}, align 16{{$}}
80*f4a2713aSLionel Sambuc   return _mm_loadr_pd(y);
81*f4a2713aSLionel Sambuc }
82*f4a2713aSLionel Sambuc 
83*f4a2713aSLionel Sambuc __m128d test_load_sd(void* y) {
84*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_load_sd
85*f4a2713aSLionel Sambuc   // CHECK: load double* {{.*}}, align 1{{$}}
86*f4a2713aSLionel Sambuc   return _mm_load_sd(y);
87*f4a2713aSLionel Sambuc }
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc __m128d test_loadh_pd(__m128d x, void* y) {
90*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadh_pd
91*f4a2713aSLionel Sambuc   // CHECK: load double* {{.*}}, align 1{{$}}
92*f4a2713aSLionel Sambuc   return _mm_loadh_pd(x, y);
93*f4a2713aSLionel Sambuc }
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc __m128d test_loadl_pd(__m128d x, void* y) {
96*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadl_pd
97*f4a2713aSLionel Sambuc   // CHECK: load double* {{.*}}, align 1{{$}}
98*f4a2713aSLionel Sambuc   return _mm_loadl_pd(x, y);
99*f4a2713aSLionel Sambuc }
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc void test_store_sd(__m128d x, void* y) {
102*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_store_sd
103*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} double* {{.*}}, align 1{{$}}
104*f4a2713aSLionel Sambuc   _mm_store_sd(y, x);
105*f4a2713aSLionel Sambuc }
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc void test_store1_pd(__m128d x, void* y) {
108*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_store1_pd
109*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} double* {{.*}}, align 1{{$}}
110*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} double* {{.*}}, align 1{{$}}
111*f4a2713aSLionel Sambuc   _mm_store1_pd(y, x);
112*f4a2713aSLionel Sambuc }
113*f4a2713aSLionel Sambuc 
114*f4a2713aSLionel Sambuc void test_storer_pd(__m128d x, void* y) {
115*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_storer_pd
116*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} <2 x double>* {{.*}}, align 16{{$}}
117*f4a2713aSLionel Sambuc   _mm_storer_pd(y, x);
118*f4a2713aSLionel Sambuc }
119*f4a2713aSLionel Sambuc 
120*f4a2713aSLionel Sambuc void test_storeh_pd(__m128d x, void* y) {
121*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_storeh_pd
122*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} double* {{.*}}, align 1{{$}}
123*f4a2713aSLionel Sambuc   _mm_storeh_pd(y, x);
124*f4a2713aSLionel Sambuc }
125*f4a2713aSLionel Sambuc 
126*f4a2713aSLionel Sambuc void test_storel_pd(__m128d x, void* y) {
127*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_storel_pd
128*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} double* {{.*}}, align 1{{$}}
129*f4a2713aSLionel Sambuc   _mm_storel_pd(y, x);
130*f4a2713aSLionel Sambuc }
131*f4a2713aSLionel Sambuc 
132*f4a2713aSLionel Sambuc __m128i test_loadl_epi64(void* y) {
133*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_loadl_epi64
134*f4a2713aSLionel Sambuc   // CHECK: load i64* {{.*}}, align 1{{$}}
135*f4a2713aSLionel Sambuc   return _mm_loadl_epi64(y);
136*f4a2713aSLionel Sambuc }
137*f4a2713aSLionel Sambuc 
138*f4a2713aSLionel Sambuc __m128i test_mm_minpos_epu16(__m128i x) {
139*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_minpos_epu16
140*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.phminposuw
141*f4a2713aSLionel Sambuc   return _mm_minpos_epu16(x);
142*f4a2713aSLionel Sambuc }
143*f4a2713aSLionel Sambuc 
144*f4a2713aSLionel Sambuc __m128i test_mm_mpsadbw_epu8(__m128i x, __m128i y) {
145*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_mpsadbw_epu8
146*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.mpsadbw
147*f4a2713aSLionel Sambuc   return _mm_mpsadbw_epu8(x, y, 1);
148*f4a2713aSLionel Sambuc }
149*f4a2713aSLionel Sambuc 
150*f4a2713aSLionel Sambuc __m128 test_mm_dp_ps(__m128 x, __m128 y) {
151*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_dp_ps
152*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.dpps
153*f4a2713aSLionel Sambuc   return _mm_dp_ps(x, y, 2);
154*f4a2713aSLionel Sambuc }
155*f4a2713aSLionel Sambuc 
156*f4a2713aSLionel Sambuc __m128d test_mm_dp_pd(__m128d x, __m128d y) {
157*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_dp_pd
158*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.dppd
159*f4a2713aSLionel Sambuc   return _mm_dp_pd(x, y, 2);
160*f4a2713aSLionel Sambuc }
161*f4a2713aSLionel Sambuc 
162*f4a2713aSLionel Sambuc __m128 test_mm_round_ps(__m128 x) {
163*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_round_ps
164*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.round.ps
165*f4a2713aSLionel Sambuc   return _mm_round_ps(x, 2);
166*f4a2713aSLionel Sambuc }
167*f4a2713aSLionel Sambuc 
168*f4a2713aSLionel Sambuc __m128 test_mm_round_ss(__m128 x, __m128 y) {
169*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_round_ss
170*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.round.ss
171*f4a2713aSLionel Sambuc   return _mm_round_ss(x, y, 2);
172*f4a2713aSLionel Sambuc }
173*f4a2713aSLionel Sambuc 
174*f4a2713aSLionel Sambuc __m128d test_mm_round_pd(__m128d x) {
175*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_round_pd
176*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.round.pd
177*f4a2713aSLionel Sambuc   return _mm_round_pd(x, 2);
178*f4a2713aSLionel Sambuc }
179*f4a2713aSLionel Sambuc 
180*f4a2713aSLionel Sambuc __m128d test_mm_round_sd(__m128d x, __m128d y) {
181*f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @test_mm_round_sd
182*f4a2713aSLionel Sambuc   // CHECK: @llvm.x86.sse41.round.sd
183*f4a2713aSLionel Sambuc   return _mm_round_sd(x, y, 2);
184*f4a2713aSLionel Sambuc }
185*f4a2713aSLionel Sambuc 
186*f4a2713aSLionel Sambuc void test_storel_epi64(__m128i x, void* y) {
187*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_storel_epi64
188*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} i64* {{.*}}, align 1{{$}}
189*f4a2713aSLionel Sambuc   _mm_storel_epi64(y, x);
190*f4a2713aSLionel Sambuc }
191*f4a2713aSLionel Sambuc 
192*f4a2713aSLionel Sambuc void test_stream_si32(int x, void *y) {
193*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_stream_si32
194*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} i32* {{.*}}, align 1, !nontemporal
195*f4a2713aSLionel Sambuc   _mm_stream_si32(y, x);
196*f4a2713aSLionel Sambuc }
197*f4a2713aSLionel Sambuc 
198*f4a2713aSLionel Sambuc void test_stream_si64(long long x, void *y) {
199*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_stream_si64
200*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} i64* {{.*}}, align 1, !nontemporal
201*f4a2713aSLionel Sambuc   _mm_stream_si64(y, x);
202*f4a2713aSLionel Sambuc }
203*f4a2713aSLionel Sambuc 
204*f4a2713aSLionel Sambuc void test_stream_si128(__m128i x, void *y) {
205*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_stream_si128
206*f4a2713aSLionel Sambuc   // CHECK: store {{.*}} <2 x i64>* {{.*}}, align 16, !nontemporal
207*f4a2713aSLionel Sambuc   _mm_stream_si128(y, x);
208*f4a2713aSLionel Sambuc }
209*f4a2713aSLionel Sambuc 
210*f4a2713aSLionel Sambuc void test_extract_epi16(__m128i __a) {
211*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @test_extract_epi16
212*f4a2713aSLionel Sambuc   // CHECK: [[x:%.*]] = and i32 %{{.*}}, 7
213*f4a2713aSLionel Sambuc   // CHECK: extractelement <8 x i16> %{{.*}}, i32 [[x]]
214*f4a2713aSLionel Sambuc   _mm_extract_epi16(__a, 8);
215*f4a2713aSLionel Sambuc }
216*f4a2713aSLionel Sambuc 
217*f4a2713aSLionel Sambuc int test_extract_ps(__m128i __a) {
218*f4a2713aSLionel Sambuc   // CHECK-LABEL: @test_extract_ps
219*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x float> %{{.*}}, i32 0
220*f4a2713aSLionel Sambuc   return _mm_extract_ps(__a, 4);
221*f4a2713aSLionel Sambuc }
222*f4a2713aSLionel Sambuc 
223*f4a2713aSLionel Sambuc int test_extract_epi8(__m128i __a) {
224*f4a2713aSLionel Sambuc   // CHECK-LABEL: @test_extract_epi8
225*f4a2713aSLionel Sambuc   // CHECK: extractelement <16 x i8> %{{.*}}, i32 0
226*f4a2713aSLionel Sambuc   return _mm_extract_epi8(__a, 16);
227*f4a2713aSLionel Sambuc }
228*f4a2713aSLionel Sambuc 
229*f4a2713aSLionel Sambuc int test_extract_epi32(__m128i __a) {
230*f4a2713aSLionel Sambuc   // CHECK-LABEL: @test_extract_epi32
231*f4a2713aSLionel Sambuc   // CHECK: extractelement <4 x i32> %{{.*}}, i32 0
232*f4a2713aSLionel Sambuc   return _mm_extract_epi32(__a, 4);
233*f4a2713aSLionel Sambuc }
234*f4a2713aSLionel Sambuc 
235*f4a2713aSLionel Sambuc void test_insert_epi32(__m128i __a, int b) {
236*f4a2713aSLionel Sambuc   // CHECK-LABEL: @test_insert_epi32
237*f4a2713aSLionel Sambuc   // CHECK: insertelement <4 x i32> %{{.*}}, i32 %{{.*}}, i32 0
238*f4a2713aSLionel Sambuc    _mm_insert_epi32(__a, b, 4);
239*f4a2713aSLionel Sambuc }
240