Add AArch64 NEON parity generation and recovery functions

This commit is contained in:
Andrea Mazzoleni 2026-06-04 22:05:59 +02:00
parent 0dd193788b
commit 6d193d31df
12 changed files with 1755 additions and 6 deletions

View file

@ -16,7 +16,8 @@ jobs:
- run: brew install automake
- run: autoreconf -i
- run: ./configure --enable-warning-as-error
- run: make all dist check
- run: cd raid/test && make all test
- run: make all dist check
build-linux:
runs-on: ubuntu-latest
steps:

View file

@ -22,6 +22,9 @@ SnapRAID HISTORY
By scaling to 512-bit ZMM registers, the implementation now processes
64 bytes per iteration, effectively doubling the data width of the
previous AVX2 routines.
* Implemented AArch64 (ARM64) NEON support for parity generation and
data recovery, significantly improving performance on ARM-based
platforms.
* Improved the chances of a successful recovery after an interrupted
sync. This is achieved by removing the sync optimization of not
recomputing the parity if the input data matches the expected hash.

View file

@ -27,6 +27,7 @@ snapraid_SOURCES = \
raid/int.c \
raid/x86.c \
raid/gfni.c \
raid/neon.c \
raid/intz.c \
raid/x86z.c \
raid/helper.c \

View file

@ -274,6 +274,9 @@ void speed(int period, int nd, int size)
printf("%8s", "int8");
printf("%8s", "int32");
printf("%8s", "int64");
#ifdef CONFIG_NEON
printf("%8s", "neon");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "sse2");
@ -325,6 +328,15 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen1_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -388,6 +400,15 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen2_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -473,6 +494,15 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_genz_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -526,6 +556,15 @@ void speed(int period, int nd, int size)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen3_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -606,6 +645,15 @@ void speed(int period, int nd, int size)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen4_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -686,6 +734,15 @@ void speed(int period, int nd, int size)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen5_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -765,6 +822,15 @@ void speed(int period, int nd, int size)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen6_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -835,6 +901,9 @@ void speed(int period, int nd, int size)
printf("%8s", "");
printf("%8s", "best");
printf("%8s", "int8");
#ifdef CONFIG_NEON
printf("%8s", "neon");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3())
printf("%8s", "ssse3");
@ -865,6 +934,18 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(1, raid_gen1_neon);
/* +1 to avoid GEN1 optimized case */
raid_rec1_neon(1, id, ip + 1, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -940,6 +1021,18 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(2, raid_gen2_neon);
/* +1 to avoid GEN2 optimized case */
raid_rec2_neon(2, id, ip + 1, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1018,6 +1111,17 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(3, raid_gen3_neon);
raid_recX_neon(3, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1096,6 +1200,17 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(4, raid_gen4_neon);
raid_recX_neon(4, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1175,6 +1290,17 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(5, raid_gen5_neon);
raid_recX_neon(5, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1253,6 +1379,17 @@ void speed(int period, int nd, int size)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
/* ensure to use same hardware in the delta step */
raid_gen_force(6, raid_gen6_neon);
raid_recX_neon(6, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {

View file

@ -23,7 +23,13 @@
#define CONFIG_X86 1
#define CONFIG_X86_64 1
#endif
#if defined(__arm__) || defined(__aarch64__)
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
#define CONFIG_NEON 1
#endif
#endif
#endif
/*
* Includes anything required for compatibility.
@ -144,6 +150,16 @@ void raid_recX_avx2gfni(int nr, int *id, int *ip, int nd, size_t size, void **vv
void raid_rec1_avx512gfni(int nr, int *id, int *ip, int nd, size_t size, void **vv);
void raid_rec2_avx512gfni(int nr, int *id, int *ip, int nd, size_t size, void **vv);
void raid_recX_avx512gfni(int nr, int *id, int *ip, int nd, size_t size, void **vv);
void raid_gen1_neon(int nd, size_t size, void **vv);
void raid_gen2_neon(int nd, size_t size, void **vv);
void raid_genz_neon(int nd, size_t size, void **vv);
void raid_gen3_neon(int nd, size_t size, void **vv);
void raid_gen4_neon(int nd, size_t size, void **vv);
void raid_gen5_neon(int nd, size_t size, void **vv);
void raid_gen6_neon(int nd, size_t size, void **vv);
void raid_rec1_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv);
void raid_rec2_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv);
void raid_recX_neon(int nr, int *id, int *ip, int nd, size_t size, void **vv);
/*
* Functions for parity computation.
@ -348,5 +364,23 @@ static __always_inline void raid_avx_end(void)
}
#endif /* CONFIG_X86 */
#ifdef CONFIG_NEON
static __always_inline void raid_neon_begin(void)
{
}
static __always_inline void raid_neon_end(void)
{
asm volatile ("" : : : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
asm volatile ("" : : : "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15");
asm volatile ("" : : : "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23");
asm volatile ("" : : : "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31");
}
void raid_register_neon(void);
#endif
#endif

View file

@ -251,6 +251,9 @@ void raid_init(void)
raid_register_avx2gfni();
raid_register_avx512gfni();
#endif
#ifdef CONFIG_NEON
raid_register_neon();
#endif
/* set the default mode */
raid_mode(RAID_MODE_CAUCHY);

1408
raid/neon.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -9119,7 +9119,7 @@ const uint8_t __aligned(256) raid_gfcauchy[6][256] =
},
};
#ifdef CONFIG_X86
#if defined(CONFIG_X86) || defined(CONFIG_NEON)
/**
* PSHUFB tables for the Cauchy matrix.
*
@ -14653,7 +14653,7 @@ const uint8_t __aligned(256) raid_gfcauchypshufb[251][5][2][16] =
};
#endif
#ifdef CONFIG_X86
#if defined(CONFIG_X86) || defined(CONFIG_NEON)
/**
* PSHUFB tables for generic multiplication.
*
@ -24805,7 +24805,7 @@ const uint8_t __aligned(256) raid_gfcauchy[6][256] =
},
};
#ifdef CONFIG_X86
#if defined(CONFIG_X86) || defined(CONFIG_NEON)
/**
* PSHUFB tables for the Cauchy matrix.
*
@ -30339,7 +30339,7 @@ const uint8_t __aligned(256) raid_gfcauchypshufb[251][5][2][16] =
};
#endif
#ifdef CONFIG_X86
#if defined(CONFIG_X86) || defined(CONFIG_NEON)
/**
* PSHUFB tables for generic multiplication.
*

View file

@ -216,6 +216,9 @@ int raid_test_rec(int mode, int nd, size_t size)
test_setup(i) = raid_rec1_avx512gfni;
#endif
#endif
#endif
#ifdef CONFIG_NEON
test_setup(i) = raid_rec1_neon;
#endif
} else if (i == 2) {
test_setup(i) = raid_rec2_int8;
@ -234,6 +237,9 @@ int raid_test_rec(int mode, int nd, size_t size)
test_setup(i) = raid_rec2_avx512gfni;
#endif
#endif
#endif
#ifdef CONFIG_NEON
test_setup(i) = raid_rec2_neon;
#endif
} else {
test_setup(i) = raid_recX_int8;
@ -252,6 +258,9 @@ int raid_test_rec(int mode, int nd, size_t size)
test_setup(i) = raid_recX_avx512gfni;
#endif
#endif
#endif
#ifdef CONFIG_NEON
test_setup(i) = raid_recX_neon;
#endif
}
}
@ -370,6 +379,11 @@ int raid_test_par(int mode, int nd, size_t size)
test_setup(2) = raid_gen2_int32;
test_setup(2) = raid_gen2_int64;
#ifdef CONFIG_NEON
test_setup(1) = raid_gen1_neon;
test_setup(2) = raid_gen2_neon;
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
test_setup(1) = raid_gen1_sse2;
@ -404,6 +418,13 @@ int raid_test_par(int mode, int nd, size_t size)
test_setup(5) = raid_gen5_int8;
test_setup(6) = raid_gen6_int8;
#ifdef CONFIG_NEON
test_setup(3) = raid_gen3_neon;
test_setup(4) = raid_gen4_neon;
test_setup(5) = raid_gen5_neon;
test_setup(6) = raid_gen6_neon;
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
test_setup(3) = raid_gen3_ssse3;
@ -450,6 +471,10 @@ int raid_test_par(int mode, int nd, size_t size)
test_setup(3) = raid_genz_int32;
test_setup(3) = raid_genz_int64;
#ifdef CONFIG_NEON
test_setup(3) = raid_genz_neon;
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
test_setup(3) = raid_genz_sse2;

View file

@ -36,7 +36,7 @@ CFLAGS += -O2 -DUSE_RAID_AES
else
CFLAGS += -O0 --coverage -DCOVERAGE=1 -DNDEBUG=1
endif
OBJS = raid.o check.o int.o intz.o x86.o x86z.o gfni.o tables.o memory.o test.o helper.o module.o
OBJS = raid.o check.o int.o intz.o x86.o x86z.o gfni.o neon.o tables.o memory.o test.o helper.o module.o
%.o: ../%.c
$(CC) $(CFLAGS) -c -o $@ $<

View file

@ -30,6 +30,9 @@ int main(void)
raid_init();
#ifdef CONFIG_NEON
printf("Including ARM NEON\n");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2())
printf("Including x86 SSE2\n");

View file

@ -125,6 +125,9 @@ void speed(void)
printf("%8s", "int8");
printf("%8s", "int32");
printf("%8s", "int64");
#ifdef CONFIG_NEON
printf("%8s", "neon");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "sse2");
@ -179,6 +182,15 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen1_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -242,6 +254,15 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen2_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -327,6 +348,15 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_genz_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
SPEED_START {
@ -381,6 +411,15 @@ void speed(void)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen3_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -459,6 +498,15 @@ void speed(void)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen4_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -537,6 +585,15 @@ void speed(void)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen5_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -615,6 +672,15 @@ void speed(void)
printf("%8s", "");
printf("%8s", "");
#ifdef CONFIG_NEON
SPEED_START {
raid_gen6_neon(nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2()) {
printf("%8s", "");
@ -684,6 +750,9 @@ void speed(void)
printf("%8s", "");
printf("%8s", "best");
printf("%8s", "int8");
#ifdef CONFIG_NEON
printf("%8s", "neon");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3())
printf("%8s", "ssse3");
@ -713,6 +782,17 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(1, raid_gen1_neon);
/* +1 to avoid GEN1 optimized case */
raid_rec1_neon(1, id, ip + 1, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -782,6 +862,17 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(2, raid_gen2_neon);
/* +1 to avoid GEN2 optimized case */
raid_rec2_neon(2, id, ip + 1, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -854,6 +945,16 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(3, raid_gen3_neon);
raid_recX_neon(3, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -921,6 +1022,16 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(4, raid_gen4_neon);
raid_recX_neon(4, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -992,6 +1103,16 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(5, raid_gen5_neon);
raid_recX_neon(5, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1063,6 +1184,16 @@ void speed(void)
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#ifdef CONFIG_NEON
SPEED_START {
raid_gen_force(6, raid_gen6_neon);
raid_recX_neon(6, id, ip, nd, size, v);
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
fflush(stdout);
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_ssse3()) {
SPEED_START {
@ -1133,6 +1264,9 @@ int main(void)
raid_init();
#ifdef CONFIG_NEON
printf("Including ARM NEON\n");
#endif
#ifdef CONFIG_X86
if (raid_cpu_has_sse2())
printf("Including x86 SSE2\n");