From patchwork Tue Apr 2 19:08:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Zadeck X-Patchwork-Id: 233124 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 43D1E2C014A for ; Wed, 3 Apr 2013 06:09:10 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=ws20jb+pFglAjKwdi 39QPt8Reax2fAeow5/AeQb0GV1a79qi+cmF8NqIqHCKLCJBAyjQ0I4EKdcasmYSW i/h8RsSRP2skA1bceo3PgN+2XVFg8NDwAi+D/gc6CCQT0DyfFjP+pJ9yuYhEJ/1b +Qpd88Sas1SGq3bFTRHXfiZRVk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=Oo8ikZHlvUwVuygcM2glMj1 iTak=; b=gvaz//rmYSzo9yX+1UbCqhSlU9Hebpj22rwXFayu2R6cuQAeTNPlN2x uqDgCDjDFGD/Z5DYcfQjxRjQ9EmhhQae5bJf4LAGmfcxnprH+YJbSIG5MfBM+0tD 6C1gWx4o1+aRnztH7+qLNUCT2jkGZNkZOf+IF7TTkwT0JlMvd/jI= Received: (qmail 11578 invoked by alias); 2 Apr 2013 19:09:00 -0000 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 Received: (qmail 11519 invoked by uid 89); 2 Apr 2013 19:08:52 -0000 X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE autolearn=ham version=3.3.1 Received: from mail-vc0-f182.google.com (HELO mail-vc0-f182.google.com) (209.85.220.182) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 02 Apr 2013 19:08:49 +0000 Received: by mail-vc0-f182.google.com with SMTP id ht11so814473vcb.13 for ; Tue, 02 Apr 2013 12:08:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-gm-message-state; bh=Tc7PK/1+GmCdUTGFVTyWDqIfL6UsxlUIAG4tMBjfxFs=; b=mqDYQAvSTAQwVtGIbz9XiqJlRAlFjHuWoyQjkZM2sKii8eglvqjpEKQ4nyAUIakFY+ 8XKKMXhdtAcLODCxgAoOl3raIYR/uE+KUQz0XDUpPNw81O6sOkUip4Zqq6mCJN7SoiNA POXvjNj4VeT1s4xkWJ4W4WVLng3hMRRZYwYPMKhBc5sZ0k2I+V+6/Kl+omZh1y49r2H3 JbA62doviiWSgmFrap7hKBOb+xe0R0nE5oV4v2iNDxu3Lc+ITKjnmhNoRRpucXcfvOID 8dPuB0N+GH7/mvQZGVTdZuYqe+VyGISFyIsFCZQC2FXrlenxobf5l+4Hn2QaW8QKgmd7 bumA== X-Received: by 10.52.75.65 with SMTP id a1mr11505847vdw.79.1364929727864; Tue, 02 Apr 2013 12:08:47 -0700 (PDT) Received: from [192.168.1.10] (pool-108-46-172-132.nycmny.fios.verizon.net. [108.46.172.132]) by mx.google.com with ESMTPS id q5sm2850161vdj.5.2013.04.02.12.08.41 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Apr 2013 12:08:42 -0700 (PDT) Message-ID: <515B2CB9.1000801@naturalbridge.com> Date: Tue, 02 Apr 2013 15:08:41 -0400 From: Kenneth Zadeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: Richard Biener CC: "Joseph S. Myers" , Mike Stump , gcc-patches , rdsandiford@googlemail.com, Ian Lance Taylor Subject: Re: patch to fix constant math - first small patch - patch ping for the next stage 1 References: <506C72C7.7090207@naturalbridge.com> <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> <512D51DE.6010005@naturalbridge.com> <51587791.9090105@naturalbridge.com> <515AE1CF.2020001@naturalbridge.com> In-Reply-To: X-Gm-Message-State: ALoCoQnp4DfSRwlZZACAePma92XTiSSVDrb28/YNtw1BSukEzYuWly/v89zp9O1JlovZ2eWnHiNA X-Virus-Found: No this time for sure. kenny On 04/02/2013 10:54 AM, Richard Biener wrote: > On Tue, Apr 2, 2013 at 3:49 PM, Kenneth Zadeck wrote: >> Richard, >> >> did everything that you asked here. bootstrapped and regtested on x86-64. >> ok to commit? > diff --git a/gcc/hwint.c b/gcc/hwint.c > index 330b42c..7e5b85c 100644 > --- a/gcc/hwint.c > +++ b/gcc/hwint.c > @@ -204,3 +204,33 @@ least_common_multiple (HOST_WIDE_INT a, HOST_WIDE_INT b) > { > return mul_hwi (abs_hwi (a) / gcd (a, b), abs_hwi (b)); > } > + > +#ifndef ENABLE_CHECKING > +/* Sign extend SRC starting from PREC. */ > + > +HOST_WIDE_INT > +sext_hwi (HOST_WIDE_INT src, unsigned int prec) > > this should go to hwint.h, and without the masking of prec. > while ... > > diff --git a/gcc/hwint.h b/gcc/hwint.h > index da62fad..9dddf05 100644 > --- a/gcc/hwint.h > +++ b/gcc/hwint.h > @@ -276,4 +316,42 @@ 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. */ > + > +#ifdef ENABLE_CHECKING > +extern HOST_WIDE_INT sext_hwi (HOST_WIDE_INT, unsigned int); > +#else > +static inline HOST_WIDE_INT > +sext_hwi (HOST_WIDE_INT src, unsigned int prec) > +{ > + gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT); > > this should go to hwint.c (also without masking prec). > > Richard. > > > > >> kenny >> >> >> On 04/02/2013 05:38 AM, Richard Biener wrote: >>> On Sun, Mar 31, 2013 at 7:51 PM, Kenneth Zadeck >>> wrote: >>>> richard, >>>> >>>> I was able to add everything except for the checking asserts. While I >>>> think that this is a reasonable idea, it is difficult to add that to a >>>> function that is defined in hwint.h because of circular includes. I >>>> could >>>> move this another file (though this appears to be the logical correct >>>> place >>>> for it), or we can do without the asserts. >>>> >>>> The context is that [sz]ext_hwi is that are used are over the compiler >>>> but >>>> are generally written out long. The wide-int class uses them also, but >>>> wide-int did not see like the right place for them to live and i believe >>>> that you suggested that i move them. >>>> >>>> ok to commit, or do you have a suggested resolution to the assert issue? >>> Yes, do >>> >>> #ifdef ENABLE_CHECKING >>> extern HOST_WIDE_INT sext_hwi (HOST_WIDE_INT, unsigned int); >>> #else >>> +/* Sign extend SRC starting from PREC. */ >>> + >>> +static inline HOST_WIDE_INT >>> +sext_hwi (HOST_WIDE_INT src, unsigned int prec) >>> +{ >>> + if (prec == HOST_BITS_PER_WIDE_INT) >>> + return src; >>> + else >>> + { >>> int shift = HOST_BITS_PER_WIDE_INT - prec; >>> + return (src << shift) >> shift; >>> + } >>> +} >>> #endif >>> >>> and for ENABLE_CHECKING only provide an out-of-line implementation >>> in hwint.c. That's how we did it with abs_hwi (well, we just do not >>> provide >>> an inline variant there - that's another possibility). >>> >>> Note that hwint.h is always included after config.h so the ENABLE_CHECKING >>> definition should be available. >>> >>> Richard. >>> >>>> kenny >>>> >>>> >>>> On 03/27/2013 10:13 AM, Richard Biener wrote: >>>>> On Wed, Feb 27, 2013 at 1:22 AM, Kenneth Zadeck >>>>> wrote: >>>>>> Here is the first of my wide int patches with joseph's comments and the >>>>>> patch rot removed. >>>>>> >>>>>> I would like to get these pre approved for the next stage 1. >>>>> + int shift = HOST_BITS_PER_WIDE_INT - (prec & >>>>> (HOST_BITS_PER_WIDE_INT - 1)); >>>>> >>>>> I think this should gcc_checking_assert that prec is not out of range >>>>> (any reason why prec is signed int and not unsigned int?) rather than >>>>> ignore bits in 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); >>>>> +} >>>>> >>>>> likewise. Also I'm not sure I agree about the signedness of the result >>>>> / >>>>> src. >>>>> zext_hwi (-1, HOST_BITS_PER_WIDE_INT) < 0 is true which is odd. >>>>> >>>>> The patch misses context of uses, so I'm not sure what the above >>>>> functions >>>>> are intended to do. >>>>> >>>>> Richard. >>>>> >>>>>> 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). >>>>>>> 2013-4-02 Kenneth Zadeck * hwint.c (sext_hwi, zext_hwi): New functions. * 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.c b/gcc/hwint.c index 330b42c..92d54a3 100644 --- a/gcc/hwint.c +++ b/gcc/hwint.c @@ -204,3 +204,35 @@ least_common_multiple (HOST_WIDE_INT a, HOST_WIDE_INT b) { return mul_hwi (abs_hwi (a) / gcd (a, b), abs_hwi (b)); } + +#ifndef ENABLE_CHECKING +/* Sign extend SRC starting from PREC. */ + +HOST_WIDE_INT +sext_hwi (HOST_WIDE_INT src, unsigned int prec) +{ + gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT); + + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + { + int shift = HOST_BITS_PER_WIDE_INT - prec; + return (src << shift) >> shift; + } +} + +/* Zero extend SRC starting from PREC. */ + +unsigned HOST_WIDE_INT +zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) +{ + gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT); + + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + return src & (((HOST_WIDE_INT)1 << prec) - 1); +} + +#endif diff --git a/gcc/hwint.h b/gcc/hwint.h index da62fad..dbf0239 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -76,6 +76,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 @@ -93,9 +127,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 @@ -103,6 +141,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" @@ -276,4 +316,36 @@ 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. */ + +#ifdef ENABLE_CHECKING +extern HOST_WIDE_INT sext_hwi (HOST_WIDE_INT, unsigned int); +#else +static inline HOST_WIDE_INT +sext_hwi (HOST_WIDE_INT src, unsigned int prec) +{ + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + { + int shift = HOST_BITS_PER_WIDE_INT - prec; + return (src << shift) >> shift; + } +} +#endif + +/* Zero extend SRC starting from PREC. */ +#ifdef ENABLE_CHECKING +extern unsigned HOST_WIDE_INT zext_hwi (unsigned HOST_WIDE_INT, unsigned int); +#else +static inline unsigned HOST_WIDE_INT +zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) +{ + if (prec == HOST_BITS_PER_WIDE_INT) + return src; + else + return src & (((HOST_WIDE_INT)1 << prec) - 1); +} +#endif + #endif /* ! GCC_HWINT_H */