Re: [fpc-devel] if-then-else expression

2025-08-29 Thread Stefan Glienke via fpc-devel
Parameter evaluation order is ub so you cannot rely on that, regardless of inlining. And even though the intrinsic could behave differently it still looks like a regular function call and also might clash with existing similarly named existing function. > On 27/08/2025 16:40 CEST Hairy Pixels v

Re: [fpc-devel] Copy() and ZeroBaseStrings

2025-04-07 Thread Stefan Glienke via fpc-devel
No because the feature is related to the state of the ZBS switch at the source code location, not to the string instance. > On 07/04/2025 19:40 CEST Bart via fpc-devel > wrote: > > > On Mon, Apr 7, 2025 at 1:12 PM Marco van de Voort via fpc-devel > wrote: > > > IMHO it is a feature better

Re: [fpc-devel] 2 Ideas for generic TDictionary and other hash containers

2025-03-27 Thread Stefan Glienke via fpc-devel
For your second feature request it just needs a method added to THashSet that retrieves the stored item based on the passed key. > On 27/03/2025 12:28 CET Martin Frb via fpc-devel > wrote: > > > There are 2 features, I am missing. > > And I can't see a way to add them via subclassing, as th

Re: [fpc-devel] 2 Ideas for generic TDictionary and other hash containers

2025-03-27 Thread Stefan Glienke via fpc-devel
It does not violate the contract imho. In a TDictionary it would return a pointer to V which is valid because it either retrieved an existing entry or added a new one with default(v). I implemented this a while ago in Spring4D roughly following the API that was introduced in .NET some time ago.

Re: [fpc-devel] LEA instruction speed

2023-10-10 Thread Stefan Glienke via fpc-devel
Be my guest making https://github.com/spring4d/benchmark compatible for all platforms you need it for. > On 10/10/2023 11:13 CEST J. Gareth Moreton via fpc-devel > wrote: > > > Thanks Tomas, > > Nothing is broken, but the timing measurement isn't precise enough. > > Normally I have a much

Re: [fpc-devel] Division nodes

2023-05-15 Thread Stefan Glienke via fpc-devel
> FWIW in 3.2.2 I don't see the -1 check and the idiv causes an int overflow > exception. But silently returning 0 for min_int div -1 feels very wrong IMO. Pardon, debugger fooled me - I was meant to say "silently returning min_int". > > On 15/05/2023 18:43 CEST Kirinn via fpc-devel > > wrote:

Re: [fpc-devel] Division nodes

2023-05-15 Thread Stefan Glienke via fpc-devel
FWIW in 3.2.2 I don't see the -1 check and the idiv causes an int overflow exception. But silently returning 0 for min_int div -1 feels very wrong imo. > On 15/05/2023 18:43 CEST Kirinn via fpc-devel > wrote: > > > I didn't see a mention of it in this discussion thread, but dividing the > la

Re: [fpc-devel] Division nodes

2023-05-11 Thread Stefan Glienke via fpc-devel
Looks like a rather disadvantageous way to avoid the idiv instruction because x div -1 = -x and x mod -1 = 0. I ran a quick benchmark doing a lot of integer divisions where sometimes (randomly) the divisor was -1. When the occurence was rare enough (~5%) the performance was not impacted, the hi

Re: [fpc-devel] Additional generic type constraints

2023-02-22 Thread Stefan Glienke via fpc-devel
> I think Delphi basically has the same constraints as C# Not quite (well maybe back then when they implemented them but C# improved since)- also they are subtly implemented differently. In C# the constraint *class* means "a reference type" - in Delphi it actually means it has to be a class. C

Re: [fpc-devel] Sorting tests

2022-11-29 Thread Stefan Glienke via fpc-devel
More like a variation of that: TimSort - but that's rather a beast to implement properly and efficient. Am 29.11.2022 um 14:41 schrieb J. Gareth Moreton via fpc-devel: Quicksort is not inherently stable because of what happens if a value is equal to the pivot - more specifically, which of the

Re: [fpc-devel] Sorting tests

2022-11-29 Thread Stefan Glienke via fpc-devel
That is not a very good IntroSort to be honest. It is missing using InsertionSort for small numbers and it does not do the median-of-3 pivot selection. Am 29.11.2022 um 09:22 schrieb Nikolay Nikolov via fpc-devel: On 11/24/22 20:51, J. Gareth Moreton via fpc-devel wrote: Hi everyone, I just

Re: [fpc-devel] Sorting tests

2022-11-29 Thread Stefan Glienke via fpc-devel
Where exactly can that stable quicksort be found? rtl/inc/sortbase.pp looks pretty much like standard quicksort to me. Am 29.11.2022 um 11:08 schrieb Sven Barth via fpc-devel: J. Gareth Moreton via fpc-devel schrieb am Di., 29. Nov. 2022, 10:09: Surely that's a bug in the comparison func

Re: [fpc-devel] Sorting tests

2022-11-28 Thread Stefan Glienke via fpc-devel
Nevermind - I guess there is: https://www.freepascal.org/docs-html/rtl/system/gettypekind.html Am 28.11.2022 um 12:35 schrieb Stefan Glienke via fpc-devel: In Delphi that would be the https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.GetTypeKind intrinsic - I could not find

Re: [fpc-devel] Sorting tests

2022-11-28 Thread Stefan Glienke via fpc-devel
In Delphi that would be the https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.GetTypeKind intrinsic - I could not find that one in the 3.2.0 feature list. Am 28.11.2022 um 11:17 schrieb J. Gareth Moreton via fpc-devel: Well that spoils that idea!  Is there any way to determine if

Re: [fpc-devel] Sorting tests

2022-11-27 Thread Stefan Glienke via fpc-devel
ere's a way that that can be implemented in a cross-platform way, or if there's a wa to identify if a generic type is a pointer/managed type. Kit On 25/11/2022 16:00, Stefan Glienke via fpc-devel wrote: >From experience I can tell that IntroSort is fast enough. The main perfo

Re: [fpc-devel] Sorting tests

2022-11-25 Thread Stefan Glienke via fpc-devel
From experience I can tell that IntroSort is fast enough. The main performance improvement usually comes from treating anything that is a managed type such as strings as Pointers - instead of three string assignments that cause a bunch of unnecessary atomic operations you then just have 3 point

Re: [fpc-devel] Question about memory alignment (again!)

2022-08-18 Thread Stefan Glienke via fpc-devel
Interestingly this is what clang also does: https://godbolt.org/z/Y4v14f9s3 > On 17/08/2022 02:21 CEST J. Gareth Moreton via fpc-devel > wrote: > > > Hi everyone, > > Recently I've made some optimisations centred around the SHR instruction > on x86, and there was one pair of instructions

Re: [fpc-devel] x86 TEST instruction

2022-06-30 Thread Stefan Glienke via fpc-devel
Both clang and gcc seem to do this > On 30/06/2022 17:28 CEST J. Gareth Moreton via fpc-devel > wrote: > > > This was what I was working on: > > https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/252 > > The same question applies regarding the TEST instruction, but it's a > litt

Re: [fpc-devel] ConvUtils: ConvTypeToFamily and ConvFamilyToDescription conundrums

2022-06-09 Thread Stefan Glienke via fpc-devel
Am 09.06.2022 um 16:07 schrieb Bart via fpc-devel: On Thu, Jun 9, 2022 at 1:53 PM Stefan Glienke via fpc-devel wrote: I usually don't take 20 year old compilers as reference That's all that I have. I do Lazarus/Fpc as a hobby and am unwilling to spend lost of money on Delphi. Also

Re: [fpc-devel] ConvUtils: ConvTypeToFamily and ConvFamilyToDescription conundrums

2022-06-09 Thread Stefan Glienke via fpc-devel
Am 08.06.2022 um 19:24 schrieb Bart via fpc-devel: On Wed, Jun 8, 2022 at 3:55 PM Stefan Glienke via fpc-devel wrote: Actually the behavior in Delphi depends on the $R switch. D7: {$R+} ConvTypeToDescription(-1)=[$] {$R-} ConvTypeToDescription(-1)=[$] Bart I usually don&#

Re: [fpc-devel] ConvUtils: ConvTypeToFamily and ConvFamilyToDescription conundrums

2022-06-08 Thread Stefan Glienke via fpc-devel
> On 08/06/2022 14:58 Bart via fpc-devel wrote: > > code like this will not raise an exception Delphi, while it does > in Fpc: > > var > L: Integer; > begin > L:=-1; > writeln('ConvTypeToDescription(L)=',ConvTypeToDescription(L)); // > prints [$] in D7, EAccessViolation in fpc > e

Re: [fpc-devel] Thoughts: Make FillChar etc. an intrinsic for specialised performance potential

2022-04-19 Thread Stefan Glienke via fpc-devel
vel > wrote: > > > Interesting - I wasn't aware of this intrinsic!  I'll make a note of > that one. > > It might be useful to transform FillChar calls to the Default intrinsic > at the node level. > > Gareth aka. Kit > > On 19/04/2022 12:43, Stefan Gl

Re: [fpc-devel] Thoughts: Make FillChar etc. an intrinsic for specialised performance potential

2022-04-19 Thread Stefan Glienke via fpc-devel
rth via fpc-devel > wrote: > > > Stefan Glienke via fpc-devel schrieb am Di., > 19. Apr. 2022, 12:38: > > If you want to zero small records more efficiently it might be better using > > Default(t) for that and looking at optimizing the code the compiler > &g

Re: [fpc-devel] Thoughts: Make FillChar etc. an intrinsic for specialised performance potential

2022-04-19 Thread Stefan Glienke via fpc-devel
If you want to zero small records more efficiently it might be better using Default(t) for that and looking at optimizing the code the compiler generates for that as it seems it produces an empty temp variable which it assigns instead of simply zeroing the record variable where default() is bein

Re: [fpc-devel] case is

2022-03-23 Thread Stefan Glienke via fpc-devel
JEP 420 is hardly a misnomer because it is so much more than just type checking in a switch statement - hence pattern matching. You can see in the various examples that you can combine all kinds of boolean expressions - C# has had this for quite a while and they are constantly improving it. That

Re: [fpc-devel] Register renaming and false dependency question

2021-10-18 Thread Stefan Glienke via fpc-devel
won't code it, > although in the case of the "fast mod" algorithm, it appears very > frequently, so should probably be coded directly, especially as the > multiplication can take 3 cycles, depending on the processor, and is the > limiting factor. > > Gareth aka. K

Re: [fpc-devel] Register renaming and false dependency question

2021-10-17 Thread Stefan Glienke via fpc-devel
According to compiler explorer clang, gcc and msvc compile this to the same code with -O3 as FPC does. So I would assume that is fine. Am 17.10.2021 um 13:25 schrieb J. Gareth Moreton via fpc-devel: Hi everyone, While reading up on some algorithms, I came across a recommendation of using a sh

Re: [fpc-devel] New deep optimisation

2021-10-01 Thread Stefan Glienke via fpc-devel
Keep in mind that usually test/cmp and jcc instructions are macrofused but only if they are directly adjacent. Am 01.10.2021 um 18:10 schrieb J. Gareth Moreton via fpc-devel: Hi everyone, I've started playing around with an optimisation on x86 platforms that looks for common instructions that