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 1sOagA-0009nT-HE for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2024 10:24:07 +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 1sOag8-000zt4-8C for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2024 10:24:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOag6-000zsW-Sz for pgsql-hackers@lists.postgresql.org; Tue, 02 Jul 2024 10:24:04 +0000 Received: from fhigh3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOag4-0001DX-Jt for pgsql-hackers@postgresql.org; Tue, 02 Jul 2024 10:24:02 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3206B1140346; Tue, 2 Jul 2024 06:23:59 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Tue, 02 Jul 2024 06:23:59 -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=1719915839; x=1720002239; bh=Bj2PETgkn+ iPMlcXPvCG0Hzzi7rVw1OLZlQiPqcX92Y=; b=bIwk+pFyFmuF+TJ2Ad51dAk3JY cZAwOV8bz7Q4TTga882OYoQtLBrAnXQp3Hm0WRBl8VNDl/cyNPOSY+vMWgTODETA 8/unTCsNLh7t5R0Y+c9V1d4Pi3ua4nPMgLrZkzGKLRr1pMSX6NGXB3cnKtIOP6GQ 9HqabneOJ7DB/T8/0g88SKUJ1xX8Y78onQSI6nZBRGazxHx2A15hPp1+/yW/jAQy 1qdBJYMpVGUpg4+nzHE+YEt/HgypwAmt7s6OkM/J3T/uWOw3VnNHF3AtFqyjUPva lkU+SZ38qZJlJ26wSnGEW4oZ9NdbOqMma5r0vaOmezF1DnwJbYV+/lCpb7Lw== 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=1719915839; x=1720002239; bh=Bj2PETgkn+iPMlcXPvCG0Hzzi7rV w1OLZlQiPqcX92Y=; b=EUWw2O/N3xIRIPvUmfPUQxi+Tu++8dmsg1dT2IXOjpgy 4+kAfsAMGWgkVppRYzyQFJxFTwZ0vzTK7d/jaRHtu+2eBlmZ4/ZAfdPlF/NvJQA0 hW8fI6aAOZgvNreeQesP87YCFERFISL1svphtIjJ6zMNKeav5aux1cOFebBMk2ii P4Y+hyBJ0/cHrbwn5jvf3yjD3K2CGayTJDUCU/S2R1h5KQULjRd0+sJII5FgLKDz D1r2xWcaSph+Hxm7uEGPxn7ovHdkxYHJbnmpmFH1d92XwaV+mVmbbW+kjhyc39Oa NSXgRtACY3DSbclX5qRmtbtWyqF0pHNvdQBxOP8c1w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehgddvhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdflohgv lhculfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtf frrghtthgvrhhnpefhfedugeffvddtteeluefhffekledtudekhfekkeeileelfffhfedt ffejgfejfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjohgvlhestghomhhpihhlvghrrdhorhhg X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E47AA31A0065; Tue, 2 Jul 2024 06:23:58 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb MIME-Version: 1.0 Message-Id: <0459ded5-6daf-4bf0-9ab0-e1f11ab15ec6@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> Date: Tue, 02 Jul 2024 12:23: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 2, 2024, at 11:05, Joel Jacobson wrote: > On Tue, Jul 2, 2024, at 10:22, Dean Rasheed wrote: >> Shortly after posting that, I realised that there was a small bug. This bit: >> >> case 2: >> newdig = (int) var1digits[1] * var2digits[res_ndigits - 4]; >> >> isn't quite right in the case where rscale is less than the full >> result. In that case, the least significant result digit has a >> contribution from one more var2 digit, so it needs to be: >> >> newdig = (int) var1digits[1] * var2digits[res_ndigits - 4]; >> if (res_ndigits - 3 < var2ndigits) >> newdig += (int) var1digits[0] * var2digits[res_ndigits - 3]; >> Just to be able to verify mul_var() is working as expected when rscale is less than the full result, I've added a numeric_mul_patched() function that takes a third rscale_adjustment parameter: I've tried to get a different result with and without the fix, but I'm failing to hit the bug. Can you think of an example that should trigger the bug? Example usage: SELECT numeric_mul_patched(9999.999,2,0); var1ndigits=1 var2ndigits=2 rscale=3 numeric_mul_patched --------------------- 19999.998 (1 row) SELECT numeric_mul_patched(9999.999,2,1); var1ndigits=1 var2ndigits=2 rscale=4 numeric_mul_patched --------------------- 19999.9980 (1 row) SELECT numeric_mul_patched(9999.999,2,-1); var1ndigits=1 var2ndigits=2 rscale=2 numeric_mul_patched --------------------- 20000.00 (1 row) SELECT numeric_mul_patched(9999.999,2,-2); var1ndigits=1 var2ndigits=2 rscale=1 numeric_mul_patched --------------------- 20000.0 (1 row) /Joel