1 /* PR target/44606 */
2 /* { dg-do run } */
3 /* { dg-options "-O2" } */
4 
5 #include <stdio.h>
6 
7 extern void abort (void);
8 
9  typedef struct _PixelPacket { 	unsigned char r, g, b; }
10  PixelPacket;
11 #define ARRAYLEN(X) (sizeof(X)/sizeof(X[0]))
12 PixelPacket q[6];
13 #define COLS (ARRAYLEN(q) - 1)
14 PixelPacket p[2*COLS + 22];
15 #define Minify(POS, WEIGHT) do {	\
16 	total_r += (WEIGHT)*(p[POS].r);	\
17 	total_g += (WEIGHT)*(p[POS].g);	\
18 	total_b += (WEIGHT)*(p[POS].b);	\
19 } while (0)
20 unsigned long columns = COLS;
main(void)21 int main(void)
22 {
23 	static const unsigned char answers[COLS] = { 31, 32, 34, 35, 36 };
24 	unsigned long x;
25 	for (x = 0; x < sizeof(p)/sizeof(p[0]); x++) {
26 		p[x].b = (x + 34) | 1;
27 	}
28 	for (x = 0; x < columns; x++) {
29 		double total_r = 0, total_g = 0, total_b = 0;
30 		double saved_r = 0, saved_g = 0, saved_b = 0;
31 		Minify(2*x +  0,  3.0);
32 		Minify(2*x +  1,  7.0);
33 		Minify(2*x +  2,  7.0);
34 		saved_r = total_r;
35 		saved_g = total_g;
36 		Minify(2*x + 11, 15.0);
37 		Minify(2*x + 12,  7.0);
38 		Minify(2*x + 18,  7.0);
39 		Minify(2*x + 19, 15.0);
40 		Minify(2*x + 20, 15.0);
41 		Minify(2*x + 21,  7.0);
42 		q[x].r = (unsigned char)(total_r/128.0 + 0.5);
43 		q[x].g = (unsigned char)(total_g/128.0 + 0.5);
44 		q[x].b = (unsigned char)(total_b/128.0 + 0.5);
45 		fprintf(stderr, "r:%f g:%f b:%f\n", saved_r, saved_g, saved_b);
46 	}
47 	for (x = 0; x < COLS; x++) {
48 		if (answers[x] != q[x].b)
49 			abort();
50 	}
51 	return 0;
52 }
53