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 1inVtO-0004gV-Pe for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jan 2020 22:58:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1inVtN-00081Z-CG for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jan 2020 22:58:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1inVtN-00081S-0U for pgsql-hackers@lists.postgresql.org; Fri, 03 Jan 2020 22:58:05 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1inVtI-0001eZ-4v for pgsql-hackers@lists.postgresql.org; Fri, 03 Jan 2020 22:58:03 +0000 Received: by mail-wm1-x333.google.com with SMTP id d73so9626977wmd.1 for ; Fri, 03 Jan 2020 14:57:59 -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=Z3O4RKwYDV4EHDevFlEbAJ1HAa/lcWu/ZpyI2rd4Eh4=; b=JVr2qxd3UdcDgDqcHl7VptW22piz7rExBxyyj6fLR6dLx9EIYAip32xIEuuj/HPR87 xTLeESyneXXrDsGN+hhmFUJoHWGQUmBV6B9QZY8qSUEwQJJxEVcarig2FSJOVTPUfEUC SXbuSCBXY8XW1cRi2lpm/76N6PcC78kwcA9NhGMnk6gazEkJI34ZpdqdFGri0bHFeiYs /s5V3NBN/tfT2OWITlfRuW0WKuEoq2tGi7McqflGjXeoCrj/FoeKV7iV+++OSXrW0Oqq uxBtxRz00gzleoUv72xc6TIe9SQqCIXOCNqLQPGp3yr8xoIs984jcD9ZiudAKXTOapsK E88g== 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=Z3O4RKwYDV4EHDevFlEbAJ1HAa/lcWu/ZpyI2rd4Eh4=; b=H+TtbO4zt6hu7evmoRibQ6EFpyYwpTALk7ZQabZaareOq/Au4uXHocxqTukv7rOwI6 YStHm5tVyS6EHDz4tbWh2bQrADoHOtnTO3+7Zr/MwhNS5e9lzFJpHqlm3OJVmoDmU+yQ 2tDLLWajBx3pF3s7/Ee4VmIjG21VRFr/Ar5Mxy27er/MyzY3yO/dqpL6FDTaRt9MtpaM dgchD7unIEySErAKFH5RojWeBz/30dY1onWcbHr6a7wAYlf4BttdEOgkXdg3upKuX5SH Mw2GEhwP7vUdAe80yUW2bG+Ucp5TR3BxBDXFB///KnIpHeVaxMk35ygLph7Znx5+8xJ/ eKcg== X-Gm-Message-State: APjAAAWAz3vVyVCle5at6gpqKfI6WSGl60yxDMj24cKHR3/1WM1xHZKl /5PZ3SE+07SsQe+TpgCmJp7oZsAuer+0kshzPxqKDTlS6NuxX45yltCTUaZusaj6JmaYAkJ30Qh 7ktCeTfEBD+U8G+D8wOXKXRjZfAGIbHHm5a8R9R8Fx32t556HzzXoVVFH+5zl0h/BLVdFBRAY7T PTzV3dpDroZAA+O0wOlg== X-Google-Smtp-Source: APXvYqxKGkBwIjgsP6/R0VGHmtIyejt7aIak9jRTdCKKyTbCXiHo4/PTZxeef072E7jHrnHymM+kLw== X-Received: by 2002:a1c:6404:: with SMTP id y4mr21869722wmb.143.1578092278239; Fri, 03 Jan 2020 14:57:58 -0800 (PST) Received: from [10.8.8.7] ([185.94.189.189]) by smtp.gmail.com with ESMTPSA id u7sm13652595wmj.3.2020.01.03.14.57.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jan 2020 14:57:57 -0800 (PST) Subject: Re: Greatest Common Divisor To: Fabien COELHO Cc: Tom Lane , 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> From: Vik Fearing Message-ID: <5bf72c6b-1290-2ba0-770b-8a13e899fd98@2ndquadrant.com> Date: Fri, 3 Jan 2020 23:57:54 +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: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/01/2020 20:14, Fabien COELHO wrote: > > Bonsoir Vik, > >  +int4gcd_internal(int32 arg1, int32 arg2) >  +{ >  +       int32   swap; >  + >  +       /* >  +        * Put the greater value in arg1. >  +        * This would happen automatically in the loop below, but > avoids  an >  +        * expensive modulo simulation on some architectures. >  +        */ >  +       if (arg1 < arg2) >  +       { >  +               swap = arg1; >  +               arg1 = arg2; >  +               arg2 = swap; >  +       } > > > 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? > I'm unsure about gcd(INT_MIN, 0) should error. Possibly 0 would be nicer? What justification for that do you have? -- Vik Fearing