[fpc-devel] Aligned dynamic arrays

2019-03-30 Thread denisgolovan
Hi all Sorry for possible starting a new thread as I've just managed to subscribe to the list. Could we discuss more options here? Maybe separate aligned array is a better alternative? I mean a new type fully backward compatible with dynamic arrays, but with additional requirements (more spe

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

[fpc-devel] Low-cost encoding reduces PPU size by 10%

2019-03-30 Thread J. Gareth Moreton
Hi everyone, Sorry if the title sounds like a clickbait you find everywhere on the Internet, and I apologise again for using FPC as my kind of personal research ground! I've just submitted a patch that uses a cheap, customised encoding system to minimise the number of bytes required to store fi

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 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 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 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
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 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 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 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 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 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 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 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: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 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 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 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 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 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 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 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 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