From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26392 invoked by alias); 9 Feb 2008 02:52:11 -0000 Received: (qmail 26384 invoked by uid 22791); 9 Feb 2008 02:52:11 -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; Sat, 09 Feb 2008 02:51:48 +0000 Received: from zps36.corp.google.com (zps36.corp.google.com [172.25.146.36]) by smtp-out.google.com with ESMTP id m192pjDH026851 for ; Fri, 8 Feb 2008 18:51:45 -0800 Received: from smtp.corp.google.com (spacemonkey1.corp.google.com [192.168.120.115]) by zps36.corp.google.com with ESMTP id m192pgYr031236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 8 Feb 2008 18:51:45 -0800 Received: from localhost.localdomain.google.com (69-36-227-131.cust.layer42.net [69.36.227.131] (may be forged)) (authenticated bits=0) by smtp.corp.google.com (8.13.8/8.13.8) with ESMTP id m192pbNS020471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 8 Feb 2008 18:51:41 -0800 bTo: "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> <719dced30802081842u349d66bao619441f3261c770@mail.gmail.com> From: Ian Lance Taylor Date: Sat, 09 Feb 2008 02:52:00 -0000 In-Reply-To: <719dced30802081842u349d66bao619441f3261c770@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/msg00067.txt.bz2 "Godmar Back" writes: > gback@top [324](~/tmp) > cat switch.c > enum four { A, B, C, D }; > extern void g(int); > > void f(enum four x) > { > switch (x) > { > case A: g(1); break; > case B: g(2); break; > case C: g(3); break; > case D: g(4); break; > default: gcc_unreachable(); > } > } You don't have enough cases. gcc will always uses a binary search if there are fewer than five cases. Try this one. Ian enum four { A, B, C, D, E, F, G, H, I, J, K, L, M, N }; extern void g(int); void f(enum four x) { switch (x) { case A: g(1); break; case B: g(2); break; case C: g(3); break; case D: g(4); break; case E: g(5); break; case F: g(6); break; case G: g(7); break; case H: g(8); break; case I: g(9); break; case J: g(10); break; case K: g(11); break; case L: g(12); break; case M: g(13); break; case N: g(14); break; default: gcc_unreachable(); } }