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

Re: [fpc-devel] Producing assembly with less branches?

2020-07-19 Thread Stefan Glienke
Am 20.07.2020 um 02:37 schrieb J. Gareth Moreton: On 19/07/2020 22:37, Stefan Glienke wrote: clang and gcc emit this - I would guess they detect quite some common patterns like this.  ...   cmp eax, edx   mov edx, -1   setg    al   movzx   eax, al   cmovl   eax, edx   ret I think I

Re: [fpc-devel] Producing assembly with less branches?

2020-07-19 Thread Stefan Glienke
- Reply to message - Subject: [fpc-devel] Producing assembly with less branches? From: Stefan Glienke To: Hi, not sure if anything significantly changed in trunk compared to 3.2 wrt to optimized code being generated but I am quite disappointed that fpc (checked win64 with -O3 and

[fpc-devel] Producing assembly with less branches?

2020-07-19 Thread Stefan Glienke
Hi, not sure if anything significantly changed in trunk compared to 3.2 wrt to optimized code being generated but I am quite disappointed that fpc (checked win64 with -O3 and -O4) does not use cmovxx instructions and alike for the most basic things and produces terrible code like this: unit1

Re: [fpc-devel] Minor debate with ISO standard on case blocks

2019-07-30 Thread Stefan Glienke
Actually I prefer a compiler error/warning on such cases - so being able to write an exhaustive case is a very good option over eventually getting runtime errors - oh, yeah we all have exhaustive unit tests don't we? ;) TypeScript for example has the never type which can be used to write a comp

Re: [fpc-devel] modeswitch multihelpers

2019-05-13 Thread Stefan Glienke
...@delfire.net > wrote: > > > On Mon, May 13, 2019 at 7:09 AM Ondrej Pokorny mailto:laza...@kluug.net > wrote: > > > > > > On 13.05.2019 11:59, Stefan Glienke wrote: > > > > > > > When I wrote "existing code&qu

Re: [fpc-devel] modeswitch multihelpers

2019-05-13 Thread Stefan Glienke
On Mon, 13 May 2019 11:33:36 +0200 (CEST) > Stefan Glienke mailto:sglie...@dsharp.org > wrote: > > > > I want to argue that the way this is implemented is asking for > easily > > introducing defects into existing code by extending/modifyin

Re: [fpc-devel] modeswitch multihelpers

2019-05-13 Thread Stefan Glienke
I want to argue that the way this is implemented is asking for easily introducing defects into existing code by extending/modifying helpers causing methods to creep into scope. If multiple helpers should be considered they should be treated equally and not by order treating equally named methods

Re: [fpc-devel] Wrong docs: not initialized global variables

2018-07-03 Thread Stefan Glienke
SetLength should not cause anything uninitialized. It enlarges or shrinks the data and keeps any prior data as it was, new allocated memory is zeroed (at least that is how it works in the Delphi RTL and I would be very surprised if FPC would do any different). The core issue imo is temp var reu

Re: [fpc-devel] Managed Types, Undefined Bhaviour

2018-06-29 Thread Stefan Glienke
Am 29.06.2018 um 20:10 schrieb Jonas Maebe: That does not make any sense to me from a language design point of view. Either the language guarantees that managed function results are initialised to empty, or it does not. The fact that these are the same or different temps, or if there are no te

Re: [fpc-devel] Managed Types, Undefined Bhaviour

2018-06-29 Thread Stefan Glienke
passed. Am 29.06.2018 um 18:27 schrieb Jonas Maebe: On 29/06/18 17:57, Stefan Glienke wrote: Now we are back to using temp variables (both Delphi and FPC do) but FPC again reuses its temp variable for A and B while Delphi uses different ones. Now for some integer this might not be a big issue

Re: [fpc-devel] Managed Types, Undefined Bhaviour

2018-06-29 Thread Stefan Glienke
Let me add some information to this issue - as I think this is one - before this drifted into the interface chaining thing: When you execute this code in Delphi it will print 0 while on FPC it prints 42: type Vector = array of integer; function DoSomething (len: Integer): Vector; begin SetL

Re: [fpc-devel] Unexpected behaviour with intermediate results

2018-06-12 Thread Stefan Glienke
The real bug imo is that is that it even generates shl and shr instructions. b := (a shl x) shr x should be just compile to b := a for x in 0..24 and a being 8bit (which is what several C++ compilers do afaik) > On 12 June 2018 at 02:07 "J. Gareth Moreton" > wrote: > > > https://bugs.freepasca

Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-17 Thread Stefan Glienke
11:52 schrieb Stefan Glienke: FWIW this has been changed in Delphi 10.2 and does not compile anymore but gives: E2010 Incompatible types: 'Dynamic array' and 'Pointer' That is what I would have expected. Could you please test what the following does in D10.2? var arr:

Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-17 Thread Stefan Glienke
FWIW this has been changed in Delphi 10.2 and does not compile anymore but gives: E2010 Incompatible types: 'Dynamic array' and 'Pointer' > On 16 April 2018 at 17:21 Martok wrote: > > > Hi all, > > I have started debugging 0031215, and discovered something slightly unrelated, > but odd. I hope s

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-09-01 Thread Stefan Glienke
ather than just chaining them together). Am 01.09.2017 um 18:38 schrieb Sven Barth: Am 01.09.2017 14:50 schrieb "Stefan Glienke" mailto:sglie...@dsharp.org>>: > > > For generics the only way to support them is that you must explicitly specialize a generic helper t

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-09-01 Thread Stefan Glienke
> For generics the only way to support them is that you must explicitly > specialize a generic helper type. The compiler won't do any type inference > for you. IMO this makes them rather useless. Is that a technical limitation or just something you did not want to do? I don't know much about co

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-09-01 Thread Stefan Glienke
I consider that as terribly hard to maintain code. As soon as you move around statements, refactor things everything gets messed up. No thanks. > On 01 September 2017 at 12:15 Maciej Izak wrote: > > > 2017-09-01 11:41 GMT+02:00 Stefan Glienke : > > > Again you w

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-09-01 Thread Stefan Glienke
What I am lobbying for in Delphi are interface helpers and helpers for generic types in general. I just saw that FPC currently has the same limitation. That also on your list? > On 01 September 2017 at 11:07 Sven Barth wrote: > > > Am 01.09.2017 08:47 schrieb "Stefan Glienk

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-09-01 Thread Stefan Glienke
. > On 01 September 2017 at 09:40 Ondrej Pokorny wrote: > > > On 01.09.2017 8:47, Stefan Glienke wrote: > > Inheritance seems like the obvious way but you just defer the "I > > cannot extend the builtin helpers" problem. > > If any third party code decides to do so

Re: [fpc-devel] Allow record helper inheritance in Delphi mode

2017-08-31 Thread Stefan Glienke
Inheritance seems like the obvious way but you just defer the "I cannot extend the builtin helpers" problem. If any third party code decides to do so you are at the same point again because now do you inherit from the third party helper or from the builtin one? What if two third parties inherit f

Re: [fpc-devel] Optimizing unused return values of inline functions

2017-08-22 Thread Stefan Glienke
Often a fluent API has some grammar described via different interfaces that are implemented by either one (in this case you always return Self) or different classes. It is not just to chain methods together that you could also write like you did. > On 22 August 2017 at 13:15 Michael Van Canneyt

Re: [fpc-devel] Optimizing unused return values of inline functions

2017-08-21 Thread Stefan Glienke
Isn't rax needed for the call to Free? ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Re: [fpc-devel] "Default" discussion for SmartPointers etc

2016-07-28 Thread Stefan Glienke
> Well, I think this addition is not necessary, maybe even dangerous. > I can live with the 'ascetic' version :-) > > Since the following: > > Procedure SomeTest(Var X : Integer); > > begin >X:=1; > end; > > Var >A : TNullable; > > begin >SomeTest(A^); > end. > > Will lead to a c

Re: [fpc-devel] "Default" discussion for SmartPointers etc

2016-07-28 Thread Stefan Glienke
One thing that I did not see mentioned here is the fact that introducing "operator hoisting" by introducing that default feature will not solve nullables at all. I think a basic rule of nullables (at least in C# where I know them from) is the fact that operators can only be applied to a nullable i

Re: [fpc-devel] Array of char

2015-02-26 Thread Stefan Glienke
Maybe in D7 this works and in Delphi XE7 you also can get away with it when passing it directly to Writeln but this will throw a nice AV and the end: program Project1; const Str = 'TEST'; var Data: array of Char; s: string; begin SetLength(Data, Length(Str)); Move(Str[1], Data[0], Lengt