public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
	Alexander Monakov <amonakov@ispras.ru>
Cc: libc-alpha@sourceware.org,
	Noah Goldstein <goldstein.w.n@gmail.com>,
	Zack Weinberg <zack@owlfolio.org>
Subject: Re: [PATCH v2] stdlib: Reinstate stable mergesort implementation on qsort
Date: Fri, 12 Jan 2024 10:22:15 -0300	[thread overview]
Message-ID: <923cbce1-e11e-4765-93ea-d0b942dea296@linaro.org> (raw)
In-Reply-To: <87il3ykd9w.fsf@oldenburg.str.redhat.com>



On 12/01/24 08:21, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> diff --git a/manual/search.texi b/manual/search.texi
>> index a550858478..5691bf2f2b 100644
>> --- a/manual/search.texi
> 
>> @@ -199,8 +199,9 @@ Functions}):
>>  The @code{qsort} function derives its name from the fact that it was
>>  originally implemented using the ``quick sort'' algorithm.
>>  
>> +The implementation of @code{qsort} in this library might not be an
>> +in-place sort and might thereby use an extra amount of memory to store
>> +the array.
>>  @end deftypefun
> 
> I'd appreciate if a native speaker could have look at this.

I will update with Alexander's suggestion.

> 
>> +typedef uint32_t __attribute__ ((__may_alias__)) u32_alias_t;
>> +typedef uint64_t __attribute__ ((__may_alias__)) u64_alias_t;
> 
> What's the code generation impact of may_alias here?

I did not see any code difference on x86_64 and aarch64 [1], the alias
s used mainly to avoid possible undefined behaviour (similar to what 
we do on string-optype.h for the generic string routines).

> 
>> +    case SWAP_VOID_ARG:
>> +      while (n1 > 0 && n2 > 0)
>> +	{
>> +	  if ((*cmp) (*(const void **) b1, *(const void **) b2, arg) <= 0)
>> +	    {
>> +	      *(void **) tmp = *(void **) b1;
>> +	      b1 += sizeof (void *);
>> +	      --n1;
>> +	    }
>> +	  else
>> +	    {
>> +	      *(void **) tmp = *(void **) b2;
>> +	      b2 += sizeof (void *);
>> +	      --n2;
>> +	    }
>> +	  tmp += sizeof (void *);
>> +	}
>> +    default:
>> +      while (n1 > 0 && n2 > 0)
> 
> Missing break before “default:”.

Ack.

> 
>>  void
>>  __qsort_r (void *const pbase, size_t total_elems, size_t size,
>>  	   __compar_d_fn_t cmp, void *arg)
>>  {
>>    if (total_elems <= 1)
>>      return;
>>  
>> +  char tmp[QSORT_STACK_SIZE];
>> +  size_t total_size = total_elems * size;
>> +  char *buf;
> 
> You need to ensure alignment now that you aren't using alloca anymore, I
> think.

Indeed, I will update to follow alloca alignment.

> 
> Rest looks okay.
> 
> Thanks,
> Florian
> 

[1] https://godbolt.org/z/nEf34WhrM

      parent reply	other threads:[~2024-01-12 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 14:15 Adhemerval Zanella
2024-01-12 11:21 ` Florian Weimer
2024-01-12 11:50   ` Alexander Monakov
2024-01-12 13:22   ` Adhemerval Zanella Netto [this message]

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=923cbce1-e11e-4765-93ea-d0b942dea296@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=amonakov@ispras.ru \
    --cc=fweimer@redhat.com \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=zack@owlfolio.org \
    /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).