modernc.org/ccgo/v3@v3.16.14/lib/testdata/CompCert-3.6/test/c/mandelbrot.c (about)

     1  /* The Computer Language Shootout
     2     http://shootout.alioth.debian.org/
     3  
     4     contributed by Greg Buchholz
     5  
     6     for the debian (AMD) machine...
     7     compile flags:  -O3 -ffast-math -march=athlon-xp -funroll-loops
     8  
     9     for the gp4 (Intel) machine...
    10     compile flags:  -O3 -ffast-math -march=pentium4 -funroll-loops
    11  */
    12  
    13  #include <stdio.h>
    14  #include <stdlib.h>
    15  
    16  int main (int argc, char **argv)
    17  {
    18      int w, h, bit_num = 0;
    19      char byte_acc = 0;
    20      int i, iter = 50;
    21      double x, y, limit = 2.0;
    22      double Zr, Zi, Cr, Ci, Tr, Ti;
    23  
    24      if (argc < 2) {
    25        w = h = 1000;
    26      } else {
    27        w = h = atoi(argv[1]);
    28      }
    29  
    30      printf("P4\n%d %d\n",w,h);
    31  
    32      for(y=0;y<h;++y)
    33      {
    34          for(x=0;x<w;++x)
    35          {
    36              Zr = Zi = Tr = Ti = 0.0;
    37              Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
    38  
    39              for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
    40              {
    41                  Zi = 2.0*Zr*Zi + Ci;
    42                  Zr = Tr - Ti + Cr;
    43                  Tr = Zr * Zr;
    44                  Ti = Zi * Zi;
    45              }
    46  
    47              byte_acc <<= 1;
    48              if(Tr+Ti <= limit*limit) byte_acc |= 0x01;
    49  
    50              ++bit_num;
    51  
    52              if(bit_num == 8)
    53              {
    54                  putc(byte_acc,stdout);
    55                  byte_acc = 0;
    56                  bit_num = 0;
    57              }
    58              else if(x == w-1)
    59              {
    60                  byte_acc <<= (8-w%8);
    61                  putc(byte_acc,stdout);
    62                  byte_acc = 0;
    63                  bit_num = 0;
    64              }
    65          }
    66      }
    67      return 0;
    68  }
    69  
    70  /***********
    71   build & benchmark results
    72  
    73  BUILD COMMANDS FOR: mandelbrot.gcc-2.gcc
    74  
    75  Fri Sep 15 03:05:43 PDT 2006
    76  
    77  /usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -funroll-loops -march=pentium4 -D_ISOC9X_SOURCE -mfpmath=sse -msse2 -lm mandelbrot.gcc-2.c -o mandelbrot.gcc-2.gcc_run
    78  mandelbrot.gcc-2.c: In function 'main':
    79  mandelbrot.gcc-2.c:23: warning: implicit declaration of function 'atoi'
    80  mandelbrot.gcc-2.c:62: warning: control reaches end of non-void function
    81  
    82  =================================================================
    83  COMMAND LINE (%A is single numeric argument):
    84  
    85  mandelbrot.gcc-2.gcc_run %A
    86  N=3000
    87  
    88  PROGRAM OUTPUT
    89  ==============
    90  P4
    91  3000 3000
    92  ****************/