Recent

Author Topic: FPC Feature Request - Enhanced Memory Manager  (Read 5801 times)

MathMan

  • Sr. Member
  • ****
  • Posts: 325
FPC Feature Request - Enhanced Memory Manager
« on: July 20, 2015, 10:26:55 am »
Hi all,

I am currently running FPC 2.6.4 but have so far not looked into the looming FPC 3.x.x - so my request may already be addressed.

I understand that there is a way to integrate self developed memory Managers but there is one simple thing that might enhance usability if integrated into the core RTL.

What I would like to be able is to control the alignment of memory allocated on the heap via a control - e.g. {$HEAP_ALIGN xx} where xx is a power of 2. I see this in terms of software optimization as this way I could align heap memory to processor cache line sizes (and other stuff).

What are your thoughts - is this reasonable? And if so how to proceed?

Kind regards,
MathMan

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #1 on: July 20, 2015, 01:04:55 pm »
Adding compiler directives require you to modify the compiler. You can of course use the macro system to supply that value instead.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #2 on: July 20, 2015, 01:15:15 pm »
The memory manager is a library (rtl/inc/heap*),  and to modify it that way you wouldn't need to modify the compiler.

Extract those files to an unit, modify it to force 16-byte alignment, load it as first unit in your program, and it should work.

The heapmgr is not simple though.

Laksen

  • Hero Member
  • *****
  • Posts: 754
    • J-Software
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #3 on: July 20, 2015, 04:38:18 pm »
The current memory manager aligns blocks at 16 bytes and 32 bytes for 64 bit targets already.

Not sure which instructions would gain from anything above that?

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #4 on: July 21, 2015, 09:23:44 am »
The memory manager is a library (rtl/inc/heap*),  and to modify it that way you wouldn't need to modify the compiler.

Extract those files to an unit, modify it to force 16-byte alignment, load it as first unit in your program, and it should work.

The heapmgr is not simple though.

As said above I am willing to take that route but first wanted to explore common view on making the alignment value accessible in general.

Before I start working on this - is there somebody around who did this already and could hint me to the places in the sources that I would need to change? I fully agree that the heapmgr is not simple, and before I spend hours in futile work I'll gladly take any hints from experts.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #5 on: July 21, 2015, 09:28:55 am »
The current memory manager aligns blocks at 16 bytes and 32 bytes for 64 bit targets already.

Not sure which instructions would gain from anything above that?

AVX512 in Skylake this year?  :D :D
« Last Edit: July 21, 2015, 10:05:56 am by marcov »

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #6 on: July 21, 2015, 09:31:59 am »
The current memory manager aligns blocks at 16 bytes and 32 bytes for 64 bit targets already.

Not sure which instructions would gain from anything above that?

It's not about making a single instruction fast but mainly speeding up routines in general by working on data chunks which are in line with the cache structure. E.g. on the low level one can move data from memory into the processor in a very fast way by utilizing certain SSE instructions which require that 64 bytes are read in sequence - MOVDQA instruction. On higher levels one can arrange loops working with data in a more efficient way if the data is aligned to cache line sizes. Finally it should be possible to minimize cache trashing effects.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: FPC Feature Request - Enhanced Memory Manager
« Reply #7 on: July 21, 2015, 09:34:22 am »
Before I start working on this - is there somebody around who did this already and could hint me to the places in the sources that I would need to change? I fully agree that the heapmgr is not simple, and before I spend hours in futile work I'll gladly take any hints from experts.

Try to ask in mailing list ( fpc-devel ).

http://www.freepascal.org/maillist.var
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

 

TinyPortal © 2005-2018