Recent

Author Topic: fpc lines of code  (Read 14880 times)

airpas

  • Full Member
  • ***
  • Posts: 179
fpc lines of code
« on: March 04, 2015, 11:11:37 pm »
the openhub.net said that fpc source has 300k lines of code , is that true?
https://www.openhub.net/p/freepascal

btw , i did't expect that gcc has 14.5 million lines of code , that's incredibly giant
http://www.phoronix.com/scan.php?page=news_item&px=MTg3OTQ

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: fpc lines of code
« Reply #1 on: March 04, 2015, 11:29:31 pm »
I don't know, but I still prefer pascal over C even if it lacks 14.2 million lines of code

Laksen

  • Hero Member
  • *****
  • Posts: 745
    • J-Software
Re: fpc lines of code
« Reply #2 on: March 04, 2015, 11:44:15 pm »
The total count of lines in the FPC codebase is about 3 million. But that includes a lot of runtime, packages, headers, testsuites, etc..

It's a silly thing to compare :P

Edit: I messed up my line counter, but I still only count about 3 million lines in total in whatever version of GCC I have locally.
« Last Edit: March 04, 2015, 11:52:33 pm by Laksen »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fpc lines of code
« Reply #3 on: March 05, 2015, 07:57:10 am »
Why don't you do it yourself? Just need wc -l + a bit bash scripting for loop over the files, perhaps bc for summing up. Note that the Makefiles are generated from Makefile.fpc but both are still counted.

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: fpc lines of code
« Reply #4 on: March 05, 2015, 12:04:36 pm »
This picture illustrates that GCC has no more than 5 500 000 lines of code
https://vmakarov.fedorapeople.org/spec/comparison.html
But perhaps the standard library is not included?

For FreePascal 3 CLOC code line counter program shows me 2 153 983 lines of code (with standard library);
In fpc/compiler subdirectory: 284 873 lines of code

PS: less is more if you know what I mean
Too late to escape fate

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: fpc lines of code
« Reply #5 on: March 05, 2015, 08:28:43 pm »
I reckon the number of bugs is also proportional to the number of code lines...

airpas

  • Full Member
  • ***
  • Posts: 179
Re: fpc lines of code
« Reply #6 on: March 05, 2015, 09:49:55 pm »
thats true , but it also indicate that a lot of improvement has been added .
the mandelbrot example built with gcc 4.9 without optimization -O0 is faster than fpc with -O4 switch !

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: fpc lines of code
« Reply #7 on: March 06, 2015, 09:29:17 pm »
For the massive floating point calculations in the mandelbrot, the benefit of optimisations is small in the first place.
But with FPUTYPE SSE2 and a few other mods I can reduce the execution time from 2200ms to 1600ms on my machine (FPC 2.6.4)

Code: [Select]
program mandelbrot;
 uses windows;
const
   ixmax = 2500;
   iymax = 2000;
   cxmin = -2.5;
   cxmax =  1.5;
   cymin = -2.0;
   cymax =  2.0;
   maxcolorcomponentvalue = 255;
   maxiteration = 200;
   escaperadius = 2;
 
type
   colortype = record
      red   : byte;
      green : byte;
      blue  : byte;
   end;
 
var
   ix, iy      : integer;
   cx, cy      : real;
   pixelwidth  : real = (cxmax - cxmin) / ixmax;
   pixelheight : real = (cymax - cymin) / iymax;
   filename    : string = 'new1.ppm';
   comment     : string = '# ';
   outfile     : textfile;
   color       : colortype;
   zx, zy      : real;
   zx2, zy2    : real;
   iteration   : integer;
   er2         : real = (escaperadius * escaperadius);
   tm : longword;
begin
   tm := GetTickCount();
   {$I-}
   assign(outfile, filename);
   rewrite(outfile);
   if ioresult <> 0 then
   begin
      writeln(stderr, 'unable to open output file: ', filename);
      exit;
   end;
 
   writeln(outfile, 'P6');
   writeln(outfile, ' ', comment);
   writeln(outfile, ' ', ixmax);
   writeln(outfile, ' ', iymax);
   writeln(outfile, ' ', maxcolorcomponentvalue);
 
   for iy := 1 to iymax do
   begin
      cy := cymin + (iy - 1)*pixelheight;
      if abs(cy) < pixelheight / 2 then cy := 0.0;
      for ix := 1 to ixmax do
      begin
         cx := cxmin + (ix - 1)*pixelwidth;
         zx := 0.0;
         zy := 0.0;
         zx2 := zx*zx;
         zy2 := zy*zy;
         iteration := 0;
         while (iteration < maxiteration) and (zx2 + zy2 < er2) do
         begin
            zy := 2*zx*zy + cy;
            zx := zx2 - zy2 + cx;
            zx2 := zx*zx;
            zy2 := zy*zy;
            iteration := iteration + 1;
         end;
         if iteration = maxiteration then
         begin
            color.red   := 0;
            color.green := 0;
            color.blue  := 0;
         end
         else
         begin
            color.red   := 255;
            color.green := 255;
            color.blue  := 255;
         end;
         write(outfile, chr(color.red), chr(color.green), chr(color.blue));
      end;
   end;
 
   close(outfile);
   writeln(GetTickCount() - tm,'ms');
   readln;
end.




engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: fpc lines of code
« Reply #8 on: March 06, 2015, 10:47:30 pm »
thats true , but it also indicate that a lot of improvement has been added .
the mandelbrot example built with gcc 4.9 without optimization -O0 is faster than fpc with -O4 switch !
@Airpas
It would be nice if you share both Pascal, and C[++] code you used, and speed results.

@Nitorami
I did a few modifications. Would you mind trying this:
Code: [Select]
program project1;
uses windows;
{$FPUTYPE X87}//<---- 1 - using x87
{ $FPUTYPE SSE2}
const
   ixmax = 2500;
   iymax = 2000;
   cxmin = -2.5;
   cxmax =  1.5;
   cymin = -2.0;
   cymax =  2.0;
   maxcolorcomponentvalue = 255;
   maxiteration = 200;
   escaperadius = 2;

type
   colortype = record
      red   : byte;
      green : byte;
      blue  : byte;
   end;

  real = double;//<----- 2 - using double instead of real
var
   ix, iy      : integer;
   cx, cy      : real;
   pixelwidth  : real = (cxmax - cxmin) / ixmax;
   pixelheight : real = (cymax - cymin) / iymax;
   filename    : string = 'new1.ppm';
   comment     : string = '# ';
   outfile     : textfile;
   color       : colortype;
   dwcolor     : DWORD absolute color;//<---- 3 - never mind (not used)
   zx, zy      : real;
   zx2, zy2    : real;
   iteration   : integer;
   er2         : real = (escaperadius * escaperadius);
   tm : longword;
begin
   tm := GetTickCount();
   {$I-}
   assign(outfile, filename);
   rewrite(outfile);
   if ioresult <> 0 then
   begin
      writeln(stderr, 'unable to open output file: ', filename);
      exit;
   end;

   writeln(outfile, 'P6');
   writeln(outfile, ' ', comment);
   writeln(outfile, ' ', ixmax);
   writeln(outfile, ' ', iymax);
   writeln(outfile, ' ', maxcolorcomponentvalue);

   cx := cxmin - pixelwidth;//<---- 4 - to replace mutiplicaion in inner loop (see 5)
   for iy := 1 to iymax do
   begin
      cy := cymin + (iy - 1)*pixelheight;
      if abs(cy) < pixelheight / 2 then cy := 0.0;
      for ix := 1 to ixmax do
      begin
         //cx := cxmin + (ix - 1)*pixelwidth;//<---- 5(a) - check next line
         cx := cx + pixelwidth;//<---- 5(b) - Addition instead of mutiplication
         zx := 0.0;
         zy := 0.0;
         zx2 := zx*zx;
         zy2 := zy*zy;
         iteration := 0;
         while (iteration < maxiteration) and (zx2 + zy2 < er2) do
         begin
            zy := 2*zx*zy + cy;
            zx := zx2 - zy2 + cx;
            zx2 := zx*zx;
            zy2 := zy*zy;
            iteration := iteration + 1;
         end;
         if iteration = maxiteration then
         begin
            //dwcolor := dwcolor and $FF000000;
            color.red   := 0;
            color.green := 0;
            color.blue  := 0;//}
         end
         else
         begin
            //dwcolor := dwcolor or $00FFFFFF;
            color.red   := 255;
            color.green := 255;
            color.blue  := 255;//}
         end;
         //write(outfile, chr(color.red), chr(color.green), chr(color.blue)); //<---- 6 - no strings
      end;
   end;

   close(outfile);
   writeln(GetTickCount() - tm,'ms');
   readln;
end.
« Last Edit: March 06, 2015, 10:59:35 pm by engkin »

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: fpc lines of code
« Reply #9 on: March 06, 2015, 11:37:15 pm »
Just by curiosity, I did few runs at engkin's modified project.

Quote
157ms with {$FPUTYPE X87}
234ms with {$FPUTYPE SSE2}

Mind you, test program was run under virtualized environment.

FPC is trunk version (revision 30110) and was built with these options:
Quote
OPT=-gw2 -godwarfsets -gl -O- -OoNO -Xs- -Si- -vb -XX -CX -dTEST_WIN32_SEH
COMPILER_OPTIONS=-gw2 -godwarfsets -gl -O- -OoNO -Xs- -Si- -vb -XX -CX -dTEST_WIN32_SEH


Project was built with these options: 
Quote
-MObjFPC -Scghi -gw2 -godwarfsets -gl -l -vewnhibq -Filib\i386-win32 -Fu. -FUlib\i386-win32 -FEbin\i386-win32-win32\

CPU : 
Quote
AMD64 Family 16 Model 6 Stepping 2 AuthenticAMD ~2877 Mhz

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: fpc lines of code
« Reply #10 on: March 07, 2015, 01:36:01 am »
Code: [Select]
program project1;

{$mode objfpc}{$H+}

{.$FPUTYPE X87} //<---- 1 - using x87
{$FPUTYPE SSE2}

uses
  Classes, SysUtils, StreamIO, windows;


const
   ixmax = 2500;
   iymax = 2000;
   cxmin = -2.5;
   cxmax =  1.5;
   cymin = -2.0;
   cymax =  2.0;
   maxcolorcomponentvalue = 255;
   maxiteration = 200;
   escaperadius = 2;

type
   colortype = record
      red   : byte;
      green : byte;
      blue  : byte;
   end;

   real = double;

var
   ix, iy      : integer;
   cx, cy      : real;
   pixelwidth  : real = (cxmax - cxmin) / ixmax;
   pixelheight : real = (cymax - cymin) / iymax;
   filename    : string = 'new1.ppm';
   comment     : string = '# ';
   outfile     : textfile;
   color       : colortype;
   zx, zy      : real;
   zx2, zy2    : real;
   iteration   : integer;
   er2         : real = (escaperadius * escaperadius);
   tm : longword;
   AFileStream : TFileStream;
   AMemoryStream : TMemoryStream;
   APChar : PByte;
begin
   AFileStream := TFileStream.Create(filename, fmCreate);
   AMemoryStream := TMemoryStream.Create;
   AMemoryStream.Size := ixmax * iymax * 3;
   AMemoryStream.Position := 0;
   APChar := AMemoryStream.Memory;

(*   {$I-}
   assign(outfile, filename);
   rewrite(outfile);
   if ioresult <> 0 then
   begin
      writeln(stderr, 'unable to open output file: ', filename);
      exit;
   end;*)

   AssignStream(outfile, AFileStream);
   rewrite(outfile);

   writeln(outfile, 'P6');
   writeln(outfile, ' ', comment);
   writeln(outfile, ' ', ixmax);
   writeln(outfile, ' ', iymax);
   writeln(outfile, ' ', maxcolorcomponentvalue);

   tm := GetTickCount();

   for iy := 1 to iymax do
   begin
      cy := cymin + (iy - 1)*pixelheight;
      cx := cxmin - pixelwidth;
      if abs(cy) < pixelheight / 2 then cy := 0.0;
      for ix := 1 to ixmax do
      begin
         cx := cx + pixelwidth;
         zx := 0.0;
         zy := 0.0;
         zx2 := zx*zx;
         zy2 := zy*zy;
         iteration := 0;
         while (iteration < maxiteration) and (zx2 + zy2 < er2) do
         begin
            zy := 2*zx*zy + cy;
            zx := zx2 - zy2 + cx;
            zx2 := zx*zx;
            zy2 := zy*zy;
            iteration := iteration + 1;
         end;
         if iteration = maxiteration then
         begin
            color.red   := 0;
            color.green := 0;
            color.blue  := 0;
         end
         else
         begin
            color.red   := 255;
            color.green := 255;
            color.blue  := 255;
         end;
         //write(outfile, chr(color.red), chr(color.green), chr(color.blue));
       {  AMemoryStream.Write(color.red, SizeOf(color.red));
         AMemoryStream.Write(color.green, SizeOf(color.green));
         AMemoryStream.Write(color.blue, SizeOf(color.blue)); }
         APChar^ := color.red;
         Inc(APChar);
         APChar^ := color.green;
         Inc(APChar);
         APChar^ := color.blue;
         Inc(APChar);
      end;
   end;

   writeln(GetTickCount() - tm,'ms');

   close(outfile);

   AFileStream.Seek(0, soEnd);
   AFileStream.CopyFrom(AMemoryStream, 0);

   FreeAndNil(AFileStream);
   FreeAndNil(AMemoryStream);

   readln;
end.


With this code and compiler option -O4, I can get between 998ms and 1029ms execution times in real hardware.

EDIT : Same code with FPC 2.6.5 (fixes) with -O3 option, gives between 2511ms and 1592ms.
« Last Edit: March 07, 2015, 02:00:09 am by Cyrax »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fpc lines of code
« Reply #11 on: March 07, 2015, 05:53:29 am »
With this code and compiler option -O4, I can get between 998ms and 1029ms execution times in real hardware.

EDIT : Same code with FPC 2.6.5 (fixes) with -O3 option, gives between 2511ms and 1592ms.
x64 real hardware:
- 2.6.4: -CX -XXs -O3 -OoREGVAR  -CpATHLON64 -CfSSE64
- 3.1.1: -CX -XXs -O4 -OoREGVAR  -CpCOREAVX2 -CfAVX2
Code: [Select]
2.6.4 - 3.1.1
1530.000125058000000 ms - 576.9997369498014500 ms
1531.000295653940000 ms - 572.0001412555575400 ms
1526.000071316960000 ms - 575.0000244006514500 ms
1526.000071316960000 ms - 573.9998538047075300 ms
1524.999900721010000 ms - 575.0000244006514500 ms
1502.000377513470000 ms - 658.9998956769704800 ms
1414.000452496110000 ms - 587.9997275769710500 ms
1439.000316895540000 ms - 620.0001575052738200 ms
1526.000071316960000 ms - 671.0000569000840200 ms
1501.000206917520000 ms - 573.9998538047075300 ms
;)

airpas

  • Full Member
  • ***
  • Posts: 179
Re: fpc lines of code
« Reply #12 on: March 07, 2015, 07:36:18 am »
nice results , well i retest on pentium-4  2.8mhz and now fpc 3.1.1 is faster than gcc .
so as said befor its nearly impossible to get the fastest code over all CPU's
in short it depend on lots of things .
btw , the -Cfsse(x) is more effective now with fpc 3.1.1 , thats really promising :D , respect

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: fpc lines of code
« Reply #13 on: March 07, 2015, 11:05:19 am »
Wait a moment. Don't be carried away by the momentum. You should be suspicious when there is a factor 4 improvement.

@Engkin: Your code runs in some 500ms here but it only generates a white picture, even when reinserting the write command. You should always check whether the code still generates the desired output.

@Cyrax: What dou you mean by "real hardware" ? Execution time here is 3300ms with X87 and 1600 with SSE2.


Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: fpc lines of code
« Reply #14 on: March 07, 2015, 12:36:15 pm »
...
@Cyrax: What dou you mean by "real hardware" ? Execution time here is 3300ms with X87 and 1600 with SSE2.

Not virtualized aka in the real thing. See attached image(s) for info what kind of CPU I'm on running.

Did you try out my modified version of your program?
« Last Edit: March 07, 2015, 12:46:59 pm by Cyrax »

 

TinyPortal © 2005-2018