Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bob Eager Newsgroups: comp.misc Subject: Re: The 8-Byte Two-Step Date: 20 Sep 2014 21:14:48 GMT Lines: 33 Message-ID: References: <01T8OImfoeUtayhTm1xJJ0vS@dont-email.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net eU4anmyeMjYrrADH3+NmKAX2ao5OsHzT1usKSBtrvDAOtnqbl/ Cancel-Lock: sha1:uXSeD/8h1kgZjnNGE1VI7bUGLWk= User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: csiph.com comp.misc:5007 On Sat, 20 Sep 2014 20:41:29 +0000, Rich wrote: > http://zinascii.com/2014/the-8-byte-two-step.html > > While studying the Illumos queue implementation I came across a line > of code that left me quite perplexed. > > #define MQ_ALIGNSIZE 8 /* 64-bit alignment */ ... temp = > (mqhp->mq_maxsz + MQ_ALIGNSIZE - 1) & ~(MQ_ALIGNSIZE - 1); > > I knew it had something to do with alignment on a 64-bit boundary, > but just how the hell was it doing it? Why is it subtracting one from > the alignment size? Why is it negating the expression on the right? > Why is it adding to the max message size? What the hell is going on? > > At first I attempted to derive the pattern in my head but kept losing > my place; forced to start over multiple times. After placing my pride > on the bookshelf next to me, I wrote some C to help decode the > mystery. The program breaks the expression into its three parts, > printing the base-2 representation of each step. Here are some test > runs with different sizes: > > ... Standard bit of code. I can't remember when I didn't know that one! -- Using UNIX since v6 (1975)... Use the BIG mirror service in the UK: http://www.mirrorservice.org