From patchwork Thu Nov 8 17:37:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Zadeck X-Patchwork-Id: 197860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 91B6A2C00C6 for ; Fri, 9 Nov 2012 05:05:51 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1353002751; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=hKga1ZsAfnaWMZ4mfxg25Sg81tE=; b=gOtc0mBJo7tAMZIO7Y2RpDusZaVLWv3fkQ7urPdPnnM2E+Z1TR3jGmXmwCjxFG tAonE/UMxpRN/Gr8y94LBp9vy/zYkY4r0vqJVDYRMqVYaEgZRAEj7mFvlNuGNP4Y 9VUPOjpWnOucP2pCrWNyoKWBbu4wBTFhj0isArvqgaPVs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ARbB4krLthiZKHLqrwdfwyyKm+E4vpRMqpDjdBofGLN5YlksaXdU5A2xDBjOO/ QTX0jr/PlMquL5GZ8I9gqXvllVGs2sfOT6G/4E0Af/l3HicqCmN91hYQWjOIEFOx d7kktxs9ycKUp09zPDSnr38F/D62bsgBe7xiMn13EJbkw=; Received: (qmail 30754 invoked by alias); 8 Nov 2012 17:37:47 -0000 Received: (qmail 30598 invoked by uid 22791); 8 Nov 2012 17:37:46 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, UPPERCASE_50_75 X-Spam-Check-By: sourceware.org Received: from mail-ie0-f175.google.com (HELO mail-ie0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Nov 2012 17:37:40 +0000 Received: by mail-ie0-f175.google.com with SMTP id c13so4798622ieb.20 for ; Thu, 08 Nov 2012 09:37:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:x-gm-message-state; bh=Q3mCOfWjLeS5E0Ye81VSCK2lqFg6xUhdlHDZ/vH2M0U=; b=TdEA4IP+aKjG+sy6ECDxEfefCZ5V6HgWf3W1WHMCO6cwVDqFTPZ/tDfBIa8opgcIBA w3nwJQVK2nwsTQIZL6VbUBf4tNcKWPMEJ3MwFrr8E/9fMSena2V8Has0pSaHMHSpR1we BGYPwL93mbfv0fxTI3WtydtAt/4eJ2Y1TGjzxEupEjM4YnYdMLs9i1+Q7XE8ugjAH/YE hXLQQRUDSkErhXsOOOhuF9os1ZVHOL15ffq1dP4fOpgiJZmsrjXFPP3fqa8YNdmqR0nD sJniEq7uG/7WKlYRpRSWa5S31I2FFMTwCdDj+YgDdbxm0FA4G+poD7USKWt8lI6MjJNn o1Mg== Received: by 10.50.91.195 with SMTP id cg3mr20761942igb.57.1352396260271; Thu, 08 Nov 2012 09:37:40 -0800 (PST) Received: from ?IPv6:2001:468:913:2044:8cd6:57e:6865:70be? ([2001:468:913:2044:8cd6:57e:6865:70be]) by mx.google.com with ESMTPS id x5sm4846247igc.14.2012.11.08.09.37.38 (version=SSLv3 cipher=OTHER); Thu, 08 Nov 2012 09:37:38 -0800 (PST) Message-ID: <509BEDE0.70409@naturalbridge.com> Date: Thu, 08 Nov 2012 12:37:36 -0500 From: Kenneth Zadeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: "Joseph S. Myers" CC: Richard Guenther , Mike Stump , gcc-patches , rdsandiford@googlemail.com Subject: Re: patch to fix constant math - first small patch References: <506C72C7.7090207@naturalbridge.com> <506D9544.7020408@naturalbridge.com> <506DD085.7080608@naturalbridge.com> <87txuaox52.fsf@talisman.home> <87lifli6oj.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> <87ehldi2kr.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> <87a9w1hzq1.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> <506F0C1A.5010705@naturalbridge.com> <87lifkhlo9.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> <506F5B50.2040800@naturalbridge.com> In-Reply-To: X-Gm-Message-State: ALoCoQkfkpERAoOqLFIrSiV4DP6BIsQar2bUNK4YRszCUZLRQEzt7nX67tFQ8Iu4ng4WYnzZfAQp Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Joseph, Here is a revised patch with the change you asked for. There have been no other comments. May I commit it? Kenny On 10/05/2012 08:14 PM, Joseph S. Myers wrote: > On Fri, 5 Oct 2012, Kenneth Zadeck wrote: > >> +# define HOST_HALF_WIDE_INT_PRINT "h" > This may cause problems on hosts not supporting %hd (MinGW?), and there's > no real need for using "h" here given the promotion of short to int; you > can just use "" (rather than e.g. needing special handling in xm-mingw32.h > like is done for HOST_LONG_LONG_FORMAT). > 2012-10-5 Kenneth Zadeck * hwint.h (HOST_BITS_PER_HALF_WIDE_INT, HOST_HALF_WIDE_INT, HOST_HALF_WIDE_INT_PRINT, HOST_HALF_WIDE_INT_PRINT_C, HOST_HALF_WIDE_INT_PRINT_DEC, HOST_HALF_WIDE_INT_PRINT_DEC_C, HOST_HALF_WIDE_INT_PRINT_UNSIGNED, HOST_HALF_WIDE_INT_PRINT_HEX, HOST_HALF_WIDE_INT_PRINT_HEX_PURE): New symbols. (sext_hwi, zext_hwi): New functions. diff --git a/gcc/hwint.h b/gcc/hwint.h index ca47148..87371b5 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -77,6 +77,40 @@ extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; # endif #endif +/* Print support for half a host wide int. */ +#define HOST_BITS_PER_HALF_WIDE_INT (HOST_BITS_PER_WIDE_INT / 2) +#if HOST_BITS_PER_HALF_WIDE_INT == HOST_BITS_PER_LONG +# define HOST_HALF_WIDE_INT long +# define HOST_HALF_WIDE_INT_PRINT HOST_LONG_FORMAT +# define HOST_HALF_WIDE_INT_PRINT_C "L" +# define HOST_HALF_WIDE_INT_PRINT_DEC "%" HOST_HALF_WIDE_INT_PRINT "d" +# define HOST_HALF_WIDE_INT_PRINT_DEC_C HOST_HALF_WIDE_INT_PRINT_DEC HOST_HALF_WIDE_INT_PRINT_C +# define HOST_HALF_WIDE_INT_PRINT_UNSIGNED "%" HOST_HALF_WIDE_INT_PRINT "u" +# define HOST_HALF_WIDE_INT_PRINT_HEX "%#" HOST_HALF_WIDE_INT_PRINT "x" +# define HOST_HALF_WIDE_INT_PRINT_HEX_PURE "%" HOST_HALF_WIDE_INT_PRINT "x" +#elif HOST_BITS_PER_HALF_WIDE_INT == HOST_BITS_PER_INT +# define HOST_HALF_WIDE_INT int +# define HOST_HALF_WIDE_INT_PRINT "" +# define HOST_HALF_WIDE_INT_PRINT_C "" +# define HOST_HALF_WIDE_INT_PRINT_DEC "%" HOST_HALF_WIDE_INT_PRINT "d" +# define HOST_HALF_WIDE_INT_PRINT_DEC_C HOST_HALF_WIDE_INT_PRINT_DEC HOST_HALF_WIDE_INT_PRINT_C +# define HOST_HALF_WIDE_INT_PRINT_UNSIGNED "%" HOST_HALF_WIDE_INT_PRINT "u" +# define HOST_HALF_WIDE_INT_PRINT_HEX "%#" HOST_HALF_WIDE_INT_PRINT "x" +# define HOST_HALF_WIDE_INT_PRINT_HEX_PURE "%" HOST_HALF_WIDE_INT_PRINT "x" +#elif HOST_BITS_PER_HALF_WIDE_INT == HOST_BITS_PER_SHORT +# define HOST_HALF_WIDE_INT short +# define HOST_HALF_WIDE_INT_PRINT "" +# define HOST_HALF_WIDE_INT_PRINT_C "" +# define HOST_HALF_WIDE_INT_PRINT_DEC "%" HOST_HALF_WIDE_INT_PRINT "d" +# define HOST_HALF_WIDE_INT_PRINT_DEC_C HOST_HALF_WIDE_INT_PRINT_DEC HOST_HALF_WIDE_INT_PRINT_C +# define HOST_HALF_WIDE_INT_PRINT_UNSIGNED "%" HOST_HALF_WIDE_INT_PRINT "u" +# define HOST_HALF_WIDE_INT_PRINT_HEX "%#" HOST_HALF_WIDE_INT_PRINT "x" +# define HOST_HALF_WIDE_INT_PRINT_HEX_PURE "%" HOST_HALF_WIDE_INT_PRINT "x" +#else +#error Please add support for HOST_HALF_WIDE_INT +#endif + + #define HOST_WIDE_INT_1 HOST_WIDE_INT_C(1) /* This is a magic identifier which allows GCC to figure out the type @@ -94,9 +128,13 @@ typedef HOST_WIDE_INT __gcc_host_wide_int__; # if HOST_BITS_PER_WIDE_INT == 64 # define HOST_WIDE_INT_PRINT_DOUBLE_HEX \ "0x%" HOST_LONG_FORMAT "x%016" HOST_LONG_FORMAT "x" +# define HOST_WIDE_INT_PRINT_PADDED_HEX \ + "%016" HOST_LONG_FORMAT "x" # else # define HOST_WIDE_INT_PRINT_DOUBLE_HEX \ "0x%" HOST_LONG_FORMAT "x%08" HOST_LONG_FORMAT "x" +# define HOST_WIDE_INT_PRINT_PADDED_HEX \ + "%08" HOST_LONG_FORMAT "x" # endif #else # define HOST_WIDE_INT_PRINT HOST_LONG_LONG_FORMAT @@ -104,6 +142,8 @@ typedef HOST_WIDE_INT __gcc_host_wide_int__; /* We can assume that 'long long' is at least 64 bits. */ # define HOST_WIDE_INT_PRINT_DOUBLE_HEX \ "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x" +# define HOST_WIDE_INT_PRINT_PADDED_HEX \ + "%016" HOST_LONG_LONG_FORMAT "x" #endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */ #define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d" @@ -277,4 +317,32 @@ extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT); extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT); extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT); +/* Sign extend SRC starting from PREC. */ + +static inline HOST_WIDE_INT +sext_hwi (HOST_WIDE_INT src, int prec) +{ + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + { + int shift = HOST_BITS_PER_WIDE_INT - (prec & (HOST_BITS_PER_WIDE_INT - 1)); + return (src << shift) >> shift; + } +} + +/* Zero extend SRC starting from PREC. */ + +static inline HOST_WIDE_INT +zext_hwi (HOST_WIDE_INT src, int prec) +{ + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + return src & (((HOST_WIDE_INT)1 + << (prec & (HOST_BITS_PER_WIDE_INT - 1))) - 1); +} + + + #endif /* ! GCC_HWINT_H */