[fpc-pascal] Cache-line alignment for records
Matias Ezequiel Vara Larsen
matiasevara at gmail.com
Wed Mar 29 13:22:29 CEST 2023
On Mon, Mar 27, 2023 at 08:52:40PM +0200, Jonas Maebe via fpc-pascal wrote:
> On 27/03/2023 09:28, Matias Ezequiel Vara Larsen via fpc-pascal wrote:
> > Apologies in the case this subject has been already discussed. I require
> > that some global variables be cache-line aligned. This is a requirement
> > for per-CPU variables that are statically defined to prevent cache
> > ping-pong. Is there any way to do this at fpc when the record is
> > declared?
>
> {$push}
> {$codealign varmin=16}
> {$codealign constmin=16}
> const
> constdata: array[0..3] of longint = (1,2,3,4);
>
> var
> x: array[0..15] of longint;
> {$pop}
>
> However, the maximum alignment you can specify this way is limited per
> target (hardcoded in the compiler). In 3.2.x, it's 16 bytes for most desktop
> targets. On 3.3.x, it's 64 bytes for most desktop targets.
>
I've tried this (fpc 3.2.0) and it correctly aligns to 64 bytes (x86 cacheline):
{$push}
{$codealign varmin=64}
var
x: array[0..15] of longint;
{$pop}
The generated assembler is:
.section .bss
.balign 64
.type U_$P$PROGRAM_$$_X, at object
.size U_$P$PROGRAM_$$_X,64
U_$P$PROGRAM_$$_X:
.zero 64
Is it possible to define "varmin" as a constant or symbol instead of using
the actual value each time?
Matias
More information about the fpc-pascal
mailing list