public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/51653] New: More compact std::tuple
@ 2011-12-22 12:34 marc.glisse at normalesup dot org
  2011-12-22 13:11 ` [Bug libstdc++/51653] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: marc.glisse at normalesup dot org @ 2011-12-22 12:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51653

             Bug #: 51653
           Summary: More compact std::tuple
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: marc.glisse@normalesup.org


Created attachment 26166
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26166
proof of concept

Hello,

as a low priority enhancement possibility, I think it would be nice if
std::tuple was more compact. This would allow people to just use tuple<field1,
field2,field3> instead of having to think about the likelihood of the size of
each field to get a good layout. For instance, sizeof(tuple<char,int,char>)
could be 2*sizeof(int) (on platforms where sizeof(int)>1) instead of the
current 3*sizeof(int) by reordering internally as int,char,char. Empty fields
could all be moved to the beginning to avoid problems with
tuple<Empty,Empty,int> having size 2*sizeof(int) (an ABI weirdness).
Independently, derivation could be used more often for _Head_base (not final
and not virtual? more restrictions?) so that tuple<char,tuple<char,int>> has
only size 2*sizeof(int) (note that this kind of compression won't happen for
POD).

The main drawback is that it will complicate code. In many cases, tuple is just
used as an intermediate (forward_as_tuple followed by get) and we don't care
about the tuple layout, so it would needlessly slow down compilation and, as
any complication, it might hinder some flaky optimizations.

There are 2 main ways to implement this.
- a compiler intrinsic could be created that asks the compiler to reorder bases
for a dense layout (suggested by Jonathan Wakely). Note that this is not pragma
pack, as things should remain properly aligned.
- a pure library solution is possible too. I am attaching a proof of concept. I
know my code tends to be unreadable, but it shows that, taking out the ordering
function, the remaining tuple code can be fairly simple (mytuple__ is 6 lines,
the body of myget is 1 line, and the rest is implemented on top without needing
to know how the basis is implemented). Obviously I didn't implement the whole
interface.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-06 11:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-22 12:34 [Bug libstdc++/51653] New: More compact std::tuple marc.glisse at normalesup dot org
2011-12-22 13:11 ` [Bug libstdc++/51653] " redi at gcc dot gnu.org
2011-12-25  2:12 ` marc.glisse at normalesup dot org
2012-08-22 20:24 ` glisse at gcc dot gnu.org
2014-06-23 23:13 ` redi at gcc dot gnu.org
2021-12-06  5:02 ` pinskia at gcc dot gnu.org
2021-12-06  7:40 ` glisse at gcc dot gnu.org
2021-12-06 11:35 ` redi at gcc dot gnu.org
2021-12-06 11:37 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).