From patchwork Sun Aug 12 20:15:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 176801 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 1E0C42C0082 for ; Mon, 13 Aug 2012 06:16:02 +1000 (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=1345407363; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:Date:From:To:Cc:Subject: Message-ID:MIME-Version:Content-Type:Content-Disposition: User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=rlbvtw8 Ebc9ClfBIc+2VH1GrQbQ=; b=hcHGP/9Fv+6vwJUGVcksT5g+V4kH2QGGPe5gyH4 LJSb/eJJQNnQ/RACduUUCuGfXNvwSVi6uKCWbFaWfVkmbAxH0OhcHLjr8iKun8DT wswuhjoVGlE2qWDMfCumoChkvUQNqTPz/sQbA1mKWNxmdZqTGrou9C83e8oqy661 SLXQ= 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:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=BICkQlk6JlCvnOSF0O1tgxODN7kymiwDdOFfcjI5p306Y+DOlhR0K9aedcUcIU 3YUEOw9JPuwIRou55uqFACpnQxg3L1+nbjYnr21wbI6L+1sDsXtaiHQhrPZqA4Eq nVx9EqBa1UOdIKIVJy9AiSmfzKWiYJpJ/pk88tfBS/e5Y=; Received: (qmail 27689 invoked by alias); 12 Aug 2012 20:15:53 -0000 Received: (qmail 27665 invoked by uid 22791); 12 Aug 2012 20:15:44 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_IV, TW_UC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ee0-f73.google.com (HELO mail-ee0-f73.google.com) (74.125.83.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Aug 2012 20:15:18 +0000 Received: by eeke49 with SMTP id e49so139550eek.2 for ; Sun, 12 Aug 2012 13:15:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:organization:user-agent:x-gm-message-state; bh=MULFCq+sAXYwg1wnVcC/opS3vgOEg1ZdX7NQCVdRqGQ=; b=R/VnVyMs+yVGK+Jj0KJRCou/XpFs7wef+arEIr6RSqA/QGL0yoVHVdUsFWVlFFm8mt 4ulIxPPs8s6jDY1b93wd5+XauSwrJroJPuI9ivtcDM+hMGFlQ7hrpElCIEDmhb11AOlp v7PCiLSUD+56JtFgqQwfQF11nr0PgM80CDz/y+WMe9JrWnTDT4JunuBgC3ykYdhSsX/8 evRaCLIi8rkYWRY02PbIfokNbIuWN0Qt3ufVBwufCitbZRiR8VpdhPvryjqhH7nTEyMe DBCdmLnhx3yvE6n4rz51cDOLgdcPQJ4U5u3TGErPpfeZQ5gmrsgJbRwE7dQT/1Wbf8Vj mafg== Received: by 10.14.194.132 with SMTP id m4mr7882222een.0.1344802516354; Sun, 12 Aug 2012 13:15:16 -0700 (PDT) Received: by 10.14.194.132 with SMTP id m4mr7882214een.0.1344802516263; Sun, 12 Aug 2012 13:15:16 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id 46si7646726eed.1.2012.08.12.13.15.16 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sun, 12 Aug 2012 13:15:16 -0700 (PDT) Received: from torture.tor.corp.google.com (torture.tor.corp.google.com [172.29.41.4]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id B190820004E; Sun, 12 Aug 2012 13:15:15 -0700 (PDT) Received: by torture.tor.corp.google.com (Postfix, from userid 54752) id 242BCC0890; Sun, 12 Aug 2012 16:15:15 -0400 (EDT) Date: Sun, 12 Aug 2012 16:15:15 -0400 From: Diego Novillo To: gcc-patches@gcc.gnu.org, Lawrence Crowl Cc: Richard Guenther , Richard Henderson Subject: Merge C++ conversion into trunk (5/6 - double_int rewrite) Message-ID: <20120812201515.GA14973@google.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQnGBa02g07De9f5LafR4vOKx8ILnJCKnMjsdkOcu83r03uVDhqjCLzD/0pW7b0HQ8Nmej7MSVVlaVk8lAlhuraklcVeN5ir/LpaQ8xYXDEH3Z1M/UpbPiXo+kroW1rSHEP7UK6aBgoonNFxQQe6pFifPau67Uf8snYfDgy7VVup25KU0XhqGTlE2RDDR/R6pnWnUg5OihPRrhBEn6nN/bN2uAI5OXLJTBB+8UY1S8/SqhDRAOQ= X-IsSubscribed: yes 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 This implements the double_int rewrite. See http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00711.html for details. Diego. 2012-08-12 Lawrence Crowl * hash-table.h (typedef double_int): Change to struct (POD). (double_int::make): New overloads for int to double-int conversion. (double_int::mask): New. (double_int::max_value): New. (double_int::min_value): New. (double_int::operator ++): New. (double_int::operator --): New. (double_int::operator *=): New. (double_int::operator +=): New. (double_int::operator -=): New. (double_int::to_signed): New. (double_int::to_unsigned): New. (double_int::fits_unsigned): New. (double_int::fits_signed): New. (double_int::fits): New. (double_int::trailing_zeros): New. (double_int::popcount): New. (double_int::multiple_of): New. (double_int::set_bit): New. (double_int::mul_with_sign): New. (double_int::operator * (binary)): New. (double_int::operator + (binary)): New. (double_int::operator - (binary)): New. (double_int::operator - (unary)): New. (double_int::operator ~ (unary)): New. (double_int::operator & (binary)): New. (double_int::operator | (binary)): New. (double_int::operator ^ (binary)): New. (double_int::and_not): New. (double_int::lshift): New. (double_int::rshift): New. (double_int::alshift): New. (double_int::arshift): New. (double_int::llshift): New. (double_int::lrshift): New. (double_int::lrotate): New. (double_int::rrotate): New. (double_int::div): New. (double_int::sdiv): New. (double_int::udiv): New. (double_int::mod): New. (double_int::smod): New. (double_int::umod): New. (double_int::divmod): New. (double_int::sdivmod): New. (double_int::udivmod): New. (double_int::ext): New. (double_int::zext): New. (double_int::sext): New. (double_int::is_zero): New. (double_int::is_one): New. (double_int::is_minus_one): New. (double_int::is_negative): New. (double_int::cmp): New. (double_int::ucmp): New. (double_int::scmp): New. (double_int::ult): New. (double_int::ugt): New. (double_int::slt): New. (double_int::sgt): New. (double_int::max): New. (double_int::smax): New. (double_int::umax): New. (double_int::min): New. (double_int::smin): New. (double_int::umin): New. (double_int::operator ==): New. (double_int::operator !=): New. (shwi_to_double_int): Change implementation to use member function. (double_int_minus_one): Likewise. (double_int_zero): Likewise. (double_int_one): Likewise. (double_int_two): Likewise. (double_int_ten): Likewise. (uhwi_to_double_int): Likewise. (double_int_to_shwi): Likewise. (double_int_to_uhwi): Likewise. (double_int_fits_in_uhwi_p): Likewise. (double_int_fits_in_shwi_p): Likewise. (double_int_fits_in_hwi_p): Likewise. (double_int_mul): Likewise. (double_int_mul_with_sign): Likewise. (double_int_add): Likewise. (double_int_sub): Likewise. (double_int_neg): Likewise. (double_int_div): Likewise. (double_int_sdiv): Likewise. (double_int_udiv): Likewise. (double_int_mod): Likewise. (double_int_smod): Likewise. (double_int_umod): Likewise. (double_int_divmod): Likewise. (double_int_sdivmod): Likewise. (double_int_udivmod): Likewise. (double_int_multiple_of): Likewise. (double_int_setbit): Likewise. (double_int_ctz): Likewise. (double_int_not): Likewise. (double_int_ior): Likewise. (double_int_and): Likewise. (double_int_and_not): Likewise. (double_int_xor): Likewise. (double_int_lshift): Likewise. (double_int_rshift): Likewise. (double_int_lrotate): Likewise. (double_int_rrotate): Likewise. (double_int_cmp): Likewise. (double_int_scmp): Likewise. (double_int_ucmp): Likewise. (double_int_max): Likewise. (double_int_smax): Likewise. (double_int_umax): Likewise. (double_int_min): Likewise. (double_int_smin): Likewise. (double_int_umin): Likewise. (double_int_ext): Likewise. (double_int_sext): Likewise. (double_int_zext): Likewise. (double_int_mask): Likewise. (double_int_max_value): Likewise. (double_int_min_value): Likewise. (double_int_zero_p): Likewise. (double_int_one_p): Likewise. (double_int_minus_one_p): Likewise. (double_int_equal_p): Likewise. (double_int_popcount): Likewise. * hash-table.c (double_int_mask): Reuse implementation for double_int::mask. (double_int_max_value): Likewise. (double_int_min_value): Likewise. (double_int_ext): Likewise. (double_int_zext): Likewise. (double_int_sext): Likewise. (double_int_mul_with_sign): Likewise. (double_int_divmod): Likewise. (double_int_sdivmod): Likewise. (double_int_udivmod): Likewise. (double_int_div): Likewise. (double_int_sdiv): Likewise. (double_int_udiv): Likewise. (double_int_mod): Likewise. (double_int_smod): Likewise. (double_int_umod): Likewise. (double_int_multiple_of): Likewise. (double_int_lshift): Likewise. (double_int_rshift): Likewise. (double_int_lrotate): Likewise. (double_int_rrotate): Likewise. (double_int_cmp): Likewise. (double_int_ucmp): Likewise. (double_int_scmp): Likewise. (double_int_max): Likewise. (double_int_smax): Likewise. (double_int_umax): Likewise. (double_int_min): Likewise. (double_int_smin): Likewise. (double_int_umin): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int_min): Likewise. (double_int::alshift): New. (double_int::arshift): New. (double_int::llshift): New. (double_int::lrshift): New. (double_int::ult): New. (double_int::ugt): New. (double_int::slt): New. (double_int::sgt): New. (double_int_setbit): Reuse implementation for double_int::set_bit, which avoids a name conflict with a macro. (double_int_double_int_ctz): Reuse implementation for double_int::trailing_zeros. (double_int_fits_in_shwi_p): Reuse implementation for double_int::fits_signed. (double_int_fits_in_hwi_p): Reuse implementation for double_int::fits. (double_int_mul): Reuse implementation for binary double_int::operator *. (double_int_add): Likewise. (double_int_sub): Likewise. (double_int_neg): Reuse implementation for unary double_int::operator -. (double_int_max_value): Likewise. * fixed-value.c: Change to use member functions introduced above. diff --git a/gcc/double-int.c b/gcc/double-int.c index 1204dc7..953f081 100644 --- a/gcc/double-int.c +++ b/gcc/double-int.c @@ -610,7 +610,7 @@ div_and_round_double (unsigned code, int uns, /* Returns mask for PREC bits. */ double_int -double_int_mask (unsigned prec) +double_int::mask (unsigned prec) { unsigned HOST_WIDE_INT m; double_int mask; @@ -635,20 +635,20 @@ double_int_mask (unsigned prec) of precision PREC. */ double_int -double_int_max_value (unsigned int prec, bool uns) +double_int::max_value (unsigned int prec, bool uns) { - return double_int_mask (prec - (uns ? 0 : 1)); + return double_int::mask (prec - (uns ? 0 : 1)); } /* Returns a minimum value for signed or unsigned integer of precision PREC. */ double_int -double_int_min_value (unsigned int prec, bool uns) +double_int::min_value (unsigned int prec, bool uns) { if (uns) return double_int_zero; - return double_int_lshift (double_int_one, prec - 1, prec, false); + return double_int_one.lshift (prec - 1, prec, false); } /* Clears the bits of CST over the precision PREC. If UNS is false, the bits @@ -659,20 +659,21 @@ double_int_min_value (unsigned int prec, bool uns) of CST, with the given signedness. */ double_int -double_int_ext (double_int cst, unsigned prec, bool uns) +double_int::ext (unsigned prec, bool uns) const { if (uns) - return double_int_zext (cst, prec); + return this->zext (prec); else - return double_int_sext (cst, prec); + return this->sext (prec); } -/* The same as double_int_ext with UNS = true. */ +/* The same as double_int::ext with UNS = true. */ double_int -double_int_zext (double_int cst, unsigned prec) +double_int::zext (unsigned prec) const { - double_int mask = double_int_mask (prec); + const double_int &cst = *this; + double_int mask = double_int::mask (prec); double_int r; r.low = cst.low & mask.low; @@ -681,12 +682,13 @@ double_int_zext (double_int cst, unsigned prec) return r; } -/* The same as double_int_ext with UNS = false. */ +/* The same as double_int::ext with UNS = false. */ double_int -double_int_sext (double_int cst, unsigned prec) +double_int::sext (unsigned prec) const { - double_int mask = double_int_mask (prec); + const double_int &cst = *this; + double_int mask = double_int::mask (prec); double_int r; unsigned HOST_WIDE_INT snum; @@ -714,8 +716,9 @@ double_int_sext (double_int cst, unsigned prec) /* Returns true if CST fits in signed HOST_WIDE_INT. */ bool -double_int_fits_in_shwi_p (double_int cst) +double_int::fits_signed () const { + const double_int &cst = *this; if (cst.high == 0) return (HOST_WIDE_INT) cst.low >= 0; else if (cst.high == -1) @@ -728,19 +731,20 @@ double_int_fits_in_shwi_p (double_int cst) unsigned HOST_WIDE_INT if UNS is true. */ bool -double_int_fits_in_hwi_p (double_int cst, bool uns) +double_int::fits (bool uns) const { if (uns) - return double_int_fits_in_uhwi_p (cst); + return this->fits_unsigned (); else - return double_int_fits_in_shwi_p (cst); + return this->fits_signed (); } /* Returns A * B. */ double_int -double_int_mul (double_int a, double_int b) +double_int::operator * (double_int b) const { + const double_int &a = *this; double_int ret; mul_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high); return ret; @@ -750,9 +754,9 @@ double_int_mul (double_int a, double_int b) *OVERFLOW is set to nonzero. */ double_int -double_int_mul_with_sign (double_int a, double_int b, - bool unsigned_p, int *overflow) +double_int::mul_with_sign (double_int b, bool unsigned_p, int *overflow) const { + const double_int &a = *this; double_int ret; *overflow = mul_double_with_sign (a.low, a.high, b.low, b.high, &ret.low, &ret.high, unsigned_p); @@ -762,8 +766,9 @@ double_int_mul_with_sign (double_int a, double_int b, /* Returns A + B. */ double_int -double_int_add (double_int a, double_int b) +double_int::operator + (double_int b) const { + const double_int &a = *this; double_int ret; add_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high); return ret; @@ -772,8 +777,9 @@ double_int_add (double_int a, double_int b) /* Returns A - B. */ double_int -double_int_sub (double_int a, double_int b) +double_int::operator - (double_int b) const { + const double_int &a = *this; double_int ret; neg_double (b.low, b.high, &b.low, &b.high); add_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high); @@ -783,8 +789,9 @@ double_int_sub (double_int a, double_int b) /* Returns -A. */ double_int -double_int_neg (double_int a) +double_int::operator - () const { + const double_int &a = *this; double_int ret; neg_double (a.low, a.high, &ret.low, &ret.high); return ret; @@ -796,9 +803,10 @@ double_int_neg (double_int a) stored to MOD. */ double_int -double_int_divmod (double_int a, double_int b, bool uns, unsigned code, - double_int *mod) +double_int::divmod (double_int b, bool uns, unsigned code, + double_int *mod) const { + const double_int &a = *this; double_int ret; div_and_round_double (code, uns, a.low, a.high, @@ -807,20 +815,20 @@ double_int_divmod (double_int a, double_int b, bool uns, unsigned code, return ret; } -/* The same as double_int_divmod with UNS = false. */ +/* The same as double_int::divmod with UNS = false. */ double_int -double_int_sdivmod (double_int a, double_int b, unsigned code, double_int *mod) +double_int::sdivmod (double_int b, unsigned code, double_int *mod) const { - return double_int_divmod (a, b, false, code, mod); + return this->divmod (b, false, code, mod); } -/* The same as double_int_divmod with UNS = true. */ +/* The same as double_int::divmod with UNS = true. */ double_int -double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod) +double_int::udivmod (double_int b, unsigned code, double_int *mod) const { - return double_int_divmod (a, b, true, code, mod); + return this->divmod (b, true, code, mod); } /* Returns A / B (computed as unsigned depending on UNS, and rounded as @@ -828,27 +836,27 @@ double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod) must be included before tree.h. */ double_int -double_int_div (double_int a, double_int b, bool uns, unsigned code) +double_int::div (double_int b, bool uns, unsigned code) const { double_int mod; - return double_int_divmod (a, b, uns, code, &mod); + return this->divmod (b, uns, code, &mod); } -/* The same as double_int_div with UNS = false. */ +/* The same as double_int::div with UNS = false. */ double_int -double_int_sdiv (double_int a, double_int b, unsigned code) +double_int::sdiv (double_int b, unsigned code) const { - return double_int_div (a, b, false, code); + return this->div (b, false, code); } -/* The same as double_int_div with UNS = true. */ +/* The same as double_int::div with UNS = true. */ double_int -double_int_udiv (double_int a, double_int b, unsigned code) +double_int::udiv (double_int b, unsigned code) const { - return double_int_div (a, b, true, code); + return this->div (b, true, code); } /* Returns A % B (computed as unsigned depending on UNS, and rounded as @@ -856,28 +864,28 @@ double_int_udiv (double_int a, double_int b, unsigned code) must be included before tree.h. */ double_int -double_int_mod (double_int a, double_int b, bool uns, unsigned code) +double_int::mod (double_int b, bool uns, unsigned code) const { double_int mod; - double_int_divmod (a, b, uns, code, &mod); + this->divmod (b, uns, code, &mod); return mod; } -/* The same as double_int_mod with UNS = false. */ +/* The same as double_int::mod with UNS = false. */ double_int -double_int_smod (double_int a, double_int b, unsigned code) +double_int::smod (double_int b, unsigned code) const { - return double_int_mod (a, b, false, code); + return this->mod (b, false, code); } -/* The same as double_int_mod with UNS = true. */ +/* The same as double_int::mod with UNS = true. */ double_int -double_int_umod (double_int a, double_int b, unsigned code) +double_int::umod (double_int b, unsigned code) const { - return double_int_mod (a, b, true, code); + return this->mod (b, true, code); } /* Return TRUE iff PRODUCT is an integral multiple of FACTOR, and return @@ -885,13 +893,13 @@ double_int_umod (double_int a, double_int b, unsigned code) unchanged. */ bool -double_int_multiple_of (double_int product, double_int factor, - bool unsigned_p, double_int *multiple) +double_int::multiple_of (double_int factor, + bool unsigned_p, double_int *multiple) const { double_int remainder; - double_int quotient = double_int_divmod (product, factor, unsigned_p, + double_int quotient = this->divmod (factor, unsigned_p, TRUNC_DIV_EXPR, &remainder); - if (double_int_zero_p (remainder)) + if (remainder.is_zero ()) { *multiple = quotient; return true; @@ -902,8 +910,9 @@ double_int_multiple_of (double_int product, double_int factor, /* Set BITPOS bit in A. */ double_int -double_int_setbit (double_int a, unsigned bitpos) +double_int::set_bit (unsigned bitpos) const { + double_int a = *this; if (bitpos < HOST_BITS_PER_WIDE_INT) a.low |= (unsigned HOST_WIDE_INT) 1 << bitpos; else @@ -914,8 +923,9 @@ double_int_setbit (double_int a, unsigned bitpos) /* Count trailing zeros in A. */ int -double_int_ctz (double_int a) +double_int::trailing_zeros () const { + const double_int &a = *this; unsigned HOST_WIDE_INT w = a.low ? a.low : (unsigned HOST_WIDE_INT) a.high; unsigned bits = a.low ? 0 : HOST_BITS_PER_WIDE_INT; if (!w) @@ -929,30 +939,76 @@ double_int_ctz (double_int a) otherwise use logical shift. */ double_int -double_int_lshift (double_int a, HOST_WIDE_INT count, unsigned int prec, bool arith) +double_int::lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const { + const double_int &a = *this; double_int ret; lshift_double (a.low, a.high, count, prec, &ret.low, &ret.high, arith); return ret; } -/* Shift A rigth by COUNT places keeping only PREC bits of result. Shift +/* Shift A right by COUNT places keeping only PREC bits of result. Shift left if COUNT is negative. ARITH true specifies arithmetic shifting; otherwise use logical shift. */ double_int -double_int_rshift (double_int a, HOST_WIDE_INT count, unsigned int prec, bool arith) +double_int::rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const { + const double_int &a = *this; double_int ret; lshift_double (a.low, a.high, -count, prec, &ret.low, &ret.high, arith); return ret; } +/* Arithmetic shift A left by COUNT places keeping only PREC bits of result. + Shift right if COUNT is negative. */ + +double_int +double_int::alshift (HOST_WIDE_INT count, unsigned int prec) const +{ + double_int r; + lshift_double (low, high, count, prec, &r.low, &r.high, true); + return r; +} + +/* Arithmetic shift A right by COUNT places keeping only PREC bits of result. + Shift left if COUNT is negative. */ + +double_int +double_int::arshift (HOST_WIDE_INT count, unsigned int prec) const +{ + double_int r; + lshift_double (low, high, -count, prec, &r.low, &r.high, true); + return r; +} + +/* Logical shift A left by COUNT places keeping only PREC bits of result. + Shift right if COUNT is negative. */ + +double_int +double_int::llshift (HOST_WIDE_INT count, unsigned int prec) const +{ + double_int r; + lshift_double (low, high, count, prec, &r.low, &r.high, false); + return r; +} + +/* Logical shift A right by COUNT places keeping only PREC bits of result. + Shift left if COUNT is negative. */ + +double_int +double_int::lrshift (HOST_WIDE_INT count, unsigned int prec) const +{ + double_int r; + lshift_double (low, high, -count, prec, &r.low, &r.high, false); + return r; +} + /* Rotate A left by COUNT places keeping only PREC bits of result. Rotate right if COUNT is negative. */ double_int -double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) +double_int::lrotate (HOST_WIDE_INT count, unsigned int prec) const { double_int t1, t2; @@ -960,17 +1016,17 @@ double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) if (count < 0) count += prec; - t1 = double_int_lshift (a, count, prec, false); - t2 = double_int_rshift (a, prec - count, prec, false); + t1 = this->lshift (count, prec, false); + t2 = this->rshift (prec - count, prec, false); - return double_int_ior (t1, t2); + return t1 | t2; } /* Rotate A rigth by COUNT places keeping only PREC bits of result. Rotate right if COUNT is negative. */ double_int -double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) +double_int::rrotate (HOST_WIDE_INT count, unsigned int prec) const { double_int t1, t2; @@ -978,30 +1034,31 @@ double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) if (count < 0) count += prec; - t1 = double_int_rshift (a, count, prec, false); - t2 = double_int_lshift (a, prec - count, prec, false); + t1 = this->rshift (count, prec, false); + t2 = this->lshift (prec - count, prec, false); - return double_int_ior (t1, t2); + return t1 | t2; } /* Returns -1 if A < B, 0 if A == B and 1 if A > B. Signedness of the comparison is given by UNS. */ int -double_int_cmp (double_int a, double_int b, bool uns) +double_int::cmp (double_int b, bool uns) const { if (uns) - return double_int_ucmp (a, b); + return this->ucmp (b); else - return double_int_scmp (a, b); + return this->scmp (b); } /* Compares two unsigned values A and B. Returns -1 if A < B, 0 if A == B, and 1 if A > B. */ int -double_int_ucmp (double_int a, double_int b) +double_int::ucmp (double_int b) const { + const double_int &a = *this; if ((unsigned HOST_WIDE_INT) a.high < (unsigned HOST_WIDE_INT) b.high) return -1; if ((unsigned HOST_WIDE_INT) a.high > (unsigned HOST_WIDE_INT) b.high) @@ -1018,8 +1075,9 @@ double_int_ucmp (double_int a, double_int b) and 1 if A > B. */ int -double_int_scmp (double_int a, double_int b) +double_int::scmp (double_int b) const { + const double_int &a = *this; if (a.high < b.high) return -1; if (a.high > b.high) @@ -1032,49 +1090,111 @@ double_int_scmp (double_int a, double_int b) return 0; } +/* Compares two unsigned values A and B for less-than. */ + +bool +double_int::ult (double_int b) const +{ + if ((unsigned HOST_WIDE_INT) high < (unsigned HOST_WIDE_INT) b.high) + return true; + if ((unsigned HOST_WIDE_INT) high > (unsigned HOST_WIDE_INT) b.high) + return false; + if (low < b.low) + return true; + return false; +} + +/* Compares two unsigned values A and B for greater-than. */ + +bool +double_int::ugt (double_int b) const +{ + if ((unsigned HOST_WIDE_INT) high > (unsigned HOST_WIDE_INT) b.high) + return true; + if ((unsigned HOST_WIDE_INT) high < (unsigned HOST_WIDE_INT) b.high) + return false; + if (low > b.low) + return true; + return false; +} + +/* Compares two signed values A and B for less-than. */ + +bool +double_int::slt (double_int b) const +{ + if (high < b.high) + return true; + if (high > b.high) + return false; + if (low < b.low) + return true; + return false; +} + +/* Compares two signed values A and B for greater-than. */ + +bool +double_int::sgt (double_int b) const +{ + if (high > b.high) + return true; + if (high < b.high) + return false; + if (low > b.low) + return true; + return false; +} + + /* Compares two values A and B. Returns max value. Signedness of the comparison is given by UNS. */ double_int -double_int_max (double_int a, double_int b, bool uns) +double_int::max (double_int b, bool uns) { - return (double_int_cmp (a, b, uns) == 1) ? a : b; + return (this->cmp (b, uns) == 1) ? *this : b; } /* Compares two signed values A and B. Returns max value. */ -double_int double_int_smax (double_int a, double_int b) +double_int +double_int::smax (double_int b) { - return (double_int_scmp (a, b) == 1) ? a : b; + return (this->scmp (b) == 1) ? *this : b; } /* Compares two unsigned values A and B. Returns max value. */ -double_int double_int_umax (double_int a, double_int b) +double_int +double_int::umax (double_int b) { - return (double_int_ucmp (a, b) == 1) ? a : b; + return (this->ucmp (b) == 1) ? *this : b; } /* Compares two values A and B. Returns mix value. Signedness of the comparison is given by UNS. */ -double_int double_int_min (double_int a, double_int b, bool uns) +double_int +double_int::min (double_int b, bool uns) { - return (double_int_cmp (a, b, uns) == -1) ? a : b; + return (this->cmp (b, uns) == -1) ? *this : b; } /* Compares two signed values A and B. Returns min value. */ -double_int double_int_smin (double_int a, double_int b) +double_int +double_int::smin (double_int b) { - return (double_int_scmp (a, b) == -1) ? a : b; + return (this->scmp (b) == -1) ? *this : b; } /* Compares two unsigned values A and B. Returns min value. */ -double_int double_int_umin (double_int a, double_int b) +double_int +double_int::umin (double_int b) { - return (double_int_ucmp (a, b) == -1) ? a : b; + return (this->ucmp (b) == -1) ? *this : b; } /* Splits last digit of *CST (taken as unsigned) in BASE and returns it. */ @@ -1102,19 +1222,19 @@ dump_double_int (FILE *file, double_int cst, bool uns) unsigned digits[100], n; int i; - if (double_int_zero_p (cst)) + if (cst.is_zero ()) { fprintf (file, "0"); return; } - if (!uns && double_int_negative_p (cst)) + if (!uns && cst.is_negative ()) { fprintf (file, "-"); - cst = double_int_neg (cst); + cst = -cst; } - for (n = 0; !double_int_zero_p (cst); n++) + for (n = 0; !cst.is_zero (); n++) digits[n] = double_int_split_digit (&cst, 10); for (i = n - 1; i >= 0; i--) fprintf (file, "%u", digits[i]); @@ -1130,10 +1250,10 @@ mpz_set_double_int (mpz_t result, double_int val, bool uns) bool negate = false; unsigned HOST_WIDE_INT vp[2]; - if (!uns && double_int_negative_p (val)) + if (!uns && val.is_negative ()) { negate = true; - val = double_int_neg (val); + val = -val; } vp[0] = val.low; @@ -1191,9 +1311,9 @@ mpz_get_double_int (const_tree type, mpz_t val, bool wrap) res.low = vp[0]; res.high = (HOST_WIDE_INT) vp[1]; - res = double_int_ext (res, TYPE_PRECISION (type), TYPE_UNSIGNED (type)); + res = res.ext (TYPE_PRECISION (type), TYPE_UNSIGNED (type)); if (mpz_sgn (val) < 0) - res = double_int_neg (res); + res = -res; return res; } diff --git a/gcc/double-int.h b/gcc/double-int.h index 4c4c1b3..b1c54c7 100644 --- a/gcc/double-int.h +++ b/gcc/double-int.h @@ -50,10 +50,132 @@ along with GCC; see the file COPYING3. If not see numbers with precision higher than HOST_WIDE_INT). It might be less confusing to have them both signed or both unsigned. */ -typedef struct +typedef struct double_int { +public: + /* Normally, we would define constructors to create instances. + Two things prevent us from doing so. + First, defining a constructor makes the class non-POD in C++03, + and we certainly want double_int to be a POD. + Second, the GCC conding conventions prefer explicit conversion, + and explicit conversion operators are not available until C++11. */ + + static double_int from_unsigned (unsigned HOST_WIDE_INT cst); + static double_int from_signed (HOST_WIDE_INT cst); + + /* No copy assignment operator or destructor to keep the type a POD. */ + + /* There are some special value-creation static member functions. */ + + static double_int mask (unsigned prec); + static double_int max_value (unsigned int prec, bool uns); + static double_int min_value (unsigned int prec, bool uns); + + /* The following functions are mutating operations. */ + + double_int &operator ++(); // prefix + double_int &operator --(); // prefix + double_int &operator *= (double_int); + double_int &operator += (double_int); + double_int &operator -= (double_int); + + /* The following functions are non-mutating operations. */ + + /* Conversion functions. */ + + HOST_WIDE_INT to_signed () const; + unsigned HOST_WIDE_INT to_unsigned () const; + + /* Conversion query functions. */ + + bool fits_unsigned() const; + bool fits_signed() const; + bool fits (bool uns) const; + + /* Attribute query functions. */ + + int trailing_zeros () const; + int popcount () const; + + /* Arithmetic query operations. */ + + bool multiple_of (double_int, bool, double_int *) const; + + /* Arithmetic operation functions. */ + + double_int set_bit (unsigned) const; + double_int mul_with_sign (double_int, bool, int *) const; + + double_int operator * (double_int b) const; + double_int operator + (double_int b) const; + double_int operator - (double_int b) const; + double_int operator - () const; + double_int operator ~ () const; + double_int operator & (double_int b) const; + double_int operator | (double_int b) const; + double_int operator ^ (double_int b) const; + double_int and_not (double_int b) const; + + double_int lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const; + double_int rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const; + double_int alshift (HOST_WIDE_INT count, unsigned int prec) const; + double_int arshift (HOST_WIDE_INT count, unsigned int prec) const; + double_int llshift (HOST_WIDE_INT count, unsigned int prec) const; + double_int lrshift (HOST_WIDE_INT count, unsigned int prec) const; + double_int lrotate (HOST_WIDE_INT count, unsigned int prec) const; + double_int rrotate (HOST_WIDE_INT count, unsigned int prec) const; + + /* You must ensure that double_int::ext is called on the operands + of the following operations, if the precision of the numbers + is less than HOST_BITS_PER_DOUBLE_INT bits. */ + double_int div (double_int, bool, unsigned) const; + double_int sdiv (double_int, unsigned) const; + double_int udiv (double_int, unsigned) const; + double_int mod (double_int, bool, unsigned) const; + double_int smod (double_int, unsigned) const; + double_int umod (double_int, unsigned) const; + double_int divmod (double_int, bool, unsigned, double_int *) const; + double_int sdivmod (double_int, unsigned, double_int *) const; + double_int udivmod (double_int, unsigned, double_int *) const; + + /* Precision control functions. */ + + double_int ext (unsigned prec, bool uns) const; + double_int zext (unsigned prec) const; + double_int sext (unsigned prec) const; + + /* Comparative functions. */ + + bool is_zero () const; + bool is_one () const; + bool is_minus_one () const; + bool is_negative () const; + + int cmp (double_int b, bool uns) const; + int ucmp (double_int b) const; + int scmp (double_int b) const; + + bool ult (double_int b) const; + bool ugt (double_int b) const; + bool slt (double_int b) const; + bool sgt (double_int b) const; + + double_int max (double_int b, bool uns); + double_int smax (double_int b); + double_int umax (double_int b); + + double_int min (double_int b, bool uns); + double_int smin (double_int b); + double_int umin (double_int b); + + bool operator == (double_int cst2) const; + bool operator != (double_int cst2) const; + + /* Please migrate away from using these member variables publically. */ + unsigned HOST_WIDE_INT low; HOST_WIDE_INT high; + } double_int; #define HOST_BITS_PER_DOUBLE_INT (2 * HOST_BITS_PER_WIDE_INT) @@ -63,66 +185,148 @@ typedef struct /* Constructs double_int from integer CST. The bits over the precision of HOST_WIDE_INT are filled with the sign bit. */ -static inline double_int -shwi_to_double_int (HOST_WIDE_INT cst) +inline +double_int double_int::from_signed (HOST_WIDE_INT cst) { double_int r; - r.low = (unsigned HOST_WIDE_INT) cst; r.high = cst < 0 ? -1 : 0; - return r; } +/* FIXME(crowl): Remove after converting callers. */ +static inline double_int +shwi_to_double_int (HOST_WIDE_INT cst) +{ + return double_int::from_signed (cst); +} + /* Some useful constants. */ +/* FIXME(crowl): Maybe remove after converting callers? + The problem is that a named constant would not be as optimizable, + while the functional syntax is more verbose. */ -#define double_int_minus_one (shwi_to_double_int (-1)) -#define double_int_zero (shwi_to_double_int (0)) -#define double_int_one (shwi_to_double_int (1)) -#define double_int_two (shwi_to_double_int (2)) -#define double_int_ten (shwi_to_double_int (10)) +#define double_int_minus_one (double_int::from_signed (-1)) +#define double_int_zero (double_int::from_signed (0)) +#define double_int_one (double_int::from_signed (1)) +#define double_int_two (double_int::from_signed (2)) +#define double_int_ten (double_int::from_signed (10)) /* Constructs double_int from unsigned integer CST. The bits over the precision of HOST_WIDE_INT are filled with zeros. */ -static inline double_int -uhwi_to_double_int (unsigned HOST_WIDE_INT cst) +inline +double_int double_int::from_unsigned (unsigned HOST_WIDE_INT cst) { double_int r; - r.low = cst; r.high = 0; - return r; } +/* FIXME(crowl): Remove after converting callers. */ +static inline double_int +uhwi_to_double_int (unsigned HOST_WIDE_INT cst) +{ + return double_int::from_unsigned (cst); +} + +inline double_int & +double_int::operator ++ () +{ + *this + double_int_one; + return *this; +} + +inline double_int & +double_int::operator -- () +{ + *this - double_int_one; + return *this; +} + +inline double_int & +double_int::operator *= (double_int b) +{ + *this = *this * b; + return *this; +} + +inline double_int & +double_int::operator += (double_int b) +{ + *this = *this + b; + return *this; +} + +inline double_int & +double_int::operator -= (double_int b) +{ + *this = *this - b; + return *this; +} + /* Returns value of CST as a signed number. CST must satisfy - double_int_fits_in_shwi_p. */ + double_int::fits_signed. */ +inline HOST_WIDE_INT +double_int::to_signed () const +{ + return (HOST_WIDE_INT) low; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline HOST_WIDE_INT double_int_to_shwi (double_int cst) { - return (HOST_WIDE_INT) cst.low; + return cst.to_signed (); } /* Returns value of CST as an unsigned number. CST must satisfy - double_int_fits_in_uhwi_p. */ + double_int::fits_unsigned. */ + +inline unsigned HOST_WIDE_INT +double_int::to_unsigned () const +{ + return low; +} +/* FIXME(crowl): Remove after converting callers. */ static inline unsigned HOST_WIDE_INT double_int_to_uhwi (double_int cst) { - return cst.low; + return cst.to_unsigned (); } -bool double_int_fits_in_hwi_p (double_int, bool); -bool double_int_fits_in_shwi_p (double_int); - /* Returns true if CST fits in unsigned HOST_WIDE_INT. */ +inline bool +double_int::fits_unsigned () const +{ + return high == 0; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline bool double_int_fits_in_uhwi_p (double_int cst) { - return cst.high == 0; + return cst.fits_unsigned (); +} + +/* Returns true if CST fits in signed HOST_WIDE_INT. */ + +/* FIXME(crowl): Remove after converting callers. */ +inline bool +double_int_fits_in_shwi_p (double_int cst) +{ + return cst.fits_signed (); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline bool +double_int_fits_in_hwi_p (double_int cst, bool uns) +{ + return cst.fits (uns); } /* The following operations perform arithmetics modulo 2^precision, @@ -130,88 +334,258 @@ double_int_fits_in_uhwi_p (double_int cst) you are representing numbers with precision less than HOST_BITS_PER_DOUBLE_INT bits. */ -double_int double_int_mul (double_int, double_int); -double_int double_int_mul_with_sign (double_int, double_int, bool, int *); -double_int double_int_add (double_int, double_int); -double_int double_int_sub (double_int, double_int); -double_int double_int_neg (double_int); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_mul (double_int a, double_int b) +{ + return a * b; +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_mul_with_sign (double_int a, double_int b, + bool unsigned_p, int *overflow) +{ + return a.mul_with_sign (b, unsigned_p, overflow); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_add (double_int a, double_int b) +{ + return a + b; +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_sub (double_int a, double_int b) +{ + return a - b; +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_neg (double_int a) +{ + return -a; +} /* You must ensure that double_int_ext is called on the operands of the following operations, if the precision of the numbers is less than HOST_BITS_PER_DOUBLE_INT bits. */ -double_int double_int_div (double_int, double_int, bool, unsigned); -double_int double_int_sdiv (double_int, double_int, unsigned); -double_int double_int_udiv (double_int, double_int, unsigned); -double_int double_int_mod (double_int, double_int, bool, unsigned); -double_int double_int_smod (double_int, double_int, unsigned); -double_int double_int_umod (double_int, double_int, unsigned); -double_int double_int_divmod (double_int, double_int, bool, unsigned, double_int *); -double_int double_int_sdivmod (double_int, double_int, unsigned, double_int *); -double_int double_int_udivmod (double_int, double_int, unsigned, double_int *); -bool double_int_multiple_of (double_int, double_int, bool, double_int *); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_div (double_int a, double_int b, bool uns, unsigned code) +{ + return a.div (b, uns, code); +} -double_int double_int_setbit (double_int, unsigned); -int double_int_ctz (double_int); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_sdiv (double_int a, double_int b, unsigned code) +{ + return a.sdiv (b, code); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_udiv (double_int a, double_int b, unsigned code) +{ + return a.udiv (b, code); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_mod (double_int a, double_int b, bool uns, unsigned code) +{ + return a.mod (b, uns, code); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_smod (double_int a, double_int b, unsigned code) +{ + return a.smod (b, code); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_umod (double_int a, double_int b, unsigned code) +{ + return a.umod (b, code); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_divmod (double_int a, double_int b, bool uns, + unsigned code, double_int *mod) +{ + return a.divmod (b, uns, code, mod); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_sdivmod (double_int a, double_int b, unsigned code, double_int *mod) +{ + return a.sdivmod (b, code, mod); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_udivmod (double_int a, double_int b, unsigned code, double_int *mod) +{ + return a.udivmod (b, code, mod); +} + +/***/ + +/* FIXME(crowl): Remove after converting callers. */ +inline bool +double_int_multiple_of (double_int product, double_int factor, + bool unsigned_p, double_int *multiple) +{ + return product.multiple_of (factor, unsigned_p, multiple); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_setbit (double_int a, unsigned bitpos) +{ + return a.set_bit (bitpos); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline int +double_int_ctz (double_int a) +{ + return a.trailing_zeros (); +} /* Logical operations. */ /* Returns ~A. */ +inline double_int +double_int::operator ~ () const +{ + double_int result; + result.low = ~low; + result.high = ~high; + return result; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline double_int double_int_not (double_int a) { - a.low = ~a.low; - a.high = ~a.high; - return a; + return ~a; } /* Returns A | B. */ +inline double_int +double_int::operator | (double_int b) const +{ + double_int result; + result.low = low | b.low; + result.high = high | b.high; + return result; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline double_int double_int_ior (double_int a, double_int b) { - a.low |= b.low; - a.high |= b.high; - return a; + return a | b; } /* Returns A & B. */ +inline double_int +double_int::operator & (double_int b) const +{ + double_int result; + result.low = low & b.low; + result.high = high & b.high; + return result; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline double_int double_int_and (double_int a, double_int b) { - a.low &= b.low; - a.high &= b.high; - return a; + return a & b; } /* Returns A & ~B. */ +inline double_int +double_int::and_not (double_int b) const +{ + double_int result; + result.low = low & ~b.low; + result.high = high & ~b.high; + return result; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline double_int double_int_and_not (double_int a, double_int b) { - a.low &= ~b.low; - a.high &= ~b.high; - return a; + return a.and_not (b); } /* Returns A ^ B. */ +inline double_int +double_int::operator ^ (double_int b) const +{ + double_int result; + result.low = low ^ b.low; + result.high = high ^ b.high; + return result; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline double_int double_int_xor (double_int a, double_int b) { - a.low ^= b.low; - a.high ^= b.high; - return a; + return a ^ b; } /* Shift operations. */ -double_int double_int_lshift (double_int, HOST_WIDE_INT, unsigned int, bool); -double_int double_int_rshift (double_int, HOST_WIDE_INT, unsigned int, bool); -double_int double_int_lrotate (double_int, HOST_WIDE_INT, unsigned int); -double_int double_int_rrotate (double_int, HOST_WIDE_INT, unsigned int); + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_lshift (double_int a, HOST_WIDE_INT count, unsigned int prec, + bool arith) +{ + return a.lshift (count, prec, arith); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_rshift (double_int a, HOST_WIDE_INT count, unsigned int prec, + bool arith) +{ + return a.rshift (count, prec, arith); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_lrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) +{ + return a.lrotate (count, prec); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_rrotate (double_int a, HOST_WIDE_INT count, unsigned int prec) +{ + return a.rrotate (count, prec); +} /* Returns true if CST is negative. Of course, CST is considered to be signed. */ @@ -222,29 +596,115 @@ double_int_negative_p (double_int cst) return cst.high < 0; } -int double_int_cmp (double_int, double_int, bool); -int double_int_scmp (double_int, double_int); -int double_int_ucmp (double_int, double_int); +/* FIXME(crowl): Remove after converting callers. */ +inline int +double_int_cmp (double_int a, double_int b, bool uns) +{ + return a.cmp (b, uns); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline int +double_int_scmp (double_int a, double_int b) +{ + return a.scmp (b); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline int +double_int_ucmp (double_int a, double_int b) +{ + return a.ucmp (b); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_max (double_int a, double_int b, bool uns) +{ + return a.max (b, uns); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_smax (double_int a, double_int b) +{ + return a.smax (b); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_umax (double_int a, double_int b) +{ + return a.umax (b); +} -double_int double_int_max (double_int, double_int, bool); -double_int double_int_smax (double_int, double_int); -double_int double_int_umax (double_int, double_int); -double_int double_int_min (double_int, double_int, bool); -double_int double_int_smin (double_int, double_int); -double_int double_int_umin (double_int, double_int); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_min (double_int a, double_int b, bool uns) +{ + return a.min (b, uns); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_smin (double_int a, double_int b) +{ + return a.smin (b); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_umin (double_int a, double_int b) +{ + return a.umin (b); +} void dump_double_int (FILE *, double_int, bool); /* Zero and sign extension of numbers in smaller precisions. */ -double_int double_int_ext (double_int, unsigned, bool); -double_int double_int_sext (double_int, unsigned); -double_int double_int_zext (double_int, unsigned); -double_int double_int_mask (unsigned); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_ext (double_int a, unsigned prec, bool uns) +{ + return a.ext (prec, uns); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_sext (double_int a, unsigned prec) +{ + return a.sext (prec); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_zext (double_int a, unsigned prec) +{ + return a.zext (prec); +} -double_int double_int_max_value (unsigned int, bool); -double_int double_int_min_value (unsigned int, bool); +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_mask (unsigned prec) +{ + return double_int::mask (prec); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_max_value (unsigned int prec, bool uns) +{ + return double_int::max_value (prec, uns); +} + +/* FIXME(crowl): Remove after converting callers. */ +inline double_int +double_int_min_value (unsigned int prec, bool uns) +{ + return double_int::min_value (prec, uns); +} #define ALL_ONES (~((unsigned HOST_WIDE_INT) 0)) @@ -254,69 +714,128 @@ double_int double_int_min_value (unsigned int, bool); /* Returns true if CST is zero. */ +inline bool +double_int::is_zero () const +{ + return low == 0 && high == 0; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline bool double_int_zero_p (double_int cst) { - return cst.low == 0 && cst.high == 0; + return cst.is_zero (); } /* Returns true if CST is one. */ +inline bool +double_int::is_one () const +{ + return low == 1 && high == 0; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline bool double_int_one_p (double_int cst) { - return cst.low == 1 && cst.high == 0; + return cst.is_one (); } /* Returns true if CST is minus one. */ +inline bool +double_int::is_minus_one () const +{ + return low == ALL_ONES && high == -1; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline bool double_int_minus_one_p (double_int cst) { - return (cst.low == ALL_ONES && cst.high == -1); + return cst.is_minus_one (); +} + +/* Returns true if CST is negative. */ + +inline bool +double_int::is_negative () const +{ + return high < 0; } /* Returns true if CST1 == CST2. */ +inline bool +double_int::operator == (double_int cst2) const +{ + return low == cst2.low && high == cst2.high; +} + +/* FIXME(crowl): Remove after converting callers. */ static inline bool double_int_equal_p (double_int cst1, double_int cst2) { - return cst1.low == cst2.low && cst1.high == cst2.high; + return cst1 == cst2; +} + +/* Returns true if CST1 != CST2. */ + +inline bool +double_int::operator != (double_int cst2) const +{ + return low != cst2.low || high != cst2.high; } /* Return number of set bits of CST. */ +inline int +double_int::popcount () const +{ + return popcount_hwi (high) + popcount_hwi (low); +} + +/* FIXME(crowl): Remove after converting callers. */ static inline int double_int_popcount (double_int cst) { - return popcount_hwi (cst.high) + popcount_hwi (cst.low); + return cst.popcount (); } /* Legacy interface with decomposed high/low parts. */ +/* FIXME(crowl): Remove after converting callers. */ extern int add_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool); +/* FIXME(crowl): Remove after converting callers. */ #define add_double(l1,h1,l2,h2,lv,hv) \ add_double_with_sign (l1, h1, l2, h2, lv, hv, false) +/* FIXME(crowl): Remove after converting callers. */ extern int neg_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *); +/* FIXME(crowl): Remove after converting callers. */ extern int mul_double_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool); +/* FIXME(crowl): Remove after converting callers. */ extern int mul_double_wide_with_sign (unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool); +/* FIXME(crowl): Remove after converting callers. */ #define mul_double(l1,h1,l2,h2,lv,hv) \ mul_double_with_sign (l1, h1, l2, h2, lv, hv, false) +/* FIXME(crowl): Remove after converting callers. */ extern void lshift_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT, HOST_WIDE_INT, unsigned int, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *, bool); +/* FIXME(crowl): Remove after converting callers. */ extern int div_and_round_double (unsigned, int, unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT, HOST_WIDE_INT, unsigned HOST_WIDE_INT *, diff --git a/gcc/fixed-value.c b/gcc/fixed-value.c index 97aa8b5..9a34bc5 100644 --- a/gcc/fixed-value.c +++ b/gcc/fixed-value.c @@ -111,13 +111,11 @@ fixed_from_string (FIXED_VALUE_TYPE *f, const char *str, enum machine_mode mode) /* From the spec, we need to evaluate 1 to the maximal value. */ f->data.low = -1; f->data.high = -1; - f->data = double_int_ext (f->data, - GET_MODE_FBIT (f->mode) - + GET_MODE_IBIT (f->mode), 1); + f->data = f->data.zext (GET_MODE_FBIT (f->mode) + + GET_MODE_IBIT (f->mode)); } else - f->data = double_int_ext (f->data, - SIGNED_FIXED_POINT_MODE_P (f->mode) + f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode) + GET_MODE_FBIT (f->mode) + GET_MODE_IBIT (f->mode), UNSIGNED_FIXED_POINT_MODE_P (f->mode)); @@ -159,8 +157,8 @@ fixed_saturate1 (enum machine_mode mode, double_int a, double_int *f, double_int max; max.low = -1; max.high = -1; - max = double_int_ext (max, i_f_bits, 1); - if (double_int_cmp (a, max, 1) == 1) + max = max.zext (i_f_bits); + if (a.ugt (max)) { if (sat_p) *f = max; @@ -173,21 +171,19 @@ fixed_saturate1 (enum machine_mode mode, double_int a, double_int *f, double_int max, min; max.high = -1; max.low = -1; - max = double_int_ext (max, i_f_bits, 1); + max = max.zext (i_f_bits); min.high = 0; min.low = 1; - lshift_double (min.low, min.high, i_f_bits, - HOST_BITS_PER_DOUBLE_INT, - &min.low, &min.high, 1); - min = double_int_ext (min, 1 + i_f_bits, 0); - if (double_int_cmp (a, max, 0) == 1) + min = min.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT); + min = min.sext (1 + i_f_bits); + if (a.sgt (max)) { if (sat_p) *f = max; else overflow_p = true; } - else if (double_int_cmp (a, min, 0) == -1) + else if (a.slt (min)) { if (sat_p) *f = min; @@ -221,10 +217,10 @@ fixed_saturate2 (enum machine_mode mode, double_int a_high, double_int a_low, max_r.low = 0; max_s.high = -1; max_s.low = -1; - max_s = double_int_ext (max_s, i_f_bits, 1); - if (double_int_cmp (a_high, max_r, 1) == 1 - || (double_int_equal_p (a_high, max_r) && - double_int_cmp (a_low, max_s, 1) == 1)) + max_s = max_s.zext (i_f_bits); + if (a_high.ugt (max_r) + || (a_high == max_r && + a_low.ugt (max_s))) { if (sat_p) *f = max_s; @@ -239,27 +235,25 @@ fixed_saturate2 (enum machine_mode mode, double_int a_high, double_int a_low, max_r.low = 0; max_s.high = -1; max_s.low = -1; - max_s = double_int_ext (max_s, i_f_bits, 1); + max_s = max_s.zext (i_f_bits); min_r.high = -1; min_r.low = -1; min_s.high = 0; min_s.low = 1; - lshift_double (min_s.low, min_s.high, i_f_bits, - HOST_BITS_PER_DOUBLE_INT, - &min_s.low, &min_s.high, 1); - min_s = double_int_ext (min_s, 1 + i_f_bits, 0); - if (double_int_cmp (a_high, max_r, 0) == 1 - || (double_int_equal_p (a_high, max_r) && - double_int_cmp (a_low, max_s, 1) == 1)) + min_s = min_s.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT); + min_s = min_s.sext (1 + i_f_bits); + if (a_high.sgt (max_r) + || (a_high == max_r && + a_low.ugt (max_s))) { if (sat_p) *f = max_s; else overflow_p = true; } - else if (double_int_cmp (a_high, min_r, 0) == -1 - || (double_int_equal_p (a_high, min_r) && - double_int_cmp (a_low, min_s, 1) == -1)) + else if (a_high.slt (min_r) + || (a_high == min_r && + a_low.ult (min_s))) { if (sat_p) *f = min_s; @@ -297,19 +291,19 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, /* This was a conditional expression but it triggered a bug in Sun C 5.5. */ if (subtract_p) - temp = double_int_neg (b->data); + temp = -b->data; else temp = b->data; unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); f->mode = a->mode; - f->data = double_int_add (a->data, temp); + f->data = a->data + temp; if (unsigned_p) /* Unsigned type. */ { if (subtract_p) /* Unsigned subtraction. */ { - if (double_int_cmp (a->data, b->data, 1) == -1) + if (a->data.ult (b->data)) { if (sat_p) { @@ -322,9 +316,9 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, } else /* Unsigned addition. */ { - f->data = double_int_ext (f->data, i_f_bits, 1); - if (double_int_cmp (f->data, a->data, 1) == -1 - || double_int_cmp (f->data, b->data, 1) == -1) + f->data = f->data.zext (i_f_bits); + if (f->data.ult (a->data) + || f->data.ult (b->data)) { if (sat_p) { @@ -353,22 +347,17 @@ do_fixed_add (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, { f->data.low = 1; f->data.high = 0; - lshift_double (f->data.low, f->data.high, i_f_bits, - HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, 1); + f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT); if (get_fixed_sign_bit (a->data, i_f_bits) == 0) { - double_int one; - one.low = 1; - one.high = 0; - f->data = double_int_sub (f->data, one); + --f->data; } } else overflow_p = true; } } - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); return overflow_p; } @@ -386,11 +375,10 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, f->mode = a->mode; if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT) { - f->data = double_int_mul (a->data, b->data); - lshift_double (f->data.low, f->data.high, - (-GET_MODE_FBIT (f->mode)), + f->data = a->data * b->data; + f->data = f->data.lshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, !unsigned_p); + !unsigned_p); overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); } else @@ -412,43 +400,43 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, b_low.high = 0; /* Perform four multiplications. */ - low_low = double_int_mul (a_low, b_low); - low_high = double_int_mul (a_low, b_high); - high_low = double_int_mul (a_high, b_low); - high_high = double_int_mul (a_high, b_high); + low_low = a_low * b_low; + low_high = a_low * b_high; + high_low = a_high * b_low; + high_high = a_high * b_high; /* Accumulate four results to {r, s}. */ temp1.high = high_low.low; temp1.low = 0; - s = double_int_add (low_low, temp1); - if (double_int_cmp (s, low_low, 1) == -1 - || double_int_cmp (s, temp1, 1) == -1) + s = low_low + temp1; + if (s.ult (low_low) + || s.ult (temp1)) carry ++; /* Carry */ temp1.high = s.high; temp1.low = s.low; temp2.high = low_high.low; temp2.low = 0; - s = double_int_add (temp1, temp2); - if (double_int_cmp (s, temp1, 1) == -1 - || double_int_cmp (s, temp2, 1) == -1) + s = temp1 + temp2; + if (s.ult (temp1) + || s.ult (temp2)) carry ++; /* Carry */ temp1.low = high_low.high; temp1.high = 0; - r = double_int_add (high_high, temp1); + r = high_high + temp1; temp1.low = low_high.high; temp1.high = 0; - r = double_int_add (r, temp1); + r += temp1; temp1.low = carry; temp1.high = 0; - r = double_int_add (r, temp1); + r += temp1; /* We need to subtract b from r, if a < 0. */ if (!unsigned_p && a->data.high < 0) - r = double_int_sub (r, b->data); + r -= b->data; /* We need to subtract a from r, if b < 0. */ if (!unsigned_p && b->data.high < 0) - r = double_int_sub (r, a->data); + r -= a->data; /* Shift right the result by FBIT. */ if (GET_MODE_FBIT (f->mode) == HOST_BITS_PER_DOUBLE_INT) @@ -470,29 +458,23 @@ do_fixed_multiply (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, } else { - lshift_double (s.low, s.high, - (-GET_MODE_FBIT (f->mode)), - HOST_BITS_PER_DOUBLE_INT, - &s.low, &s.high, 0); - lshift_double (r.low, r.high, - (HOST_BITS_PER_DOUBLE_INT + s = s.llshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT); + f->data = r.llshift ((HOST_BITS_PER_DOUBLE_INT - GET_MODE_FBIT (f->mode)), - HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, 0); + HOST_BITS_PER_DOUBLE_INT); f->data.low = f->data.low | s.low; f->data.high = f->data.high | s.high; s.low = f->data.low; s.high = f->data.high; - lshift_double (r.low, r.high, - (-GET_MODE_FBIT (f->mode)), + r = r.lshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT, - &r.low, &r.high, !unsigned_p); + !unsigned_p); } overflow_p = fixed_saturate2 (f->mode, r, s, &f->data, sat_p); } - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); return overflow_p; } @@ -510,11 +492,10 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, f->mode = a->mode; if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT) { - lshift_double (a->data.low, a->data.high, - GET_MODE_FBIT (f->mode), + f->data = a->data.lshift (GET_MODE_FBIT (f->mode), HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, !unsigned_p); - f->data = double_int_div (f->data, b->data, unsigned_p, TRUNC_DIV_EXPR); + !unsigned_p); + f->data = f->data.div (b->data, unsigned_p, TRUNC_DIV_EXPR); overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); } else @@ -527,7 +508,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, /* If a < 0, negate a. */ if (!unsigned_p && a->data.high < 0) { - pos_a = double_int_neg (a->data); + pos_a = -a->data; num_of_neg ++; } else @@ -536,7 +517,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, /* If b < 0, negate b. */ if (!unsigned_p && b->data.high < 0) { - pos_b = double_int_neg (b->data); + pos_b = -b->data; num_of_neg ++; } else @@ -551,24 +532,15 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, } else { - lshift_double (pos_a.low, pos_a.high, - GET_MODE_FBIT (f->mode), - HOST_BITS_PER_DOUBLE_INT, - &s.low, &s.high, 0); - lshift_double (pos_a.low, pos_a.high, - - (HOST_BITS_PER_DOUBLE_INT + s = pos_a.llshift (GET_MODE_FBIT (f->mode), HOST_BITS_PER_DOUBLE_INT); + r = pos_a.llshift (- (HOST_BITS_PER_DOUBLE_INT - GET_MODE_FBIT (f->mode)), - HOST_BITS_PER_DOUBLE_INT, - &r.low, &r.high, 0); + HOST_BITS_PER_DOUBLE_INT); } /* Divide r by pos_b to quo_r. The remainder is in mod. */ - div_and_round_double (TRUNC_DIV_EXPR, 1, r.low, r.high, pos_b.low, - pos_b.high, &quo_r.low, &quo_r.high, &mod.low, - &mod.high); - - quo_s.high = 0; - quo_s.low = 0; + quo_r = r.divmod (pos_b, 1, TRUNC_DIV_EXPR, &mod); + quo_s = double_int_zero; for (i = 0; i < HOST_BITS_PER_DOUBLE_INT; i++) { @@ -576,37 +548,34 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, int leftmost_mod = (mod.high < 0); /* Shift left mod by 1 bit. */ - lshift_double (mod.low, mod.high, 1, HOST_BITS_PER_DOUBLE_INT, - &mod.low, &mod.high, 0); + mod = mod.llshift (1, HOST_BITS_PER_DOUBLE_INT); /* Test the leftmost bit of s to add to mod. */ if (s.high < 0) mod.low += 1; /* Shift left quo_s by 1 bit. */ - lshift_double (quo_s.low, quo_s.high, 1, HOST_BITS_PER_DOUBLE_INT, - &quo_s.low, &quo_s.high, 0); + quo_s = quo_s.llshift (1, HOST_BITS_PER_DOUBLE_INT); /* Try to calculate (mod - pos_b). */ - temp = double_int_sub (mod, pos_b); + temp = mod - pos_b; - if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1) + if (leftmost_mod == 1 || mod.ucmp (pos_b) != -1) { quo_s.low += 1; mod = temp; } /* Shift left s by 1 bit. */ - lshift_double (s.low, s.high, 1, HOST_BITS_PER_DOUBLE_INT, - &s.low, &s.high, 0); + s = s.llshift (1, HOST_BITS_PER_DOUBLE_INT); } if (num_of_neg == 1) { - quo_s = double_int_neg (quo_s); + quo_s = -quo_s; if (quo_s.high == 0 && quo_s.low == 0) - quo_r = double_int_neg (quo_r); + quo_r = -quo_r; else { quo_r.low = ~quo_r.low; @@ -618,7 +587,7 @@ do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, overflow_p = fixed_saturate2 (f->mode, quo_r, quo_s, &f->data, sat_p); } - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); return overflow_p; } @@ -643,10 +612,9 @@ do_fixed_shift (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT || (!left_p)) { - lshift_double (a->data.low, a->data.high, - left_p ? b->data.low : (-b->data.low), + f->data = a->data.lshift (left_p ? b->data.low : (-b->data.low), HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, !unsigned_p); + !unsigned_p); if (left_p) /* Only left shift saturates. */ overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); } @@ -661,23 +629,20 @@ do_fixed_shift (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, } else { - lshift_double (a->data.low, a->data.high, - b->data.low, + temp_low = a->data.lshift (b->data.low, HOST_BITS_PER_DOUBLE_INT, - &temp_low.low, &temp_low.high, !unsigned_p); + !unsigned_p); /* Logical shift right to temp_high. */ - lshift_double (a->data.low, a->data.high, - b->data.low - HOST_BITS_PER_DOUBLE_INT, - HOST_BITS_PER_DOUBLE_INT, - &temp_high.low, &temp_high.high, 0); + temp_high = a->data.llshift (b->data.low - HOST_BITS_PER_DOUBLE_INT, + HOST_BITS_PER_DOUBLE_INT); } if (!unsigned_p && a->data.high < 0) /* Signed-extend temp_high. */ - temp_high = double_int_ext (temp_high, b->data.low, unsigned_p); + temp_high = temp_high.ext (b->data.low, unsigned_p); f->data = temp_low; overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data, sat_p); } - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); return overflow_p; } @@ -692,8 +657,8 @@ do_fixed_neg (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, bool sat_p) bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); f->mode = a->mode; - f->data = double_int_neg (a->data); - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = -a->data; + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); if (unsigned_p) /* Unsigned type. */ { @@ -718,7 +683,7 @@ do_fixed_neg (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, bool sat_p) /* Saturate to the maximum by subtracting f->data by one. */ f->data.low = -1; f->data.high = -1; - f->data = double_int_ext (f->data, i_f_bits, 1); + f->data = f->data.zext (i_f_bits); } else overflow_p = true; @@ -789,25 +754,25 @@ fixed_compare (int icode, const FIXED_VALUE_TYPE *op0, switch (code) { case NE_EXPR: - return !double_int_equal_p (op0->data, op1->data); + return op0->data != op1->data; case EQ_EXPR: - return double_int_equal_p (op0->data, op1->data); + return op0->data == op1->data; case LT_EXPR: - return double_int_cmp (op0->data, op1->data, + return op0->data.cmp (op1->data, UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == -1; case LE_EXPR: - return double_int_cmp (op0->data, op1->data, + return op0->data.cmp (op1->data, UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != 1; case GT_EXPR: - return double_int_cmp (op0->data, op1->data, + return op0->data.cmp (op1->data, UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == 1; case GE_EXPR: - return double_int_cmp (op0->data, op1->data, + return op0->data.cmp (op1->data, UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != -1; default: @@ -835,19 +800,15 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, /* Left shift a to temp_high, temp_low based on a->mode. */ double_int temp_high, temp_low; int amount = GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode); - lshift_double (a->data.low, a->data.high, - amount, + temp_low = a->data.lshift (amount, HOST_BITS_PER_DOUBLE_INT, - &temp_low.low, &temp_low.high, SIGNED_FIXED_POINT_MODE_P (a->mode)); /* Logical shift right to temp_high. */ - lshift_double (a->data.low, a->data.high, - amount - HOST_BITS_PER_DOUBLE_INT, - HOST_BITS_PER_DOUBLE_INT, - &temp_high.low, &temp_high.high, 0); + temp_high = a->data.llshift (amount - HOST_BITS_PER_DOUBLE_INT, + HOST_BITS_PER_DOUBLE_INT); if (SIGNED_FIXED_POINT_MODE_P (a->mode) && a->data.high < 0) /* Signed-extend temp_high. */ - temp_high = double_int_ext (temp_high, amount, 0); + temp_high = temp_high.sext (amount); f->mode = mode; f->data = temp_low; if (SIGNED_FIXED_POINT_MODE_P (a->mode) == @@ -885,10 +846,9 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, /* Set to maximum. */ f->data.low = -1; /* Set to all ones. */ f->data.high = -1; /* Set to all ones. */ - f->data = double_int_ext (f->data, - GET_MODE_FBIT (f->mode) - + GET_MODE_IBIT (f->mode), - 1); /* Clear the sign. */ + f->data = f->data.zext (GET_MODE_FBIT (f->mode) + + GET_MODE_IBIT (f->mode)); + /* Clear the sign. */ } else overflow_p = true; @@ -903,10 +863,8 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, { /* Right shift a to temp based on a->mode. */ double_int temp; - lshift_double (a->data.low, a->data.high, - GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode), + temp = a->data.lshift (GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode), HOST_BITS_PER_DOUBLE_INT, - &temp.low, &temp.high, SIGNED_FIXED_POINT_MODE_P (a->mode)); f->mode = mode; f->data = temp; @@ -944,10 +902,9 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, /* Set to maximum. */ f->data.low = -1; /* Set to all ones. */ f->data.high = -1; /* Set to all ones. */ - f->data = double_int_ext (f->data, - GET_MODE_FBIT (f->mode) - + GET_MODE_IBIT (f->mode), - 1); /* Clear the sign. */ + f->data = f->data.zext (GET_MODE_FBIT (f->mode) + + GET_MODE_IBIT (f->mode)); + /* Clear the sign. */ } else overflow_p = true; @@ -959,8 +916,7 @@ fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, } } - f->data = double_int_ext (f->data, - SIGNED_FIXED_POINT_MODE_P (f->mode) + f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode) + GET_MODE_FBIT (f->mode) + GET_MODE_IBIT (f->mode), UNSIGNED_FIXED_POINT_MODE_P (f->mode)); @@ -988,19 +944,14 @@ fixed_convert_from_int (FIXED_VALUE_TYPE *f, enum machine_mode mode, } else { - lshift_double (a.low, a.high, - amount, - HOST_BITS_PER_DOUBLE_INT, - &temp_low.low, &temp_low.high, 0); + temp_low = a.llshift (amount, HOST_BITS_PER_DOUBLE_INT); /* Logical shift right to temp_high. */ - lshift_double (a.low, a.high, - amount - HOST_BITS_PER_DOUBLE_INT, - HOST_BITS_PER_DOUBLE_INT, - &temp_high.low, &temp_high.high, 0); + temp_high = a.llshift (amount - HOST_BITS_PER_DOUBLE_INT, + HOST_BITS_PER_DOUBLE_INT); } if (!unsigned_p && a.high < 0) /* Signed-extend temp_high. */ - temp_high = double_int_ext (temp_high, amount, 0); + temp_high = temp_high.sext (amount); f->mode = mode; f->data = temp_low; @@ -1038,10 +989,9 @@ fixed_convert_from_int (FIXED_VALUE_TYPE *f, enum machine_mode mode, /* Set to maximum. */ f->data.low = -1; /* Set to all ones. */ f->data.high = -1; /* Set to all ones. */ - f->data = double_int_ext (f->data, - GET_MODE_FBIT (f->mode) - + GET_MODE_IBIT (f->mode), - 1); /* Clear the sign. */ + f->data = f->data.zext (GET_MODE_FBIT (f->mode) + + GET_MODE_IBIT (f->mode)); + /* Clear the sign. */ } else overflow_p = true; @@ -1051,8 +1001,7 @@ fixed_convert_from_int (FIXED_VALUE_TYPE *f, enum machine_mode mode, &f->data, sat_p); } } - f->data = double_int_ext (f->data, - SIGNED_FIXED_POINT_MODE_P (f->mode) + f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode) + GET_MODE_FBIT (f->mode) + GET_MODE_IBIT (f->mode), UNSIGNED_FIXED_POINT_MODE_P (f->mode)); @@ -1093,10 +1042,8 @@ fixed_convert_from_real (FIXED_VALUE_TYPE *f, enum machine_mode mode, { f->data.low = 1; f->data.high = 0; - lshift_double (f->data.low, f->data.high, i_f_bits, - HOST_BITS_PER_DOUBLE_INT, - &f->data.low, &f->data.high, 1); - f->data = double_int_ext (f->data, 1 + i_f_bits, 0); + f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT); + f->data = f->data.sext (1 + i_f_bits); } } else @@ -1108,12 +1055,12 @@ fixed_convert_from_real (FIXED_VALUE_TYPE *f, enum machine_mode mode, { f->data.low = -1; f->data.high = -1; - f->data = double_int_ext (f->data, i_f_bits, 1); + f->data = f->data.zext (i_f_bits); } else overflow_p = true; } - f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); + f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p); return overflow_p; }