mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: Valentin Ochs <a@0au.de>
Subject: Re: [musl] Superfluous shift in qsort()?
Date: Wed, 1 Jul 2020 16:44:56 -0400	[thread overview]
Message-ID: <20200701204456.GI6430@brightrain.aerifal.cx> (raw)
In-Reply-To: <20200701185026.GA6635@voyager>

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

  reply	other threads:[~2020-07-01 20:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 18:50 Markus Wichmann
2020-07-01 20:44 ` Rich Felker [this message]
2020-07-01 21:23   ` Valentin Ochs
2020-07-02 14:44     ` Markus Wichmann
2020-07-06 22:01       ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200701204456.GI6430@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=a@0au.de \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).