This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Char shifts promoted to int. Why?
- From: Dorit Nuzman <DORIT at il dot ibm dot com>
- To: Paul Schlie <schlie at comcast dot net>
- Cc: gcc at gcc dot gnu dot org, Paul Brook <paul at codesourcery dot com>
- Date: Wed, 20 Dec 2006 00:32:25 +0200
- Subject: Re: Char shifts promoted to int. Why?
>
> ((char)x) = ((char)( ((int)((char)x)) << ((int)c) ) ) ::
> ((char)x) = ((char)( ((char)x) << ((int)c) ) )
>
> if the shift count ((int)x) is semantically preserved.
>
> thereby conditionally shifting left ((char)x) by ((int)c) if c is less
than
> the smaller of it's shifted operand's or target's precision (both being
char
> in this instance) or otherwise returning 0; is semantically equivalent
and
> typically more efficient on smaller lightly pipelined machines without
> needing to literally promote the shifted operand to int width.
>
Something along these lines may be useful to do in the vectorizer when we
get code like this:
> ((char)x) = ((char)( ((int)((char)x)) << ((int)c) ) )
and don't feel like doing all the unpacking of chars to ints and then
packing the ints to chars after the shift. An alternative could be to
transform the above pattern to:
char_x1 = 0
char_x2 = char_x << c
char_x = ((int)c < size_of_char) ? char_x2 : char_x1
and vectorize that (since we already know how to vectorize selects).
dorit