[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3994975e-89a5-d2b5-60be-a8633ddc3733@zytor.com>
Date: Sat, 4 Mar 2017 11:15:17 -0800
From: "H. Peter Anvin" <hpa@...or.com>
To: Russell King - ARM Linux <linux@...linux.org.uk>,
Jiri Slaby <jslaby@...e.cz>
Cc: akpm@...ux-foundation.org, linux-kernel@...r.kernel.org,
Richard Henderson <rth@...ddle.net>,
Ivan Kokshaysky <ink@...assic.park.msu.ru>,
Matt Turner <mattst88@...il.com>,
Vineet Gupta <vgupta@...opsys.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will.deacon@....com>,
Richard Kuo <rkuo@...eaurora.org>,
Tony Luck <tony.luck@...el.com>,
Fenghua Yu <fenghua.yu@...el.com>,
Michal Simek <monstr@...str.eu>,
Ralf Baechle <ralf@...ux-mips.org>,
Jonas Bonn <jonas@...thpole.se>,
Stefan Kristiansson <stefan.kristiansson@...nalahti.fi>,
Stafford Horne <shorne@...il.com>,
"James E.J. Bottomley" <jejb@...isc-linux.org>,
Helge Deller <deller@....de>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Paul Mackerras <paulus@...ba.org>,
Michael Ellerman <mpe@...erman.id.au>,
Martin Schwidefsky <schwidefsky@...ibm.com>,
Heiko Carstens <heiko.carstens@...ibm.com>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
Rich Felker <dalias@...c.org>,
"David S. Miller" <davem@...emloft.net>,
Chris Metcalf <cmetcalf@...lanox.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Chris Zankel <chris@...kel.net>,
Max Filippov <jcmvbkbc@...il.com>,
Arnd Bergmann <arnd@...db.de>, x86@...nel.org,
linux-alpha@...r.kernel.org, linux-snps-arc@...ts.infradead.org,
linux-arm-kernel@...ts.infradead.org,
linux-hexagon@...r.kernel.org, linux-ia64@...r.kernel.org,
linux-mips@...ux-mips.org, openrisc@...ts.librecores.org,
linux-parisc@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-s390@...r.kernel.org, linux-sh@...r.kernel.org,
sparclinux@...r.kernel.org, linux-xtensa@...ux-xtensa.org,
linux-arch@...r.kernel.org
Subject: Re: [PATCH 1/3] futex: remove duplicated code
On 03/04/17 05:05, Russell King - ARM Linux wrote:
>>
>> +static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
>> +{
>> + int op = (encoded_op >> 28) & 7;
>> + int cmp = (encoded_op >> 24) & 15;
>> + int oparg = (encoded_op << 8) >> 20;
>> + int cmparg = (encoded_op << 20) >> 20;
>
> Hmm. 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".
>
For readability, perhaps we should make sign- and zero-extension an
explicit facility?
/*
* Truncate an integer x to n bits, using sign- or
* zero-extension, respectively.
*/
static inline __const_func__ s32 sex32(s32 x, int n)
{
return (x << (32-n)) >> (32-n);
}
static inline __const_func__ s64 sex64(s64 x, int n)
{
return (x << (64-n)) >> (64-n);
}
#define sex(x,y) \
((__typeof__(x)) \
(((__builtin_constant_p(y) && ((y) <= 32)) || \
(sizeof(x) <= sizeof(s32))) \
? sex32((x),(y)) : sex64((x),(y))))
static inline __const_func__ u32 zex32(u32 x, int n)
{
return (x << (32-n)) >> (32-n);
}
static inline __const_func__ u64 zex64(u64 x, int n)
{
return (x << (64-n)) >> (64-n);
}
#define zex(x,y) \
((__typeof__(x)) \
(((__builtin_constant_p(y) && ((y) <= 32)) || \
(sizeof(x) <= sizeof(u32))) \
? zex32((x),(y)) : zex64((x),(y))))
Powered by blists - more mailing lists