This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How can I make this code friendly to GCC's optimizer?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Steven Stewart-Gallus <sstewartgallus00 at mylangara dot bc dot ca>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 16 Mar 2014 18:58:30 +0000
- Subject: Re: How can I make this code friendly to GCC's optimizer?
- Authentication-results: sourceware.org; auth=none
- References: <faa2a6721c7b8 dot 5325f060 at langara dot bc dot ca>
On 16 March 2014 18:41, Steven Stewart-Gallus wrote:
>
> Converting an unsigned integer to a signed integer is easy in C. The
> implicit conversion works fine. However, converting from a signed
> integer to an unsigned integer invokes implementation defined
> behaviour (or can raise an implementation defined signal) if "the
> value cannot be represented in it". So I wrote some simple code to
> convert a uint_fast32_t to an int_fast32_t.
Since GCC (and Clang) do what you expect when converting from a signed
integer to an unsigned integer, the most optimizer-friendly thing to
do is rely on the implementation-defined conversion rather than doing
it yourself.