From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3151 invoked by alias); 7 Oct 2011 17:35:34 -0000 Received: (qmail 3012 invoked by uid 22791); 7 Oct 2011 17:35:33 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ka.mail.enyo.de (HELO ka.mail.enyo.de) (87.106.162.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Oct 2011 17:35:18 +0000 Received: from [172.17.135.4] (helo=deneb.enyo.de) by ka.mail.enyo.de with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) id 1RCEKJ-0005xb-TD; Fri, 07 Oct 2011 19:35:15 +0200 Received: from fw by deneb.enyo.de with local (Exim 4.72) (envelope-from ) id 1RCEKJ-0005Wp-Kt; Fri, 07 Oct 2011 19:35:15 +0200 From: Florian Weimer To: Ulf Magnusson Cc: gcc@gcc.gnu.org Subject: Re: Option to make unsigned->signed conversion always well-defined? References: <87sjn5g638.fsf@mid.deneb.enyo.de> Date: Fri, 07 Oct 2011 22:24:00 -0000 In-Reply-To: (Ulf Magnusson's message of "Fri, 7 Oct 2011 19:20:15 +0200") Message-ID: <87pqi8k8mk.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg00113.txt.bz2 * Ulf Magnusson: > Are you thinking of something like this? > > bool overflow_bit2(unsigned int a, unsigned int b) { > const unsigned int ashift = a << 24; > const unsigned int bshift = b << 24; > const unsigned int sum = a + b; > return (int)(~(a ^ b) & (a ^ sum)) < 0; > } Yes, but rather like : bool overflow_bit2(unsigned char a, unsigned char b) { const unsigned char sum = a + b; return ((signed char)(~(a ^ b) & (a ^ sum))) < 0; } It still results in abysmal code, given that this should result in two or three instructions on most architectures. Are machine code insertions an option?