[OT] "3-byte struct" rule

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Mar 1 09:19:31 PST 2007


Lionello Lunesu wrote:
>> .... So it only breaks if a 3-byte struct or anything larger than 4 
>> bytes is passed as the last parameter and that parameter is out or inout.
> 
> Do you happen to have any idea why 3-byte structs aren't passed in EAX 
> (while 1, 2 and 4-byte structs are) ?
> 
> I've been wondering about this.

You'll have to ask Walter to be sure, but I guess so no distinction 
needs to be made based on what members they have.

Let's consider the cases:
A one byte struct most likely either has no members (IIRC 1 is the 
minimum size) or 1 char/byte/ubyte passed in AL.
A 2-byte struct either has two such members (AL & AH) or a single 
(u)short/wchar (AX).
A 4-byte struct most likely has one four-byte member (EAX) or two 
members of which at least one is 2 bytes (not as easily split, but the 
other case is probably more likely). Four one-byte members are also 
possible, but probably even less likely.

A three-byte struct on the other hand, has almost by definition three 
one-byte members. (anything larger than one byte has natural .align > 1, 
though this can be overridden)
So in this case the most likely case will be harder to split from the 
register.

That's my guess, anyway.



More information about the Digitalmars-d mailing list