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 1inXCL-0007NK-Hi for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jan 2020 00:21:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1inXCK-0002t6-9n for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jan 2020 00:21:44 +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 1inXCJ-0002sz-Rz for pgsql-hackers@lists.postgresql.org; Sat, 04 Jan 2020 00:21:44 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1inXCH-0007sx-EP for pgsql-hackers@lists.postgresql.org; Sat, 04 Jan 2020 00:21:43 +0000 Received: by mail-wm1-x32c.google.com with SMTP id b19so9688977wmj.4 for ; Fri, 03 Jan 2020 16:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=GcxgGSMIApQ0drhg4jCGJyUA1MmwWiHgQ0W20id3e7M=; b=lv8ysmTF8C2cNzo0LzhkupdPJQPlTwp4g2BRKdzJEoNaB2urgcmmUb6wLviM0//Xw+ gjkPOoJlXdoZc+EegyC4tXwwpeKKORlKkyiLEShHbjYlEonHa1T6Z5xl6WmT6JuySdp/ unoaNrSMZcVbMsdPti7S4wkTUhEJUNbn9jhD4z0K0zmmsZDj+mXQuqJ1+1nYfL05VbWV MZrLSLPpzsYjAPECb/MQ/ddtRqeZXkZFVvzuNzFifbjTUHuCNHBwVZ1yH6fTIDJANTmc JTAO6+3g9Q4caz+JmyL0AfNFeL66QSXSc/OhUxnYcEFBFY0hqRIO03lYd0KtONenBGTi urkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=GcxgGSMIApQ0drhg4jCGJyUA1MmwWiHgQ0W20id3e7M=; b=QuFHVWiY8d2UAMsQFs0Lob2+6e0CdFcv0aA5ORYZaKondr9UWX/BYNB4JZJUogA/VM b1L13hAnm9895oWPqHszTzwa2cpg7zNHWEf7eq+2l8w3bkZE1IfJRGacoZ1qHZ1jOdE3 XSgCVKhCds9Rekq2yjCYJFysxQNL+b+cMAFnP/WK/DFGGl3pd9qbFjtfTizuc/EXComH VvfpJPreOPDlr+qXiwomkw+ZIkm5r80N3MEo95bQ0DuzT502fqG2k71et6kQVfFFcVCP CVPLy0MHecnXuHW9wjsfClyrADiW4un8IgqiuRzfAwu+5FEUeV4rOnlrQBJA0I4rCZl/ xlyA== X-Gm-Message-State: APjAAAVLoFNC8UxNrpDq/3BlzI9uWxwgUnQAle7pvdaMPf3KXBBitI5Z 6acp0tuaHNRnrlFws7ZpIKEO1RgFtP4RGcCP4VrA6x8f7fPchh/zwJqpRXNHSDud6ZFsJaPzzm9 qGzS5XEY2wTLfTvFPpJbwJSfkkXmhReQr7HN57NJjSdMoSqIBZMuSIo5Fz1nPpxiGyquLBCw0sF D/FerYMrMBY67PBaFRGA== X-Google-Smtp-Source: APXvYqzkTDJ06S3KJj2Sr84ky96mCcROIrV9WB1LOKJDqNFZGCIcd9czDPFItRGYJXPLYh4ULEADPQ== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr21508421wmh.94.1578097299496; Fri, 03 Jan 2020 16:21:39 -0800 (PST) Received: from [10.8.8.7] ([185.94.189.189]) by smtp.gmail.com with ESMTPSA id w19sm13624378wmc.22.2020.01.03.16.21.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jan 2020 16:21:38 -0800 (PST) Subject: Re: Greatest Common Divisor To: Tom Lane Cc: Fabien COELHO , Stephen Frost , Dean Rasheed , Chapman Flack , PostgreSQL Hackers References: <5E08D947.9000902@anastigmatix.net> <20200102145712.GN3195@tamriel.snowman.net> <16242.1577977961@sss.pgh.pa.us> <6855727c-3836-21cc-18f9-e79227b99079@2ndquadrant.com> <5bf72c6b-1290-2ba0-770b-8a13e899fd98@2ndquadrant.com> <13445.1578095358@sss.pgh.pa.us> From: Vik Fearing Message-ID: Date: Sat, 4 Jan 2020 01:21:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <13445.1578095358@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/01/2020 00:49, Tom Lane wrote: > Vik Fearing writes: >> On 03/01/2020 20:14, Fabien COELHO wrote: >>> The point of swapping is to a void possibly expensive modulo, but this >>> should be done on absolute values, otherwise it may not achieve its >>> purpose as stated by the comment? >> Ah, true. How widespread are these architectures that need this special >> treatment? Is it really worth handling? > On some older RISC architectures, integer division is really slow, like > slower than floating-point. I'm not sure if that's true on any platform > people still care about though. In recent years, CPU architects have been > able to throw all the transistors they needed at such problems. On a > machine with single-cycle divide, it's likely that the extra > compare-and-branch is a net loss. OK. > Might be worth checking it on ARM in particular, as being a RISC > architecture that's still popular. I don't know how I would check this. > Also, if we end up having a "numeric" implementation, it absolutely is > worth it for that, because there is nothing cheap about numeric_div. The patch includes a numeric version, and I take care to short-circuit everything I can. > I'd be sort of inclined to have the swap in the other implementations > just to keep the algorithms as much alike as possible. They can't quite be the same behavior because numeric doesn't have the unrepresentable -INT_MIN problem, and integers don't have NaN. -- Vik Fearing