From patchwork Mon Sep 27 09:30:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 65824 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 24D34B70F1 for ; Mon, 27 Sep 2010 19:31:10 +1000 (EST) Received: (qmail 8601 invoked by alias); 27 Sep 2010 09:31:03 -0000 Received: (qmail 8575 invoked by uid 22791); 27 Sep 2010 09:31:00 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp4.tin.it (HELO vsmtp4.tin.it) (212.216.176.224) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Sep 2010 09:30:52 +0000 Received: from [192.168.0.4] (79.47.193.60) by vsmtp4.tin.it (8.5.113) id 4BCE3CBE0C0F85EE; Mon, 27 Sep 2010 11:30:49 +0200 Message-ID: <4CA06448.7090107@oracle.com> Date: Mon, 27 Sep 2010 11:30:48 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Thunderbird/3.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Small std::pow clean-up 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 Hi, for a long time __pow_helper and __cmath_power remained unused in std::cmath. Also, for std::complex, something similar is used only in C++98 mode. Clean-up the whole thing. Tested x86_64-linux, committed to mainline. Paolo. /////////////////////// 2010-09-27 Paolo Carlini * include/c_std/cmath (__pow_helper): Remove. (__cmath_power): Remove declaration. * include/c_global/cmath: Likewise. * include/std/complex (__complex_pow_unsigned): Add. (pow(const complex<_Tp>&, int)): Use the latter. * include/c_std/cmath.tcc: Remove file. * include/c_global/cmath.tcc: Likewise. * acinclude.m4: Adjust. * include/Makefile.am: Likewise. * configure: Regenerate. * include/Makefile.in: Likewise. Index: include/std/complex =================================================================== --- include/std/complex (revision 164644) +++ include/std/complex (working copy) @@ -951,12 +951,32 @@ // raised to the __y-th power. The branch // cut is on the negative axis. #ifndef __GXX_EXPERIMENTAL_CXX0X__ + template + complex<_Tp> + __complex_pow_unsigned(complex<_Tp> __x, unsigned __n) + { + complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1); + + while (__n >>= 1) + { + __x *= __x; + if (__n % 2) + __y *= __x; + } + + return __y; + } + // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 844. complex pow return type is ambiguous. template inline complex<_Tp> pow(const complex<_Tp>& __z, int __n) - { return std::__pow_helper(__z, __n); } + { + return __n < 0 + ? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -__n) + : std::__complex_pow_unsigned(__z, __n); + } #endif template Index: include/c_std/cmath =================================================================== --- include/c_std/cmath (revision 164644) +++ include/c_std/cmath (working copy) @@ -77,10 +77,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - // Forward declaration of a helper function. This really should be - // an `exported' forward declaration. - template _Tp __cmath_power(_Tp, unsigned int); - inline double abs(double __x) { return __builtin_fabs(__x); } @@ -344,15 +340,6 @@ modf(long double __x, long double* __iptr) { return __builtin_modfl(__x, __iptr); } - template - inline _Tp - __pow_helper(_Tp __x, int __n) - { - return __n < 0 - ? _Tp(1)/__cmath_power(__x, -__n) - : __cmath_power(__x, __n); - } - using ::pow; inline float @@ -590,8 +577,4 @@ #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ #endif -#ifndef _GLIBCXX_EXPORT_TEMPLATE -# include #endif - -#endif Index: include/c_std/cmath.tcc =================================================================== --- include/c_std/cmath.tcc (revision 164644) +++ include/c_std/cmath.tcc (working copy) @@ -1,55 +0,0 @@ -// -*- C++ -*- C math library. - -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 -// Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// Under Section 7 of GPL version 3, you are granted additional -// permissions described in the GCC Runtime Library Exception, version -// 3.1, as published by the Free Software Foundation. - -// You should have received a copy of the GNU General Public License and -// a copy of the GCC Runtime Library Exception along with this program; -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -// . - -// This file was written by Gabriel Dos Reis - -/** @file cmath.tcc - * This is a Standard C++ Library file. - */ - -#ifndef _GLIBCXX_CMATH_TCC -#define _GLIBCXX_CMATH_TCC 1 - -_GLIBCXX_BEGIN_NAMESPACE(std) - - template - inline _Tp - __cmath_power(_Tp __x, unsigned int __n) - { - _Tp __y = __n % 2 ? __x : _Tp(1); - - while (__n >>= 1) - { - __x = __x * __x; - if (__n % 2) - __y = __y * __x; - } - - return __y; - } - -_GLIBCXX_END_NAMESPACE - -#endif Index: include/c_global/cmath =================================================================== --- include/c_global/cmath (revision 164644) +++ include/c_global/cmath (working copy) @@ -76,20 +76,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - // Forward declaration of a helper function. This really should be - // an `exported' forward declaration. - template - _Tp __cmath_power(_Tp, unsigned int); - - template - inline _Tp - __pow_helper(_Tp __x, int __n) - { - return __n < 0 - ? _Tp(1)/__cmath_power(__x, -__n) - : __cmath_power(__x, __n); - } - inline double abs(double __x) { return __builtin_fabs(__x); } @@ -859,10 +845,6 @@ #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ #endif -#ifndef _GLIBCXX_EXPORT_TEMPLATE -# include -#endif - #ifdef __GXX_EXPERIMENTAL_CXX0X__ # if defined(_GLIBCXX_INCLUDE_AS_TR1) # error C++0x header cannot be included from TR1 header Index: include/c_global/cmath.tcc =================================================================== --- include/c_global/cmath.tcc (revision 164644) +++ include/c_global/cmath.tcc (working copy) @@ -1,55 +0,0 @@ -// -*- C++ -*- C math library. - -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 -// Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// Under Section 7 of GPL version 3, you are granted additional -// permissions described in the GCC Runtime Library Exception, version -// 3.1, as published by the Free Software Foundation. - -// You should have received a copy of the GNU General Public License and -// a copy of the GCC Runtime Library Exception along with this program; -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -// . - -// This file was written by Gabriel Dos Reis - -/** @file cmath.tcc - * This is a Standard C++ Library file. - */ - -#ifndef _GLIBCXX_CMATH_TCC -#define _GLIBCXX_CMATH_TCC 1 - -_GLIBCXX_BEGIN_NAMESPACE(std) - - template - inline _Tp - __cmath_power(_Tp __x, unsigned int __n) - { - _Tp __y = __n % 2 ? __x : _Tp(1); - - while (__n >>= 1) - { - __x = __x * __x; - if (__n % 2) - __y = __y * __x; - } - - return __y; - } - -_GLIBCXX_END_NAMESPACE - -#endif Index: include/Makefile.am =================================================================== --- include/Makefile.am (revision 164644) +++ include/Makefile.am (working copy) @@ -824,15 +824,8 @@ ${profile_impl_srcdir}/profiler_list_to_vector.h \ ${profile_impl_srcdir}/profiler_list_to_slist.h -# Some of the different "C" header models need extra files. # Some "C" header schemes require the "C" compatibility headers. # For --enable-cheaders=c_std -if GLIBCXX_C_HEADERS_EXTRA -c_base_headers_extra = ${c_base_srcdir}/cmath.tcc -else -c_base_headers_extra = -endif - if GLIBCXX_C_HEADERS_COMPATIBILITY c_compatibility_headers_extra = ${c_compatibility_headers} else @@ -915,10 +908,10 @@ # List of all timestamp files. By keeping only one copy of this list, both # CLEANFILES and all-local are kept up-to-date. allstamped = \ - stamp-std stamp-bits stamp-c_base stamp-c_base_extra \ - stamp-c_compatibility stamp-backward stamp-ext stamp-pb \ - stamp-tr1 stamp-tr1-impl stamp-decimal stamp-debug \ - stamp-parallel stamp-profile stamp-profile-impl stamp-host + stamp-std stamp-bits stamp-c_base stamp-c_compatibility \ + stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-tr1-impl \ + stamp-decimal stamp-debug stamp-parallel stamp-profile \ + stamp-profile-impl stamp-host # List of all files that are created by explicit building, editing, or # catenation. Index: acinclude.m4 =================================================================== --- acinclude.m4 (revision 164644) +++ acinclude.m4 (working copy) @@ -1695,16 +1695,11 @@ c_compatibility=yes fi - if test $enable_cheaders = c_global || test $enable_cheaders = c_std; then - c_extra=yes - fi - AC_SUBST(C_INCLUDE_DIR) GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C, test $enable_cheaders = c) GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_STD, test $enable_cheaders = c_std) GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_GLOBAL, test $enable_cheaders = c_global) GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_COMPATIBILITY, test $c_compatibility = yes) - GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_EXTRA, test $c_extra = yes) ])