From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31267 invoked by alias); 28 Jul 2010 15:53:33 -0000 Received: (qmail 31113 invoked by uid 22791); 28 Jul 2010 15:53:32 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1.commerzbank.com (HELO mail1.commerzbank.com) (212.149.48.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Jul 2010 15:53:23 +0000 Received: by mail1.commerzbank.com (Commerzbank Mail-System, from userid 1002) id 5FB061A83EE; Wed, 28 Jul 2010 17:53:20 +0200 (CEST) X-Spam-Virus: No Received: from mail1.commerzbank.com (localhost [127.0.0.1]) by mail1.commerzbank.com (Commerzbank Mail-System) with ESMTP id AB7281A83DA; Wed, 28 Jul 2010 17:53:16 +0200 (CEST) Received: from pfx1.commerzbank.com (intern.postfix.commerzbank.com [172.16.71.213]) by mail1.commerzbank.com (Commerzbank Mail-System) with ESMTPS id A55221A83D6; Wed, 28 Jul 2010 17:53:16 +0200 (CEST) Received: by pfx1.commerzbank.com (Commerzbank Internal Mail-System, from userid 1001) id 838553B561; Wed, 28 Jul 2010 17:53:16 +0200 (CEST) Received: from sv035511.ztb.icb.commerzbank.com (sv035511.ztb.icb.commerzbank.com [140.13.159.110]) by pfx1.commerzbank.com (Commerzbank Internal Mail-System) with ESMTP id 6BAE72B2C7; Wed, 28 Jul 2010 17:53:16 +0200 (CEST) Received: from SE000319.ztb.icb.commerzbank.com ([140.26.56.30]) by sv035511.ztb.icb.commerzbank.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 28 Jul 2010 17:53:16 +0200 MIME-Version: 1.0 Subject: RE: optimization question: mpl Date: Wed, 28 Jul 2010 15:53:00 -0000 Message-ID: <824586E7387D1443B5DD024DAC75B91C139049@SE000319.ztb.icb.commerzbank.com> In-Reply-To: References: <824586E7387D1443B5DD024DAC75B91C139048@SE000319.ztb.icb.commerzbank.com> From: "Hite, Christopher" To: "Richard Guenther" Cc: Content-class: urn:content-classes:message Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg00404.txt.bz2 > Generally without knowing the compiler version you are using > it is hard to tell.=20=20 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=3D1; static void decode(DecodeContext& ){} }; struct M2{ static const int id=3D2; static void decode(DecodeContext& ){} }; struct M3{ static const int id=3D3; static void decode(DecodeContext& ){} }; template struct ListMember; template <> struct ListMember<1>{ typedef M1 type; }; template <> struct ListMember<2>{ typedef M2 type; }; template <> struct ListMember<3>{ typedef M3 type; }; template void foo(int id, DecodeContext& dc) { typedef typename ListMember::type M; if(M::id=3D=3Did) M::decode(dc); else foo(id,dc); } template<> void foo<0>(int id, DecodeContext& dc) {} int main(){ DecodeContext& dc=3D *(DecodeContext*)0;// junk for now int id=3D2; //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 >=20 > 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.