public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stepan Golosunov <stepan@golosunov.pp.ru>
To: Florian Weimer <fweimer@redhat.com>
Cc: "Adhemerval Zanella Netto" <adhemerval.zanella@linaro.org>,
	"Andrew Pinski" <pinskia@gmail.com>,
	"Cristian Rodríguez" <cristian@rodriguez.im>,
	"Adhemerval Zanella via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: rustc SIGILL since qsort_r patches
Date: Tue, 7 Nov 2023 18:57:00 +0400	[thread overview]
Message-ID: <ZUpQPFgkpXCFCfMm@sghpc.golosunov.pp.ru> (raw)
In-Reply-To: <87fs1hd8ae.fsf@oldenburg.str.redhat.com>

On Tue, Nov 07, 2023 at 02:04:09PM +0100, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
> > On 07/11/23 08:09, Florian Weimer wrote:
> >> * Adhemerval Zanella Netto:
> >> 
> >>> Just a side note that the quicksort implementation was also used for
> >>> size (number of elements times size per element) larger than the
> >>> installed system RAM (_SC_PHYS_PAGES / size > _SC_PAGESIZE) or
> >>> whether malloc fails.  So it is a latent issue, that did not trigger
> >>> before by chance.  
> >> 
> >> Is it ever beneficial to call the comparison function with identical
> >> pointers, though?
> >
> > Afaik this how introsort works, and I am not aware of any comparison
> > sort with O(1) worst-case space complexity that does not require
> > a comparison callback that work as <=>.
> 
> I think the LLVM code will only assert if it is called with equal
> pointers, as the array elements are expected to be distinct (hence the
> assert).
> 
> My question is more along these lines: If the pointers are equal, does
> it make sense to perform the indirection function call?  I guess that
> depends on the nature of the comparison function.
> 
> I'm not sure where equal-pointers call happens, but why wouldn't
> something like this be an overall win?
> 
>   while (k <= n / 2)
>     {
>       size_t j = 2 * k;

Shouldn't this be

      size_t j = 2 * k + 1;

instead? Looks like the existing formula is designed for base-1
arrays.


>       if (j < n && cmp (base + (j * size), base + ((j + 1) * size), arg) < 0)
> 	j++;
> 
> +     if (k ==j)
> +      continue;
>       if (cmp (base + (k * size), base + (j * size), arg) >= 0)
> 	break;
> 
>       do_swap (base + (size * j), base + (k * size), size, swap_type);
>       k = j;
>     }
> 
> 
> Thanks,
> Florian
> 

  parent reply	other threads:[~2023-11-07 14:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-05  0:55 Cristian Rodríguez
2023-11-05  1:10 ` Andrew Pinski
2023-11-05  1:13   ` Andrew Pinski
2023-11-05 12:15     ` Cristian Rodríguez
2023-11-06 14:13   ` Adhemerval Zanella Netto
2023-11-07 11:09     ` Florian Weimer
2023-11-07 12:48       ` Adhemerval Zanella Netto
2023-11-07 13:04         ` Florian Weimer
2023-11-07 13:07           ` Adhemerval Zanella Netto
2023-11-07 13:13           ` Florian Weimer
2023-11-07 13:26             ` Adhemerval Zanella Netto
2023-11-07 14:02               ` Florian Weimer
2023-11-07 14:57           ` Stepan Golosunov [this message]
2023-11-07 16:05             ` Florian Weimer
2023-11-17 10:35               ` Florian Weimer
2023-11-17 11:44                 ` Adhemerval Zanella Netto
2023-11-17 13:33                   ` Florian Weimer
2023-11-17 13:57                     ` Florian Weimer
2023-11-17 16:17                       ` Florian Weimer
2023-11-17 18:37                         ` Adhemerval Zanella
2023-11-07 14:32 ` Florian Weimer
2023-11-08 14:19   ` Florian Weimer
2023-11-08 19:56     ` Cristian Rodríguez
2023-11-09 11:49       ` Cristian Rodríguez
2023-11-09 12:40         ` Adhemerval Zanella Netto

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=ZUpQPFgkpXCFCfMm@sghpc.golosunov.pp.ru \
    --to=stepan@golosunov.pp.ru \
    --cc=adhemerval.zanella@linaro.org \
    --cc=cristian@rodriguez.im \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=pinskia@gmail.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).