2018-01-16 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / group-no-gaps-1.c
blobbcea180b2ff522cd40da194c955ff111340176b4
1 /* { dg-require-effective-target mmap } */
3 #include <sys/mman.h>
4 #include <stdio.h>
6 #define COUNT 320
7 #define MMAP_SIZE 0x20000
8 #define ADDRESS1 0x1122000000
9 #define ADDRESS2 (ADDRESS1 + MMAP_SIZE * 16)
10 #define TYPE unsigned int
12 #ifndef MAP_ANONYMOUS
13 #define MAP_ANONYMOUS MAP_ANON
14 #endif
16 #define RHS0(B) b[B]
17 #define RHS1(B) RHS0(B) + b[(B) + 1]
18 #define RHS2(B) RHS1(B) + b[(B) + 2]
19 #define RHS3(B) RHS2(B) + b[(B) + 3]
20 #define RHS4(B) RHS3(B) + b[(B) + 4]
21 #define RHS5(B) RHS4(B) + b[(B) + 5]
22 #define RHS6(B) RHS5(B) + b[(B) + 6]
23 #define RHS7(B) RHS6(B) + b[(B) + 7]
25 #define LHS0(B) a[B]
26 #define LHS1(B) LHS0(B) = a[(B) + 1]
27 #define LHS2(B) LHS1(B) = a[(B) + 2]
28 #define LHS3(B) LHS2(B) = a[(B) + 3]
29 #define LHS4(B) LHS3(B) = a[(B) + 4]
30 #define LHS5(B) LHS4(B) = a[(B) + 5]
31 #define LHS6(B) LHS5(B) = a[(B) + 6]
32 #define LHS7(B) LHS6(B) = a[(B) + 7]
34 #define DEF_GROUP_SIZE(MULT, GAP, NO_GAP) \
35 void __attribute__((noinline, noclone)) \
36 gap_load_##MULT (TYPE *__restrict a, TYPE *__restrict b) \
37 { \
38 for (int i = 0; i < COUNT; i++) \
39 a[i] = RHS##GAP (i * MULT); \
40 } \
41 void __attribute__((noinline, noclone)) \
42 no_gap_load_##MULT (TYPE *__restrict a, TYPE *__restrict b) \
43 { \
44 for (int i = 0; i < COUNT; i++) \
45 a[i] = RHS##NO_GAP (i * MULT); \
46 } \
47 void __attribute__((noinline, noclone)) \
48 gap_store_##MULT (TYPE *__restrict a, TYPE *__restrict b) \
49 { \
50 for (int i = 0; i < COUNT; i++) \
51 LHS##GAP (i * MULT) = b[i]; \
52 } \
53 void __attribute__((noinline, noclone)) \
54 no_gap_store_##MULT (TYPE *__restrict a, TYPE *__restrict b) \
55 { \
56 for (int i = 0; i < COUNT; i++) \
57 LHS##NO_GAP (i * MULT) = b[i]; \
60 #define USE_GROUP_SIZE(MULT) \
61 gap_load_##MULT (end_x - COUNT, end_y - COUNT * MULT + 1); \
62 no_gap_load_##MULT (end_x - COUNT, end_y - COUNT * MULT); \
63 gap_store_##MULT (end_x - COUNT * MULT + 1, end_y - COUNT); \
64 no_gap_store_##MULT (end_x - COUNT * MULT, end_y - COUNT)
66 DEF_GROUP_SIZE (2, 0, 1)
67 DEF_GROUP_SIZE (3, 1, 2)
68 DEF_GROUP_SIZE (4, 2, 3)
69 DEF_GROUP_SIZE (5, 3, 4)
70 DEF_GROUP_SIZE (6, 4, 5)
71 DEF_GROUP_SIZE (7, 5, 6)
72 DEF_GROUP_SIZE (8, 6, 7)
74 int
75 main (void)
77 void *x, *y;
78 TYPE *end_x, *end_y;
80 x = mmap ((void *) ADDRESS1, MMAP_SIZE, PROT_READ | PROT_WRITE,
81 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
82 if (x == MAP_FAILED)
84 perror ("mmap");
85 return 1;
88 y = mmap ((void *) ADDRESS2, MMAP_SIZE, PROT_READ | PROT_WRITE,
89 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
90 if (y == MAP_FAILED)
92 perror ("mmap");
93 return 1;
96 end_x = (TYPE *) ((char *) x + MMAP_SIZE);
97 end_y = (TYPE *) ((char *) y + MMAP_SIZE);
99 USE_GROUP_SIZE (2);
100 USE_GROUP_SIZE (3);
101 USE_GROUP_SIZE (4);
102 USE_GROUP_SIZE (5);
103 USE_GROUP_SIZE (6);
104 USE_GROUP_SIZE (7);
105 USE_GROUP_SIZE (8);
107 return 0;