Chris Lattner | 02b3c26 | 2007-08-27 05:23:45 +0000 | [diff] [blame^] | 1 | // RUN: clang -emit-llvm %s |
| 2 | |
| 3 | /* Sparc is not C99-compliant */ |
| 4 | #if defined(sparc) || defined(__sparc__) || defined(__sparcv9) |
| 5 | |
| 6 | int main() { 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 | #if defined(__FreeBSD__) || defined(__OpenBSD__) |
| 29 | #include <complex.h> |
| 30 | #elif defined(__APPLE__) |
| 31 | #include <math.h> |
| 32 | #else |
| 33 | #include <tgmath.h> |
| 34 | #endif |
| 35 | |
| 36 | #include <stdio.h> |
| 37 | |
| 38 | volatile double __complex__ accum; |
| 39 | |
| 40 | void mandel() { |
| 41 | int x, y, n; |
| 42 | for (y = 0; y < IMAGE_HEIGHT; ++y) { |
| 43 | for (x = 0; x < IMAGE_WIDTH; ++x) { |
| 44 | double __complex__ c = (START_X+x*step_X) + (START_Y+y*step_Y) * I; |
| 45 | double __complex__ z = 0.0; |
| 46 | |
| 47 | for (n = 0; n < MAX_ITER; ++n) { |
| 48 | z = z * z + c; |
| 49 | if (hypot(__real__ z, __imag__ z) >= ESCAPE) |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | if (n == MAX_ITER) |
| 54 | putchar(' '); |
| 55 | else if (n > 6) |
| 56 | putchar('.'); |
| 57 | else if (n > 3) |
| 58 | putchar('+'); |
| 59 | else if (n > 2) |
| 60 | putchar('x'); |
| 61 | else |
| 62 | putchar('*'); |
| 63 | } |
| 64 | putchar('\n'); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | int main() { |
| 69 | mandel(); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | #endif /* sparc */ |