On Fri, 30 Jan 2015, Jeff Law wrote:

> +/* If we are testing a single bit resulting from a binary
> +   operation in precision P1 where the operands were widened
> +   precision P2 and the tested bit is the sign bit for
> +   precision P2.  Rewrite so the binary operation is in
> +   precision P2.  */

To avoid introducing undefined behavior, if the operation is arithmetic 
rather than bitwise and the original type with precision P2 is signed then 
you need to convert the operands to the corresponding unsigned type.

(I'm not sure how you avoid needing to convert the final result back to 
the original type of the expression to avoid type mismatches in the 
containing expression, but such a conversion back to the original type 
would need to be a zero-extension not a sign-extension and so for that I'd 
suppose the inner type should be unsigned even for bitwise operations.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to