Debian Codegraph @

gcc/testsuite/gcc.dg/vect/pr94994.c

raw
1 #include <stdint.h>
2 #include "tree-vect.h"
3
4 #define BLOCK_SIZE (sizeof (uint32_t))
5
6 struct unaligned {
7 uint32_t x;
8 } __attribute__((packed, may_alias));
9
10 static inline uint32_t
11 load_unaligned (const char *p)
12 {
13 return ((struct unaligned *) p)->x;
14 }
15
16 static inline void
17 store_unaligned (uint32_t x, char *p)
18 {
19 ((struct unaligned *) p)->x = x;
20 }
21
22 void __attribute__((noipa))
23 copy (char *dst, const char *src, size_t n)
24 {
25 for (size_t i = 0; i < n; i += BLOCK_SIZE)
26 store_unaligned (load_unaligned (src + i), dst + i);
27 }
28
29 #define INPUT_SIZE 64
30 #define MAX_STEP 32
31
32 char x[INPUT_SIZE + MAX_STEP];
33
34 int
35 main (void)
36 {
37 check_vect ();
38
39 for (unsigned int i = 1; i < MAX_STEP; ++i)
40 {
41 for (unsigned int j = 0; j < INPUT_SIZE + MAX_STEP; ++j)
42 x[j] = j + 10;
43 copy (x + i, x, INPUT_SIZE);
44 #pragma GCC novector
45 for (int j = 0; j < INPUT_SIZE + i; ++j)
46 {
47 int expected;
48 if (j < i)
49 expected = j + 10;
50 else if (i >= BLOCK_SIZE)
51 expected = j % i + 10;
52 else if ((j - i) % BLOCK_SIZE < i)
53 expected = x[j - i];
54 else
55 expected = j - i + 10;
56 if (x[j] != expected)
57 __builtin_abort ();
58 }
59 }
60
61 return 0;
62 }