Skip to content

Commit 2c705a2

Browse files
committed
raid: Fix doc and base functions for min sources
The raid functions xor_gen, pq_gen and check functions must have at least two sources. Fixes #175 Change-Id: I2e4509e037c2b1dc88f3f7449d80f4c763e1e124 Signed-off-by: Greg Tucker <[email protected]>
1 parent ebb78fc commit 2c705a2

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

include/raid.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C" {
5252
* This function determines what instruction sets are enabled and
5353
* selects the appropriate version at runtime.
5454
*
55-
* @param vects Number of source+dest vectors in array.
55+
* @param vects Number of source+dest vectors in array. Must be > 2.
5656
* @param len Length of each vector in bytes.
5757
* @param array Array of pointers to source and dest. For XOR the dest is
5858
* the last pointer. ie array[vects-1]. Src and dest
@@ -70,7 +70,7 @@ int xor_gen(int vects, int len, void **array);
7070
* This function determines what instruction sets are enabled and
7171
* selects the appropriate version at runtime.
7272
*
73-
* @param vects Number of vectors in array.
73+
* @param vects Number of vectors in array. Must be > 1.
7474
* @param len Length of each vector in bytes.
7575
* @param array Array of pointers to vectors. Src and dest pointers
7676
* must be aligned to 16B.
@@ -87,7 +87,7 @@ int xor_check(int vects, int len, void **array);
8787
* This function determines what instruction sets are enabled and
8888
* selects the appropriate version at runtime.
8989
*
90-
* @param vects Number of source+dest vectors in array.
90+
* @param vects Number of source+dest vectors in array. Must be > 3.
9191
* @param len Length of each vector in bytes. Must be 32B aligned.
9292
* @param array Array of pointers to source and dest. For P+Q the dest
9393
* is the last two pointers. ie array[vects-2],
@@ -107,7 +107,7 @@ int pq_gen(int vects, int len, void **array);
107107
* This function determines what instruction sets are enabled and
108108
* selects the appropriate version at runtime.
109109
*
110-
* @param vects Number of vectors in array including P&Q.
110+
* @param vects Number of vectors in array including P&Q. Must be > 3.
111111
* @param len Length of each vector in bytes. Must be 16B aligned.
112112
* @param array Array of pointers to source and P, Q. P and Q parity
113113
* are assumed to be the last two pointers in the array.
@@ -127,7 +127,7 @@ int pq_check(int vects, int len, void **array);
127127
* @brief Generate XOR parity vector from N sources.
128128
* @requires SSE4.1
129129
*
130-
* @param vects Number of source+dest vectors in array.
130+
* @param vects Number of source+dest vectors in array. Must be > 2.
131131
* @param len Length of each vector in bytes.
132132
* @param array Array of pointers to source and dest. For XOR the dest is
133133
* the last pointer. ie array[vects-1]. Src and dest pointers
@@ -143,7 +143,7 @@ int xor_gen_sse(int vects, int len, void **array);
143143
* @brief Generate XOR parity vector from N sources.
144144
* @requires AVX
145145
*
146-
* @param vects Number of source+dest vectors in array.
146+
* @param vects Number of source+dest vectors in array. Must be > 2.
147147
* @param len Length of each vector in bytes.
148148
* @param array Array of pointers to source and dest. For XOR the dest is
149149
* the last pointer. ie array[vects-1]. Src and dest pointers
@@ -159,7 +159,7 @@ int xor_gen_avx(int vects, int len, void **array);
159159
* @brief Checks that array has XOR parity sum of 0 across all vectors.
160160
* @requires SSE4.1
161161
*
162-
* @param vects Number of vectors in array.
162+
* @param vects Number of vectors in array. Must be > 1.
163163
* @param len Length of each vector in bytes.
164164
* @param array Array of pointers to vectors. Src and dest pointers
165165
* must be aligned to 16B.
@@ -174,7 +174,7 @@ int xor_check_sse(int vects, int len, void **array);
174174
* @brief Generate P+Q parity vectors from N sources.
175175
* @requires SSE4.1
176176
*
177-
* @param vects Number of source+dest vectors in array.
177+
* @param vects Number of source+dest vectors in array. Must be > 3.
178178
* @param len Length of each vector in bytes. Must be 16B aligned.
179179
* @param array Array of pointers to source and dest. For P+Q the dest
180180
* is the last two pointers. ie array[vects-2],
@@ -192,7 +192,7 @@ int pq_gen_sse(int vects, int len, void **array);
192192
* @brief Generate P+Q parity vectors from N sources.
193193
* @requires AVX
194194
*
195-
* @param vects Number of source+dest vectors in array.
195+
* @param vects Number of source+dest vectors in array. Must be > 3.
196196
* @param len Length of each vector in bytes. Must be 16B aligned.
197197
* @param array Array of pointers to source and dest. For P+Q the dest
198198
* is the last two pointers. ie array[vects-2],
@@ -210,7 +210,7 @@ int pq_gen_avx(int vects, int len, void **array);
210210
* @brief Generate P+Q parity vectors from N sources.
211211
* @requires AVX2
212212
*
213-
* @param vects Number of source+dest vectors in array.
213+
* @param vects Number of source+dest vectors in array. Must be > 3.
214214
* @param len Length of each vector in bytes. Must be 32B aligned.
215215
* @param array Array of pointers to source and dest. For P+Q the dest
216216
* is the last two pointers. ie array[vects-2],
@@ -228,7 +228,7 @@ int pq_gen_avx2(int vects, int len, void **array);
228228
* @brief Checks that array of N sources, P and Q are consistent across all vectors.
229229
* @requires SSE4.1
230230
*
231-
* @param vects Number of vectors in array including P&Q.
231+
* @param vects Number of vectors in array including P&Q. Must be > 3.
232232
* @param len Length of each vector in bytes. Must be 16B aligned.
233233
* @param array Array of pointers to source and P, Q. P and Q parity
234234
are assumed to be the last two pointers in the array.
@@ -242,7 +242,7 @@ int pq_check_sse(int vects, int len, void **array);
242242

243243
/**
244244
* @brief Generate P+Q parity vectors from N sources, runs baseline version.
245-
* @param vects Number of source+dest vectors in array.
245+
* @param vects Number of source+dest vectors in array. Must be > 3.
246246
* @param len Length of each vector in bytes. Must be 16B aligned.
247247
* @param array Array of pointers to source and dest. For P+Q the dest
248248
* is the last two pointers. ie array[vects-2],
@@ -258,7 +258,7 @@ int pq_gen_base(int vects, int len, void **array);
258258

259259
/**
260260
* @brief Generate XOR parity vector from N sources, runs baseline version.
261-
* @param vects Number of source+dest vectors in array.
261+
* @param vects Number of source+dest vectors in array. Must be > 2.
262262
* @param len Length of each vector in bytes.
263263
* @param array Array of pointers to source and dest. For XOR the dest is
264264
* the last pointer. ie array[vects-1]. Src and dest pointers
@@ -273,7 +273,7 @@ int xor_gen_base(int vects, int len, void **array);
273273
/**
274274
* @brief Checks that array has XOR parity sum of 0 across all vectors, runs baseline version.
275275
*
276-
* @param vects Number of vectors in array.
276+
* @param vects Number of vectors in array. Must be > 1.
277277
* @param len Length of each vector in bytes.
278278
* @param array Array of pointers to vectors. Src and dest pointers
279279
* must be aligned to 16B.
@@ -287,7 +287,7 @@ int xor_check_base(int vects, int len, void **array);
287287
/**
288288
* @brief Checks that array of N sources, P and Q are consistent across all vectors, runs baseline version.
289289
*
290-
* @param vects Number of vectors in array including P&Q.
290+
* @param vects Number of vectors in array including P&Q. Must be > 3.
291291
* @param len Length of each vector in bytes. Must be 16B aligned.
292292
* @param array Array of pointers to source and P, Q. P and Q parity
293293
* are assumed to be the last two pointers in the array.

raid/raid_base.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ int pq_gen_base(int vects, int len, void **array)
4747
unsigned long **src = (unsigned long **)array;
4848
int blocks = len / sizeof(long);
4949

50+
if (vects < 4)
51+
return 1; // Must have at least 2 src and 2 dest
52+
5053
for (i = 0; i < blocks; i++) {
5154
q = p = src[vects - 3][i];
5255

@@ -69,6 +72,9 @@ int pq_check_base(int vects, int len, void **array)
6972
unsigned char p, q, s;
7073
unsigned char **src = (unsigned char **)array;
7174

75+
if (vects < 4)
76+
return 1; // Must have at least 2 src and 2 dest
77+
7278
for (i = 0; i < len; i++) {
7379
q = p = src[vects - 3][i];
7480

@@ -94,6 +100,9 @@ int xor_gen_base(int vects, int len, void **array)
94100
unsigned char parity;
95101
unsigned char **src = (unsigned char **)array;
96102

103+
if (vects < 3)
104+
return 1; // Must have at least 2 src and 1 dest
105+
97106
for (i = 0; i < len; i++) {
98107
parity = src[0][i];
99108
for (j = 1; j < vects - 1; j++)
@@ -113,6 +122,9 @@ int xor_check_base(int vects, int len, void **array)
113122
unsigned char parity;
114123
unsigned char **src = (unsigned char **)array;
115124

125+
if (vects < 2)
126+
return 1; // Must have at least 2 src
127+
116128
for (i = 0; i < len; i++) {
117129
parity = 0;
118130
for (j = 0; j < vects; j++)

0 commit comments

Comments
 (0)