linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: George Spelvin <lkml@sdf.org>
To: adrian.hunter@intel.com, ard.biesheuvel@linaro.org,
	benh@kernel.crashing.org, bp@alien8.de, darrick.wong@oracle.com,
	dchinner@redhat.com, dedekind1@gmail.com,
	gregkh@linuxfoundation.org, hpa@zytor.com, jlbec@evilplan.org,
	jpoimboe@redhat.com, linux-kernel@vger.kernel.org,
	linux-mtd@lists.infradead.org,
	linux-snps-arc@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, lkml@sdf.org, mark@fasheh.com,
	mingo@redhat.com, mpe@ellerman.id.au,
	naveen.n.rao@linux.vnet.ibm.com, ocfs2-devel@oss.oracle.com,
	paulus@samba.org, richard@nod.at, sfr@canb.auug.org.au,
	st5pub@yandex.ru, tglx@linutronix.de, vgupta@synopsys.com,
	x86@kernel.org
Cc: akpm@linux-foundation.org, amir73il@gmail.com,
	andriy.shevchenko@linux.intel.com, ashish.samant@oracle.com,
	ge.changwei@h3c.com, gustavo@embeddedor.com, jannh@google.com,
	jiang.biao2@zte.com.cn, jiangyiwen@huawei.com, jslaby@suse.cz,
	kamalesh@linux.vnet.ibm.com, keescook@chromium.org,
	lchen@suse.com, linux@rasmusvillemoes.dk, malat@debian.org,
	mhocko@suse.com, npiggin@gmail.com, peterz@infradead.org,
	piaojun@huawei.com, rppt@linux.ibm.com,
	yamada.masahiro@socionext.com, yuehaibing@huawei.com
Subject: Re: [PATCH 0/5] simple sort swap function usage improvements
Date: Sat, 30 Mar 2019 17:16:02 GMT	[thread overview]
Message-ID: <201903301716.x2UHG23t020732@sdf.org> (raw)
In-Reply-To: <18626931553963861@sas1-b3ec53dbc12b.qloud-c.yandex.net>

Great work; that is indeed a logical follow-on.

Reviewed by: George Spelvin <lkml@sdf.org>

I you feel even more ambitious, you could try impementing Rasmus
Villemoes' idea of having generic *compare* functions.  (It's on
my to-do list, but I haven't made meaningful progress yet, and I'm
happy to pawn it off.)

A significant fraction of the time, the sort key is a 4- or 8-byte
integer field in a structure at a small offset from the base or
list_head.

A function pointer < 4096 could be interpreted as encoding:
- Key size (1 bit)
- Key signedness (1 bit)
- Sort direction (1 bit)
- Offset (9 bits; +/-256 words = +/-1024 bytes, or 0..511 words from start)

With the correct level of preprocessor hackery,
SIMPLE_CMP_ASCENDING(struct type, key_field)
SIMPLE_LIST_CMP_ASCENDING(struct type, list_field, key_field)
SIMPLE_CMP_DESCENDING(struct type, key_field)
SIMPLE_LIST_CMP_DESCENDING(struct type, list_field, key_field)

could encode all that and cause a compile-time error if the key
is the wrong type or the offset is out of range.

  parent reply	other threads:[~2019-03-30 17:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-30 16:37 [PATCH 0/5] simple sort swap function usage improvements Andrey Abramov
2019-03-30 16:40 ` [PATCH 1/5] arch/arc: unwind.c: replace swap function with built-in one Andrey Abramov
2019-03-30 16:41 ` [PATCH 2/5] powerpc: module_[32|64].c: " Andrey Abramov
     [not found]   ` <87zhpaox14.fsf@concordia.ellerman.id.au>
2019-04-02 19:11     ` Andrey Abramov
2019-03-30 16:42 ` [PATCH 3/5] ocfs2: dir,refcounttree,xattr: replace swap functions " Andrey Abramov
2019-03-30 16:43 ` [PATCH 4/5] ubifs: find.c: replace swap function " Andrey Abramov
2019-03-30 16:43 ` [PATCH 5/5] Lib: sort.h: replace int size with size_t size in the swap function Andrey Abramov
     [not found]   ` <20190330183826.GB21828@kroah.com>
2019-03-30 20:15     ` George Spelvin
2019-03-30 20:24       ` Greg KH
2019-03-30 21:49         ` George Spelvin
2019-03-31  7:00       ` Andrey Abramov
2019-03-31 10:54         ` gregkh
2019-04-01 14:47           ` David Laight
2019-04-01 18:01             ` Vineet Gupta
2019-04-01 18:14               ` Andrey Abramov
2019-04-01 18:22                 ` Vineet Gupta
2019-03-30 17:16 ` George Spelvin [this message]
2019-04-01 21:08   ` [PATCH 0/5] simple sort swap function usage improvements Rasmus Villemoes

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=201903301716.x2UHG23t020732@sdf.org \
    --to=lkml@sdf.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=ashish.samant@oracle.com \
    --cc=benh@kernel.crashing.org \
    --cc=bp@alien8.de \
    --cc=darrick.wong@oracle.com \
    --cc=dchinner@redhat.com \
    --cc=dedekind1@gmail.com \
    --cc=ge.changwei@h3c.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=jiang.biao2@zte.com.cn \
    --cc=jiangyiwen@huawei.com \
    --cc=jlbec@evilplan.org \
    --cc=jpoimboe@redhat.com \
    --cc=jslaby@suse.cz \
    --cc=kamalesh@linux.vnet.ibm.com \
    --cc=keescook@chromium.org \
    --cc=lchen@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=malat@debian.org \
    --cc=mark@fasheh.com \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=piaojun@huawei.com \
    --cc=richard@nod.at \
    --cc=rppt@linux.ibm.com \
    --cc=sfr@canb.auug.org.au \
    --cc=st5pub@yandex.ru \
    --cc=tglx@linutronix.de \
    --cc=vgupta@synopsys.com \
    --cc=x86@kernel.org \
    --cc=yamada.masahiro@socionext.com \
    --cc=yuehaibing@huawei.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 NNTP newsgroup(s).