From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24486 invoked by alias); 22 Jul 2016 21:13:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 24453 invoked by uid 89); 22 Jul 2016 21:13:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=gcc-help X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-yw0-f172.google.com Received: from mail-yw0-f172.google.com (HELO mail-yw0-f172.google.com) (209.85.161.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 22 Jul 2016 21:12:49 +0000 Received: by mail-yw0-f172.google.com with SMTP id r9so114634431ywg.0; Fri, 22 Jul 2016 14:12:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KiDw4gv9Lnho5WCkA1WVP+1KdMK2LxAAu4/f/Hf1AUI=; b=an0mJKzs6B0I0qqPcrdEknFrdU7xl4UPdYd3bkOPzSaQgaNAndtaWmM1/FuvPrfyW2 QVDnAiCr3eDdC7YC216hfbjzeyy+g1PeZkIdh8Ysun/j6xMpejk6y8aR4LyFN/qqTz+I 598kUtMSvufqD166UrWJj/j+WtgpcUPLNpgK6fkKse9F/K8jXFyj+O/P9TyaEIRhY6cC DA8eeWFh0DUXVhVo19fWGfDOa0jq6Rq8SnNoAOrWeWk9+/8t7QoMnkM/lSQGbx28iXXl HuhxZRAtqTn6/+z5GHoRe8bZIAtRK2L4SO6YQXNhUE00zs4/PTejYipLjhJKLq6Ir59I glOA== X-Gm-Message-State: AEkoouvhovyD9qCh7rTWXugNUvrHf5GeheYRirhMu8OFXFfquNzUBYZvUM6ksLelsGk3+hdqb+oHasIRsPZE8Q== X-Received: by 10.37.97.205 with SMTP id v196mr2660636ybb.146.1469221967455; Fri, 22 Jul 2016 14:12:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.37.134 with HTTP; Fri, 22 Jul 2016 14:12:28 -0700 (PDT) In-Reply-To: <20160722075534.GK4264@redhat.com> References: <57882528.8010501@verizon.net> <20160722075142.GJ4264@redhat.com> <20160722075534.GK4264@redhat.com> From: NightStrike Date: Fri, 22 Jul 2016 21:13:00 -0000 Message-ID: Subject: Re: [libstdc++] Add C++17clamp To: Jonathan Wakely Cc: Ed Smith-Rowland <3dw4rd@verizon.net>, "libstdc++@gcc.gnu.org" , gcc-patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg01513.txt.bz2 Would it be possible to fix the missed optimization to give the better asm without having to do -ffast-math as mentioned here: https://gcc.gnu.org/ml/gcc-help/2014-11/msg00034.html If so, then the proposed implementation would be optimized for the simple case. On Fri, Jul 22, 2016 at 3:55 AM, Jonathan Wakely wrote: > On 22/07/16 08:51 +0100, Jonathan Wakely wrote: >> >> On 21/07/16 19:38 -0400, NightStrike wrote: >>> >>> On Thu, Jul 14, 2016 at 7:50 PM, Ed Smith-Rowland <3dw4rd@verizon.net> >>> wrote: >>>> >>>> Here is an implementation of P0025 >>>> An algorithm to "clamp" a value between a pair of boundary values. >>>> >>>> Testing is almost finished - looks good so far. >>>> >>>> OK if testing passes? >>>> >>>> I didn't see a feature test in any of the SD-6 papers or P0025. >>>> >>> >>> This is not an efficient implementation. See here: >>> >>> https://gcc.gnu.org/ml/gcc-help/2014-10/msg00112.html >>> >>> Which I derived from this SO answer (which is sadly not the accepted >>> answer at this time): >>> >>> http://stackoverflow.com/a/16659263 >>> >>> I suggest using the very efficient method that requires a temporary. >> >> >> That isn't a valid implementation of std::clamp, since it performs a >> copy. The template argument might not even be copyable. > > > > We could possibly dispatch to such an implementation for arithmetic > types, but we wouldn't want to do it for all copyable types. There's > no way you can know whether making that local copy is expensive for an > arbitrary type, and making a copy isn't allowed anyway. >