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