[fpc-devel] Aligned dynamic arrays
Sven Barth
pascaldragon at googlemail.com
Thu Mar 28 23:08:25 CET 2019
Am 28.03.2019 um 15:17 schrieb Ryan Joseph:
>
>> Also I don't think that a simple "do alignment or not" will be sufficient. What kind of alignment do you pick? What if the user needs more alignment? So it would probably be best to add a new SetLengthAligned of which the second argument is the alignment followed by the lengths.
> That’s correct, there’s an alignment parameter also, not just a boolean. The header may need to include the desired alignment also for copy operations but I’m not sure yet.
>
> Since the offset is going to be part of the header now (and possibly the desired alignment) does it matter that this will affect all dynamic arrays? It’s probably only 4 bytes but still worth considering.
I'm not a fan of introducing a separate header for this. And abusing
some bits of the existing fields as flags just means that other parts of
dynarr.inc have to be touched even though we avoided that by ordering it
as [padding][header][data].
>> In dynarr.inc you then add a new setlength variant that takes an additional alignment parameter while the old one without alignment calls the new one with alignment 1.
>>
>> Note: the compiler can call the new one for both variants, but the old one is required for bootstrapping, so you could surround that with {$if not defined(ver3_0) and not defined(ver3_2)}.
> You mean if the compiler is < 3.0 then don’t parse the new SetLength variant?
No, I mean it like this:
=== code begin ===
procedure int_dynarray_setlength_aligned(var p : pointer;pti : pointer;
dimcount : sizeint;dims : pdynarrayindex;alignment :
longint);[external name 'FPC_DYNARR_SETLENGTH_ALIGNED'];
{$if defined(ver3_0) or defined(ver3_2)}
procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
dimcount : sizeint;dims :
pdynarrayindex);[Public,Alias:'FPC_DYNARR_SETLENGTH']; compilerproc;
begin
int_dynarray_setlength_aligned(p,pti,dimcount,dims,1);
end;
{$endif}
=== code end ===
If the compiler always calls the aligned variant (on call less) then the
one without alignment is only required for bootstrapping with 3.0.4 or 3.2.
Regards,
Sven
More information about the fpc-devel
mailing list