[PATCH] Implement switch statements with bit tests
Falk Hueffner
falk.hueffner@student.uni-tuebingen.de
Fri Jan 24 16:37:00 GMT 2003
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
More information about the Gcc-patches
mailing list