| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-std=c99" } */ |
| 3 |
/* { dg-additional-options "-O3 -march=armv8-a" } */ |
| 4 |
|
| 5 |
/* Ensure correct creation of SVE Vector-length agnostic (VLA SVE) vector |
| 6 |
function calls from scalar versions in accordance with the Vector Function |
| 7 |
Application Binary Interface Specification for AArch64 (AAVPCS). |
| 8 |
|
| 9 |
We check for correctness in: |
| 10 |
- Vector function name mangling, with the grammar: |
| 11 |
|
| 12 |
vector name := prefix "_" name |
| 13 |
prefix := "_ZGV" isa mask <len> <parameters> |
| 14 |
|
| 15 |
Whereby: |
| 16 |
- <isa> := "s" for SVE |
| 17 |
- <mask> := "M" for Mask |
| 18 |
- <len> := "x" for VLA SVE |
| 19 |
|
| 20 |
resulting in: |
| 21 |
<prefix> := "_ZGVsMx" <parameters> |
| 22 |
|
| 23 |
with each vector parameter contributing a "v" to the prefix. |
| 24 |
|
| 25 |
- Parameter and return value mapping: |
| 26 |
- Unless marked with uniform or linear OpenMP clauses, parameters and |
| 27 |
return values are expected to map to vectors. |
| 28 |
- Where the lane-size of a parameter is less than the widest data size |
| 29 |
for a given function, the resulting vector should be unpacked and |
| 30 |
populated via extending loads. |
| 31 |
|
| 32 |
- Finally, we also make sure we can correctly generate calls to the same |
| 33 |
function, differing only in the target architecture (i.e. SVE vs SIMD), |
| 34 |
ensuring that each call points to the correctly-mangled vector function |
| 35 |
and employs the correct ABI. For example, for `fn' we may expect: |
| 36 |
|
| 37 |
for #pragma GCC target("+sve"): _ZGVsMxvv_fn |
| 38 |
for #pragma GCC target("+simd): _ZGVnN4vv_fn */ |
| 39 |
|
| 40 |
#pragma GCC target ("+sve") |
| 41 |
/* { dg-final { scan-assembler {\s+_ZGVsMxv_fn0\n} } } */ |
| 42 |
extern int __attribute__ ((simd, const)) fn0 (int); |
| 43 |
void test_fn0 (int *a, int *b, int n) |
| 44 |
{ |
| 45 |
for (int i = 0; i < n; ++i) |
| 46 |
a[i] += fn0 (b[i]); |
| 47 |
} |
| 48 |
|
| 49 |
/* { dg-final { scan-assembler {\s+_ZGVsMxvv_fn1\n} } } */ |
| 50 |
extern int __attribute__ ((simd, const)) fn1 (short, int); |
| 51 |
void test_fn1 (int *a, int *b, short *c, int n) |
| 52 |
{ |
| 53 |
for (int i = 0; i < n; ++i) |
| 54 |
a[i] = fn1 (c[i], b[i]); |
| 55 |
} |
| 56 |
|
| 57 |
/* { dg-final { scan-assembler {\s+_ZGVsMxvv_fn2\n} } } */ |
| 58 |
extern short __attribute__ ((simd, const)) fn2 (short, int); |
| 59 |
void test_fn2 (short *a, int *b, short *c, int n) |
| 60 |
{ |
| 61 |
for (int i = 0; i < n; ++i) |
| 62 |
a[i] = fn2 (c[i], b[i]); |
| 63 |
} |
| 64 |
|
| 65 |
/* { dg-final { scan-assembler {\s+_ZGVsMxvv_fn3\n} } } */ |
| 66 |
extern char __attribute__ ((simd, const)) fn3 (int, char); |
| 67 |
void test_fn3 (int *a, int *b, char *c, int n) |
| 68 |
{ |
| 69 |
for (int i = 0; i < n; ++i) |
| 70 |
a[i] = (int) (fn3 (b[i], c[i]) + c[i]); |
| 71 |
} |
| 72 |
|
| 73 |
/* { dg-final { scan-assembler {\s+_ZGVsMxvv_fn4\n} } } */ |
| 74 |
extern short __attribute__ ((simd, const)) fn4 (int, short); |
| 75 |
void test_fn4 (int *a, int *b, short *c, int n) |
| 76 |
{ |
| 77 |
for (int i = 0; i < n; ++i) |
| 78 |
a[i] = (int) (fn4 (b[i], c[i]) + c[i]); |
| 79 |
} |
| 80 |
|
| 81 |
#pragma GCC reset_options |
| 82 |
#pragma GCC target ("+simd") |
| 83 |
/* { dg-final { scan-assembler {\s+_ZGVnN4vv_fn4\n} } } */ |
| 84 |
extern short __attribute__ ((simd, const)) fn4 (int, short); |
| 85 |
void test_fn5 (int *a, int *b, short *c, int n) |
| 86 |
{ |
| 87 |
for (int i = 0; i < n; ++i) |
| 88 |
a[i] = (int) (fn4 (b[i], c[i]) + c[i]); |
| 89 |
} |