From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22716 invoked by alias); 11 Feb 2008 17:55:06 -0000 Received: (qmail 22708 invoked by uid 22791); 11 Feb 2008 17:55:06 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 11 Feb 2008 17:54:46 +0000 Received: from zps75.corp.google.com (zps75.corp.google.com [172.25.146.75]) by smtp-out.google.com with ESMTP id m1BHsbCi014114; Mon, 11 Feb 2008 09:54:37 -0800 Received: from smtp.corp.google.com (spacemonkey1.corp.google.com [192.168.120.115]) by zps75.corp.google.com with ESMTP id m1BHsaV8006754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 11 Feb 2008 09:54:37 -0800 Received: from localhost.localdomain.google.com (adsl-76-249-168-94.dsl.pltn13.sbcglobal.net [76.249.168.94]) (authenticated bits=0) by smtp.corp.google.com (8.13.8/8.13.8) with ESMTP id m1BHsafr018704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 11 Feb 2008 09:54:36 -0800 To: "Godmar Back" Cc: gcc-help@gcc.gnu.org Subject: Re: optimization of switch statements on i386 References: <719dced30802081629g19f67f6fi76dfaa0ede35b7aa@mail.gmail.com> <719dced30802081630q6fca95a4u747533463c9177f7@mail.gmail.com> <719dced30802081901j4db41c18wbb930be9d9791e4c@mail.gmail.com> From: Ian Lance Taylor Date: Mon, 11 Feb 2008 17:55:00 -0000 In-Reply-To: <719dced30802081901j4db41c18wbb930be9d9791e4c@mail.gmail.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes 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/msg00078.txt.bz2 "Godmar Back" writes: > 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.) gcc_unreachable means nothing special to gcc. If you look at the resulting code, you will see that it just compiles into a function call. If you use -Wall you will see that the function was not declared before being called. gcc_unreachable is used in the gcc source code itself, but that is different from being recognized in gcc. It is defined as a macro in gcc/system.h for use when building gcc itself: #define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__)) There is no way to tell gcc that the default branch is never taken, although it will omit the default branch if it can prove that the value is never out of range based on earlier conditional checks. Ian