Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 30, 2019, at 5:02 PM, Jonas Maebe wrote: > > How is this done in the Metal C headers? Looking this now it appears the padding may be put in the actual vector. Maybe those macros put it in there? The fields of the struct need to be aligned on 16 bytes (4 floats) so. Does c++ even all

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Anthony Walter
Oh and might as well add dot product and cross product for vectors as well > ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Anthony Walter
On a related note, since a lot of the discussion here seems related to vector types, I seem to recall someone recently published an mmx, sse1/2/3/4, simd set of routines related to vector operations. I don't use much asm other than just being familiar with the basics of ia32 from long ago, but I do

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Jonas Maebe
On 30/03/2019 14:59, Ryan Joseph wrote: On Mar 30, 2019, at 9:10 AM, Jonas Maebe wrote: FPC always aligns data to its alignment as specified by the platform ABI. {$align x} can be used to limit this alignment to a lower number. It cannot be used to increase it. This caused us quite a bit

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread J. Gareth Moreton
I always get nervous of mode switches because it's hard to remember them or realise they exist, and it feels a little hacky, like it's a kind of compatibility setting more than anything else.  Like at one point, I preferred there was an explicit way to set a type's alignment so there's no ambiguit

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Mattias Gaertner via fpc-devel
On Sat, 30 Mar 2019 12:57:48 -0400 Ryan Joseph wrote: > > On Mar 30, 2019, at 12:53 PM, Mattias Gaertner via fpc-devel > > wrote: > > > > I guess you mean auto dereferencing. > > {$ModeSwitch AutoDeref} > > Yeah I just found this by looking around in the compiler. Mind. > Blown. No idea that

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 30, 2019, at 12:53 PM, Mattias Gaertner via fpc-devel > wrote: > > I guess you mean auto dereferencing. > {$ModeSwitch AutoDeref} Yeah I just found this by looking around in the compiler. Mind. Blown. No idea that existed! Regards, Ryan Joseph _

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Mattias Gaertner via fpc-devel
On Sat, 30 Mar 2019 10:03:12 -0400 Ryan Joseph wrote: > > On Mar 30, 2019, at 9:55 AM, Jonas Maebe > > wrote: > >> You are not required to dereference pointers to write to them. > >> var > >> P: PPoint; > >> begin > >> P := AlignedArray[0]; > >> P.X := 3; // can be okay > >> AlignedArra

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 30, 2019, at 9:55 AM, Jonas Maebe wrote: > >> You are not required to dereference pointers to write to them. >> var >> P: PPoint; >> begin >> P := AlignedArray[0]; >> P.X := 3; // can be okay >> AlignedArray[0].Y := 4; // can be okay as well > > That only works in {$mode delp

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread denisgolovan
> 1) In you example you are writing this with normal arrays: > > A[0].X := 0; > > And in my implementation it's exactly the same. Regarding writing the entire > type directly > > A[0]^ := V; > > If using the caret symbol ^ or an Item property is a deal breaker, then this > can be simplified

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 30, 2019, at 9:10 AM, Jonas Maebe wrote: > > FPC always aligns data to its alignment as specified by the platform ABI. > {$align x} can be used to limit this alignment to a lower number. It cannot > be used to increase it. This caused us quite a bit of problems with the Metal framew

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Jonas Maebe
On 30/03/2019 14:42, Anthony Walter wrote: You are not required to dereference pointers to write to them. var   P: PPoint; begin   P := AlignedArray[0];   P.X := 3; // can be okay   AlignedArray[0].Y := 4;  // can be okay as well That only works in {$mode delphi} Jonas __

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Anthony Walter
You are not required to dereference pointers to write to them. var P: PPoint; begin P := AlignedArray[0]; P.X := 3; // can be okay AlignedArray[0].Y := 4; // can be okay as well ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://li

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Anthony Walter
1) In you example you are writing this with normal arrays: A[0].X := 0; And in my implementation it's exactly the same. Regarding writing the entire type directly A[0]^ := V; If using the caret symbol ^ or an Item property is a deal breaker, then this can be simplified using a custom smart poin

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Jonas Maebe
On 30/03/2019 14:07, Ryan Joseph wrote: I never got $align to work for records. FPC always aligns data to its alignment as specified by the platform ABI. {$align x} can be used to limit this alignment to a lower number. It cannot be used to increase it. Why not use a similar directive for

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 30, 2019, at 12:56 AM, Anthony Walter wrote: > > So the default property indexer returns references and not values. If you > want values specifically you can use the Item property indexer. > > This way we can either access fields directly on the items withing the array > like so: >

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread denisgolovan
Exactly, alignment might be well attached to array or array element type. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Ryan Joseph
> On Mar 29, 2019, at 5:30 PM, denisgolovan wrote: > > Also I'd like to get an idea how this functionality is to play with existing > alignment directives for records. I never got $align to work for records. Isn’t that supposed to pad the fields to 16 bytes? Doesn’t work for me. {$push} {$a

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread denisgolovan
Hi Jonas Vector type in FPC is too good to be true. I didn't dare to dream about it so far :) BR, Denis ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread denisgolovan
Hi Anthony > The more that I think about it, the more I am believe that using my approach > is probably the best solution. Hear me out please. > > First, it would be fairly easy to implement copy on write logic with a custom > record class. > > Second, because it's Pascal code, it's entirely

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Jonas Maebe
On 29/03/2019 22:30, denisgolovan wrote: Could we discuss more options here? Since this is mostly about vectors, I think the best approach is to add an actual vector type to the compiler (Vector Pascal may serve as inspiration on how to integrate it in the language). Anything from dynamic ar

Re: [fpc-devel] Aligned dynamic arrays

2019-03-30 Thread Anthony Walter
Denis, The more that I think about it, the more I am believe that using my approach is probably the best solution. Hear me out please. First, it would be fairly easy to implement copy on write logic with a custom record class. Second, because it's Pascal code, it's entirely possible to fully cus

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Anthony Walter
Inside the type I have: TAlignedArray = record public type TReference = ^T; TValue = T; ... procedure Push(const Item: TValue); function Pop: TValue; property Length: Integer read FLength write SetLength; property Reference[Index: Integer]: TReference read G

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Ryan Joseph
> On Mar 29, 2019, at 9:15 PM, Anthony Walter wrote: > > Ryan, actually ... > > A.Length := 1; > A[0].X := 100; > > ... does work in my implementation. Really, how? [] property uses a getter which copies the array right? I’mm not aware of how to do this in Pascal without pointers. Regards,

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Anthony Walter
Ryan, actually ... A.Length := 1; A[0].X := 100; ... does work in my implementation. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Ryan Joseph
> On Mar 29, 2019, at 5:25 PM, Sven Barth via fpc-devel > wrote: > > Ignoring something is not an answer. At least there'd need to be a runtime > error. > > Thinking about it maybe it would be better to follow Anthony's idea with the > record and not try to adjust/extend a language mechanis

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Marco van de Voort
Op 3/28/2019 om 11:40 PM schreef Anthony Walter: Here is a brief follow up. I am working on other projects at the moment, but I am confident this a simple solution. Please tell me if this somehow will not fit you needs. My needs are simple: - auto clean like dynamic arrays. - preferably tran

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Sven Barth via fpc-devel
Am 29.03.2019 um 17:53 schrieb Ryan Joseph: First minor snag, fpc_dynarray_insert, fpc_dynarray_concat can allocate new arrays like SetLength can. Do we need to make aligned variants for these also? Using array + operators there is no possibility to set alignment. var a, b: array of integer

Re: [fpc-devel] Aligned dynamic arrays / Maybe implement in mem-mgr?

2019-03-29 Thread Ryan Joseph
> On Mar 29, 2019, at 1:21 PM, Martin Frb wrote: > > Question: Should the alignment be "user data" or "type info". > Does it need to be determined at runtime, and set to different values (for > the same type/variable) at runtime? I’m just doing what Sven said I could do, which is store the in

Re: [fpc-devel] Aligned dynamic arrays / Maybe implement in mem-mgr?

2019-03-29 Thread Martin Frb
On 29/03/2019 17:53, Ryan Joseph wrote: First minor snag, fpc_dynarray_insert, fpc_dynarray_concat can allocate new arrays like SetLength can. Do we need to make aligned variants for these also? Using array + operators there is no possibility to set alignment. 1) ignore the problem 2) make ext

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Ryan Joseph
First minor snag, fpc_dynarray_insert, fpc_dynarray_concat can allocate new arrays like SetLength can. Do we need to make aligned variants for these also? Using array + operators there is no possibility to set alignment. var a, b: array of integer; begin a += [1]; // no way to set alignment

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread Anthony Walter
Gareth, There is a bounty for this? I wonder if my solution is acceptable. Also, my solution, or any for that matter, could be enhanced to make the alignment size configurable per each array aligned array. That is, memory alignment starting position and page size could be defined by each array. T

Re: [fpc-devel] Aligned dynamic arrays

2019-03-29 Thread J. Gareth Moreton
I wonder if there's any incentive to have such a feature in-built in the compiler.  The bounty on #34031 has probably expired by now.  If not, then your unit would be a great addition. Page-aligned memory is probably something that warrants further discussion with the core team. Gareth aka. Kit

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Anthony Walter
Here is the full implementation of aligned arrays, let me know if it works for you. https://www.getlazarus.org/arrays/ Here is another example: uses AlignArrays; procedure Test; var VertexData: TAlignedArray; V: PVec3; I: Integer; begin VertexData.Length := 100; // page sized and alig

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread J. Gareth Moreton
Just to add a minor thing... while usually you don't have to align memory any more coarsely than 16 bytes for XMM, 32 bytes for YMM and 64 bytes for ZMM, the 4 kB granularity is useful for paging, especially if you're reading or writing to a swap file.  An entire library of functions for such memo

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Anthony Walter
Here is a brief follow up. I am working on other projects at the moment, but I am confident this a simple solution. Please tell me if this somehow will not fit you needs. Create a new type that is compatible with Array where Array = type array of T. Define implcit conversions between the to types

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Sven Barth via fpc-devel
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 ali

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Sven Barth via fpc-devel
Am 28.03.2019 um 18:41 schrieb Ryan Joseph: Now I’m using “cd /rtl; make all FPC=/path/to/compiler” to build the RTL but this is obviously slow and unnecessary. Is there a quicker way to build just the unit which contains dynarr.inc and have all the objects files to be put in the correct locat

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Anthony Walter
Ryan, this is just a thought. Do you need the flat memory address to start on an even 4 KB boundary or are you okay with the memory address starting at any DWORD address and spanning an even 4 KB after that address? In the latter case I have an easy solution for you. If the former I am unsure how

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Christo Crause
On Thu, 28 Mar 2019, 20:34 Ryan Joseph, wrote: > Now I’m using “cd /rtl; make all FPC=/path/to/compiler” to build the RTL > but this is obviously slow and unnecessary. Is there a quicker way to build > just the unit which contains dynarr.inc and have all the objects files to > be put in the corre

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Ryan Joseph
Now I’m using “cd /rtl; make all FPC=/path/to/compiler” to build the RTL but this is obviously slow and unnecessary. Is there a quicker way to build just the unit which contains dynarr.inc and have all the objects files to be put in the correct location? Regards, Ryan Joseph _

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Ryan Joseph
> On Mar 28, 2019, at 4:17 AM, Sven Barth via fpc-devel > wrote: > > The order should be > > [padding] [header] [data] > > with the offset being part of the header. This way you reduce the changes > needed to only those that allocate/free an array. Yeah that’s probably the better idea bec

Re: [fpc-devel] Aligned dynamic arrays

2019-03-28 Thread Sven Barth via fpc-devel
Ryan Joseph schrieb am Do., 28. März 2019, 03:01: > Here’s the basic structure: > > [header][padding][offset][head] > > [head] being the start of the elements (the pointer to the first element > of the array) and aligned to the requested amount. Keep in mind the head is > the pointer which is pas

Re: [fpc-devel] Aligned dynamic arrays

2019-03-27 Thread Ryan Joseph
> On Mar 27, 2019, at 9:13 PM, Martin Frb wrote: > > 2 Ideas, well 1 Idea, 1comment... > > The Idea: > Would it not be easier to: > - allocate mem, with extra space for align, unless memmanager can handle > align. > - return the alligned pointer for the array, so all array ops will work > ex

Re: [fpc-devel] Aligned dynamic arrays

2019-03-27 Thread Martin Frb
On 28/03/2019 00:43, Ryan Joseph wrote: I would like to attempt to implement this feature request (https://bugs.freepascal.org/view.php?id=34031 for my boss) which has the SetLength intrinsic return aligned memory. We need this for the Metal framework which requires all vertex buffer memory to