Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ioRs7-0001Vm-10 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2020 12:52:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ioRs5-0006z0-JX for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2020 12:52:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ioRs5-0006yt-AL for pgsql-hackers@lists.postgresql.org; Mon, 06 Jan 2020 12:52:37 +0000 Received: from courriel.mines-paristech.fr ([77.158.173.149] helo=antispam-1.ensmp.fr) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ioRs2-00034n-UK for pgsql-hackers@lists.postgresql.org; Mon, 06 Jan 2020 12:52:36 +0000 Received: from smtp-4.mines-paristech.fr (smtp-4.ensmp.fr [77.158.173.143]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by antispam-1.ensmp.fr (antispam.mines-paristech.fr) with ESMTPS id DBB7256055; Mon, 6 Jan 2020 13:52:33 +0100 (CET) Received: from pseudo (sfr-14.cri.mines-paristech.fr [77.158.180.238]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp-4.mines-paristech.fr (Postfix) with ESMTPSA id BB7962C01EC; Mon, 6 Jan 2020 13:52:33 +0100 (CET) Date: Mon, 6 Jan 2020 13:52:33 +0100 (CET) From: Fabien COELHO X-X-Sender: fabien@pseudo To: Robert Haas cc: Vik Fearing , Tom Lane , Stephen Frost , Dean Rasheed , Chapman Flack , PostgreSQL Hackers Subject: Re: Greatest Common Divisor In-Reply-To: Message-ID: References: <5E08D947.9000902@anastigmatix.net> <20200102145712.GN3195@tamriel.snowman.net> <16242.1577977961@sss.pgh.pa.us> <6855727c-3836-21cc-18f9-e79227b99079@2ndquadrant.com> <32b8af34-8f87-c30f-5555-2325bd140a59@2ndquadrant.com> <13b5bbd5-6784-528f-9fd7-9fa43250be51@2ndquadrant.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2056645051-1992234690-1578315153=:24609" X-CLAMAV-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrvdehtddggeejucetufdoteggodetrfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvufgjkfhffgggtgesmhdtreertderjeenucfhrhhomhephfgrsghivghnucevqffgnffjqfcuoegtohgvlhhhohestghrihdrvghnshhmphdrfhhrqeenucfkphepjeejrdduheekrddukedtrddvfeeknecurfgrrhgrmhepmhhouggvpehsmhhtphhouhht X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --2056645051-1992234690-1578315153=:24609 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT Hello Robert, >> if (arg1 == PG_INT32_MIN) >> if (arg2 == 0 || arg2 == PG_INT32_MIN) >> >> And possibly a "likely" on the while. > > I don't think decoration the code with likely() and unlikely() all > over the place is a very good idea. > Odds are good that we'll end up with a bunch that are actually > non-optimal, and nobody will ever figure it out because it's hard to > figure out. My 0.02€: I'd tend to disagree. Modern pipelined processors can take advantage of speculative execution on branches, so if you know which branch is the more likely it can help. Obviously if you get it wrong it does not, but for the above cases it seems to me that they are rather straightforward. It also provides some "this case is expected to be exceptional" semantics to people reading the code. > I have a hard time believing that we're going to be much > worse off if we just write the code normally. I think that your point applies to more general programming in postgres, but this is not the context here. For low-level arithmetic code like this one, with tests and loops containing very few hardware instructions, I think that helping compiler optimizations is a good idea. Maybe in the "while" the compiler would assume that it is going to loop anyway by default, so it may be less useful there. -- Fabien. --2056645051-1992234690-1578315153=:24609--