From: Peter Zijlstra <peterz@infradead.org>
To: zengzhaoxiu@163.com
Cc: linux-kernel@vger.kernel.org, bp@suse.de,
gnomes@lxorguk.ukuu.org.uk, andi@firstfloor.org,
dvyukov@google.com, Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Denys Vlasenko <dvlasenk@redhat.com>
Subject: Re: [patch V4 09/31] bitops: Add x86-specific parity functions
Date: Wed, 11 May 2016 11:31:39 +0200 [thread overview]
Message-ID: <20160511093139.GA3206@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1462958205-24890-1-git-send-email-zengzhaoxiu@163.com>
On Wed, May 11, 2016 at 05:16:38PM +0800, zengzhaoxiu@163.com wrote:
> +static inline unsigned int __arch_parity4(unsigned int w)
> +{
> + unsigned int res = 0;
> +
> + asm("test $0xf, %1; setpo %b0"
> + : "+q" (res)
> + : "r" (w)
> + : "cc");
> +
> + return res;
> +}
> +
> +static inline unsigned int __arch_parity8(unsigned int w)
> +{
> + unsigned int res = 0;
> +
> + asm("test %1, %1; setpo %b0"
> + : "+q" (res)
> + : "r" (w)
> + : "cc");
> +
> + return res;
> +}
> +
> +static inline unsigned int __arch_parity16(unsigned int w)
> +{
> + unsigned int res = 0;
> +
> + asm("xor %h1, %b1; setpo %b0"
> + : "+q" (res), "+q" (w)
> + : : "cc");
> +
> + return res;
> +}
Please use the GEN_*_RMWcc() stuff to avoid the setpo where possible.
> +
> +#ifdef CONFIG_64BIT
> +/* popcnt %eax, %eax -- redundant REX prefix for alignment */
> +#define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc0"
> +/* popcnt %rax, %rax */
> +#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc0"
> +#else
> +/* popcnt %eax, %eax */
> +#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"
> +#endif
Yuck, please don't duplicate stuff like this.
> +
> +static __always_inline unsigned int __arch_parity32(unsigned int w)
> +{
> + unsigned int res;
> + unsigned int tmp;
> +
> + asm(ALTERNATIVE(
> + " mov %%eax, %1 \n"
> + " shr $16, %%eax \n"
> + " xor %1, %%eax \n"
> + " xor %%ah, %%al \n"
> + " mov $0, %%eax \n"
> + " setpo %%al \n",
> + POPCNT32 " \n"
> + " and $1, %%eax \n",
> + X86_FEATURE_POPCNT)
> + : "=a" (res), "=&r" (tmp)
> + : "a" (w)
> + : "cc");
> +
> + return res;
> +}
How many bytes does that end up being? Should we make it a call?
next prev parent reply other threads:[~2016-05-11 9:32 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 8:25 [patch V4 00/31] bitops: add " zengzhaoxiu
2016-05-11 8:47 ` [patch V4 01/31] " zengzhaoxiu
2016-05-11 14:32 ` Martin Kepplinger
2016-05-11 9:06 ` [patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h zengzhaoxiu
2016-05-11 10:06 ` Jesper Nilsson
2016-05-11 10:42 ` Catalin Marinas
2016-05-11 13:52 ` Vineet Gupta
2016-05-11 15:24 ` Mark Salter
2016-05-11 9:09 ` [patch V4 03/31] bitops: Add alpha-specific parity functions zengzhaoxiu
2016-05-11 9:09 ` [patch V4 04/31] bitops: Add blackfin-specific " zengzhaoxiu
2016-05-11 9:10 ` [patch V4 05/31] bitops: Add ia-specific " zengzhaoxiu
2016-06-29 15:15 ` [patch V4 05/31] bitops: Add ia64-specific " zengzhaoxiu
2016-05-11 9:10 ` [patch V4 06/31] bitops: Tile and MIPS (if has usable __builtin_popcount) use popcount " zengzhaoxiu
2016-05-11 9:11 ` [patch V4 07/31] bitops: Add powerpc-specific " zengzhaoxiu
2016-05-11 9:13 ` [patch V4 08/31] bitops: Add sparc-specific " zengzhaoxiu
2016-05-11 23:59 ` David Miller
2016-05-11 9:16 ` [patch V4 09/31] bitops: Add x86-specific " zengzhaoxiu
2016-05-11 9:31 ` Peter Zijlstra [this message]
2016-05-11 9:52 ` Borislav Petkov
2016-05-16 15:49 ` Zhaoxiu Zeng
2016-05-16 17:06 ` Peter Zijlstra
2016-05-16 19:22 ` H. Peter Anvin
2016-05-17 11:22 ` Peter Zijlstra
2016-05-16 19:19 ` H. Peter Anvin
2016-06-29 15:04 ` zengzhaoxiu
2016-05-11 9:17 ` [patch V4 10/31] sunrpc: use parity8 zengzhaoxiu
2016-05-11 9:17 ` [patch V4 11/31] mips: use parity functions in cerr-sb1.c zengzhaoxiu
2016-05-11 9:18 ` [patch V4 12/31] lib: bch: use parity32 zengzhaoxiu
2016-05-11 9:18 ` [patch V4 13/31] media: use parity8 in vivid-vbi-gen.c zengzhaoxiu
2016-05-11 9:19 ` [patch V4 14/31] media: use parity functions in saa7115 zengzhaoxiu
2016-07-01 11:53 ` Hans Verkuil
2016-05-11 9:19 ` [patch V4 15/31] input: use parity32 in grip_mp zengzhaoxiu
2016-05-11 9:19 ` [patch V4 16/31] input: use parity64 in sidewinder zengzhaoxiu
2016-05-11 9:19 ` [patch V4 17/31] input: use parity16 in ams_delta_serio zengzhaoxiu
2016-05-11 9:19 ` [patch V4 18/31] scsi: use parity32 in isci's phy zengzhaoxiu
2016-05-11 9:20 ` [patch V4 19/31] mtd: use parity16 in ssfdc zengzhaoxiu
2016-05-11 9:21 ` [patch V4 20/31] mtd: use parity functions in inftlcore zengzhaoxiu
2016-05-11 9:21 ` [patch V4 21/31] crypto: use parity functions in qat_hal zengzhaoxiu
2016-05-11 9:22 ` [patch V4 22/31] mtd: use parity16 in sm_ftl zengzhaoxiu
2016-05-11 9:22 ` [patch V4 23/31] ethernet: use parity8 in sun/niu.c zengzhaoxiu
2016-05-11 23:59 ` David Miller
2016-05-11 9:22 ` [patch V4 24/31] input: use parity8 in pcips2 zengzhaoxiu
2016-05-11 9:22 ` [patch V4 25/31] input: use parity8 in sa1111ps2 zengzhaoxiu
2016-05-11 9:22 ` [patch V4 26/31] iio: use parity32 in adxrs450 zengzhaoxiu
2016-05-11 9:23 ` [patch V4 27/31] serial: use parity32 in max3100 zengzhaoxiu
2016-06-25 17:25 ` Greg Kroah-Hartman
2016-06-29 14:57 ` [patch V4 27/31] serial: use parity8 " zengzhaoxiu
2016-06-29 16:43 ` Greg KH
2016-06-29 17:25 ` zengzhaoxiu
2016-05-11 9:24 ` [patch V4 28/31] input: use parity8 in elantech zengzhaoxiu
2016-05-11 9:24 ` [patch V4 29/31] ethernet: use parity8 in broadcom/tg3.c zengzhaoxiu
2016-05-11 23:59 ` David Miller
2016-05-11 9:24 ` [patch V4 30/31] crypto: use parity_long is sahara.c zengzhaoxiu
2016-06-29 15:18 ` [patch V4 30/31] crypto: use parity_long in sahara.c zengzhaoxiu
2016-05-11 9:24 ` [patch V4 31/31] edac: use parity8 in amd64_edac.c zengzhaoxiu
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=20160511093139.GA3206@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andi@firstfloor.org \
--cc=bp@suse.de \
--cc=dvlasenk@redhat.com \
--cc=dvyukov@google.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=zengzhaoxiu@163.com \
--cc=zhaoxiu.zeng@gmail.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
Powered by JetHome