Recent

Author Topic: Why CMem?  (Read 2548 times)

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Why CMem?
« on: August 15, 2019, 01:45:27 pm »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8939
Re: Why CMem?
« Reply #1 on: August 15, 2019, 01:49:50 pm »
Don't duplicate questions. Answered in the other thread.
Most people that want to use threading should learn to patch their jeans first: use a needle.

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #2 on: August 15, 2019, 01:53:01 pm »
Don't duplicate questions. Answered in the other thread.
Your answer is not clear for me.
Moderator - If my question is duplicated, please remove my post.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8939
Re: Why CMem?
« Reply #3 on: August 15, 2019, 02:12:00 pm »
Most people that want to use threading should learn to patch their jeans first: use a needle.

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #4 on: August 15, 2019, 02:15:32 pm »
Yes @Thaddy. Same, but in other topic (post). I want clear answer.
And I think nobody can give me clear answer. Even FPC developers.
« Last Edit: August 15, 2019, 02:24:21 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

lucamar

  • Hero Member
  • *****
  • Posts: 2021
Re: Why CMem?
« Reply #5 on: August 15, 2019, 02:36:02 pm »
My guess? To make it a fairer comparison. Read the intro at "Free Pascal versus C++ g++ fastest programs"
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #6 on: August 15, 2019, 02:44:00 pm »
My guess? To make it a fairer comparison. Read the intro at "Free Pascal versus C++ g++ fastest programs"
Quote
"measuring the quality of the generated code when both compilers are presented with what amounts to the same program."
Quote
These are only the fastest programs.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #7 on: August 15, 2019, 03:29:08 pm »
FastMM, ScaleMM, BrainMM, FPC memory manager. So - CMem?
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

avra

  • Hero Member
  • *****
  • Posts: 1689
    • Additional info
Re: Why CMem?
« Reply #8 on: August 15, 2019, 03:35:06 pm »
I want clear answer.
That is a benchmark game, and since FPC has a choice with memory managers author probably tried them all and left the faster one.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #9 on: August 15, 2019, 03:38:05 pm »
I want clear answer.
That is a benchmark game, and since FPC has a choice with memory managers author probably tried them all and left the faster one.
Why CMem is the faster one?
Yes, this is a game.
« Last Edit: August 15, 2019, 03:43:02 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

BrunoK

  • Full Member
  • ***
  • Posts: 181
  • Retired programmer
Re: Why CMem?
« Reply #10 on: August 15, 2019, 04:35:00 pm »
Because cmem seems faster in multithreaded applications (by much) whereas there is no noticable difference with heap.inc in single threaded apps. 
At least on windows.
Lazarus trunk r. 59978/03.01.2019 (+/- patches regarding enabled, TScrollBar, TCursorImage). FPC 3.0.4 32 bits. (+heaptrc with leaked ClassName+Revisited TList) , Windows 10 Pro x64 (v. 1903)

julkas

  • Sr. Member
  • ****
  • Posts: 383
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Why CMem?
« Reply #11 on: August 15, 2019, 05:39:13 pm »
Because cmem seems faster in multithreaded applications (by much) whereas there is no noticable difference with heap.inc in single threaded apps. 
At least on windows.
https://github.com/graemeg/freepascal/blob/master/rtl/inc/cmem.pp
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8939
Re: Why CMem?
« Reply #12 on: August 15, 2019, 07:45:36 pm »
Why do you refer to a fork instead of the real code available from freepascal.org? It is the exact same and usually more current.
Most people that want to use threading should learn to patch their jeans first: use a needle.

Akira1364

  • Hero Member
  • *****
  • Posts: 530
Re: Why CMem?
« Reply #13 on: August 17, 2019, 05:46:37 am »
Why do you refer to a fork instead of the real code available from freepascal.org? It is the exact same and usually more current.

It's a direct mirror of the trunk FPC SVN, not a fork.

Why https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/binarytrees-fpascal-7.html uses CMem memory manager?

As the person who submitted that version of the benchmark: because CMem significantly improves the performance of multi-threaded applications in general (on Windows too, by the way). The execution time for that program without CMem is WAY longer than 3.06 seconds, to say the very least.
« Last Edit: August 17, 2019, 05:48:10 am by Akira1364 »

Thaddy

  • Hero Member
  • *****
  • Posts: 8939
Re: Why CMem?
« Reply #14 on: August 17, 2019, 07:28:00 am »
When we measured the different memory managers during the Delphi memory manager challenge we had a different conclusion, at least compared to the newer per thread allocators like scalemm, smartmm and topmm and family. It may be that a FPC conversion is possible for those. The most important think conclusion was that the Delphi MM (FastMM) and cmem do not scale.
In some applications cmem indeed outperforms the fpc default a memory manager, but it depends on application as I explained.
The benchmark sourcecode (for 32 bit) can be optained from http://fastcode.sourceforge.net/. My old collegue Andre Musche has likely a 64 bit version of SmartMMv2 as well. I will ask him.
(Lock-free context switching) My other former collegue Ivo Tops wrote topmm.
I can prepare those (smartmmv2 and topmm) for fpc - windows32/64 (did that before, but code is not current: fpc 2.0.)
[to be completed with example]
« Last Edit: August 17, 2019, 10:08:02 am by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.