From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30108 invoked by alias); 9 Feb 2008 03:02:08 -0000 Received: (qmail 30096 invoked by uid 22791); 9 Feb 2008 03:02:07 -0000 X-Spam-Check-By: sourceware.org Received: from fg-out-1718.google.com (HELO fg-out-1718.google.com) (72.14.220.158) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 09 Feb 2008 03:01:50 +0000 Received: by fg-out-1718.google.com with SMTP id d23so3021793fga.28 for ; Fri, 08 Feb 2008 19:01:47 -0800 (PST) Received: by 10.82.153.5 with SMTP id a5mr24447807bue.9.1202526107346; Fri, 08 Feb 2008 19:01:47 -0800 (PST) Received: by 10.82.177.10 with HTTP; Fri, 8 Feb 2008 19:01:47 -0800 (PST) Message-ID: <719dced30802081901j4db41c18wbb930be9d9791e4c@mail.gmail.com> Date: Sat, 09 Feb 2008 03:02:00 -0000 From: "Godmar Back" To: "Ian Lance Taylor" Subject: Re: optimization of switch statements on i386 Cc: gcc-help@gcc.gnu.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <719dced30802081629g19f67f6fi76dfaa0ede35b7aa@mail.gmail.com> <719dced30802081630q6fca95a4u747533463c9177f7@mail.gmail.com> Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-02/txt/msg00069.txt.bz2 On 08 Feb 2008 18:04:23 -0800, Ian Lance Taylor wrote: > > Look at expand_case in gcc/stmt.c. > Thanks. So I did that, and that explains why my example with 4 cases does not use a table. gcc/expr.c says: /* If the machine does not have a case insn that compares the bounds, this means extra overhead for dispatch tables, which raises the threshold for using them. */ #ifndef CASE_VALUES_THRESHOLD #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5) #endif /* CASE_VALUES_THRESHOLD */ and a binary search is used if #arms < CASE_VALUES_THRESHOLD. This leads to my next question. I increased the number of arms to 5, and retained the "default: gcc_unreachable()". Now gcc generates a bounds check, followed by a table jump. Good. Now how do I get rid of the bounds checks? Is there a way to inform gcc that the default branch is never taken? (Something along the lines of MSVC's __assert(0)? I had thought gcc_unreachable() would do that - but I may be misinformed here.) Thanks, - Godmar