This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Postioning of items within a class
- To: Richard Henderson <rth at cygnus dot com>
- Subject: Re: Postioning of items within a class
- From: Andrew Henderson <prometheus at lokigames dot com>
- Date: Wed, 12 Jul 2000 13:55:21 -0400
- CC: gcc at gcc dot gnu dot org, Joe Buck <jbuck at racerx dot synopsys dot com>
- References: <396C9753.9CCFF35B@lokigames.com> <20000712164152.A5929@cygnus.com>
Richard Henderson wrote:
> On Wed, Jul 12, 2000 at 12:05:39PM -0400, Andrew Henderson wrote:
> > 1. Is there a method by which GCC/GAS can do a similar type of
> > substitution for offsets of items within classes (like MASM does in the
> > example above)?
>
> asm ("movl %%eax, %0" : : "m"(my_pointer->item2));
>
> is the best way. That is, let gcc construct the entire memory reference.
> Of course, you're limited to 10 asm arguments, so you can't do this for
> an enormous block of code. Of course, you probably don't want to be doing
> enormous blocks of asms anyway.
I certainly don't ;>
Unfortunately, the large blocks of asm need to remain as whole inlined
blocks, so I'm somewhat stuck with converting inlined chunks of asm on the
order of several hundred lines of asm per chunk. Dozens of these offset-type
references take place within each of these chunks of asm code. I had
originally thought about breaking the various asm chunks into smaller chunks
so that I would be allowed to pass in the offsets as memory parameters (like
you suggest above). The problem is that the project is compiled with very
aggressive optimizations, and I can't risk having GCC juggling registers or
changing the stack during the gaps between asm blocks.
> (And in my experience VC++ programmers
> drop to inline assembly way too often for things they don't need. Just
> converting the whole thing back to C would be a win.)
They certainly do drop to inlined asm quite often, but they are justified in
doing so. Entertainment software favors performance over maintainability, so
inlined assembly within a codebase is often neccesary for optimum
performance. Also, the assembly (as well as the majority of the C/C++ code)
for a game project tends to be very poorly documented. This makes a
conversion from asm to C/C++ all but impossible and extremely costly in terms
of developer time.
> > 2. Failing that, is there a GCC way of querying the class and getting
> > the offsets of members within the class (perhaps an __attribute__ of
> > some sort)?
>
> There's offsetof, but that may only work for POD structures in C++.
> I don't know for sure.
Joe Buck wrote:
> ISO C++ promises only that offsetof works for PODs.
> In practice a larger number of cases should work just fine; for the
> cases that don't (e.g. virtual base classes) the concept of an offset
> is fuzzy anyway.
A quick check into the offsetof() macro shows that it is designed for
structures only. I'll have to experiment with it to see if I can coax it
into working for classes as well. Joe's e-mail response lends a positive
light to the possiblity of offsetof() working for what I need. If it does
work, I imagine I can just have the makefile for the project do a quick check
of the various classes and #define the offsets prior to the start of
compilation.
Both Joe and Richard, thank you for the help.
--
Andrew Henderson
Programmer
Loki Entertainment Software