public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Hite, Christopher" <Christopher.Hite@partner.commerzbank.com>
To: "Richard Guenther" <richard.guenther@gmail.com>
Cc: <gcc@gcc.gnu.org>
Subject: RE: optimization question: mpl
Date: Wed, 28 Jul 2010 15:53:00 -0000	[thread overview]
Message-ID: <824586E7387D1443B5DD024DAC75B91C139049@SE000319.ztb.icb.commerzbank.com> (raw)
In-Reply-To: <AANLkTinSN+dOi-oi1ZWBa+4P55+Wvn=DtPasMJ_usOUb@mail.gmail.com>

> Generally without knowing the compiler version you are using
> it is hard to tell.  
I'll use whatever's best.  Right now I'm still on 4.4.3.  I'll probably
upgrade soon to 4.5.

> The same is true without a complete compilable testcase.
I didn't want to make a test case that depends on boost::mpl. How's
this:

struct DecodeContext;

struct M1{
	static const int id=1;
	static void decode(DecodeContext& ){}
};

struct M2{
	static const int id=2;
	static void decode(DecodeContext& ){}
};

struct M3{
	static const int id=3;
	static void decode(DecodeContext& ){}
};


template <int> struct ListMember;

template <> struct ListMember<1>{ typedef M1 type; };
template <> struct ListMember<2>{ typedef M2 type; };
template <> struct ListMember<3>{ typedef M3 type; };

template<int i>
void foo(int id, DecodeContext& dc) {
	typedef typename ListMember<i>::type M;
	if(M::id==id)
		M::decode(dc);
	else
		foo<i-1>(id,dc);
}

template<>
void foo<0>(int id, DecodeContext& dc) {}



int main(){
	DecodeContext& dc= *(DecodeContext*)0;// junk for now
	int id=2; //sometime runtime dependent
	foo<3>(id,dc);
	return 0;
}


> You can use the flatten attribute to tell the compiler to inline all
> calls in a given function, like
> 
> void __attribute__((flatten)) foo(void)
> {
> ...
> decode1();
> ...
> }

That would cause decode1() to be inlined, which might not be what you
want.

Hmm maybe I could rewrite things so the switch case returns a function
pointer.  I'm guessing that would make things slower though.

  reply	other threads:[~2010-07-28 15:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-28 14:38 Hite, Christopher
2010-07-28 15:26 ` Richard Guenther
2010-07-28 15:53   ` Hite, Christopher [this message]
2010-07-28 17:26     ` Larry Evans
2010-07-28 18:17     ` Piotr Rak
2010-07-28 19:00       ` Larry Evans
2011-10-17 16:35       ` Hite, Christopher
2010-07-29 12:16   ` Larry Evans
2010-07-28 15:35 ` Larry Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=824586E7387D1443B5DD024DAC75B91C139049@SE000319.ztb.icb.commerzbank.com \
    --to=christopher.hite@partner.commerzbank.com \
    --cc=gcc@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).