Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRHSS-00EGmy-Ov for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 20:29:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sRHSQ-00HRbb-Ev for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 20:29:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRHSQ-00HRbQ-4X for pgsql-hackers@lists.postgresql.org; Tue, 09 Jul 2024 20:29:02 +0000 Received: from fhigh1-smtp.messagingengine.com ([103.168.172.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRHSN-001HBj-EC for pgsql-hackers@postgresql.org; Tue, 09 Jul 2024 20:29:01 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B33E71140DEC; Tue, 9 Jul 2024 16:28:57 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Tue, 09 Jul 2024 16:28:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1720556937; x=1720643337; bh=Tka5BDFGjt K2CY/wCGtRL2rQymjC3zbHg7AZbaTRiwg=; b=NmSGvV8hEn1VyOevE06mRG3Kqt SJ2wfdrG1EZyi3/pUpYf8IO6NIJMl7zdtn8ciqx/zg2cUmmCOqvlpia/4ZfM/xt1 EmKDmd4nJg79iBXWJgOsN07Cs1aWfrhXfk5cy/iJu3nlUNYZAftEAKGYYYL/7g+Q JLGYUBdoD3ndcULS+2YiYxLlxpp3nx7ptZVZq89F39MSpyFjw8YsnZNbd850FU4G uvWkrf6F8aVA3BTCa8ImtwaGE8t+te+CV1Q0HW+8WvphtFsG5BpxNvMvRS30+fB4 2HJ3pLFx4W+ZfYHIRK5ILOnDU6P6WvtyFPb90redvLxxobm36CwnUXEygc9Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1720556937; x=1720643337; bh=Tka5BDFGjtK2CY/wCGtRL2rQymjC 3zbHg7AZbaTRiwg=; b=XeJuvVhlDAcQMgP0+X2WvjNXfCj0EixRmt41/lmvCNGZ fKuU5x5vdpDLix+dnW7pjdMQXLn0ANpvqRAz3GU1gwF1JarXsI+auptz2eayBZwo ofackdfbej6GWdu53DzTD8MJIYPHM+U9T7f8GqlKJtR8sngvM3cVk2loOe1QMK3D Y+DKKolkhDZC5a13H707xO1Fgb1LYbdXq8++ij8SCUbI72Q2DzhS6QEwjC9IXP0G V2biIzKuLH7rRYxknAgUMBN6I2qRxwdq/3PxdJrbo8HPRKQHDO0Q1ztyQW0cG2lV QJoDSaMO9yvj9FPigZFpUGFxRdBTP0XpjdohSKf5cA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdelgdduhedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedflfho vghlucflrggtohgsshhonhdfuceojhhovghlsegtohhmphhilhgvrhdrohhrgheqnecugg ftrfgrthhtvghrnhephffggeevfffhhfeuffdvkeevtdfhhfefveevjeehlefhteeihfdv vdehjeekhefgnecuffhomhgrihhnpehgohgusgholhhtrdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhovghlsegtohhmphhilhgv rhdrohhrgh X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7260B31A0065; Tue, 9 Jul 2024 16:28:56 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-568-g843fbadbe-fm-20240701.003-g843fbadb MIME-Version: 1.0 Message-Id: <19834f2c-4bf1-4e27-85ed-ca5df0f28e03@app.fastmail.com> In-Reply-To: References: <44d2ffca-d560-4919-b85a-4d07060946aa@app.fastmail.com> <87zfr1e1uj.fsf@wibble.ilmari.org> <9ff90ff9-5ac1-4529-b2f4-f93b37734b9c@app.fastmail.com> <81348268-b9fd-4308-bf52-056070aa7c2a@app.fastmail.com> <8e909218-1965-4515-99e3-4bb5b625e004@app.fastmail.com> <0459ded5-6daf-4bf0-9ab0-e1f11ab15ec6@app.fastmail.com> <4e54bf4f-59fe-4c9a-b446-a2b64cbfd584@app.fastmail.com> <27d42b25-f328-4231-9db0-3811dc77c8cf@app.fastmail.com> <33c51978-8ee8-438c-9804-e46c0ca8f3f9@app.fastmail.com> <018dd6e8-8f21-4b3b-8d80-2d128f6d00b4@app.fastmail.com> <32510d71-8c00-4896-9c11-5ea4b3c01ffc@app.fastmail.com> <31b8386d-4bcb-4909-b7da-bbeb9a8ece55@app.fastmail.com> <42d93ebe-fbed-448f-b550-096be9e577db@app.fastmail.com> <58e5e7d2-7ad8-40b4-9b76-a5c3049346e5@app.fastmail.com> Date: Tue, 09 Jul 2024 22:28:36 +0200 From: "Joel Jacobson" To: "Dean Rasheed" Cc: =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , pgsql-hackers Subject: Re: Optimize numeric multiplication for one and two base-NBASE digit multiplicands. Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 9, 2024, at 14:01, Dean Rasheed wrote: > One thing I noticed while testing the earlier patches on this thread > was that they were significantly faster if they used unsigned integers > rather than signed integers. I think the reason is that operations > like "x / 10000" and "x % 10000" use fewer CPU instructions (on every > platform, according to godbolt.org) if x is unsigned. > > In addition, this reduces the number of times the digit array needs to > be renormalised, which seems to be the biggest factor. > > Another small optimisation that seems to be just about worthwhile is > to pull the first digit of var1 out of the main loop, so that its > contributions can be set directly in dig[], rather than being added to > it. This allows palloc() to be used to allocate dig[], rather than > palloc0(), and only requires the upper part of dig[] to be initialised > to zeros, rather than all of it. > > Together, these seem to give a decent speed-up: .. > Attachments: > * optimise-mul_var.patch I've reviewed the patch now. Code is straightforward, and comments easy to understand. LGTM. Regards, Joel