xor/arm: Replace vectorized version with intrinsics
Subsystems (3)
cover xor/arm: Replace vectorized version with intrinsics
From: Ard Biesheuvel <[email protected]>
Replace the compiler vectorized XOR implementation for ARM with the existing NEON intrinsics implementation used by arm64. This is slightly faster, and allows some minor cleanups of the type hacks in the headers now that intrinsics are the only C code permitted to use FP/SIMD instructions.
Performance (QEMU mach-virt VM running on Synquacer [Cortex-A53 @ 1 GHz]
Before:
[ 3.519687] xor: measuring software checksum speed [ 3.521725] neon : 1660 MB/sec [ 3.524733] 32regs : 1105 MB/sec [ 3.527751] 8regs : 1098 MB/sec [ 3.529911] arm4regs : 1540 MB/sec
After:
[ 3.517654] xor: measuring software checksum speed [ 3.519454] neon : 1896 MB/sec [ 3.522499] 32regs : 1090 MB/sec [ 3.525560] 8regs : 1083 MB/sec [ 3.527700] arm4regs : 1556 MB/sec
This applies onto Christoph's XOR cleanup series.
Ard Biesheuvel (5):
ARM: Add a neon-intrinsics.h header like on arm64
crypto: aegis128 - Use neon-intrinsics.h on ARM too xor/arm: Replace vectorized implementation with arm64's intrinsics xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
ARM: Remove hacked-up asm/types.h header
arch/arm/include/asm/neon-intrinsics.h | 64 +++++++ arch/arm/include/uapi/asm/types.h | 41 ----- crypto/aegis128-neon-inner.c | 4 +- lib/raid/xor/arm/xor-neon.c | 183 ++++++++++++++++++-- lib/raid/xor/arm/xor-neon.h | 7 + lib/raid/xor/arm/xor_arch.h | 7 +- lib/raid/xor/arm64/xor-neon.c | 170 +----------------- lib/raid/xor/arm64/xor-neon.h | 3 + lib/raid/xor/arm64/xor_arch.h | 4 +- lib/raid/xor/xor-8regs.c | 2 - 10 files changed, 244 insertions(+), 241 deletions(-) create mode 100644 arch/arm/include/asm/neon-intrinsics.h delete mode 100644 arch/arm/include/uapi/asm/types.h create mode 100644 lib/raid/xor/arm/xor-neon.h
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
PATCH 1/5 ARM: Add a neon-intrinsics.h header like on arm64
From: Ard Biesheuvel <[email protected]>
Add a header asm/neon-intrinsics.h similar to the one that arm64 has. This makes it possible for NEON intrinsics code to be shared seamlessly between ARM and arm64.
--- arch/arm/include/asm/neon-intrinsics.h | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+)
arch/arm/include/asm/neon-intrinsics.h new file +64 -0
@@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_NEON_INTRINSICS_H +#define __ASM_NEON_INTRINSICS_H + +#ifndef __ARM_NEON__ +#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon' +#endif + +#include <asm-generic/int-ll64.h> + +/* +* The C99 types uintXX_t that are usually defined in 'stdint.h' are not as +* unambiguous on ARM as you would expect. For the types below, there is a +* difference on ARM between GCC built for bare metal ARM, GCC built for glibc +* and the kernel itself, which results in build errors if you try to build +* with -ffreestanding and include 'stdint.h' (such as when you include +* 'arm_neon.h' in order to use NEON intrinsics) +* +* As the typedefs for these types in 'stdint.h' are based on builtin defines +* supplied by GCC, we can tweak these to align with the kernel's idea of those +* types, so 'linux/types.h' and 'stdint.h' can be safely included from the +* same source file (provided that -ffreestanding is used). +* +* int32_t uint32_t intptr_t uintptr_t +* bare metal GCC long unsigned long int unsigned int +* glibc GCC int unsigned int int unsigned int +* kernel int unsigned int long unsigned long +*/ + +#ifdef __INT32_TYPE__ +#undef __INT32_TYPE__ +#define __INT32_TYPE__ int +#endif + +#ifdef __UINT32_TYPE__ +#undef __UINT32_TYPE__ +#define __UINT32_TYPE__ unsigned int +#endif + +#ifdef __INTPTR_TYPE__ +#undef __INTPTR_TYPE__ +#define __INTPTR_TYPE__ long +#endif + +#ifdef __UINTPTR_TYPE__ +#undef __UINTPTR_TYPE__ +#define __UINTPTR_TYPE__ unsigned long +#endif + +/* +* genksyms chokes on the ARM NEON instrinsics system header, but we +* don't export anything it defines anyway, so just disregard when +* genksyms execute. +*/ +#ifndef __GENKSYMS__ +#include <arm_neon.h> +#endif + +#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic ignored "-Wincompatible-pointer-types" +#endif + +#endif /* __ASM_NEON_INTRINSICS_H */
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
PATCH 2/5 crypto: aegis128 - Use neon-intrinsics.h on ARM too
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Use the asm/neon-intrinsics.h header on ARM as well as arm64, so that the calling code does not have to know the difference.
--- crypto/aegis128-neon-inner.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
crypto/aegis128-neon-inner.c +1 -3
@@ -3,13 +3,11 @@* Copyright (C) 2019 Linaro, Ltd. <[email protected]> */ -#ifdef CONFIG_ARM64 #include <asm/neon-intrinsics.h> +#ifdef CONFIG_ARM64 #define AES_ROUND "aese %0.16b, %1.16b \n\t aesmc %0.16b, %0.16b"#else -#include <arm_neon.h> -#define AES_ROUND "aese.8 %q0, %q1 \n\t aesmc.8 %q0, %q0"#endif
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
PATCH 4/5 xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Tweak the arm64 code so that the pure NEON intrinsics implementation of XOR is shared between arm64 and ARM.
--- lib/raid/xor/arm64/xor-neon.c | 170 +------------------- lib/raid/xor/arm64/xor-neon.h | 3 + lib/raid/xor/arm64/xor_arch.h | 4 +- 3 files changed, 5 insertions(+), 172 deletions(-)
lib/raid/xor/arm64/xor-neon.c +1 -169
@@ -1,179 +1,11 @@// SPDX-License-Identifier: GPL-2.0-only -/* -* Authors: Jackie Liu <[email protected]> -* Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. -*/ #include <linux/cache.h> #include <asm/neon-intrinsics.h> #include "xor_impl.h" -#include "xor_arch.h" #include "xor-neon.h" -static void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2) -{ -uint64_t *dp1 = (uint64_t *)p1; -uint64_t *dp2 = (uint64_t *)p2; - - registeruint64x2_t v0, v1, v2, v3; -long lines = bytes / (sizeof (uint64x2_t) *4 ); - -do { -/* p1 ^= p2 */ - v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); - v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); - v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); - v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); - -/* store */ -vst1q_u64 (dp1 +0 , v0); -vst1q_u64 (dp1 +2 , v1); -vst1q_u64 (dp1 +4 , v2); -vst1q_u64 (dp1 +6 , v3); - - dp1 +=8 ; - dp2 +=8 ; - }while (--lines >0 ); -} - -static void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3) -{ -uint64_t *dp1 = (uint64_t *)p1; -uint64_t *dp2 = (uint64_t *)p2; -uint64_t *dp3 = (uint64_t *)p3; - - registeruint64x2_t v0, v1, v2, v3; -long lines = bytes / (sizeof (uint64x2_t) *4 ); - -do { -/* p1 ^= p2 */ - v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); - v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); - v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); - v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); - -/* p1 ^= p3 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); - -/* store */ -vst1q_u64 (dp1 +0 , v0); -vst1q_u64 (dp1 +2 , v1); -vst1q_u64 (dp1 +4 , v2); -vst1q_u64 (dp1 +6 , v3); - - dp1 +=8 ; - dp2 +=8 ; - dp3 +=8 ; - }while (--lines >0 ); -} - -static void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4) -{ -uint64_t *dp1 = (uint64_t *)p1; -uint64_t *dp2 = (uint64_t *)p2; -uint64_t *dp3 = (uint64_t *)p3; -uint64_t *dp4 = (uint64_t *)p4; - - registeruint64x2_t v0, v1, v2, v3; -long lines = bytes / (sizeof (uint64x2_t) *4 ); - -do { -/* p1 ^= p2 */ - v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); - v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); - v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); - v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); - -/* p1 ^= p3 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); - -/* p1 ^= p4 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp4 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp4 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp4 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp4 +6 )); - -/* store */ -vst1q_u64 (dp1 +0 , v0); -vst1q_u64 (dp1 +2 , v1); -vst1q_u64 (dp1 +4 , v2); -vst1q_u64 (dp1 +6 , v3); - - dp1 +=8 ; - dp2 +=8 ; - dp3 +=8 ; - dp4 +=8 ; - }while (--lines >0 ); -} - -static void __xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, -const unsigned long * __restrict p2, -const unsigned long * __restrict p3, -const unsigned long * __restrict p4, -const unsigned long * __restrict p5) -{ -uint64_t *dp1 = (uint64_t *)p1; -uint64_t *dp2 = (uint64_t *)p2; -uint64_t *dp3 = (uint64_t *)p3; -uint64_t *dp4 = (uint64_t *)p4; -uint64_t *dp5 = (uint64_t *)p5; - - registeruint64x2_t v0, v1, v2, v3; -long lines = bytes / (sizeof (uint64x2_t) *4 ); - -do { -/* p1 ^= p2 */ - v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); - v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); - v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); - v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); - -/* p1 ^= p3 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); - -/* p1 ^= p4 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp4 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp4 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp4 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp4 +6 )); - -/* p1 ^= p5 */ - v0 =veorq_u64 (v0,vld1q_u64 (dp5 +0 )); - v1 =veorq_u64 (v1,vld1q_u64 (dp5 +2 )); - v2 =veorq_u64 (v2,vld1q_u64 (dp5 +4 )); - v3 =veorq_u64 (v3,vld1q_u64 (dp5 +6 )); - -/* store */ -vst1q_u64 (dp1 +0 , v0); -vst1q_u64 (dp1 +2 , v1); -vst1q_u64 (dp1 +4 , v2); -vst1q_u64 (dp1 +6 , v3); - - dp1 +=8 ; - dp2 +=8 ; - dp3 +=8 ; - dp4 +=8 ; - dp5 +=8 ; - }while (--lines >0 ); -} - -__DO_XOR_BLOCKS (neon_inner, __xor_neon_2, __xor_neon_3, __xor_neon_4, - __xor_neon_5); +#include "../arm/xor-neon.c" static inline uint64x2_t eor3 (uint64x2_t p,uint64x2_t q,uint64x2_t r) {
lib/raid/xor/arm64/xor-neon.h +3 -0
@@ -1,5 +1,8 @@/* SPDX-License-Identifier: GPL-2.0-only */ +extern struct xor_block_template xor_block_neon; +extern struct xor_block_template xor_block_eor3; +void xor_gen_neon_inner (void *dest,void **srcs,unsigned int src_cnt,unsigned int bytes); void xor_gen_eor3_inner(void *dest, void **srcs, unsigned int src_cnt,
lib/raid/xor/arm64/xor_arch.h +1 -3
@@ -4,9 +4,7 @@* Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ #include <asm/simd.h> - -extern struct xor_block_template xor_block_neon; -extern struct xor_block_template xor_block_eor3; +#include "xor-neon.h" static __always_inline void __init arch_xor_init(void) {
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
PATCH 5/5 ARM: Remove hacked-up asm/types.h header
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
ARM has a special version of asm/types.h which contains overrides for certain #define's related to the C types used to back C99 types such as uint32_t and uintptr_t.
This is only needed when pulling in system headers such as stdint.h during the build, and this only happens when using NEON intrinsics, now that the compiler vectorized version of XOR has been replaced.
So drop this header entirely, and revert to the asm-generic one.
--- arch/arm/include/uapi/asm/types.h | 41 -------------------- 1 file changed, 41 deletions(-)
arch/arm/include/uapi/asm/types.h deleted +0 -41
@@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _UAPI_ASM_TYPES_H -#define _UAPI_ASM_TYPES_H - -#include <asm-generic/int-ll64.h> - -/* -* The C99 types uintXX_t that are usually defined in 'stdint.h' are not as -* unambiguous on ARM as you would expect. For the types below, there is a -* difference on ARM between GCC built for bare metal ARM, GCC built for glibc -* and the kernel itself, which results in build errors if you try to build with -* -ffreestanding and include 'stdint.h' (such as when you include 'arm_neon.h' -* in order to use NEON intrinsics) -* -* As the typedefs for these types in 'stdint.h' are based on builtin defines -* supplied by GCC, we can tweak these to align with the kernel's idea of those -* types, so 'linux/types.h' and 'stdint.h' can be safely included from the same -* source file (provided that -ffreestanding is used). -* -* int32_t uint32_t uintptr_t -* bare metal GCC long unsigned long unsigned int -* glibc GCC int unsigned int unsigned int -* kernel int unsigned int unsigned long -*/ - -#ifdef __INT32_TYPE__ -#undef __INT32_TYPE__ -#define __INT32_TYPE__ int -#endif - -#ifdef __UINT32_TYPE__ -#undef __UINT32_TYPE__ -#define __UINT32_TYPE__ unsigned int -#endif - -#ifdef __UINTPTR_TYPE__ -#undef __UINTPTR_TYPE__ -#define __UINTPTR_TYPE__ unsigned long -#endif - -#endif /* _UAPI_ASM_TYPES_H */
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
PATCH 3/5 xor/arm: Replace vectorized implementation with arm64's intrinsics
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Drop the XOR implementation generated by the vectorizer: this has always been a bit of a hack, and now that arm64 has an intrinsics version that works on ARM too, let's use that instead.
So copy the part of the arm64 code that can be shared (so not the EOR3 version). The arm64 code will be updated in a subsequent patch to share this implementation.
--- lib/raid/xor/arm/xor-neon.c | 183 ++++++++++++++++++-- lib/raid/xor/arm/xor-neon.h | 7 + lib/raid/xor/arm/xor_arch.h | 7 +- lib/raid/xor/xor-8regs.c | 2 - 4 files changed, 174 insertions(+), 25 deletions(-)
lib/raid/xor/arm/xor-neon.c +166 -17
@@ -1,26 +1,175 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (C) 2013 Linaro Ltd <[email protected]> +* Authors: Jackie Liu <[email protected]> +* Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd. */ #include "xor_impl.h" -#include "xor_arch.h" +#include "xor-neon.h" -#ifndef __ARM_NEON__ -#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon' -#endif +#include <asm/neon-intrinsics.h> -/* -* Pull in the reference implementations while instructing GCC (through -* -ftree-vectorize) to attempt to exploit implicit parallelism and emit -* NEON instructions. Clang does this by default at O2 so no pragma is -* needed. -*/ -#ifdef CONFIG_CC_IS_GCC -#pragma GCC optimize "tree-vectorize" -#endif +static void __xor_neon_2 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2) +{ +uint64_t *dp1 = (uint64_t *)p1; +uint64_t *dp2 = (uint64_t *)p2; + + registeruint64x2_t v0, v1, v2, v3; +long lines = bytes / (sizeof (uint64x2_t) *4 ); + +do { +/* p1 ^= p2 */ + v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); + v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); + v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); + v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); + +/* store */ +vst1q_u64 (dp1 +0 , v0); +vst1q_u64 (dp1 +2 , v1); +vst1q_u64 (dp1 +4 , v2); +vst1q_u64 (dp1 +6 , v3); + + dp1 +=8 ; + dp2 +=8 ; + }while (--lines >0 ); +} + +static void __xor_neon_3 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3) +{ +uint64_t *dp1 = (uint64_t *)p1; +uint64_t *dp2 = (uint64_t *)p2; +uint64_t *dp3 = (uint64_t *)p3; + + registeruint64x2_t v0, v1, v2, v3; +long lines = bytes / (sizeof (uint64x2_t) *4 ); + +do { +/* p1 ^= p2 */ + v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); + v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); + v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); + v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); + +/* p1 ^= p3 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); + +/* store */ +vst1q_u64 (dp1 +0 , v0); +vst1q_u64 (dp1 +2 , v1); +vst1q_u64 (dp1 +4 , v2); +vst1q_u64 (dp1 +6 , v3); + + dp1 +=8 ; + dp2 +=8 ; + dp3 +=8 ; + }while (--lines >0 ); +} + +static void __xor_neon_4 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4) +{ +uint64_t *dp1 = (uint64_t *)p1; +uint64_t *dp2 = (uint64_t *)p2; +uint64_t *dp3 = (uint64_t *)p3; +uint64_t *dp4 = (uint64_t *)p4; + + registeruint64x2_t v0, v1, v2, v3; +long lines = bytes / (sizeof (uint64x2_t) *4 ); + +do { +/* p1 ^= p2 */ + v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); + v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); + v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); + v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); + +/* p1 ^= p3 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); + +/* p1 ^= p4 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp4 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp4 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp4 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp4 +6 )); + +/* store */ +vst1q_u64 (dp1 +0 , v0); +vst1q_u64 (dp1 +2 , v1); +vst1q_u64 (dp1 +4 , v2); +vst1q_u64 (dp1 +6 , v3); + + dp1 +=8 ; + dp2 +=8 ; + dp3 +=8 ; + dp4 +=8 ; + }while (--lines >0 ); +} + +static void __xor_neon_5 (unsigned long bytes,unsigned long * __restrict p1, +const unsigned long * __restrict p2, +const unsigned long * __restrict p3, +const unsigned long * __restrict p4, +const unsigned long * __restrict p5) +{ +uint64_t *dp1 = (uint64_t *)p1; +uint64_t *dp2 = (uint64_t *)p2; +uint64_t *dp3 = (uint64_t *)p3; +uint64_t *dp4 = (uint64_t *)p4; +uint64_t *dp5 = (uint64_t *)p5; + + registeruint64x2_t v0, v1, v2, v3; +long lines = bytes / (sizeof (uint64x2_t) *4 ); + +do { +/* p1 ^= p2 */ + v0 =veorq_u64 (vld1q_u64 (dp1 +0 ),vld1q_u64 (dp2 +0 )); + v1 =veorq_u64 (vld1q_u64 (dp1 +2 ),vld1q_u64 (dp2 +2 )); + v2 =veorq_u64 (vld1q_u64 (dp1 +4 ),vld1q_u64 (dp2 +4 )); + v3 =veorq_u64 (vld1q_u64 (dp1 +6 ),vld1q_u64 (dp2 +6 )); + +/* p1 ^= p3 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp3 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp3 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp3 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp3 +6 )); + +/* p1 ^= p4 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp4 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp4 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp4 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp4 +6 )); + +/* p1 ^= p5 */ + v0 =veorq_u64 (v0,vld1q_u64 (dp5 +0 )); + v1 =veorq_u64 (v1,vld1q_u64 (dp5 +2 )); + v2 =veorq_u64 (v2,vld1q_u64 (dp5 +4 )); + v3 =veorq_u64 (v3,vld1q_u64 (dp5 +6 )); + +/* store */ +vst1q_u64 (dp1 +0 , v0); +vst1q_u64 (dp1 +2 , v1); +vst1q_u64 (dp1 +4 , v2); +vst1q_u64 (dp1 +6 , v3); -#define NO_TEMPLATE -#include "../xor-8regs.c" + dp1 +=8 ; + dp2 +=8 ; + dp3 +=8 ; + dp4 +=8 ; + dp5 +=8 ; + }while (--lines >0 ); +} -__DO_XOR_BLOCKS (neon_inner, xor_8regs_2, xor_8regs_3, xor_8regs_4, xor_8regs_5); +__DO_XOR_BLOCKS (neon_inner, __xor_neon_2, __xor_neon_3, __xor_neon_4, + __xor_neon_5);
lib/raid/xor/arm/xor-neon.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +extern struct xor_block_template xor_block_arm4regs; +extern struct xor_block_template xor_block_neon; + +void xor_gen_neon_inner (void *dest,void **srcs,unsigned int src_cnt, +unsigned int bytes);
lib/raid/xor/arm/xor_arch.h +1 -6
@@ -3,12 +3,7 @@* Copyright (C) 2001 Russell King */ #include <asm/neon.h> - -extern struct xor_block_template xor_block_arm4regs; -extern struct xor_block_template xor_block_neon; - -void xor_gen_neon_inner (void *dest,void **srcs,unsigned int src_cnt, -unsigned int bytes); +#include "xor-neon.h" static __always_inline void __init arch_xor_init(void) {
lib/raid/xor/xor-8regs.c +0 -2
@@ -93,11 +93,9 @@ xor_8regs_5(unsigned long bytes, unsigned long * __restrict p1, }while (--lines >0 ); } -#ifndef NO_TEMPLATE DO_XOR_BLOCKS(8regs, xor_8regs_2, xor_8regs_3, xor_8regs_4, xor_8regs_5);struct xor_block_template xor_block_8regs = { .name ="8regs" , .xor_gen = xor_gen_8regs, }; -#endif /* NO_TEMPLATE */
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
Re: [PATCH 4/5] xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
In reply to Ard BiesheuvelQuoted 4 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Tweak the arm64 code so that the pure NEON intrinsics implementation of XOR is shared between arm64 and ARM.
Instead of hiding the implementation in a header, just split xor-neon.c into two .c files, one of which could be built by arm32 as well, probably in the arm/ instead of the arm64/ subdirectory, but we can also add a new arm-common one if that's what the arm maintainers prefer.
Re: [PATCH 4/5] xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Tweak the arm64 code so that the pure NEON intrinsics implementation of XOR is shared between arm64 and ARM.
Instead of hiding the implementation in a header, just split
xor-neon.cinto two .c files, one of which could be built by arm32 as well.
That is what patch 3/5 does. This patch wires up that version into arm64, and drops the copy that has become redundant as a result.
Quoted 3 lines
probably
in the arm/ instead of the arm64/ subdirectory, but we can also add a new arm-common one if that's what the arm maintainers prefer.
Having the shared pure NEON version in arm/ is perfectly fine.
Building it as a separate compilation unit for arm64 should also be straight-forward, the only issue is that the 2-way NEON version needs to be shared with the EOR3 compilation unit.
Re: [PATCH 4/5] xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
Quoted 11 lines · Ard Biesheuvel
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Tweak the arm64 code so that the pure NEON intrinsics implementation of XOR is shared between arm64 and ARM.
Instead of hiding the implementation in a header, just split
xor-neon.cinto two .c files, one of which could be built by arm32 as well.That is what patch 3/5 does. This patch wires up that version into arm64, and drops the copy that has become redundant as a result.
Yeah, sorry - I misread the series a little.
Quoted 6 lines
Quoted 4 lines
probably
in the arm/ instead of the arm64/ subdirectory, but we can also add a new arm-common one if that's what the arm maintainers prefer.Having the shared pure NEON version in arm/ is perfectly fine.
So here would be my preference:
- keep all the arm/arm64 code in lib/raid/xor/arm
- have the neon and EOR3 code in a single xor-neon.c file, with an ifdef CONFIG_ARM64 around the EOE3 routines
This avoid the including of .c files which is always a bit ugly. But if there is a strong argument to prefer including of the .c file I can live with that as well.
Quoted 3 lines
Building it as a separate compilation unit for arm64 should also be straight-forward, the only issue is that the 2-way NEON version needs to be shared with the EOR3 compilation unit.
---end quoted text---
Re: [PATCH 4/5] xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
Quoted 24 lines · Christoph Hellwig
Quoted 11 lines · Ard Biesheuvel
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Tweak the arm64 code so that the pure NEON intrinsics implementation of XOR is shared between arm64 and ARM.
Instead of hiding the implementation in a header, just split
xor-neon.cinto two .c files, one of which could be built by arm32 as well.That is what patch 3/5 does. This patch wires up that version into arm64, and drops the copy that has become redundant as a result.
Yeah, sorry - I misread the series a little.
Quoted 6 lines
Quoted 4 lines
probably
in the arm/ instead of the arm64/ subdirectory, but we can also add a new arm-common one if that's what the arm maintainers prefer.Having the shared pure NEON version in arm/ is perfectly fine.
So here would be my preference:
Quoted 8 lines
- keep all the arm/arm64 code in
lib/raid/xor/arm
- have the neon and EOR3 code in a singlexor-neon.cfile, with an ifdefCONFIG_ARM64around the EOE3 routinesThis avoid the including of .c files which is always a bit ugly. But if there is a strong argument to prefer including of the .c file I can live with that as well.
I've respun it without the include. Instead, I've added this to arm/xor-neon.c
+#ifdef CONFIG_ARM64
+extern typeof(__xor_neon_2) __xor_eor3_2 __alias(__xor_neon_2); +#endif
so that __xor_eor3_2() exists in the arm64 build as an alias. That way, the arm64-only EOR3 implementation can just remain a separate compilation unit.
I could move the eor3 code under arm/ too, but that seems a bit odd given that it is arm64 only, and a arm64/ sub-directory exists.
Re: [PATCH 4/5] xor/arm64: Use shared NEON intrinsics implementation from 32-bit ARM
Quoted 11 lines · Ard Biesheuvel
Quoted 4 lines
This avoid the including of .c files which is always a bit ugly. But if there is a strong argument to prefer including of the .c file I can live with that as well.
I've respun it without the include. Instead, I've added this to
arm/xor-neon.c(quoted diff) +3
-0+#ifdef CONFIG_ARM64 +extern typeof(__xor_neon_2) __xor_eor3_2 __alias(__xor_neon_2); +#endif
Quoted 1 line
so that
__xor_eor3_2()exists in the arm64 build as an alias. That way, the arm64-only EOR3 implementation can just remain a separate compilation unit.
Ok.