From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Paul Eggert <eggert@cs.ucla.edu>, libc-alpha@sourceware.org
Subject: Re: [PATCH 6/7] stdlib: Optimization qsort{_r} swap implementation
Date: Mon, 22 Jan 2018 19:33:00 -0000 [thread overview]
Message-ID: <da63fac2-4f25-4a04-363a-82ad40223b56@linaro.org> (raw)
In-Reply-To: <3404a331-2832-4bf6-703f-25e3d6255d32@cs.ucla.edu>
On 22/01/2018 16:29, Paul Eggert wrote:
> On 01/22/2018 09:48 AM, Adhemerval Zanella wrote:
>> One option I have not
>> tested, and which will trade code side for performance; would parametrize
>> the qsort creation (as for the 7/7 patch in this set) to have qsort_uint32_t,
>> qsort_uint64_t, and qsort_generic for instance (which calls the swap inline).
>>
>> So we will have something as:
>>
>> void qsort (void *pbase, size_t total_elems, size_t size)
>> {
>> Â Â if (size == sizeof (uint32_t)
>> Â Â Â Â && check_alignment (base, sizeof (uint32_t)))
>> Â Â Â Â return qsort_uint32_t (pbase, total_elems, size);
>> Â Â else if (size == sizeof (uint64_t)
>> Â Â Â Â && check_alignment (base, sizeof (uint64_t)))
>> Â Â Â Â return qsort_uint64_t (pbase, total_elems, size);
>> Â Â return qsort_generic (pbase, total_elems, size);
>> }
>
> Yes, that's the option I was thinking of, except I was thinking that the first test should be "if (size == sizeof (void *) && check_alignment (base, alignof (void *))) return qsort_voidptr (pbase, total_elems, size);" because sorting arrays of pointers is the most common. (Also, check_alignment's argument should use alignof not sizeof.)
>
I add the implementation size and the results are slight better:
Results for member size 8
Sorted
nmemb | base | patched | diff
32| 1173 | 1282 | 9.29
4096| 325485 | 332451 | 2.14
32768| 3232255 | 3293842 | 1.91
524288| 65645381 | 66182948 | 0.82
Repeated
nmemb | base | patched | diff
32| 2074 | 2034 | -1.93
4096| 948339 | 913363 | -3.69
32768| 8906214 | 8651378 | -2.86
524288| 173498547 | 166294093 | -4.15
MostlySorted
nmemb | base | patched | diff
32| 2211 | 2147 | -2.89
4096| 757543 | 739765 | -2.35
32768| 7785343 | 7570811 | -2.76
524288| 133912169 | 129728791 | -3.12
Unsorted
nmemb | base | patched | diff
32| 2219 | 2191 | -1.26
4096| 1017790 | 989068 | -2.82
32768| 9747216 | 9456092 | -2.99
524288| 191726744 | 185012121 | -3.50
At the cost of large text sizes and slight more code:
# Before
$ size stdlib/qsort.os
text data bss dec hex filename
2578 0 0 2578 a12 stdlib/qsort.os
# After
$ size stdlib/qsort.os
text data bss dec hex filename
6037 0 0 6037 1795 stdlib/qsort.os
I still prefer my version where generates shorter text segment and also
optimizes for uint32_t.
next prev parent reply other threads:[~2018-01-22 19:33 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 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
2018-01-22 17:48 ` Adhemerval Zanella
2018-01-22 18:29 ` Paul Eggert
2018-01-22 19:33 ` Adhemerval Zanella [this message]
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 4/7] stdlib: Add more qsort{_r} coverage 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 5/7] stdlib: Remove use of mergesort on qsort 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 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=da63fac2-4f25-4a04-363a-82ad40223b56@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=eggert@cs.ucla.edu \
--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).