From: zengzhaoxiu@163.com To: linux-kernel@vger.kernel.org, sam@ravnborg.org Cc: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>, "David S. Miller" <davem@davemloft.net>, "wim.coekaerts@oracle.com" <wim.coekaerts@oracle.com>, Guenter Roeck <linux@roeck-us.net>, Julian Calaby <julian.calaby@gmail.com>, sparclinux@vger.kernel.org Subject: [PATCH V3 08/29] Add sparc-specific parity functions Date: Thu, 14 Apr 2016 11:08:01 +0800 [thread overview] Message-ID: <1460603291-4851-1-git-send-email-zengzhaoxiu@163.com> (raw) In-Reply-To: <1460601525-3822-1-git-send-email-zengzhaoxiu@163.com> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> Use runtime patching for sparc64, lifted from hweight Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> --- arch/sparc/include/asm/bitops_32.h | 1 + arch/sparc/include/asm/bitops_64.h | 18 ++++++ arch/sparc/kernel/sparc_ksyms_64.c | 6 ++ arch/sparc/lib/Makefile | 2 +- arch/sparc/lib/parity.S | 128 +++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 arch/sparc/lib/parity.S diff --git a/arch/sparc/include/asm/bitops_32.h b/arch/sparc/include/asm/bitops_32.h index 600ed1d..8c41896 100644 --- a/arch/sparc/include/asm/bitops_32.h +++ b/arch/sparc/include/asm/bitops_32.h @@ -98,6 +98,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) #include <asm-generic/bitops/__fls.h> #include <asm-generic/bitops/fls64.h> #include <asm-generic/bitops/hweight.h> +#include <asm-generic/bitops/parity.h> #include <asm-generic/bitops/lock.h> #include <asm-generic/bitops/find.h> #include <asm-generic/bitops/le.h> diff --git a/arch/sparc/include/asm/bitops_64.h b/arch/sparc/include/asm/bitops_64.h index 2d52240..999d504 100644 --- a/arch/sparc/include/asm/bitops_64.h +++ b/arch/sparc/include/asm/bitops_64.h @@ -47,6 +47,24 @@ unsigned int __arch_hweight16(unsigned int w); unsigned int __arch_hweight8(unsigned int w); #include <asm-generic/bitops/const_hweight.h> + +/* + * parityN: returns the parity of a N-bit word, + * i.e. the number of 1-bits in w modulo 2. + */ + +static inline unsigned int __arch_parity4(unsigned int w) +{ + w &= 0xf; + return ((PARITY_MAGIC) >> w) & 1; +} +unsigned int __arch_parity8(unsigned int w); +unsigned int __arch_parity16(unsigned int w); +unsigned int __arch_parity32(unsigned int w); +unsigned int __arch_parity64(__u64 w); + +#include <asm-generic/bitops/const_parity.h> + #include <asm-generic/bitops/lock.h> #endif /* __KERNEL__ */ diff --git a/arch/sparc/kernel/sparc_ksyms_64.c b/arch/sparc/kernel/sparc_ksyms_64.c index 9e034f2..7ee0818 100644 --- a/arch/sparc/kernel/sparc_ksyms_64.c +++ b/arch/sparc/kernel/sparc_ksyms_64.c @@ -45,6 +45,12 @@ EXPORT_SYMBOL(__arch_hweight16); EXPORT_SYMBOL(__arch_hweight32); EXPORT_SYMBOL(__arch_hweight64); +/* from parity.S */ +EXPORT_SYMBOL(__arch_parity8); +EXPORT_SYMBOL(__arch_parity16); +EXPORT_SYMBOL(__arch_parity32); +EXPORT_SYMBOL(__arch_parity64); + /* from ffs_ffz.S */ EXPORT_SYMBOL(ffs); EXPORT_SYMBOL(__ffs); diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile index 3269b02..2dbbcb1 100644 --- a/arch/sparc/lib/Makefile +++ b/arch/sparc/lib/Makefile @@ -39,7 +39,7 @@ lib-$(CONFIG_SPARC64) += GENmemcpy.o GENcopy_from_user.o GENcopy_to_user.o lib-$(CONFIG_SPARC64) += GENpatch.o GENpage.o GENbzero.o lib-$(CONFIG_SPARC64) += copy_in_user.o user_fixup.o memmove.o -lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o +lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o parity.o obj-$(CONFIG_SPARC64) += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o ucmpdi2.o diff --git a/arch/sparc/lib/parity.S b/arch/sparc/lib/parity.S new file mode 100644 index 0000000..ff84234 --- /dev/null +++ b/arch/sparc/lib/parity.S @@ -0,0 +1,128 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Author: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> + */ + +#include <linux/linkage.h> + +/* + * This file contains the generic code to calculate the odd parity + * of N-bits number, and the popc-patches. + */ + + .text + .align 32 + +/* + * unsigned int __arch_parity8(unsigned int w) + */ +ENTRY(__arch_parity8) + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity8) + .section .popc_6insn_patch, "ax" + .word __arch_parity8 + sllx %o0, 64-8, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity16(unsigned int w) + */ +ENTRY(__arch_parity16) + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity16) + .section .popc_6insn_patch, "ax" + .word __arch_parity16 + sllx %o0, 64-16, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity32(unsigned int w) + */ +ENTRY(__arch_parity32) + srl %o0, 16, %g1 + xor %o0, %g1, %o0 + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity32) + .section .popc_6insn_patch, "ax" + .word __arch_parity32 + sllx %o0, 64-32, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity64(__u64 w) + */ +ENTRY(__arch_parity64) + srlx %o0, 32, %g1 + xor %o0, %g1, %o0 + srl %o0, 16, %g1 + xor %o0, %g1, %o0 + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity64) + .section .popc_3insn_patch, "ax" + .word __arch_parity64 + popc %o0, %o0 + retl + and %o0, 1, %o0 + .previous -- 2.5.0
WARNING: multiple messages have this Message-ID (diff)
From: zengzhaoxiu@163.com To: linux-kernel@vger.kernel.org, sam@ravnborg.org Cc: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>, "David S. Miller" <davem@davemloft.net>, "wim.coekaerts@oracle.com" <wim.coekaerts@oracle.com>, Guenter Roeck <linux@roeck-us.net>, Julian Calaby <julian.calaby@gmail.com>, sparclinux@vger.kernel.org Subject: [PATCH V3 08/29] Add sparc-specific parity functions Date: Thu, 14 Apr 2016 03:08:01 +0000 [thread overview] Message-ID: <1460603291-4851-1-git-send-email-zengzhaoxiu@163.com> (raw) In-Reply-To: <1460601525-3822-1-git-send-email-zengzhaoxiu@163.com> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> Use runtime patching for sparc64, lifted from hweight Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> --- arch/sparc/include/asm/bitops_32.h | 1 + arch/sparc/include/asm/bitops_64.h | 18 ++++++ arch/sparc/kernel/sparc_ksyms_64.c | 6 ++ arch/sparc/lib/Makefile | 2 +- arch/sparc/lib/parity.S | 128 +++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 arch/sparc/lib/parity.S diff --git a/arch/sparc/include/asm/bitops_32.h b/arch/sparc/include/asm/bitops_32.h index 600ed1d..8c41896 100644 --- a/arch/sparc/include/asm/bitops_32.h +++ b/arch/sparc/include/asm/bitops_32.h @@ -98,6 +98,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) #include <asm-generic/bitops/__fls.h> #include <asm-generic/bitops/fls64.h> #include <asm-generic/bitops/hweight.h> +#include <asm-generic/bitops/parity.h> #include <asm-generic/bitops/lock.h> #include <asm-generic/bitops/find.h> #include <asm-generic/bitops/le.h> diff --git a/arch/sparc/include/asm/bitops_64.h b/arch/sparc/include/asm/bitops_64.h index 2d52240..999d504 100644 --- a/arch/sparc/include/asm/bitops_64.h +++ b/arch/sparc/include/asm/bitops_64.h @@ -47,6 +47,24 @@ unsigned int __arch_hweight16(unsigned int w); unsigned int __arch_hweight8(unsigned int w); #include <asm-generic/bitops/const_hweight.h> + +/* + * parityN: returns the parity of a N-bit word, + * i.e. the number of 1-bits in w modulo 2. + */ + +static inline unsigned int __arch_parity4(unsigned int w) +{ + w &= 0xf; + return ((PARITY_MAGIC) >> w) & 1; +} +unsigned int __arch_parity8(unsigned int w); +unsigned int __arch_parity16(unsigned int w); +unsigned int __arch_parity32(unsigned int w); +unsigned int __arch_parity64(__u64 w); + +#include <asm-generic/bitops/const_parity.h> + #include <asm-generic/bitops/lock.h> #endif /* __KERNEL__ */ diff --git a/arch/sparc/kernel/sparc_ksyms_64.c b/arch/sparc/kernel/sparc_ksyms_64.c index 9e034f2..7ee0818 100644 --- a/arch/sparc/kernel/sparc_ksyms_64.c +++ b/arch/sparc/kernel/sparc_ksyms_64.c @@ -45,6 +45,12 @@ EXPORT_SYMBOL(__arch_hweight16); EXPORT_SYMBOL(__arch_hweight32); EXPORT_SYMBOL(__arch_hweight64); +/* from parity.S */ +EXPORT_SYMBOL(__arch_parity8); +EXPORT_SYMBOL(__arch_parity16); +EXPORT_SYMBOL(__arch_parity32); +EXPORT_SYMBOL(__arch_parity64); + /* from ffs_ffz.S */ EXPORT_SYMBOL(ffs); EXPORT_SYMBOL(__ffs); diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile index 3269b02..2dbbcb1 100644 --- a/arch/sparc/lib/Makefile +++ b/arch/sparc/lib/Makefile @@ -39,7 +39,7 @@ lib-$(CONFIG_SPARC64) += GENmemcpy.o GENcopy_from_user.o GENcopy_to_user.o lib-$(CONFIG_SPARC64) += GENpatch.o GENpage.o GENbzero.o lib-$(CONFIG_SPARC64) += copy_in_user.o user_fixup.o memmove.o -lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o +lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o parity.o obj-$(CONFIG_SPARC64) += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o ucmpdi2.o diff --git a/arch/sparc/lib/parity.S b/arch/sparc/lib/parity.S new file mode 100644 index 0000000..ff84234 --- /dev/null +++ b/arch/sparc/lib/parity.S @@ -0,0 +1,128 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Author: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> + */ + +#include <linux/linkage.h> + +/* + * This file contains the generic code to calculate the odd parity + * of N-bits number, and the popc-patches. + */ + + .text + .align 32 + +/* + * unsigned int __arch_parity8(unsigned int w) + */ +ENTRY(__arch_parity8) + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity8) + .section .popc_6insn_patch, "ax" + .word __arch_parity8 + sllx %o0, 64-8, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity16(unsigned int w) + */ +ENTRY(__arch_parity16) + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity16) + .section .popc_6insn_patch, "ax" + .word __arch_parity16 + sllx %o0, 64-16, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity32(unsigned int w) + */ +ENTRY(__arch_parity32) + srl %o0, 16, %g1 + xor %o0, %g1, %o0 + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity32) + .section .popc_6insn_patch, "ax" + .word __arch_parity32 + sllx %o0, 64-32, %g1 + popc %g1, %o0 + retl + and %o0, 1, %o0 + nop + nop + .previous + +/* + * unsigned int __arch_parity64(__u64 w) + */ +ENTRY(__arch_parity64) + srlx %o0, 32, %g1 + xor %o0, %g1, %o0 + srl %o0, 16, %g1 + xor %o0, %g1, %o0 + srl %o0, 8, %g1 + xor %o0, %g1, %o0 + srl %o0, 4, %g1 + xor %o0, %g1, %o0 + and %o0, 0xf, %o0 + sethi %hi(0x6996), %g1 + or %g1, %lo(0x6996), %g1 + srl %g1, %o0, %o0 + retl + and %o0, 1, %o0 +ENDPROC(__arch_parity64) + .section .popc_3insn_patch, "ax" + .word __arch_parity64 + popc %o0, %o0 + retl + and %o0, 1, %o0 + .previous -- 2.5.0
next prev parent reply other threads:[~2016-04-14 3:10 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-04-14 2:36 [PATCH V3 00/29] bitops: add parity functions zengzhaoxiu 2016-04-14 2:36 ` zengzhaoxiu 2016-04-14 2:36 ` zengzhaoxiu 2016-04-14 2:36 ` zengzhaoxiu 2016-04-14 3:04 ` [PATCH V3 02/29] Include generic parity.h in some architectures' bitops.h zengzhaoxiu 2016-04-14 3:04 ` zengzhaoxiu 2016-04-14 3:04 ` zengzhaoxiu at 163.com 2016-04-14 3:04 ` zengzhaoxiu 2016-04-14 3:04 ` zengzhaoxiu 2016-04-14 3:04 ` zengzhaoxiu 2016-04-14 3:04 ` zengzhaoxiu 2016-04-14 3:05 ` [PATCH V3 03/29] Add alpha-specific parity functions zengzhaoxiu 2016-04-14 3:05 ` [PATCH V3 04/29] Add blackfin-specific " zengzhaoxiu 2016-04-14 3:05 ` [PATCH V3 05/29] Add ia64-specific " zengzhaoxiu 2016-04-14 3:05 ` zengzhaoxiu 2016-04-14 3:05 ` [PATCH V3 06/29] Tile and MIPS (if has usable __builtin_popcount) use popcount " zengzhaoxiu 2016-04-15 19:26 ` Chris Metcalf 2016-04-15 19:26 ` Chris Metcalf 2016-04-14 3:06 ` [PATCH V3 07/29] Add powerpc-specific " zengzhaoxiu 2016-04-14 3:08 ` zengzhaoxiu [this message] 2016-04-14 3:08 ` [PATCH V3 08/29] Add sparc-specific " zengzhaoxiu 2016-04-14 3:08 ` [PATCH V3 09/29] Add x86-specific " zengzhaoxiu 2016-04-14 3:08 ` [PATCH V3 10/29] sunrpc: use parity8 zengzhaoxiu 2016-04-14 3:09 ` [PATCH V3 11/29] mips: use parity functions in cerr-sb1.c zengzhaoxiu 2016-04-14 3:09 ` [PATCH V3 12/29] bch: use parity32 zengzhaoxiu 2016-04-14 3:09 ` [PATCH V3 13/29] media: use parity8 in vivid-vbi-gen.c zengzhaoxiu 2016-04-14 3:09 ` [PATCH V3 14/29] media: use parity functions in saa7115 zengzhaoxiu 2016-04-14 3:10 ` [PATCH V3 15/29] input: use parity32 in grip_mp zengzhaoxiu 2016-04-14 3:10 ` [PATCH V3 16/29] input: use parity64 in sidewinder zengzhaoxiu 2016-04-14 3:10 ` [PATCH V3 17/29] input: use parity16 in ams_delta_serio zengzhaoxiu 2016-04-14 3:10 ` [PATCH V3 18/29] scsi: use parity32 in isci's phy zengzhaoxiu 2016-04-14 3:10 ` [PATCH V3 19/29] mtd: use parity16 in ssfdc zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 20/29] mtd: use parity functions in inftlcore zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 21/29] crypto: use parity functions in qat_hal zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 22/29] mtd: use parity16 in sm_ftl zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 23/29] ethernet: use parity8 in sun/niu.c zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 24/29] input: use parity8 in pcips2 zengzhaoxiu 2016-04-14 3:11 ` [PATCH V3 25/29] input: use parity8 in sa1111ps2 zengzhaoxiu 2016-04-14 3:12 ` [PATCH V3 26/29] iio: use parity32 in adxrs450 zengzhaoxiu 2016-04-17 11:32 ` Jonathan Cameron 2016-04-14 3:12 ` [PATCH V3 27/29] serial: use parity32 in max3100 zengzhaoxiu 2016-04-28 21:01 ` Greg Kroah-Hartman 2016-04-14 3:12 ` [PATCH V3 28/29] input: use parity8 in elantech zengzhaoxiu 2016-04-14 3:12 ` [PATCH V3 29/29] ethernet: use parity8 in broadcom/tg3.c zengzhaoxiu 2016-04-14 4:18 ` [PATCH V3 00/29] bitops: add parity functions zengzhaoxiu 2016-04-14 4:18 ` zengzhaoxiu at 163.com 2016-04-14 4:18 ` zengzhaoxiu 2016-04-14 4:18 ` zengzhaoxiu 2016-04-14 4:18 ` zengzhaoxiu 2016-04-14 4:18 ` zengzhaoxiu 2016-04-14 4:18 ` zengzhaoxiu 2016-04-17 12:38 ` Dmitry Torokhov 2016-04-17 12:38 ` Dmitry Torokhov 2016-04-17 12:38 ` Dmitry Torokhov 2016-04-17 12:38 ` Dmitry Torokhov
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=1460603291-4851-1-git-send-email-zengzhaoxiu@163.com \ --to=zengzhaoxiu@163.com \ --cc=davem@davemloft.net \ --cc=julian.calaby@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@roeck-us.net \ --cc=sam@ravnborg.org \ --cc=sparclinux@vger.kernel.org \ --cc=wim.coekaerts@oracle.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.