From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31744 invoked by alias); 28 Jun 2005 14:05:47 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 31110 invoked by uid 22791); 28 Jun 2005 14:05:27 -0000 Received: from dumbledore.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.11) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 28 Jun 2005 14:05:27 +0000 Received: (qmail 30475 invoked from network); 28 Jun 2005 14:05:25 -0000 Received: from unknown (HELO ?192.168.189.167?) (nathan@127.0.0.2) by mail.codesourcery.com with ESMTPA; 28 Jun 2005 14:05:25 -0000 Message-ID: <42C1591F.8060309@codesourcery.com> Date: Tue, 28 Jun 2005 14:05:00 -0000 From: Nathan Sidwell User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) MIME-Version: 1.0 To: Gabriel Dos Reis CC: Michael Veksler , Daniel Berlin , Mark Mitchell , Paul Koning , gcc mailing list Subject: Re: Do C++ signed types have modulo semantics? References: <42C15026.7070304@codesourcery.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2005-06/txt/msg01115.txt.bz2 Gabriel Dos Reis wrote: > Nathan Sidwell writes: > > | Gabriel Dos Reis wrote: > | > Michael Veksler writes: > | > [...] > | > | The code is not very simple, and different codes will get optimized > | > | differently. > | > | The user will have to learn how to write this piece of code differently for > | > | each > | > | processor to have best results. > | > | | int wrap_sum(int a, int b) > | > | { > | > | if ( (a<0) != (b<0)) > | > | return a+b; // Different sign, no overflow possible. > | > | unsigned sum = (unsigned) a + b; > | > | if (sum <= MAX_INT) > | > | return sum; > | > | sum -= MIN_INT; > | > | if (sum > MAX_INT) // can be eliminated for 2's complement > | > | abort(); // oops > | > | return (int)sum + MIN_INT; > | > | } > | > | | It does not look too good optimization-wise. > | > Thanks for providing this example. This is the sort of thing I > | > faced. With pipeline process, it does harm. > | > | Please explain why > | int wrap_sum (int a, int b) > | { > | return (int) ((unsigned)a + (unsigned)b)); > | } > | is unacceptable > > Notice that in your rendition you're assuming that you can convert any > unsigned value > INT_MAX to a int without invoking undefined behaviour. > > Thus the question is whether you're accepting that as documented > behaviour of GCC, and if so, then I'm interested in which ways it > would differs from saying that is_modulo is true. That is useful for > improving over the current situation, may I point out. I give up. nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk