From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29548 invoked by alias); 18 Mar 2010 05:22:50 -0000 Received: (qmail 29539 invoked by uid 22791); 18 Mar 2010 05:22:49 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_NEUTRAL X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Mar 2010 05:22:45 +0000 Received: from mx10.gnu.org ([199.232.76.166]:59660) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ns8Bv-0000Or-U0 for gcc@gnu.org; Thu, 18 Mar 2010 01:22:44 -0400 Received: from eggs.gnu.org ([140.186.70.92]:60651) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ns8Bv-0007LU-K1 for gcc@gnu.org; Thu, 18 Mar 2010 01:22:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ns8Bt-0001aC-WB for gcc@gnu.org; Thu, 18 Mar 2010 01:22:42 -0400 Received: from mail-iw0-f202.google.com ([209.85.223.202]:61548) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ns8Bt-0001a4-T6 for gcc@gnu.org; Thu, 18 Mar 2010 01:22:41 -0400 Received: by iwn40 with SMTP id 40so1597525iwn.1 for ; Wed, 17 Mar 2010 22:22:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.173.130 with SMTP id p2mr1238067ibz.48.1268889760783; Wed, 17 Mar 2010 22:22:40 -0700 (PDT) In-Reply-To: <20100317200410.GA13807@hungry-tiger.westford.ibm.com> References: <8ac33cd71003141343g7ae78185s378fd52205e2deb1@mail.gmail.com> <20100317200410.GA13807@hungry-tiger.westford.ibm.com> Date: Thu, 18 Mar 2010 06:39:00 -0000 Message-ID: <8ac33cd71003172222i3be31fbah209f49bd83dfa9b3@mail.gmail.com> Subject: Re: Hash Function for "switch statement" From: Jae Hyuk Kwak To: Michael Meissner , gcc@gnu.org Content-Type: text/plain; charset=UTF-8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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-03/txt/msg00243.txt.bz2 On Wed, Mar 17, 2010 at 1:04 PM, Michael Meissner wrote: > Note, that many hash tables are computed by the modulus operation, which is > often fairly expensive (and on machines without a hardware divide unit, > requiring a function call). I would expect many switch statements would slow > down if you switch to a hash operation that used modolus. > Hi Michael, I agree that the cost of modulation can be high, but it can be even higher if we use a bunch of "else if". Consider the situation that a program has about 400 cases on a single switch statement. The cost of modulation will be fixed price so that there should be a certain point that the price bis lower than else if statements. If jump table is possible, it can be a choice, but jump table is not always feasible depending on the values on "case". Thank you for the reply. Jay