The Computer Language
Benchmarks Game

mandelbrot Pascal Free Pascal #3 program

source code

{ The Computer Language Benchmarks Game
  http://benchmarksgame.alioth.debian.org

  contributed by Ales Katona
  modified by Vincent Snijders
}

program mandelbrot;

var n: longint;
    TextBuf: array[0..$FFF] of byte;
    OutFile: PText;
    

procedure run;
var
  Cy, Step: double;
  x, y, bits,bit: Longint;
  function CalculatePoint(Cx, Cy: double): boolean; nostackframe; inline;
  const
    Limit = 4;
  var
    i: longint;
    Zr, Zi, Ti, Tr: Double;

  begin
    Zr := 0;  Zi := 0; Tr := 0; Ti := 0;
    for i := 1 to 50 do begin
      Zi := 2*Zr*Zi + Cy;
      Zr := Tr - Ti + Cx;
      Ti := Zi * Zi;
      Tr := Zr * Zr;
      if (Tr + Ti>=limit) then exit(true);
    end;

    CalculatePoint := false;
  end;

begin
  Step := 2/n;
  for y := 0 to n-1 do
  begin
    Cy := y * Step - 1;
    bits := 255;  bit := 128;
    for x := 0 to n-1 do
    begin
      if CalculatePoint(x * Step  - 1.5, Cy) then
        bits := bits xor bit;

      if bit > 1 then
        bit := bit shr 1
      else
      begin
        write(OutFile^, chr(bits));
        bits := 255;  bit := 128;
      end;
    end;
    if bit < 128 then write(OutFile^, chr(bits xor((bit shl 1)-1)));
  end;
end;

begin
  OutFile := @Output;
  SetTextBuf(OutFile^, TextBuf);

  Val(ParamStr(1), n);
  writeln(OutFile^, 'P4');
  writeln(OutFile^, n,' ',n);
  run;
end.
    

notes, command-line, and program output

NOTES:
32-bit Ubuntu one core
Free Pascal Compiler version 3.0.0 [2015/11/24] for i386


Mon, 30 Nov 2015 00:27:18 GMT

MAKE:
mv mandelbrot.fpascal-3.fpascal mandelbrot.fpascal-3.pas
/usr/local/src/fpc-3.0.0.i386-linux/bin/fpc -FuInclude/fpascal -XXs -Oppentiumm -Cppentiumm -O3 -Cfsse2  -oFPASCAL_RUN mandelbrot.fpascal-3.pas
Free Pascal Compiler version 3.0.0 [2015/11/24] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling mandelbrot.fpascal-3.pas
mandelbrot.fpascal-3.pas(20,3) Error: Procedure/Function declared with call option NOSTACKFRAME but without ASSEMBLER
mandelbrot.fpascal-3.pas(71) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/src/fpc-3.0.0.i386-linux/bin/ppc386 returned an error exitcode
/home/dunham/benchmarksgame/nanobench/makefiles/u32.programs.Makefile:449: recipe for target 'mandelbrot.fpascal-3.fpascal_run' failed
make: [mandelbrot.fpascal-3.fpascal_run] Error 1 (ignored)
mv FPASCAL_RUN mandelbrot.fpascal-3.fpascal_run
mv: cannot stat ‘FPASCAL_RUN’: No such file or directory
/home/dunham/benchmarksgame/nanobench/makefiles/u32.programs.Makefile:449: recipe for target 'mandelbrot.fpascal-3.fpascal_run' failed
make: [mandelbrot.fpascal-3.fpascal_run] Error 1 (ignored)
rm mandelbrot.fpascal-3.pas
0.04s to complete and log all make actions

COMMAND LINE:
./mandelbrot.fpascal-3.fpascal_run 1000

MAKE ERROR