From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9864 invoked from network); 1 Jun 2023 19:08:21 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 1 Jun 2023 19:08:21 -0000 Received: (qmail 19589 invoked by uid 550); 1 Jun 2023 19:08:18 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 19547 invoked from network); 1 Jun 2023 19:08:17 -0000 Date: Thu, 1 Jun 2023 15:08:04 -0400 From: Rich Felker To: Alexander Monakov Cc: musl@lists.openwall.com Message-ID: <20230601190803.GL4163@brightrain.aerifal.cx> References: <1fe28ea2525f112264a1a819d8ce50a97504ab8b.1684932892.git.Jens.Gustedt@inria.fr> <20230524212835.GC4163@brightrain.aerifal.cx> <20230525111653.4b0175d3@inria.fr> <917e05a1-26b9-5e13-006f-85518348c9e9@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <917e05a1-26b9-5e13-006f-85518348c9e9@ispras.ru> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [C23 new stdlib 2/4] C23: add the memalignment function On Thu, Jun 01, 2023 at 04:35:04PM +0300, Alexander Monakov wrote: > > On Thu, 25 May 2023, Jā‚‘ā‚™ā‚› Gustedt wrote: > > > Rich, > > > > on Wed, 24 May 2023 17:28:35 -0400 you (Rich Felker ) > > wrote: > > > > > There's a more efficient implementation of this function which does > > > not depend on __builtin_ctzll (which we don't): p^(p-1)&p > > > > yes, nice > > > > If you have other such nice formulas for some of the interfaces in > > , please let me know. They are hard to find in search > > engines. > > It seems this was unanswered. Hacker's Delight by Henry Warren offers > a lot of material on such topics. For this particular question it also > gives the efficient implementation: 'p & -p'. Wow, I don't know why I didn't realize this being that p&-p is a common pattern I use... Somehow I didn't see that it was the same operation. Rich