This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Implement switch statements with bit tests
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Roger Sayle <roger at www dot eyesopen dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: 24 Jan 2003 17:36:52 +0100
- Subject: Re: [PATCH] Implement switch statements with bit tests
- References: <Pine.LNX.4.44.0301232058450.21840-100000@www.eyesopen.com>
Roger Sayle <roger@www.eyesopen.com> writes:
> e.g. we'd like to convert
>
> if ((x==4) || (x==6) || (x==9) || (x==11))
>
> into
>
> if ((1<<x) & ((1<<4)|(1<<6)|(1<<9)|(1<<11)))
Wouldn't this be better:
if ((((1<<4)|(1<<6)|(1<<9)|(1<<11)) >> x) & 1)
e. g. on Alpha, it would save two instructions, since we don't need to
generate a 1, and one could use "branch if low bit set".
--
Falk