Standardize types to uint8_t and clean up legacy variables and setup boilerplate

This commit is contained in:
Andrea Mazzoleni 2026-09-02 20:45:06 +02:00
parent 27329c6f8c
commit 8f27c393d6
8 changed files with 25 additions and 173 deletions

View file

@ -33,11 +33,6 @@ library startup before normal RAID operations.
RAID_MODE_CAUCHY_AES to set mode.
Returns the mode active prior to this call.
void raid_zero(void *zero)
Registers a read-only buffer filled with zeros of block size 'size'.
The buffer must be aligned to a 64-byte boundary. Required prior to
calling raid_rec() or raid_data() for delta parity computation.
void raid_gen(int nd, int np, size_t size, void **v, int streaming)
Computes 'np' parity blocks from 'nd' data blocks. Vector 'v' contains
'nd + np' block pointers (data blocks v[0..nd-1], parity blocks
@ -96,9 +91,8 @@ Memory, Alignment and Aliasing Requirements
(size % 64 == 0).
- Memory Alignment: All data and parity blocks pointed to by 'v[]'
(as well as the zero buffer passed to raid_zero()) MUST be aligned to
a 64-byte boundary. This requirement applies to each individual block
buffer, not to the pointer array 'v' itself.
MUST be aligned to a 64-byte boundary. This requirement applies to each
individual block buffer, not to the pointer array 'v' itself.
- Buffer Aliasing: Entries in 'v[]' MAY point to the same block buffer.
Blocks are processed from lower to higher offsets. For each processed

View file

@ -704,27 +704,9 @@ static __always_inline void raid_recX_int8(int nr, int has_p, int *id, int *ip,
raid_invert(G, V, nr);
/* setup selected parity and destination pointers */
p[0] = v[nd + ip[0]];
pa[0] = v[id[0]];
if (nr >= 2) {
p[1] = v[nd + ip[1]];
pa[1] = v[id[1]];
}
if (nr >= 3) {
p[2] = v[nd + ip[2]];
pa[2] = v[id[2]];
}
if (nr >= 4) {
p[3] = v[nd + ip[3]];
pa[3] = v[id[3]];
}
if (nr >= 5) {
p[4] = v[nd + ip[4]];
pa[4] = v[id[4]];
}
if (nr >= 6) {
p[5] = v[nd + ip[5]];
pa[5] = v[id[5]];
for (j = 0; j < nr; ++j) {
p[j] = v[nd + ip[j]];
pa[j] = v[id[j]];
}
/* build the compact surviving-data list and its syndrome tables */
@ -738,17 +720,8 @@ static __always_inline void raid_recX_int8(int nr, int has_p, int *id, int *ip,
src[ns] = v[d];
S[ns][0] = table(A(ip[0], d));
if (nr >= 2)
S[ns][1] = table(A(ip[1], d));
if (nr >= 3)
S[ns][2] = table(A(ip[2], d));
if (nr >= 4)
S[ns][3] = table(A(ip[3], d));
if (nr >= 5)
S[ns][4] = table(A(ip[4], d));
if (nr >= 6)
S[ns][5] = table(A(ip[5], d));
for (j = 0; j < nr; ++j)
S[ns][j] = table(A(ip[j], d));
++ns;
}
@ -757,94 +730,9 @@ static __always_inline void raid_recX_int8(int nr, int has_p, int *id, int *ip,
BUG_ON(ns != nd - nr);
/* precompute inverse-matrix multiplication table pointers */
if (!has_p) {
R[0][0] = table(V[0 * nr + 0]);
if (nr >= 2)
R[0][1] = table(V[0 * nr + 1]);
if (nr >= 3)
R[0][2] = table(V[0 * nr + 2]);
if (nr >= 4)
R[0][3] = table(V[0 * nr + 3]);
if (nr >= 5)
R[0][4] = table(V[0 * nr + 4]);
if (nr >= 6)
R[0][5] = table(V[0 * nr + 5]);
}
if (nr >= 2) {
int rj = 1 - has_p;
R[rj][0] = table(V[rj * nr + 0]);
if (nr >= 2)
R[rj][1] = table(V[rj * nr + 1]);
if (nr >= 3)
R[rj][2] = table(V[rj * nr + 2]);
if (nr >= 4)
R[rj][3] = table(V[rj * nr + 3]);
if (nr >= 5)
R[rj][4] = table(V[rj * nr + 4]);
if (nr >= 6)
R[rj][5] = table(V[rj * nr + 5]);
}
if (nr >= 3) {
int rj = 2 - has_p;
R[rj][0] = table(V[rj * nr + 0]);
if (nr >= 2)
R[rj][1] = table(V[rj * nr + 1]);
if (nr >= 3)
R[rj][2] = table(V[rj * nr + 2]);
if (nr >= 4)
R[rj][3] = table(V[rj * nr + 3]);
if (nr >= 5)
R[rj][4] = table(V[rj * nr + 4]);
if (nr >= 6)
R[rj][5] = table(V[rj * nr + 5]);
}
if (nr >= 4) {
int rj = 3 - has_p;
R[rj][0] = table(V[rj * nr + 0]);
if (nr >= 2)
R[rj][1] = table(V[rj * nr + 1]);
if (nr >= 3)
R[rj][2] = table(V[rj * nr + 2]);
if (nr >= 4)
R[rj][3] = table(V[rj * nr + 3]);
if (nr >= 5)
R[rj][4] = table(V[rj * nr + 4]);
if (nr >= 6)
R[rj][5] = table(V[rj * nr + 5]);
}
if (nr >= 5) {
int rj = 4 - has_p;
R[rj][0] = table(V[rj * nr + 0]);
if (nr >= 2)
R[rj][1] = table(V[rj * nr + 1]);
if (nr >= 3)
R[rj][2] = table(V[rj * nr + 2]);
if (nr >= 4)
R[rj][3] = table(V[rj * nr + 3]);
if (nr >= 5)
R[rj][4] = table(V[rj * nr + 4]);
if (nr >= 6)
R[rj][5] = table(V[rj * nr + 5]);
}
if (nr >= 6) {
int rj = 5 - has_p;
R[rj][0] = table(V[rj * nr + 0]);
if (nr >= 2)
R[rj][1] = table(V[rj * nr + 1]);
if (nr >= 3)
R[rj][2] = table(V[rj * nr + 2]);
if (nr >= 4)
R[rj][3] = table(V[rj * nr + 3]);
if (nr >= 5)
R[rj][4] = table(V[rj * nr + 4]);
if (nr >= 6)
R[rj][5] = table(V[rj * nr + 5]);
}
for (j = 0; j < nr - has_p; ++j)
for (k = 0; k < nr; ++k)
R[j][k] = table(V[j * nr + k]);
for (i = 0; i < size; i += 2) {
uint8_t syn0a, syn1a, syn2a, syn3a, syn4a, syn5a;

View file

@ -6,7 +6,7 @@
void *raid_malloc_align(size_t size, size_t align_size, void **freeptr)
{
unsigned char *ptr;
uint8_t *ptr;
uintptr_t offset;
ptr = malloc(size + align_size);
@ -122,7 +122,7 @@ static const unsigned STRIDE_NOISE[16] = {
void **raid_malloc_vector_align(int n, size_t size, size_t align_size, size_t displacement_size, size_t wrap_size, void **freeptr)
{
void **v;
unsigned char *va;
uint8_t *va;
int i;
BUG_ON(n <= 0);
@ -171,7 +171,7 @@ void **raid_malloc_vector(int n, size_t size, void **freeptr)
void raid_mrand_vector(unsigned seed, int n, size_t size, void **vv)
{
unsigned char **v = (unsigned char **)vv;
uint8_t **v = (uint8_t **)vv;
int i;
size_t j;
@ -186,12 +186,12 @@ void raid_mrand_vector(unsigned seed, int n, size_t size, void **vv)
int raid_mtest_vector(int n, size_t size, void **vv)
{
unsigned char **v = (unsigned char **)vv;
uint8_t **v = (uint8_t **)vv;
int i;
size_t j;
unsigned k;
unsigned char d;
unsigned char p;
uint8_t d;
uint8_t p;
/* fill with 0 */
d = 0;

View file

@ -627,7 +627,7 @@ int raid_selftest(void)
{
const int nd = TEST_COUNT;
const size_t size = TEST_SIZE;
const int nv = nd + RAID_PARITY_MAX * 2 + 1;
const int nv = nd + RAID_PARITY_MAX * 2;
void *v_alloc;
void **v;
void *ref[TEST_COUNT + RAID_PARITY_MAX];
@ -653,9 +653,6 @@ int raid_selftest(void)
/* LCOV_EXCL_STOP */
}
memset(v[nv - 1], 0, size);
raid_zero(v[nv - 1]);
/* use the multiplication table as data */
for (i = 0; i < nd; ++i)
ref[i] = ((uint8_t *)raid_gfmul) + size * i;
@ -873,12 +870,6 @@ int raid_selftest(void)
ret = 0;
bail:
/*
* Reset the global zero buffer so that it does not point to
* the deallocated memory.
*/
raid_zero(0);
free(v);
free(v_alloc);

View file

@ -576,10 +576,7 @@ static __always_inline void raid_genX_neon(int nd, size_t size, void **vv, int n
*
* Process 64 bytes at a time across four 16-byte lanes.
*
* If P is available, preserve the complete P delta syndrome and
* reconstruct only nr - 1 missing blocks through the inverse matrix.
* The last missing block is obtained by XORing the reconstructed blocks
* out of Pdelta.
* If P is available, syndrome 0 is accumulated with XOR without table lookups.
*/
static __always_inline void raid_recX_neon_12(int nr, int has_p, int *id, int *ip, int nd, size_t size, void **vv)
{
@ -921,10 +918,7 @@ static __always_inline void raid_recX_neon_12(int nr, int has_p, int *id, int *i
* This avoids temporary syndrome buffers and the
* generation of unused parity rows.
*
* If P is available, preserve the complete P delta syndrome and
* reconstruct only nr - 1 missing blocks through the inverse matrix.
* The last missing block is obtained by XORing the reconstructed blocks
* out of Pdelta.
* If P is available, syndrome 0 is accumulated with XOR without table lookups.
*/
static __always_inline void raid_recX_neon(int nr, int has_p, int *id, int *ip, int nd, size_t size, void **vv)
{

View file

@ -525,9 +525,7 @@ static __always_inline void raid_genX_neon32(int nd, size_t size,
/*
* Recover multiple data failures using selected parity blocks with AArch32 NEON optimized for up to three failures.
*
* If P is available, keep the complete P delta syndrome in q6.
* Reconstruct only nr - 1 missing blocks through the inverse matrix and
* obtain the last block by XORing the reconstructed blocks out of Pdelta.
* If P is available, syndrome 0 is accumulated with XOR without table lookups.
*/
static __always_inline void raid_recX_neon32_123(int nr, int has_p, int *id, int *ip, int nd, size_t size, void **vv)
{
@ -829,10 +827,7 @@ static __always_inline void raid_recX_neon32_123(int nr, int has_p, int *id, int
* This avoids temporary syndrome buffers and the
* generation of unused parity rows.
*
* If P is available, preserve the complete P delta syndrome and
* reconstruct only nr - 1 missing blocks through the inverse matrix.
* The last missing block is obtained by XORing the reconstructed blocks
* out of Pdelta.
* If P is available, syndrome 0 is accumulated with XOR without table lookups.
*/
static __always_inline void raid_recX_neon32(int nr, int has_p, int *id, int *ip, int nd, size_t size, void **vv)
{

View file

@ -34,7 +34,7 @@ static int ipow(int n, int r)
static void meminc(void *dst, size_t size)
{
size_t i;
unsigned char *p = dst;
uint8_t *p = dst;
for (i = 0; i < size; ++i)
++p[i];
@ -637,7 +637,7 @@ int raid_test_rec(int mode, int nd, size_t size)
else
np = RAID_PARITY_MAX;
nv = nd + np * 2 + 2;
nv = nd + np * 2 + 1;
v = raid_malloc_vector(nv, size, &v_alloc);
if (!v) {
@ -653,9 +653,6 @@ int raid_test_rec(int mode, int nd, size_t size)
for (i = 0; i < np; ++i)
parity_save[i] = parity[i];
memset(v[nv - 2], 0, size);
raid_zero(v[nv - 2]);
waste = v[nv - 1];
/* fill with pseudo-random data with the arbitrary seed "1" */
@ -753,7 +750,7 @@ int raid_test_tail(int mode, int nd_max, size_t size)
else
np = RAID_PARITY_MAX;
nv = nd_max + np * 2 + 2;
nv = nd_max + np * 2 + 1;
v = raid_malloc_vector(nv, size, &v_alloc);
if (!v) {
@ -769,9 +766,6 @@ int raid_test_tail(int mode, int nd_max, size_t size)
for (i = 0; i < np; ++i)
parity_save[i] = parity[i];
memset(v[nv - 2], 0, size);
raid_zero(v[nv - 2]);
waste = v[nv - 1];
/* fill with pseudo-random data with the arbitrary seed "1" */

View file

@ -2141,7 +2141,7 @@ void speed(void)
int delta = TEST_DELTA;
int period = TEST_PERIOD;
nv = nd + RAID_PARITY_MAX + 1;
nv = nd + RAID_PARITY_MAX;
printf("Speed test using %u data buffers of %u bytes, for a total of %u KiB.\n", nd, size, nd * size / 1024);
printf("Memory blocks have a displacement of %u bytes to improve cache performance.\n", raid_optimal_displacement(nv));
@ -2155,10 +2155,6 @@ void speed(void)
for (i = 0; i < nd; ++i)
memset(v[i], i, size);
/* zero buffer */
memset(v[nd + RAID_PARITY_MAX], 0, size);
raid_zero(v[nd + RAID_PARITY_MAX]);
speed_mem(nd, v, size, delta, period);
raid_mode(RAID_MODE_CAUCHY_RAID);