Re: Data Structure Reorganizing Optimizations

kendall@pot.East.Sun.COM (Sam Kendall - Sun Microsystems Labs BOS)
Sat, 5 Nov 1994 05:32:53 GMT

          From comp.compilers

Related articles
[9 earlier articles]
Re: Data Structure Reorganizing Optimizations amos@nsof.co.il (1994-11-01)
Re: Data Structure Reorganizing Optimizations pardo@cs.washington.edu (1994-10-31)
Re: Data Structure Reorganizing Optimizations fjh@munta.cs.mu.OZ.AU (1994-11-02)
Re: Data Structure Reorganizing Optimizations jeremy@sour.sw.oz.au (1994-11-02)
Re: Data Structure Reorganizing Optimizations prochak@cibadiag.com (1994-11-02)
Re: Data Structure Reorganizing Optimizations pardo@cs.washington.edu (1994-11-09)
Re: Data Structure Reorganizing Optimizations kendall@pot.East.Sun.COM (1994-11-05)
Re: Data Structure Reorganizing Optimizations praetorius@figs.enet.dec.com (1994-11-09)
Re: Data Structure Reorganizing Optimizations pjensen@csi.compuserve.com (1994-11-11)
Re: Data Structure Reorganizing Optimizations glew@ichips.intel.com (1994-11-13)
Re: Data Structure Reorganizing Optimizations glew@ichips.intel.com (1994-11-13)
Re: Data Structure Reorganizing Optimizations monnier@di.epfl.ch (1994-11-14)
Re: Data Structure Reorganizing Optimizations rockwell@nova.umd.edu (1994-11-14)
[4 later articles]
| List of all articles for this month |
Newsgroups: comp.arch,comp.compilers
From: kendall@pot.East.Sun.COM (Sam Kendall - Sun Microsystems Labs BOS)
Keywords: C, optimize
Organization: Sun Microsystems Laboratories BOS
References: 94-10-108 94-10-187
Date: Sat, 5 Nov 1994 05:32:53 GMT

Does anyone have any actual results for the potential spaced saved from
automatic reorganization of structures? Unless the gains are large, it
doesn't strike me as worth thinking about--particularly not for C or
C++, since so much code would break.


However, in a particularly bit-twiddly phase of my career I did think
about it. Here is what I concluded.


First, when a particular C structure needs to be carefully ordered to
get the best packing, the programmer can do it and does.


Second, hand-packing can be harder in C++ due to inheritance. For
example:


class B { unsigned flag1:1; int i; ...; };
class D : public B { unsigned flag2:1; ...; };


(The writer of D may have no control over the source of B, or it may be
a violation of abstraction to put flag2 into D rather than B.) B's
layout has a hole bitsize(int)-1 bits long, and it would be nice if
flag2 went into that hole. It would even be consistent with the layout
constraints of C++ for an implementation to put flag2 into that hole.
But no implementation I know of does it--I believe not even if flag1 is
the last data member of B.


I asked the people who designed the layout for one very popular C++
implementation why they didn't pack this way. They said that they had
recognized the possibility, but it was just too weird. In other words,
it would break too much code and surprise too many people. I agree.


My conclusions: it's not a possibility for C or C++. It might be okay
for a language like Modula-3, because a lot less bit-twiddling goes on
in that language; but even there it is not very interesting.


----
Sam Kendall
Sun Microsystems Laboratories BOS
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.