Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2012-01-30 15:30:38
On 30.01.2012, at 21:00, Sebastian Redl wrote:
> On 30.01.2012, at 19:58, Dave Abrahams wrote:
>> I support this work. Optional should be optimal :-)
>> on Fri Jan 27 2012, Domagoj Saric <domagoj.saric-AT-littleendian.com> wrote:
>>> ps. AFAICT the only real obstacle in having really nice codegen with
>>> boost::optional<a_fundamental_type> is lack of proper ABI/compiler
>>> support for passing and returning small structs in registers...
>> Please tell me that at least *some* C++ compiler does that nowadays...?
> All Linux compilers on x64 platforms follow the AMD64 ABI, possibly with minor variations/bugs. This ABI specifies that classes are passed in registers if
> - they are trivially copyable and destructible (optional should be specialized for types that fulfill these criteria to ensure this),
> - they have no virtual functions or bases,
> - they are smaller than 2 qwords (4 qwords if all members are float, double, or SSE types), and
> - they don't contain any weird stuff, like 80-bit long doubles or unaligned fields.
> The Mac ABI for x64 is very close, though I don't know the differences.
> The Win64 ABI is far less nice about registers. It passes the first four arguments in registers, and spills everything else onto the stack. It does not pack multiple values into a register. If a value is larger than 8 bytes, it is not split across registers. The ABI description says that "aggregates" can be passed in registers, but it doesn't elaborate on whether this refers to the C++ definition of aggregates (unlikely!) or whatever else the definition is. It sounds pretty useless.
> I'm not aware of any x86-32 calling convention that passes classes of any kind in registers.
Correcting myself: the Common C++ ABI for x86-32 actually specifies that trivially copyable and destructible classes are treated just like simple values for parameter passing, so they can be passed and returned in registers. Of course, the far smaller register file of x86-32 makes that still not very useful.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk