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=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32632 invoked from network); 1 Jul 2020 20:45:14 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 1 Jul 2020 20:45:14 -0000 Received: (qmail 17848 invoked by uid 550); 1 Jul 2020 20:45:10 -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 17827 invoked from network); 1 Jul 2020 20:45:09 -0000 Date: Wed, 1 Jul 2020 16:44:56 -0400 From: Rich Felker To: musl@lists.openwall.com Cc: Valentin Ochs Message-ID: <20200701204456.GI6430@brightrain.aerifal.cx> References: <20200701185026.GA6635@voyager> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200701185026.GA6635@voyager> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Superfluous shift in qsort()? On Wed, Jul 01, 2020 at 08:50:26PM +0200, Markus Wichmann wrote: > Hi all, > > I noticed something while reading code today: Near the end of qsort(), > we have this gem: > > shl(p, 2); > pshift -= 2; > p[0] ^= 7; > shr(p, 1); > > Now, I don't know if I am missing something, but don't the shl and the > shr partially cancel out? Isn't this the same as > > shl(p, 1); > p[0] ^= 3; > > As it is, it isn't wrong, just weird. Assuming non-overflow, I think they're equivalent (also assuming you keep the pshift-=2). I've CC'd the original author but we've not been in touch for a long time so I don't know whether to expect a response. I don't have any insight on why it was done this way. Rich