From: "H. Peter Anvin" <hpa@zytor.com>
To: Stafford Horne <shorne@gmail.com>
Cc: Russell King - ARM Linux <linux@armlinux.org.uk>,
Jiri Slaby <jslaby@suse.cz>,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Richard Henderson <rth@twiddle.net>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
Matt Turner <mattst88@gmail.com>,
Vineet Gupta <vgupta@synopsys.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
Richard Kuo <rkuo@codeaurora.org>,
Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Michal Simek <monstr@monstr.eu>,
Ralf Baechle <ralf@linux-mips.org>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
"James E.J. Bottomley" <jejb@parisc-linux.org>,
Helge Deller <deller@gmx.de>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Michael Ellerman <mpe@ellerman.id.au>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
"David S. Miller"@zytor.com
Subject: Re: [PATCH 1/3] futex: remove duplicated code
Date: Sat, 04 Mar 2017 15:03:50 -0800 [thread overview]
Message-ID: <201703042304.v24N4Afu010968@mail.zytor.com> (raw)
In-Reply-To: <20170304213805.GA2449@lianli.shorne-pla.net>
<davem@davemloft.net>,Chris Metcalf <cmetcalf@mellanox.com>,Thomas Gleixner <tglx@linutronix.de>,Ingo Molnar <mingo@redhat.com>,Chris Zankel <chris@zankel.net>,Max Filippov <jcmvbkbc@gmail.com>,Arnd Bergmann <arnd@arndb.de>,x86@kernel.org,linux-alpha@vger.kernel.org,linux-snps-arc@lists.infradead.org,linux-arm-kernel@lists.infradead.org,linux-hexagon@vger.kernel.org,linux-ia64@vger.kernel.org,linux-mips@linux-mips.org,openrisc@lists.librecores.org,linux-parisc@vger.kernel.org,linuxppc-dev@lists.ozlabs.org,linux-s390@vger.kernel.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,linux-xtensa@linux-xtensa.org,linux-arch@vger.kernel.org
From: hpa@zytor.com
Message-ID: <9B46AFA6-C422-41FD-8E8A-356E44A6DCD2@zytor.com>
On March 4, 2017 1:38:05 PM PST, Stafford Horne <shorne@gmail=2Ecom> wrote:
>On Sat, Mar 04, 2017 at 11:15:17AM -0800, H=2E Peter Anvin wrote:
>> On 03/04/17 05:05, Russell King - ARM Linux wrote:
>> >> =20
>> >> +static int futex_atomic_op_inuser(int encoded_op, u32 __user
>*uaddr)
>> >> +{
>> >> + int op =3D (encoded_op >> 28) & 7;
>> >> + int cmp =3D (encoded_op >> 24) & 15;
>> >> + int oparg =3D (encoded_op << 8) >> 20;
>> >> + int cmparg =3D (encoded_op << 20) >> 20;
>> >=20
>> > Hmm=2E oparg and cmparg look like they're doing these shifts to get
>sign
>> > extension of the 12-bit values by assuming that "int" is 32-bit -
>> > probably worth a comment, or for safety, they should be "s32" so
>it's
>> > not dependent on the bit-width of "int"=2E
>> >=20
>>=20
>> For readability, perhaps we should make sign- and zero-extension an
>> explicit facility?
>
>There is some of this in already here, 32 and 64 bit versions:
>
> include/linux/bitops=2Eh
>
>Do we really need zero extension? It seems the same=2E
>
>Example implementation from bitops=2Eh
>
>static inline __s32 sign_extend32(__u32 value, int index)
>{
> __u8 shift =3D 31 - index;
> return (__s32)(value << shift) >> shift;
>}
>
>> /*
>> * Truncate an integer x to n bits, using sign- or
>> * zero-extension, respectively=2E
>> */
>> static inline __const_func__ s32 sex32(s32 x, int n)
>> {
>> return (x << (32-n)) >> (32-n);
>> }
>>=20
>> static inline __const_func__ s64 sex64(s64 x, int n)
>> {
>> return (x << (64-n)) >> (64-n);
>> }
>>=20
>> #define sex(x,y) \
>> ((__typeof__(x)) \
>> (((__builtin_constant_p(y) && ((y) <=3D 32)) || \
>> (sizeof(x) <=3D sizeof(s32))) \
>> ? sex32((x),(y)) : sex64((x),(y))))
>>=20
>> static inline __const_func__ u32 zex32(u32 x, int n)
>> {
>> return (x << (32-n)) >> (32-n);
>> }
>>=20
>> static inline __const_func__ u64 zex64(u64 x, int n)
>> {
>> return (x << (64-n)) >> (64-n);
>> }
>>=20
>> #define zex(x,y) \
>> ((__typeof__(x)) \
>> (((__builtin_constant_p(y) && ((y) <=3D 32)) || \
>> (sizeof(x) <=3D sizeof(u32))) \
>> ? zex32((x),(y)) : zex64((x),(y))))
>>=20
Signed versus unsigned=2E=2E=2E
--=20
Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E
next prev parent reply other threads:[~2017-03-04 23:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 12:27 [PATCH 1/3] futex: remove duplicated code Jiri Slaby
2017-03-03 14:08 ` Heiko Carstens
2017-03-03 14:48 ` Chris Metcalf
2017-03-04 12:49 ` Michael Ellerman
2017-03-04 13:05 ` Russell King - ARM Linux
2017-03-04 19:15 ` H. Peter Anvin
2017-03-04 21:38 ` Stafford Horne
2017-03-04 23:03 ` H. Peter Anvin [this message]
2017-03-04 23:08 ` H. Peter Anvin
2017-03-09 4:16 ` Rob Landley
2017-03-09 4:36 ` H. Peter Anvin
2017-03-06 1:52 ` Rich Felker
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=201703042304.v24N4Afu010968@mail.zytor.com \
--to=hpa@zytor.com \
--cc="David S. Miller"@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=dalias@libc.org \
--cc=deller@gmx.de \
--cc=fenghua.yu@intel.com \
--cc=heiko.carstens@de.ibm.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jejb@parisc-linux.org \
--cc=jonas@southpole.se \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mattst88@gmail.com \
--cc=monstr@monstr.eu \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=ralf@linux-mips.org \
--cc=rkuo@codeaurora.org \
--cc=rth@twiddle.net \
--cc=schwidefsky@de.ibm.com \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=tony.luck@intel.com \
--cc=vgupta@synopsys.com \
--cc=will.deacon@arm.com \
--cc=ysato@users.sourceforge.jp \
/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).