Re: [fpc-devel] Question on constref

2023-02-01 Thread Hairy Pixels via fpc-devel
> On Feb 2, 2023, at 4:38 AM, Sven Barth wrote: > > Which types are passed by-value or by-reference when using const is > determined by the size of the record and the types of the fields based on > whatever the corresponding ABI defines (e.g. the x86_64 Sys V ABI is rather > explicit about

Re: [fpc-devel] Question on constref

2023-02-01 Thread Hairy Pixels via fpc-devel
> On Feb 2, 2023, at 8:41 AM, Adriaan van Os via fpc-devel > wrote: > > On debate, see FPC issue 17442. https://gitlab.com/freepascal.org/fpc/source/-/issues/17442 Yes this is what I remember learning. What I think should be documented is what you should do for records that over a certain

Re: [fpc-devel] Question on constref

2023-02-01 Thread Adriaan van Os via fpc-devel
Hairy Pixels via fpc-devel wrote: On Feb 2, 2023, at 4:38 AM, Sven Barth wrote: Which types are passed by-value or by-reference when using const is determined by the size of the record and the types of the fields based on whatever the corresponding ABI defines (e.g. the x86_64 Sys V ABI is

Re: [fpc-devel] Question on constref

2023-02-01 Thread Michael Van Canneyt via fpc-devel
On Wed, 1 Feb 2023, Sven Barth via fpc-devel wrote: Am 01.02.2023 um 11:30 schrieb Bart via fpc-devel: I thought that constref would be OK for that (the word constref suggests to me tah the paramter will be treated (by me) to be a constant, and that it shall be passed by reference in all

Re: [fpc-devel] Question on constref

2023-02-01 Thread Adriaan van Os via fpc-devel
Sven Barth via fpc-devel wrote: There is no full documentation for that parameter modifier (someone might want to file a bug report for that), but the documentation for “const” ( https://www.freepascal.org/docs-html/current/ref/refsu67.html#x183-20700014.4.4 ) contains this: === doc begin

Re: [fpc-devel] Question on constref

2023-02-01 Thread Sven Barth via fpc-devel
Am 01.02.2023 um 15:40 schrieb Hairy Pixels via fpc-devel: On Feb 1, 2023, at 8:27 PM, Michael Van Canneyt via fpc-devel wrote: That's exactly what Adriaan is saying. With const the compiler can choose. With constref, you force it not to copy. But this is not so efficient for small

Re: [fpc-devel] Question on constref

2023-02-01 Thread Sven Barth via fpc-devel
Am 01.02.2023 um 11:30 schrieb Bart via fpc-devel: I thought that constref would be OK for that (the word constref suggests to me tah the paramter will be treated (by me) to be a constant, and that it shall be passed by reference in all cases, whereas with a const parameter the compiler decides

Re: [fpc-devel] Question on constref

2023-02-01 Thread Sven Barth via fpc-devel
Am 02.02.2023 um 02:09 schrieb Hairy Pixels: On Feb 2, 2023, at 4:38 AM, Sven Barth wrote: Which types are passed by-value or by-reference when using const is determined by the size of the record and the types of the fields based on whatever the corresponding ABI defines (e.g. the x86_64

Re: [fpc-devel] Question on constref

2023-02-01 Thread Adriaan van Os via fpc-devel
Sven Barth via fpc-devel wrote: I doubt that records larger than say 4 register widths are ever passed by-value. But I definitely can't exclude it, cause I don't know every ABI of every platform by heart. So if you want details there then study the ABIs of the platforms you use. I doubt

Re: [fpc-devel] Question on constref

2023-02-01 Thread Sven Barth via fpc-devel
Adriaan van Os via fpc-devel schrieb am Do., 2. Feb. 2023, 02:47: > Sven Barth via fpc-devel wrote: > > > There is no full documentation for that parameter modifier (someone > > might want to file a bug report for that), but the documentation for > > “const” ( > > >

Re: [fpc-devel] Question on constref

2023-02-01 Thread Hairy Pixels via fpc-devel
> On Feb 1, 2023, at 8:16 PM, Adriaan van Os via fpc-devel > wrote: > > Because, if e.g. the byte-size of a parameter is such that it fits into a CPU > register, then passing the parameter itself is more efficient than passing a > reference to it. For large byte-size parameters, const and

Re: [fpc-devel] Question on constref

2023-02-01 Thread Michael Van Canneyt via fpc-devel
On Wed, 1 Feb 2023, Hairy Pixels via fpc-devel wrote: On Feb 1, 2023, at 8:16 PM, Adriaan van Os via fpc-devel wrote: Because, if e.g. the byte-size of a parameter is such that it fits into a CPU register, then passing the parameter itself is more efficient than passing a reference to

Re: [fpc-devel] Question on constref

2023-02-01 Thread Hairy Pixels via fpc-devel
> On Feb 1, 2023, at 5:56 PM, Adriaan van Os via fpc-devel > wrote: > > "A const parameter is be passed by reference or (for small-sized parameters) > by value, whatever is most efficient. A constref parameter is guaranteed to > be passed by reference in all cases. The latter is therefore

Re: [fpc-devel] Question on constref

2023-02-01 Thread Adriaan van Os via fpc-devel
Hairy Pixels via fpc-devel wrote: On Feb 1, 2023, at 5:56 PM, Adriaan van Os via fpc-devel wrote: "A const parameter is be passed by reference or (for small-sized parameters) by value, whatever is most efficient. A constref parameter is guaranteed to be passed by reference in all cases.

Re: [fpc-devel] Question on constref

2023-02-01 Thread Adriaan van Os via fpc-devel
Bart via fpc-devel wrote: "Note that in general, it should only be used for interfacing with external code or when writing assembler routines." That is wrong. It should read "A const parameter is be passed by reference or (for small-sized parameters) by value, whatever is most efficient. A

[fpc-devel] Question on constref

2023-02-01 Thread Bart via fpc-devel
Hi, I have a function that has a parameter to a datastructure with some arrays with records is it. This function needs to return a pointer to a specific record inside that structure. The function is not supposed to alter the contents of this datastructure. So, I need to pass this structure by

Re: [fpc-devel] Question on constref

2023-02-01 Thread Bart via fpc-devel
On Wed, Feb 1, 2023 at 11:56 AM Adriaan van Os via fpc-devel wrote: > That is wrong. It should read > > "A const parameter is be passed by reference or (for small-sized parameters) > by value, whatever is > most efficient. A constref parameter is guaranteed to be passed by reference > in all

Re: [fpc-devel] Question on constref

2023-02-01 Thread Michael Van Canneyt via fpc-devel
On Wed, 1 Feb 2023, Hairy Pixels via fpc-devel wrote: On Feb 1, 2023, at 8:27 PM, Michael Van Canneyt via fpc-devel wrote: That's exactly what Adriaan is saying. With const the compiler can choose. With constref, you force it not to copy. But this is not so efficient for small parameter

Re: [fpc-devel] Question on constref

2023-02-01 Thread Hairy Pixels via fpc-devel
> On Feb 1, 2023, at 8:27 PM, Michael Van Canneyt via fpc-devel > wrote: > > That's exactly what Adriaan is saying. With const the compiler can choose. > With constref, you force it not to copy. But this is not so efficient for > small parameter sizes. So const will always pass records that

Re: [fpc-devel] Question on constref

2023-02-01 Thread Tomas Hajny via fpc-devel
On 2023-02-01 15:40, Hairy Pixels via fpc-devel wrote: On Feb 1, 2023, at 8:27 PM, Michael Van Canneyt via fpc-devel wrote: That's exactly what Adriaan is saying. With const the compiler can choose. With constref, you force it not to copy. But this is not so efficient for small parameter