From patchwork Tue Oct 2 18:53:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 188615 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 0C1FE2C0089 for ; Wed, 3 Oct 2012 04:54:09 +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=1349808850; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=wcylMlzXBX8nNypYNXTOgt3Wm/Y=; b=vlAi+eX5N7l64fE 29vWydsIJ/zS5Bl5zexPcTsVT62tX9oS1ws0ggA9MnuYKQcure2WLCTPz4q7Hh2J 6talbbUXMhAzvC0qEW+7TaclbCIKviVx5HtorBY+jYASP78T+DP0kb0Is8NUneks 0EjAXXfz+fL08s/0rHVVnhY6hnU8= 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:Received:Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=I119NyiHhPJgMv2sqXd/8TK5637wAWihrzBg9s4GqawRWZ9SQi/0+yFgtV8WTV i4SOJOP1N6YFSNrFVKXlhRCYx5XeATP4hM20L5/VlPcjuCGClIQcdDNvxihmz+iX rt4toIDz/XNPqpurYKvKwXQGcarNfuS7ru0MVHpBlOa/k=; Received: (qmail 32676 invoked by alias); 2 Oct 2012 18:54:01 -0000 Received: (qmail 32650 invoked by uid 22791); 2 Oct 2012 18:54:00 -0000 X-SWARE-Spam-Status: No, hits=-8.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_CX X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 02 Oct 2012 18:53:54 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 02 Oct 2012 20:53:47 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TJ7bG-0004XC-Nt; Tue, 02 Oct 2012 20:53:46 +0200 Date: Tue, 2 Oct 2012 20:53:46 +0200 (CEST) From: Marc Glisse To: Gabriel Dos Reis cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, olegendo@gcc.gnu.org Subject: Re: abs(long long) In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 On Tue, 2 Oct 2012, Gabriel Dos Reis wrote: > Whining on this list about libstdc++ internal macros and your dislike > of them is not going to produce anything today or tomorrow. Other compilers using libstdc++ was just an extra argument. Even if g++ was the only compiler on earth, I would still consider a compile-time test superior to a configure test. The macro __SIZEOF_INT128__ was invented precisely for this purpose. Yes, that's just more whining ;-) On Tue, 2 Oct 2012, Gabriel Dos Reis wrote: > On Tue, Oct 2, 2012 at 8:07 AM, Marc Glisse wrote: > >> Or do you mean: >> always call __builtin_llabs (whether we have an llabs or not), and let the >> compiler replace it with either (x<0)?-x:x or a library call (I assume it >> never does that unless it has seen a corresponding declaration)? > > See what we did in c/cmath and c_global/cmath. Note that llabs is quite different from asin. __builtin_llabs generates an ABS_EXPR, which will later be expanded either to a special instruction or to a condition. It never generates a call to llabs (I am not sure exactly if Paolo's instructions to use llabs meant he wanted an actual library call). __builtin_asin on the other hand is never expanded inline (except maybe for special constant input like 0) and expands to a call to the library function asin. Would the attached patch be better, assuming it passes testing? For lldiv, there is no builtin (for good reason). * include/c_std/cstdlib (abs(long long)): Define with __builtin_llabs when we have long long. (abs(__int128)): Define when we have __int128. (div(long long, long long)): Use lldiv. Index: cstdlib =================================================================== --- cstdlib (revision 191941) +++ cstdlib (working copy) @@ -128,21 +128,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using ::strtod; using ::strtol; using ::strtoul; using ::system; #ifdef _GLIBCXX_USE_WCHAR_T using ::wcstombs; using ::wctomb; #endif // _GLIBCXX_USE_WCHAR_T inline long - abs(long __i) { return labs(__i); } + abs(long __i) { return __builtin_labs(__i); } + +#ifdef _GLIBCXX_USE_LONG_LONG + inline long long + abs(long long __x) { return __builtin_llabs (__x); } +#endif + +#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) + inline __int128 + abs(__int128 __x) { return __x >= 0 ? __x : -__x; } +#endif inline ldiv_t div(long __i, long __j) { return ldiv(__i, __j); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace #if _GLIBCXX_USE_C99 #undef _Exit @@ -161,29 +171,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC using ::lldiv_t; #endif #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN; #endif #if !_GLIBCXX_USE_C99_DYNAMIC using ::_Exit; #endif - inline long long - abs(long long __x) { return __x >= 0 ? __x : -__x; } - #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC using ::llabs; inline lldiv_t div(long long __n, long long __d) - { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; } + { return ::lldiv (__n, __d); } using ::lldiv; #endif #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC extern "C" long long int (atoll)(const char *) throw (); extern "C" long long int (strtoll)(const char * __restrict, char ** __restrict, int) throw (); extern "C" unsigned long long int (strtoull)(const char * __restrict, char ** __restrict, int) throw (); @@ -198,21 +205,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace __gnu_cxx namespace std { #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC using ::__gnu_cxx::lldiv_t; #endif using ::__gnu_cxx::_Exit; - using ::__gnu_cxx::abs; #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC using ::__gnu_cxx::llabs; using ::__gnu_cxx::div; using ::__gnu_cxx::lldiv; #endif using ::__gnu_cxx::atoll; using ::__gnu_cxx::strtof; using ::__gnu_cxx::strtoll; using ::__gnu_cxx::strtoull; using ::__gnu_cxx::strtold;