From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alex Gramiak Newsgroups: gmane.emacs.devel Subject: Re: Using __builtin_expect (likely/unlikely macros) Date: Tue, 16 Apr 2019 10:10:39 -0600 Message-ID: <87o956c4n4.fsf@gmail.com> References: <87a7gst973.fsf@gmail.com> <875zrgt12q.fsf@gmail.com> <6919a4c8-df76-ea1e-34db-1fa62a360e5a@cs.ucla.edu> <87h8aykdod.fsf@gmail.com> <4fa7885e-8c66-c7c4-ff71-a013505863af@cs.ucla.edu> <2dfb837d-989d-c736-b6e6-b20c0e940596@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="109142"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: Stefan Monnier , emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 16 18:12:10 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGQgs-000SH7-6l for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 18:12:10 +0200 Original-Received: from localhost ([127.0.0.1]:39214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGQgr-0008JG-4M for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 12:12:09 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGQfT-0007vm-38 for emacs-devel@gnu.org; Tue, 16 Apr 2019 12:10:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGQfS-0006t5-8R for emacs-devel@gnu.org; Tue, 16 Apr 2019 12:10:43 -0400 Original-Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:45331) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hGQfS-0006sY-0J for emacs-devel@gnu.org; Tue, 16 Apr 2019 12:10:42 -0400 Original-Received: by mail-pg1-x52c.google.com with SMTP id y3so10552229pgk.12 for ; Tue, 16 Apr 2019 09:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=rZkcO+kxSjxyjqHR58Q0hQIJtMundoZxT+euVtsT624=; b=AIOA3c1yM5w4lfz/BaTGLH4HcynTmsUADU3hBacAEf3mYbGvAYRJcA50K2yMMGR68b k6qrM5+VL9zbopSeStEgsDZxfz7n5A9UAFf+tL2WUFY/eJzsMc4ZPgsFnPLBuQYhjT19 pfT5Awl3dU9aIeuHOFzgktjz7dBBi1l6YPOZRoOG0hnFmrK0tSorpc1RyKuZsaa6ZYU6 nYwjdPWzcAJWLhwBeumks33OoFZ6P1ekDwBOv5pvo0BcMx93FZPCoGe2GvtyWUMTS7e9 Q1DEaEozYD3vVX0dlQuDnlX/RgcDg2qWyaCWyqdQQiYbr1Ofusbzb8jwKYrDx7AoZbjx kbRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=rZkcO+kxSjxyjqHR58Q0hQIJtMundoZxT+euVtsT624=; b=J6yFtVJYolxDrNYWdR6RPE6S6yrun3ZRxCnMs22i4A+vjgaVFP+oKQmiADKemgEUgj TuES2J8YquGU/5H14pG3VKP5c8lQLrDOW5lVJJeRZltWsQH/wBel+VVMdrtMkePCfKGN 7O2P+bJGraX9y4jmJAAUpk7Y8xZnigA7SLPfHB2G0+NZO4ayKS/kt2+JRZFtA9sr6Ilw SnrlUuExnFqgSPYbC5Srq5XfikO46xq7iQQz/JMNJWv1PrgwElDx/Pm2f3P2P0JbKkAn 3DjBf7psmJgG3ZRYu2D0vDTeh4lI1ycEhn7/UUbmDf2a0QBdLpbv6PNDP0B0WdnkxiHq TqdA== X-Gm-Message-State: APjAAAWY6kx8m7RmSiEplpANya0jYIGfhI4PW/B9q3r/BcrKa/KVPU/G jbrhuZBTNSp7LlPOLM9fM6mNz+hJ X-Google-Smtp-Source: APXvYqyfW0Xi9AhHJT+8kX/UB9z3SfEg5mhpQUaKC30gj6SqCszME7H/vT4ZQyl+AynAqI71mGqgKQ== X-Received: by 2002:a65:4108:: with SMTP id w8mr76881864pgp.236.1555431040016; Tue, 16 Apr 2019 09:10:40 -0700 (PDT) Original-Received: from lylat ([2604:3d09:e37f:1500:1a72:4878:e793:7302]) by smtp.gmail.com with ESMTPSA id w11sm44229094pfi.37.2019.04.16.09.10.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Apr 2019 09:10:38 -0700 (PDT) In-Reply-To: <2dfb837d-989d-c736-b6e6-b20c0e940596@cs.ucla.edu> (Paul Eggert's message of "Tue, 16 Apr 2019 08:22:36 -0700") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235530 Archived-At: Paul Eggert writes: >> BTW I think instead of marking branches as likely or unlikely, I'd >> prefer to tell GCC that some functions "should be slow" >> (e.g. emacs_abort) so it optimizes the code paths that don't go through >> those functions to the detriment of those that do. > > GCC has the function attribute 'cold' for that. This is less intrusive than > __builtin_expect and so would be preferable. Still, the GCC manual says that > __attribute__ ((cold)) is ignored when profile feedback is available, which is > another indication that people who care about performance should be using > -fprofile-use etc. And as far as I know __attribute__ ((cold)) is rarely used: > even glibc uses it only once, in obscure code never used on GNU/Linux. > Presumably this is partly because the attribute didn't exist until about five > years ago. It would still be good to use it for default builds, no? The GCC documentation states: It is thus useful to mark functions used to handle unlikely conditions, such as perror, as cold to improve optimization of hot functions that do call marked functions in rare occasions. So the error/signal calls, wrong_type_argument, etc. would be good places for this. It doesn't indicate anything to the programmer at call sites, but that point is controversial, so slapping a few attributes down seems like a better way to go.