xref: /llvm-project/clang/test/CodeGen/mandel.c (revision 7d644e1215b376ec5e915df9ea2eeb56e2d94626)
1 // RUN: %clang_cc1 -emit-llvm %s -o %t
2 
3 /* Sparc is not C99-compliant */
4 #if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
5 
main(void)6 int main(void) { return 0; }
7 
8 #else /* sparc */
9 
10 #define ESCAPE 2
11 #define IMAGE_WIDTH 150
12 #define IMAGE_HEIGHT 50
13 #if 1
14 #define IMAGE_SIZE 60
15 #else
16 #define IMAGE_SIZE 5000
17 #endif
18 #define START_X -2.1
19 #define END_X 1.0
20 #define START_Y -1.25
21 #define MAX_ITER 100
22 
23 #define step_X ((END_X - START_X)/IMAGE_WIDTH)
24 #define step_Y ((-START_Y - START_Y)/IMAGE_HEIGHT)
25 
26 #define I 1.0iF
27 
28 int putchar(char c);
29 double hypot(double, double);
30 
31 volatile double __complex__ accum;
32 
mandel(void)33 void mandel(void) {
34   int x, y, n;
35   for (y = 0; y < IMAGE_HEIGHT; ++y) {
36     for (x = 0; x < IMAGE_WIDTH; ++x) {
37       double __complex__ c = (START_X+x*step_X) + (START_Y+y*step_Y) * I;
38       double __complex__ z = 0.0;
39 
40       for (n = 0; n < MAX_ITER; ++n) {
41         z = z * z + c;
42         if (hypot(__real__ z, __imag__ z) >= ESCAPE)
43           break;
44       }
45 
46       if (n == MAX_ITER)
47         putchar(' ');
48       else if (n > 6)
49         putchar('.');
50       else if (n > 3)
51         putchar('+');
52       else if (n > 2)
53         putchar('x');
54       else
55         putchar('*');
56     }
57     putchar('\n');
58   }
59 }
60 
main(void)61 int main(void) {
62   mandel();
63   return 0;
64 }
65 
66 #endif /* sparc */
67