1 #define N 200
2 #define DIST 32
3 
4 typedef signed char sc;
5 typedef unsigned char uc;
6 typedef signed short ss;
7 typedef unsigned short us;
8 typedef int si;
9 typedef unsigned int ui;
10 typedef signed long long sll;
11 typedef unsigned long long ull;
12 
13 #define FOR_EACH_TYPE(M) \
14   M (sc) M (uc) \
15   M (ss) M (us) \
16   M (si) M (ui) \
17   M (sll) M (ull) \
18   M (float) M (double)
19 
20 #define TEST_VALUE(I) ((I) * 5 / 2)
21 
22 #define ADD_TEST(TYPE)				\
23   TYPE a_##TYPE[N * 2];				\
24   void __attribute__((noinline, noclone))	\
25   test_##TYPE (int x, int y)			\
26   {						\
27     for (int i = 0; i < N; ++i)			\
28       a_##TYPE[i + x] += a_##TYPE[i + y];	\
29   }
30 
31 #define DO_TEST(TYPE)						\
32   for (int i = 0; i < DIST * 2; ++i)				\
33     {								\
34       for (int j = 0; j < N + DIST * 2; ++j)			\
35 	a_##TYPE[j] = TEST_VALUE (j);				\
36       test_##TYPE (i, DIST);					\
37       for (int j = 0; j < N + DIST * 2; ++j)			\
38 	{							\
39 	  TYPE expected;					\
40 	  if (j < i || j >= i + N)				\
41 	    expected = TEST_VALUE (j);				\
42 	  else if (i <= DIST)					\
43 	    expected = ((TYPE) TEST_VALUE (j)			\
44 			+ (TYPE) TEST_VALUE (j - i + DIST));	\
45 	  else							\
46 	    expected = ((TYPE) TEST_VALUE (j)			\
47 			+ a_##TYPE[j - i + DIST]);		\
48 	  if (expected != a_##TYPE[j])				\
49 	    __builtin_abort ();					\
50 	}							\
51     }
52 
FOR_EACH_TYPE(ADD_TEST)53 FOR_EACH_TYPE (ADD_TEST)
54 
55 int
56 main (void)
57 {
58   FOR_EACH_TYPE (DO_TEST)
59   return 0;
60 }
61