public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org
Subject: Re: [PATCH 6/7] stdlib: Optimization qsort{_r} swap implementation
Date: Mon, 22 Jan 2018 17:15:00 -0000	[thread overview]
Message-ID: <79fcab22-899c-1ef1-d072-0aaae977c470@cs.ucla.edu> (raw)
In-Reply-To: <3ce984d8-751c-f3e9-7dd7-e13e18f50c0e@linaro.org>

On 01/22/2018 02:55 AM, Adhemerval Zanella wrote:
> On 22/01/2018 06:27, Paul Eggert wrote:
>> Adhemerval Zanella wrote:
>>> +static inline bool
>>> +check_alignment (const void *base, size_t align)
>>> +{
>>> +  return _STRING_ARCH_unaligned || ((uintptr_t)base % (align - 1)) == 0;
>>> +}
>> Surely the '(align - 1)' was supposed to be 'align'. Has this been tested on an architecture that does not allow unaligned access?
> Yes, I checked on sparc64 machine.  This test is similar to the Linux kernel one
> at lib/sort.c.

The Linux kernel lib/sort.c test is (((unsigned long)base & (align - 1)) 
== 0), which is correct. The test above uses '% (align - 1)' instead, 
which is clearly wrong; the "%" should be "&". As the tests evidently 
did not catch the error, they need to be improved to catch it.

> It might be that your approach is faster for other architectures which do not have
> ifunc mempcpy, however I do not want to over-engineer this code since most real
> word correspond to key sizes of 4 and 8.

Thanks, that all makes sense.

One other question. Would it improve performance to partially evaluate 
qsort for the case where the key size is that of a pointer, to allow the 
swap to be done inline with four insns? I would imagine that this is the 
most common case.

  parent reply	other threads:[~2018-01-22 17:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18 17:53 [PATCH 0/7] Refactor qsort implementation Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 5/7] stdlib: Remove use of mergesort on qsort Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 4/7] stdlib: Add more qsort{_r} coverage Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 2/7] support: Add Mersenne Twister pseudo-random number generator Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 7/7] stdlib: Remove undefined behavior from qsort implementation Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 3/7] benchtests: Add bench-qsort Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 6/7] stdlib: Optimization qsort{_r} swap implementation Adhemerval Zanella
2018-01-22  8:27   ` Paul Eggert
2018-01-22 10:55     ` Adhemerval Zanella
2018-01-22 13:46       ` Alexander Monakov
2018-01-22 15:23         ` Adhemerval Zanella
2018-01-22 17:15       ` Paul Eggert [this message]
2018-01-22 17:48         ` Adhemerval Zanella
2018-01-22 18:29           ` Paul Eggert
2018-01-22 19:33             ` Adhemerval Zanella
2018-01-23  6:04               ` Paul Eggert
2018-01-23 18:28                 ` Adhemerval Zanella
2018-01-23 23:37                   ` Paul Eggert
2018-01-24 10:47                     ` Adhemerval Zanella
2018-01-18 17:53 ` [PATCH 1/7] stdlib: Adjust tst-qsort{2} to libsupport Adhemerval Zanella

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=79fcab22-899c-1ef1-d072-0aaae977c470@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.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).