Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-15 Thread Geert Uytterhoeven
Hi George, On Fri, Mar 15, 2019 at 4:36 AM George Spelvin wrote: > >> swap_bytes / swap_4byte_words / swap_8byte_words > >> swap_bytes / swap_ints / swap_longs > >> swap_1 / swap_4 / swap_8 > >> Pistols at dawn? > > On Thu, 14 Mar 2019 at 22:59:55 +0300, Andrey Abramov wrote: > > Yes, in my opini

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread George Spelvin
>> swap_bytes / swap_4byte_words / swap_8byte_words >> swap_bytes / swap_ints / swap_longs >> swap_1 / swap_4 / swap_8 >> Pistols at dawn? On Thu, 14 Mar 2019 at 22:59:55 +0300, Andrey Abramov wrote: > Yes, in my opinion, swap_bytes / swap_ints / swap_longs are the > most readable because we have

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread Andrey Abramov
> Pistols at dawn? > swap_bytes > swap_4byte_words > swap_8byte_words or >  swap_bytes / swap_ints / swap_longs >  swap_1 / swap_4 / swap_8 Yes, in my opinion, swap_bytes / swap_ints / swap_longs are the most readable because we have both swap_ints and swap_longs functions (in one file near each

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread Andy Shevchenko
On Thu, Mar 14, 2019 at 11:53:55AM +, George Spelvin wrote: > On Thu, 14 Mar 2019 at 11:41:26 +0100, Geert Uytterhoeven wrote: > > On Thu, Mar 14, 2019 at 11:10 AM George Spelvin wrote: > >> On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: > How about one of: > swap_bytes

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread George Spelvin
On Thu, 14 Mar 2019 at 11:41:26 +0100, Geert Uytterhoeven wrote: > On Thu, Mar 14, 2019 at 11:10 AM George Spelvin wrote: >> On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: How about one of: swap_bytes / swap_ints / swap_longs swap_1 / swap_4 / swap_8 >>> >>> longs are

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread Geert Uytterhoeven
Hi George, On Thu, Mar 14, 2019 at 11:10 AM George Spelvin wrote: > On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: > >> How about one of: > >> swap_bytes / swap_ints / swap_longs > >> swap_1 / swap_4 / swap_8 > > > > longs are ambiguous, so I would prefer bit-sized types. > > I alre

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread George Spelvin
On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: >> Although I'm thinking of: >> >> static bool __attribute_const__ >> is_aligned(const void *base, size_t size, unsigned char align) >> { >> unsigned char lsbits = (unsigned char)size; >> >> (void)base; >> #ifndef CONFIG_HAVE_EF

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread George Spelvin
On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: >> Although I'm thinking of: >> >> static bool __attribute_const__ >> is_aligned(const void *base, size_t size, unsigned char align) >> { >> unsigned char lsbits = (unsigned char)size; >> >> (void)base; >> #ifndef CONFIG_HAVE_EF

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-14 Thread Andy Shevchenko
On Sat, Mar 09, 2019 at 03:53:41PM +, l...@sdf.org wrote: > Andy Shevchenko wrote: > > On Thu, Feb 21, 2019 at 06:30:28AM +, George Spelvin wrote: > >> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > > > > Why #ifdef is better than if (IS_ENABLED()) ? > > Because CONFIG_HAVE_EFFICIENT_UN

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-13 Thread George Spelvin
Thank you for your thoughtful comments! On Wed, 13 Mar 2019 at 23:23:44 +0100, Rasmus Villemoes wrote: > On 21/02/2019 07.30, George Spelvin wrote: > + * @align: required aignment (typically 4 or 8) > > typo aLignment Thanks; fixed! >> + * Returns true if elements can be copied using word loads

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-13 Thread Geert Uytterhoeven
On Wed, Mar 13, 2019 at 10:23 PM Rasmus Villemoes wrote: > On 21/02/2019 07.30, George Spelvin wrote: > > +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > > + (void)base; > > +#else > > + lsbits |= (unsigned int)(size_t)base; > > The kernel usually casts pointers to long or unsigned long.

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-13 Thread Rasmus Villemoes
On 21/02/2019 07.30, George Spelvin wrote: > Rather than u32_swap and u64_swap working on 4- and 8-byte objects > directly, let them handle any multiple of 4 or 8 bytes. This speeds > up most users of sort() by avoiding fallback to the byte copy loop. > > Despite what commit ca96ab859ab4 ("lib/so

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-09 Thread George Spelvin
Andy Shevchenko wrote: > Shouldn't simple memcpy cover these case for both 32- and 64-bit > architectures? Speaking of replacing swap with copying via temporary buffers, one idea that did come to mind was avoiding swap for sufficiently small objects. Every sift-down is actually a circular shift.

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-09 Thread Andrey Abramov
> Although I'm thinking of: > > static bool __attribute_const__ > is_aligned(const void *base, size_t size, unsigned char align) > { > unsigned char lsbits = (unsigned char)size; > > (void)base; > #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > lsbits |= (unsigned char)(uintptr_t)base; > #endif >

Re: [PATCH 1/5] lib/sort: Make swap functions more generic

2019-03-09 Thread lkml
Thnk you for the feedback! Andy Shevchenko wrote: > On Thu, Feb 21, 2019 at 06:30:28AM +, George Spelvin wrote: >> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > > Why #ifdef is better than if (IS_ENABLED()) ? Because CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is bool and not tristate. IS_ENA