marcov wrote:Sounds fine. Maybe emit a warning when a value type exceeds a certain size ?
Warning already exists: 17(1) The type length is too large, consider passing BYREF
or
18(2) The length of the parameters list is too large, consider passing UDT's BYREF
fxm wrote:There are 2 thresholds to activate this kind of compiler warning on the parameter(s) declared 'As ByVal', when compiling with '-w pedantic' option (presently not noted in documentation):
Parameter length > 16 bytes (fbc 32-bit) or 32 bytes (fbc 64-bit)
=> warning 17: The type length is too large, consider passing BYREF
Parameters list length > 256 bytes (fbc 32-bit) or 512 bytes (fbc 64-bit)
=> warning 18: The length of the parameters list is too large, consider passing UDT's BYREF
But in both cases, it's just a warning: obviously 'ByRef' is not imposed by the compiler!
marcov wrote:Sounds fine. Maybe emit a warning when a value type exceeds a certain size ?
Warning already exists: 17(1) The type length is too large, consider passing BYREF
or
18(2) The length of the parameters list is too large, consider passing UDT's BYREF
Well then it is about how would I suggest, so I'm all for it ;-)
Long term, if you also going to do 8-bit embedded you might want those limits target dependent. And the only other thing I can think of is said ABI limits, where the default calling convention is register maybe. (iow where a BYVAL small record might not be on the stack but in registers). Though that is more a documentation exercise (BYval doesn't mean you can create a pointer to it) then a real problem
marcov wrote: And the only other thing I can think of is said ABI limits, where the default calling convention is register maybe. (iow where a BYVAL small record might not be on the stack but in registers). Though that is more a documentation exercise (BYval doesn't mean you can create a pointer to it) then a real problem
For fun.... Only 64bit, hard to summarize (mostly for Linux) and to understand.
Good reading ;-)
In case of hidden parameter for 'this' : (WDS) rcx or (LNX) rsi
In case of hidden pointer : (WDS) rcx or (LNX) rsi
In case of hidden parameter AND hidden pointer : (WDS) rcx/rdx and (LNX) rsi/rdi
PARAMETERS
==========
LNX
---
Byval parameter
---------------
simple datatypes
float
nb of float reg<=8 --> xmmN
nb of float reg>8 --> stack
integer
nb of int reg<=6 --> Rxx
nb of intreg >6 --> stack
structures
size of struct >16 --> stack
size <=8
only float (1-2 Single or 1 double)
nb of float reg<=8 --> xmmN
nb of float reg>8 --> stack
at least one integer
nb of intreg <=6 --> Rxx
nb of int reg>6 --> stack
size>8 and size <=16
first 8 bytes only floats
nb of float reg<=8 --> xmmN
nb of float reg>8 --> ALL on stack
at least one integer in first 8 bytes
nb of int reg<=6 --> Rxx
nb of int reg>6 --> ALL on stack
last bytes (8 or less) only floats
nb of float reg<=8 --> xmmN+1
nb of float reg>8 --> ALL on stack
at least one integer in last bytes
nb of int reg<=6 --> Rxx+
nb of intreg >6 --> ALL on stack
'ALL on stack' means that even there is a free register for the first 8 bytes
if there is no free register for the last bytes all the structure goes on stack.
Byref parameter
---------------
nb of int<=6 --> Rxx
nb of int>6 --> stack
WDS
---
Byval parameter
---------------
simple datatypes
nb arg<=4
float --> xmmN
integer --> Rxx
nb arg>4
any --> stack
structure
size<=8 and size ={1,2,4,8}
only ONE float
nb arg<=4 --> xmmN
nb arg>4 --> stack
at least one integer or 2 singles
nb arg<=4 --> Rxx
nb arg>4 --> stack
size>8 or size <>{1,2,4,8}
copy on memory as a local variable
pointer to copy nb arg<=4 --> Rxx
pointer to copy nb arg>4 --> stack
Byref parameter
---------------
nb arg<=4 --> Rxx
nb arg>4 --> stack
marcov wrote: And the only other thing I can think of is said ABI limits, where the default calling convention is register maybe. (iow where a BYVAL small record might not be on the stack but in registers). Though that is more a documentation exercise (BYval doesn't mean you can create a pointer to it) then a real problem
For fun.... Only 64bit, hard to summarize (mostly for Linux) and to understand.
Afaik FreeBSD (pre LLVM) was mostly the same, but Apple was different. But yeah, x86(_64) for Apple is on the way out, and the last non LLVM FreeBSD is already out of support.