Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy7hV-0008DF-VR for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Nov 2022 08:35:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oy7hU-0005f6-Ic for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Nov 2022 08:35:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy7hT-0005ex-HT for pgsql-hackers@lists.postgresql.org; Thu, 24 Nov 2022 08:35:16 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy7hQ-0006oM-9f for pgsql-hackers@postgresql.org; Thu, 24 Nov 2022 08:35:14 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 82FBF3200B4E; Thu, 24 Nov 2022 03:35:10 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 24 Nov 2022 03:35:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1669278910; x= 1669365310; bh=gIIcx0xIPnDcMdDuBM6H3U0ahpENQ/JyDB+pYUH9y6E=; b=U EFFDL7rLzVLrbW2a+GonbL96qkmUuWPWTcIMLOREeLmcNNgLczC/8TD0uQtjuDT9 ow9iBx08mc9jWsJFONkHy8mCuJ0JsoH7tv5BMwS31ZLUnlxC3ObT+YcjXNKvFVWQ t4qCJqn2OqHCXxSWhrKNbek4qVRGJjoTwZp5EiJpFEocbCWfRFVkc34juM7Ddua5 4iN/T42s+IZuHzTccbzFtLZE2P/LzhFuyUrpBAfHfa6n6muBZwpQGeO3HKQUtJ4+ SnoDZX74RvswkLIhY4VhfG3DRF7BuMtUxvrqApw/J26xgSiNbUyj4siTbI50Y03G wrIcg9N+SNX5TrnmcJGmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedriedvgdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvghnth gvrhhprhhishgvuggsrdgtohhmqeenucggtffrrghtthgvrhhnpeehleffgeegudejteei hfelteduvdeifffhffdvjedvffegjeekudeludehudeifeenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrrdgvihhsvghnthhrrghu thesvghnthgvrhhprhhishgvuggsrdgtohhm X-ME-Proxy: Feedback-ID: i131946ab:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Nov 2022 03:35:09 -0500 (EST) Message-ID: <068f0344-ccce-c623-3cfe-d09752db158d@enterprisedb.com> Date: Thu, 24 Nov 2022 09:35:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Non-decimal integer literals Content-Language: en-US To: David Rowley Cc: John Naylor , pgsql-hackers References: <577603ec-787b-61b8-23a2-1bd0457ed1c7@enterprisedb.com> <2317133.1643155358@sss.pgh.pa.us> <97aa22d7-b80f-efa1-f368-3dbf73a15980@enterprisedb.com> <071c40f2-15cf-5db3-8799-dbac041bb881@enterprisedb.com> <791aee01-f488-0706-2694-08c5b57a3bdd@enterprisedb.com> From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 23.11.22 09:54, David Rowley wrote: > On Wed, 23 Nov 2022 at 02:37, Peter Eisentraut > wrote: >> Here is a new patch. > > This looks like quite an inefficient way to convert a hex string into an int64: > > while (*ptr && isxdigit((unsigned char) *ptr)) > { > int8 digit = hexlookup[(unsigned char) *ptr]; > > if (unlikely(pg_mul_s64_overflow(tmp, 16, &tmp)) || > unlikely(pg_sub_s64_overflow(tmp, digit, &tmp))) > goto out_of_range; > > ptr++; > } > > I wonder if you'd be better off with something like: > > while (*ptr && isxdigit((unsigned char) *ptr)) > { > if (unlikely(tmp & UINT64CONST(0xF000000000000000))) > goto out_of_range; > > tmp = (tmp << 4) | hexlookup[(unsigned char) *ptr++]; > } > > Going by [1], clang will actually use multiplication by 16 to > implement the former. gcc is better and shifts left by 4, so likely > won't improve things for gcc. It seems worth doing it this way for > anything that does not have HAVE__BUILTIN_OP_OVERFLOW anyway. My code follows the style used for parsing the decimal integers. Keeping that consistent is valuable I think. I think the proposed change makes the code significantly harder to understand. Also, what you are suggesting here would amount to an attempt to make parsing hexadecimal integers even faster than parsing decimal integers. Is that useful?