1 extern void abort (void) __attribute__ ((noreturn));
2 
3 #define MARGIN 6
4 
5 void __attribute__ ((weak, optimize ("no-tree-vectorize")))
test(int n,int m,int offset)6 test (int n, int m, int offset)
7 {
8   int abs_n = (n < 0 ? -n : n);
9   int abs_m = (m < 0 ? -m : m);
10   int max_i = (abs_n > abs_m ? abs_n : abs_m);
11   int abs_offset = (offset < 0 ? -offset : offset);
12   int size = MARGIN * 2 + max_i * SIZE + abs_offset;
13   TYPE *array = (TYPE *) __builtin_alloca (size * sizeof (TYPE));
14   for (int i = 0; i < size; ++i)
15     array[i] = i;
16   int base_x = offset < 0 ? MARGIN - offset : MARGIN;
17   int base_y = offset < 0 ? MARGIN : MARGIN + offset;
18   int start_x = n < 0 ? base_x - n * (SIZE - 1) : base_x;
19   int start_y = m < 0 ? base_y - m * (SIZE - 1) : base_y;
20   f (&array[start_x], &array[start_y], n, m);
21   int j = 0;
22   int start = (n < 0 ? size - 1 : 0);
23   int end = (n < 0 ? -1 : size);
24   int inc = (n < 0 ? -1 : 1);
25   for (int i = start; i != end; i += inc)
26     {
27       if (j == SIZE || i != start_x + j * n)
28 	{
29 	  if (array[i] != i)
30 	    abort ();
31 	}
32       else if (n == 0)
33 	{
34 	  TYPE sum = i;
35 	  for (; j < SIZE; j++)
36 	    {
37 	      int next_y = start_y + j * m;
38 	      if (n >= 0 ? next_y < i : next_y > i)
39 		sum += array[next_y];
40 	      else if (next_y == i)
41 		sum += sum;
42 	      else
43 		sum += next_y;
44 	    }
45 	  if (array[i] != sum)
46 	    abort ();
47 	}
48       else
49 	{
50 	  int next_y = start_y + j * m;
51 	  TYPE base = i;
52 	  if (n >= 0 ? next_y < i : next_y > i)
53 	    base += array[next_y];
54 	  else
55 	    base += next_y;
56 	  if (array[i] != base)
57 	    abort ();
58 	  j += 1;
59 	}
60     }
61 }
62