From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934294AbbI1PeG (ORCPT ); Mon, 28 Sep 2015 11:34:06 -0400 Received: from smtp-out4.electric.net ([192.162.216.193]:51866 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933698AbbI1PeE (ORCPT ); Mon, 28 Sep 2015 11:34:04 -0400 From: David Laight To: "'Eric Dumazet'" CC: "'Neil Horman'" , Denys Vlasenko , "David S. Miller" , Vlad Yasevich , Marcelo Ricardo Leitner , "linux-sctp@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements Thread-Topic: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements Thread-Index: AQHQ+fS9coWJP1VXkEmk/KIB4r2oOp5R+reA///0HYCAACLAQA== Date: Mon, 28 Sep 2015 15:32:44 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1CBA431C@AcuExch.aculab.com> References: <1443443644-12825-1-git-send-email-dvlasenk@redhat.com> <20150928135127.GB5248@hmsreliant.think-freely.org> <063D6719AE5E284EB5DD2968C1650D6D1CBA41B0@AcuExch.aculab.com> <1443450427.2531.2.camel@edumazet-glaptop2.roam.corp.google.com> In-Reply-To: <1443450427.2531.2.camel@edumazet-glaptop2.roam.corp.google.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-Outbound-IP: 213.249.233.130 X-Env-From: David.Laight@ACULAB.COM X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t8SFYB0A011786 From: Eric Dumazet > Sent: 28 September 2015 15:27 > On Mon, 2015-09-28 at 14:12 +0000, David Laight wrote: > > From: Neil Horman > > > Sent: 28 September 2015 14:51 > > > On Mon, Sep 28, 2015 at 02:34:04PM +0200, Denys Vlasenko wrote: > > > > Seemingly innocuous sctp_trans_state_to_prio_map[] array > > > > is way bigger than it looks, since > > > > "[SCTP_UNKNOWN] = 2" expands into "[0xffff] = 2" ! > > > > > > > > This patch replaces it with switch() statement. > > > > What about just adding 1 (and masking) before indexing the array? > > That might require a static inline function with a local static array. > > > > Or define the array as (say) [16] and just mask the state before using > > it as an index? > > Just let the compiler do its job, instead of obfuscating source. > > Compilers can transform a switch into an (optimal) table if it is really > a gain. The compiler can choose between a jump table and nested ifs for a switch statement. I've never seen it convert one into a data array index. David ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ¥Šwÿº{.nÇ+‰·¥Š{±þG«�éÿŠ{ayºʇڙë,j­¢f£¢·hš�ï�êÿ‘êçz_è®(­éšŽŠÝ¢j"�ú¶m§ÿÿ¾«þG«�éÿ¢¸?™¨è­Ú&£ø§~�á¶iO•æ¬z·švØ^¶m§ÿÿà ÿ¶ìÿ¢¸?–I¥