xref: /llvm-project/clang/test/Sema/arm-mve-immediates.c (revision 123064dc397d478a636ba1c5960d41ad381036a0)
1 // RUN: %clang_cc1 -triple thumbv8.1m.main-none-none-eabi -target-feature +mve.fp -verify -fsyntax-only %s
2 
3 // REQUIRES: aarch64-registered-target || arm-registered-target
4 
5 #include <arm_mve.h>
6 
test_load_offsets(uint32x4_t addr32,uint64x2_t addr64)7 void test_load_offsets(uint32x4_t addr32, uint64x2_t addr64)
8 {
9   // Offsets that should be a multiple of 8 times 0,1,...,127
10   vldrdq_gather_base_s64(addr64, 0);
11   vldrdq_gather_base_s64(addr64, 8);
12   vldrdq_gather_base_s64(addr64, 2*8);
13   vldrdq_gather_base_s64(addr64, 125*8);
14   vldrdq_gather_base_s64(addr64, 126*8);
15   vldrdq_gather_base_s64(addr64, 127*8);
16   vldrdq_gather_base_s64(addr64, -125*8);
17   vldrdq_gather_base_s64(addr64, -126*8);
18   vldrdq_gather_base_s64(addr64, -127*8);
19   vldrdq_gather_base_s64(addr64, 128*8); // expected-error {{argument value 1024 is outside the valid range [-1016, 1016]}}
20   vldrdq_gather_base_s64(addr64, -128*8); // expected-error {{argument value -1024 is outside the valid range [-1016, 1016]}}
21   vldrdq_gather_base_s64(addr64, 4); // expected-error {{argument should be a multiple of 8}}
22   vldrdq_gather_base_s64(addr64, 1); // expected-error {{argument should be a multiple of 8}}
23 
24   // Offsets that should be a multiple of 4 times 0,1,...,127
25   vldrwq_gather_base_s32(addr32, 0);
26   vldrwq_gather_base_s32(addr32, 4);
27   vldrwq_gather_base_s32(addr32, 2*4);
28   vldrwq_gather_base_s32(addr32, 125*4);
29   vldrwq_gather_base_s32(addr32, 126*4);
30   vldrwq_gather_base_s32(addr32, 127*4);
31   vldrwq_gather_base_s32(addr32, -125*4);
32   vldrwq_gather_base_s32(addr32, -126*4);
33   vldrwq_gather_base_s32(addr32, -127*4);
34   vldrwq_gather_base_s32(addr32, 128*4); // expected-error {{argument value 512 is outside the valid range [-508, 508]}}
35   vldrwq_gather_base_s32(addr32, -128*4); // expected-error {{argument value -512 is outside the valid range [-508, 508]}}
36   vldrwq_gather_base_s32(addr32, 2); // expected-error {{argument should be a multiple of 4}}
37   vldrwq_gather_base_s32(addr32, 1); // expected-error {{argument should be a multiple of 4}}
38 
39   // Show that the polymorphic store intrinsics get the right set of
40   // error checks after overload resolution. These ones expand to the
41   // 8-byte granular versions...
42   vstrdq_scatter_base(addr64, 0, addr64);
43   vstrdq_scatter_base(addr64, 8, addr64);
44   vstrdq_scatter_base(addr64, 2*8, addr64);
45   vstrdq_scatter_base(addr64, 125*8, addr64);
46   vstrdq_scatter_base(addr64, 126*8, addr64);
47   vstrdq_scatter_base(addr64, 127*8, addr64);
48   vstrdq_scatter_base(addr64, -125*8, addr64);
49   vstrdq_scatter_base(addr64, -126*8, addr64);
50   vstrdq_scatter_base(addr64, -127*8, addr64);
51   vstrdq_scatter_base(addr64, 128*8, addr64); // expected-error {{argument value 1024 is outside the valid range [-1016, 1016]}}
52   vstrdq_scatter_base(addr64, -128*8, addr64); // expected-error {{argument value -1024 is outside the valid range [-1016, 1016]}}
53   vstrdq_scatter_base(addr64, 4, addr64); // expected-error {{argument should be a multiple of 8}}
54   vstrdq_scatter_base(addr64, 1, addr64); // expected-error {{argument should be a multiple of 8}}
55 
56   /// ... and these ones to the 4-byte.
57   vstrwq_scatter_base(addr32, 0, addr32);
58   vstrwq_scatter_base(addr32, 4, addr32);
59   vstrwq_scatter_base(addr32, 2*4, addr32);
60   vstrwq_scatter_base(addr32, 125*4, addr32);
61   vstrwq_scatter_base(addr32, 126*4, addr32);
62   vstrwq_scatter_base(addr32, 127*4, addr32);
63   vstrwq_scatter_base(addr32, -125*4, addr32);
64   vstrwq_scatter_base(addr32, -126*4, addr32);
65   vstrwq_scatter_base(addr32, -127*4, addr32);
66   vstrwq_scatter_base(addr32, 128*4, addr32); // expected-error {{argument value 512 is outside the valid range [-508, 508]}}
67   vstrwq_scatter_base(addr32, -128*4, addr32); // expected-error {{argument value -512 is outside the valid range [-508, 508]}}
68   vstrwq_scatter_base(addr32, 2, addr32); // expected-error {{argument should be a multiple of 4}}
69   vstrwq_scatter_base(addr32, 1, addr32); // expected-error {{argument should be a multiple of 4}}
70 }
71 
test_lane_indices(uint8x16_t v16,uint16x8_t v8,uint32x4_t v4,uint64x2_t v2)72 void test_lane_indices(uint8x16_t v16, uint16x8_t v8,
73                        uint32x4_t v4, uint64x2_t v2)
74 {
75   vgetq_lane_u8(v16, -1); // expected-error {{argument value -1 is outside the valid range [0, 15]}}
76   vgetq_lane_u8(v16, 0);
77   vgetq_lane_u8(v16, 15);
78   vgetq_lane_u8(v16, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
79 
80   vgetq_lane_u16(v8, -1); // expected-error {{argument value -1 is outside the valid range [0, 7]}}
81   vgetq_lane_u16(v8, 0);
82   vgetq_lane_u16(v8, 7);
83   vgetq_lane_u16(v8, 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}
84 
85   vgetq_lane_u32(v4, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}}
86   vgetq_lane_u32(v4, 0);
87   vgetq_lane_u32(v4, 3);
88   vgetq_lane_u32(v4, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
89 
90   vgetq_lane_u64(v2, -1); // expected-error {{argument value -1 is outside the valid range [0, 1]}}
91   vgetq_lane_u64(v2, 0);
92   vgetq_lane_u64(v2, 1);
93   vgetq_lane_u64(v2, 2); // expected-error {{argument value 2 is outside the valid range [0, 1]}}
94 
95   vsetq_lane_u8(23, v16, -1); // expected-error {{argument value -1 is outside the valid range [0, 15]}}
96   vsetq_lane_u8(23, v16, 0);
97   vsetq_lane_u8(23, v16, 15);
98   vsetq_lane_u8(23, v16, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
99 
100   vsetq_lane_u16(23, v8, -1); // expected-error {{argument value -1 is outside the valid range [0, 7]}}
101   vsetq_lane_u16(23, v8, 0);
102   vsetq_lane_u16(23, v8, 7);
103   vsetq_lane_u16(23, v8, 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}
104 
105   vsetq_lane_u32(23, v4, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}}
106   vsetq_lane_u32(23, v4, 0);
107   vsetq_lane_u32(23, v4, 3);
108   vsetq_lane_u32(23, v4, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
109 
110   vsetq_lane_u64(23, v2, -1); // expected-error {{argument value -1 is outside the valid range [0, 1]}}
111   vsetq_lane_u64(23, v2, 0);
112   vsetq_lane_u64(23, v2, 1);
113   vsetq_lane_u64(23, v2, 2); // expected-error {{argument value 2 is outside the valid range [0, 1]}}
114 }
115 
test_immediate_shifts(uint8x16_t vb,uint16x8_t vh,uint32x4_t vw)116 void test_immediate_shifts(uint8x16_t vb, uint16x8_t vh, uint32x4_t vw)
117 {
118   vshlq_n(vb, 0);
119   vshlq_n(vb, 7);
120   vshlq_n(vh, 0);
121   vshlq_n(vh, 15);
122   vshlq_n(vw, 0);
123   vshlq_n(vw, 31);
124 
125   vshlq_n(vb, -1); // expected-error {{argument value -1 is outside the valid range [0, 7]}}
126   vshlq_n(vb, 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}
127   vshlq_n(vh, -1); // expected-error {{argument value -1 is outside the valid range [0, 15]}}
128   vshlq_n(vh, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
129   vshlq_n(vw, -1); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
130   vshlq_n(vw, 32); // expected-error {{argument value 32 is outside the valid range [0, 31]}}
131 
132   vqshlq_n(vb, 0);
133   vqshlq_n(vb, 7);
134   vqshlq_n(vh, 0);
135   vqshlq_n(vh, 15);
136   vqshlq_n(vw, 0);
137   vqshlq_n(vw, 31);
138 
139   vqshlq_n(vb, -1); // expected-error {{argument value -1 is outside the valid range [0, 7]}}
140   vqshlq_n(vb, 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}
141   vqshlq_n(vh, -1); // expected-error {{argument value -1 is outside the valid range [0, 15]}}
142   vqshlq_n(vh, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
143   vqshlq_n(vw, -1); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
144   vqshlq_n(vw, 32); // expected-error {{argument value 32 is outside the valid range [0, 31]}}
145 
146   vsliq(vb, vb, 0);
147   vsliq(vb, vb, 7);
148   vsliq(vh, vh, 0);
149   vsliq(vh, vh, 15);
150   vsliq(vw, vw, 0);
151   vsliq(vw, vw, 31);
152 
153   vsliq(vb, vb, -1); // expected-error {{argument value -1 is outside the valid range [0, 7]}}
154   vsliq(vb, vb, 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}
155   vsliq(vh, vh, -1); // expected-error {{argument value -1 is outside the valid range [0, 15]}}
156   vsliq(vh, vh, 16); // expected-error {{argument value 16 is outside the valid range [0, 15]}}
157   vsliq(vw, vw, -1); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
158   vsliq(vw, vw, 32); // expected-error {{argument value 32 is outside the valid range [0, 31]}}
159 
160   vshllbq(vb, 1);
161   vshllbq(vb, 8);
162   vshllbq(vh, 1);
163   vshllbq(vh, 16);
164 
165   vshllbq(vb, 0); // expected-error {{argument value 0 is outside the valid range [1, 8]}}
166   vshllbq(vb, 9); // expected-error {{argument value 9 is outside the valid range [1, 8]}}
167   vshllbq(vh, 0); // expected-error {{argument value 0 is outside the valid range [1, 16]}}
168   vshllbq(vh, 17); // expected-error {{argument value 17 is outside the valid range [1, 16]}}
169 
170   vshrq(vb, 1);
171   vshrq(vb, 8);
172   vshrq(vh, 1);
173   vshrq(vh, 16);
174   vshrq(vw, 1);
175   vshrq(vw, 32);
176 
177   vshrq(vb, 0); // expected-error {{argument value 0 is outside the valid range [1, 8]}}
178   vshrq(vb, 9); // expected-error {{argument value 9 is outside the valid range [1, 8]}}
179   vshrq(vh, 0); // expected-error {{argument value 0 is outside the valid range [1, 16]}}
180   vshrq(vh, 17); // expected-error {{argument value 17 is outside the valid range [1, 16]}}
181   vshrq(vw, 0); // expected-error {{argument value 0 is outside the valid range [1, 32]}}
182   vshrq(vw, 33); // expected-error {{argument value 33 is outside the valid range [1, 32]}}
183 
184   vshrntq(vb, vh, 1);
185   vshrntq(vb, vh, 8);
186   vshrntq(vh, vw, 1);
187   vshrntq(vh, vw, 16);
188 
189   vshrntq(vb, vh, 0); // expected-error {{argument value 0 is outside the valid range [1, 8]}}
190   vshrntq(vb, vh, 9); // expected-error {{argument value 9 is outside the valid range [1, 8]}}
191   vshrntq(vh, vw, 0); // expected-error {{argument value 0 is outside the valid range [1, 16]}}
192   vshrntq(vh, vw, 17); // expected-error {{argument value 17 is outside the valid range [1, 16]}}
193 
194   vsriq(vb, vb, 1);
195   vsriq(vb, vb, 8);
196   vsriq(vh, vh, 1);
197   vsriq(vh, vh, 16);
198   vsriq(vw, vw, 1);
199   vsriq(vw, vw, 32);
200 
201   vsriq(vb, vb, 0); // expected-error {{argument value 0 is outside the valid range [1, 8]}}
202   vsriq(vb, vb, 9); // expected-error {{argument value 9 is outside the valid range [1, 8]}}
203   vsriq(vh, vh, 0); // expected-error {{argument value 0 is outside the valid range [1, 16]}}
204   vsriq(vh, vh, 17); // expected-error {{argument value 17 is outside the valid range [1, 16]}}
205   vsriq(vw, vw, 0); // expected-error {{argument value 0 is outside the valid range [1, 32]}}
206   vsriq(vw, vw, 33); // expected-error {{argument value 33 is outside the valid range [1, 32]}}
207 }
208 
test_simd_bic_orr(int16x8_t h,int32x4_t w)209 void test_simd_bic_orr(int16x8_t h, int32x4_t w)
210 {
211     h = vbicq(h, 0x0000);
212     h = vbicq(h, 0x0001);
213     h = vbicq(h, 0x00FF);
214     h = vbicq(h, 0x0100);
215     h = vbicq(h, 0x0101); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
216     h = vbicq(h, 0x01FF); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
217     h = vbicq(h, 0xFF00);
218 
219     w = vbicq(w, 0x00000000);
220     w = vbicq(w, 0x00000001);
221     w = vbicq(w, 0x000000FF);
222     w = vbicq(w, 0x00000100);
223     w = vbicq(w, 0x0000FF00);
224     w = vbicq(w, 0x00010000);
225     w = vbicq(w, 0x00FF0000);
226     w = vbicq(w, 0x01000000);
227     w = vbicq(w, 0xFF000000);
228     w = vbicq(w, 0x01000001); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
229     w = vbicq(w, 0x01FFFFFF); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
230 
231     h = vorrq(h, 0x0000);
232     h = vorrq(h, 0x0001);
233     h = vorrq(h, 0x00FF);
234     h = vorrq(h, 0x0100);
235     h = vorrq(h, 0x0101); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
236     h = vorrq(h, 0x01FF); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
237     h = vorrq(h, 0xFF00);
238 
239     w = vorrq(w, 0x00000000);
240     w = vorrq(w, 0x00000001);
241     w = vorrq(w, 0x000000FF);
242     w = vorrq(w, 0x00000100);
243     w = vorrq(w, 0x0000FF00);
244     w = vorrq(w, 0x00010000);
245     w = vorrq(w, 0x00FF0000);
246     w = vorrq(w, 0x01000000);
247     w = vorrq(w, 0xFF000000);
248     w = vorrq(w, 0x01000001); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
249     w = vorrq(w, 0x01FFFFFF); // expected-error-re {{argument should be an 8-bit value shifted by a multiple of 8 bits{{$}}}}
250 }
251 
test_simd_vmvn(void)252 void test_simd_vmvn(void)
253 {
254     uint16x8_t h;
255     h = vmvnq_n_u16(0x0000);
256     h = vmvnq_n_u16(0x0001);
257     h = vmvnq_n_u16(0x00FF);
258     h = vmvnq_n_u16(0x0100);
259     h = vmvnq_n_u16(0x0101); // expected-error {{argument should be an 8-bit value shifted by a multiple of 8 bits, or in the form 0x??FF}}
260     h = vmvnq_n_u16(0x01FF);
261     h = vmvnq_n_u16(0xFF00);
262 
263     uint32x4_t w;
264     w = vmvnq_n_u32(0x00000000);
265     w = vmvnq_n_u32(0x00000001);
266     w = vmvnq_n_u32(0x000000FF);
267     w = vmvnq_n_u32(0x00000100);
268     w = vmvnq_n_u32(0x0000FF00);
269     w = vmvnq_n_u32(0x00010000);
270     w = vmvnq_n_u32(0x00FF0000);
271     w = vmvnq_n_u32(0x01000000);
272     w = vmvnq_n_u32(0xFF000000);
273     w = vmvnq_n_u32(0x01000001); // expected-error {{argument should be an 8-bit value shifted by a multiple of 8 bits, or in the form 0x??FF}}
274     w = vmvnq_n_u32(0x01FFFFFF); // expected-error {{argument should be an 8-bit value shifted by a multiple of 8 bits, or in the form 0x??FF}}
275     w = vmvnq_n_u32(0x0001FFFF); // expected-error {{argument should be an 8-bit value shifted by a multiple of 8 bits, or in the form 0x??FF}}
276     w = vmvnq_n_u32(0x000001FF);
277 }
278 
test_vidup(void)279 void test_vidup(void)
280 {
281     vidupq_n_u16(0x12345678, 1);
282     vidupq_n_u16(0x12345678, 2);
283     vidupq_n_u16(0x12345678, 4);
284     vidupq_n_u16(0x12345678, 8);
285 
286     vidupq_n_u16(0x12345678, 0); // expected-error {{argument value 0 is outside the valid range [1, 8]}}
287     vidupq_n_u16(0x12345678, 16); // expected-error {{argument value 16 is outside the valid range [1, 8]}}
288     vidupq_n_u16(0x12345678, -1); // expected-error {{argument value -1 is outside the valid range [1, 8]}}
289     vidupq_n_u16(0x12345678, -2); // expected-error {{argument value -2 is outside the valid range [1, 8]}}
290     vidupq_n_u16(0x12345678, -4); // expected-error {{argument value -4 is outside the valid range [1, 8]}}
291     vidupq_n_u16(0x12345678, -8); // expected-error {{argument value -8 is outside the valid range [1, 8]}}
292     vidupq_n_u16(0x12345678, 3); // expected-error {{argument should be a power of 2}}
293     vidupq_n_u16(0x12345678, 7); // expected-error {{argument should be a power of 2}}
294 }
295 
test_vcvtq(void)296 void test_vcvtq(void)
297 {
298     uint16x8_t vec_u16;
299     float16x8_t vec_f16;
300     vcvtq_n_f16_u16(vec_u16, 0); // expected-error {{argument value 0 is outside the valid range [1, 16]}}
301     vcvtq_n_f16_u16(vec_u16, 1);
302     vcvtq_n_f16_u16(vec_u16, 16);
303     vcvtq_n_f16_u16(vec_u16, 17); // expected-error {{argument value 17 is outside the valid range [1, 16]}}
304 
305     int32x4_t vec_s32;
306     float32x4_t vec_f32;
307     vcvtq_n_s32_f32(vec_s32, -1); // expected-error {{argument value -1 is outside the valid range [1, 32]}}
308     vcvtq_n_s32_f32(vec_s32, 1);
309     vcvtq_n_s32_f32(vec_s32, 32);
310     vcvtq_n_s32_f32(vec_s32, 33); // expected-error {{argument value 33 is outside the valid range [1, 32]}}
311 }
312