|
Message-ID: <20200701212309.5ooyvfq47sh4llwi@mae> Date: Wed, 1 Jul 2020 23:23:09 +0200 From: Valentin Ochs <a@....de> To: musl@...ts.openwall.com Subject: Re: Superfluous shift in qsort()? On Wed, Jul 01, 2020 at 04:44:56PM -0400, Rich Felker wrote: > 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). Yes, it looks that way. I'm afraid I don't have any further insight - it's been quite a while since I thought about the qsort code, and I've not been doing much work on algorithms over the last couple of years. The only thing I can think of is that one could figure out which behaviour with regard to overflow in shl() should be the valid one. I suspect that replacing it would be valid and this is some transformation I did while implementing smoothsort without realizing that this can be simplified. Cheers, Valentin
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.