]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/isa-l/include/erasure_code.h
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
31 #ifndef _ERASURE_CODE_H_
32 #define _ERASURE_CODE_H_
35 * @file erasure_code.h
36 * @brief Interface to functions supporting erasure code encode and decode.
38 * This file defines the interface to optimized functions used in erasure
39 * codes. Encode and decode of erasures in GF(2^8) are made by calculating the
40 * dot product of the symbols (bytes in GF(2^8)) across a set of buffers and a
41 * set of coefficients. Values for the coefficients are determined by the type
42 * of erasure code. Using a general dot product means that any sequence of
43 * coefficients may be used including erasure codes based on random
45 * Multiple versions of dot product are supplied to calculate 1-6 output
46 * vectors in one pass.
47 * Base GF multiply and divide functions can be sped up by defining
48 * GF_LARGE_TABLES at the expense of memory size.
52 #include "gf_vect_mul.h"
59 * @brief Initialize tables for fast Erasure Code encode and decode.
61 * Generates the expanded tables needed for fast encode or decode for erasure
62 * codes on blocks of data. 32bytes is generated for each input coefficient.
64 * @param k The number of vector sources or rows in the generator matrix
66 * @param rows The number of output vectors to concurrently encode/decode.
67 * @param a Pointer to sets of arrays of input coefficients used to encode
69 * @param gftbls Pointer to start of space for concatenated output tables
70 * generated from input coefficients. Must be of size 32*k*rows.
74 void ec_init_tables(int k
, int rows
, unsigned char* a
, unsigned char* gftbls
);
77 * @brief Generate or decode erasure codes on blocks of data, runs appropriate version.
79 * Given a list of source data blocks, generate one or multiple blocks of
80 * encoded data as specified by a matrix of GF(2^8) coefficients. When given a
81 * suitable set of coefficients, this function will perform the fast generation
82 * or decoding of Reed-Solomon type erasure codes.
84 * This function determines what instruction sets are enabled and
85 * selects the appropriate version at runtime.
87 * @param len Length of each block of data (vector) of source or dest data.
88 * @param k The number of vector sources or rows in the generator matrix
90 * @param rows The number of output vectors to concurrently encode/decode.
91 * @param gftbls Pointer to array of input tables generated from coding
92 * coefficients in ec_init_tables(). Must be of size 32*k*rows
93 * @param data Array of pointers to source input buffers.
94 * @param coding Array of pointers to coded output buffers.
98 void ec_encode_data(int len
, int k
, int rows
, unsigned char *gftbls
, unsigned char **data
,
99 unsigned char **coding
);
102 * @brief Generate or decode erasure codes on blocks of data, runs baseline version.
104 * Baseline version of ec_encode_data() with same parameters.
106 void ec_encode_data_base(int len
, int srcs
, int dests
, unsigned char *v
, unsigned char **src
,
107 unsigned char **dest
);
110 * @brief Generate update for encode or decode of erasure codes from single source, runs appropriate version.
112 * Given one source data block, update one or multiple blocks of encoded data as
113 * specified by a matrix of GF(2^8) coefficients. When given a suitable set of
114 * coefficients, this function will perform the fast generation or decoding of
115 * Reed-Solomon type erasure codes from one input source at a time.
117 * This function determines what instruction sets are enabled and selects the
118 * appropriate version at runtime.
120 * @param len Length of each block of data (vector) of source or dest data.
121 * @param k The number of vector sources or rows in the generator matrix
123 * @param rows The number of output vectors to concurrently encode/decode.
124 * @param vec_i The vector index corresponding to the single input source.
125 * @param g_tbls Pointer to array of input tables generated from coding
126 * coefficients in ec_init_tables(). Must be of size 32*k*rows
127 * @param data Pointer to single input source used to update output parity.
128 * @param coding Array of pointers to coded output buffers.
131 void ec_encode_data_update(int len
, int k
, int rows
, int vec_i
, unsigned char *g_tbls
,
132 unsigned char *data
, unsigned char **coding
);
135 * @brief Generate update for encode or decode of erasure codes from single source.
137 * Baseline version of ec_encode_data_update().
140 void ec_encode_data_update_base(int len
, int k
, int rows
, int vec_i
, unsigned char *v
,
141 unsigned char *data
, unsigned char **dest
);
144 * @brief GF(2^8) vector dot product, runs baseline version.
146 * Does a GF(2^8) dot product across each byte of the input array and a constant
147 * set of coefficients to produce each byte of the output. Can be used for
148 * erasure coding encode and decode. Function requires pre-calculation of a
149 * 32*vlen byte constant array based on the input coefficients.
151 * @param len Length of each vector in bytes. Must be >= 16.
152 * @param vlen Number of vector sources.
153 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based
154 * on the array of input coefficients. Only elements 32*CONST*j + 1
155 * of this array are used, where j = (0, 1, 2...) and CONST is the
156 * number of elements in the array of input coefficients. The
157 * elements used correspond to the original input coefficients.
158 * @param src Array of pointers to source inputs.
159 * @param dest Pointer to destination data array.
164 void gf_vect_dot_prod_base(int len
, int vlen
, unsigned char *gftbls
,
165 unsigned char **src
, unsigned char *dest
);
168 * @brief GF(2^8) vector dot product, runs appropriate version.
170 * Does a GF(2^8) dot product across each byte of the input array and a constant
171 * set of coefficients to produce each byte of the output. Can be used for
172 * erasure coding encode and decode. Function requires pre-calculation of a
173 * 32*vlen byte constant array based on the input coefficients.
175 * This function determines what instruction sets are enabled and
176 * selects the appropriate version at runtime.
178 * @param len Length of each vector in bytes. Must be >= 32.
179 * @param vlen Number of vector sources.
180 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based
181 * on the array of input coefficients.
182 * @param src Array of pointers to source inputs.
183 * @param dest Pointer to destination data array.
187 void gf_vect_dot_prod(int len
, int vlen
, unsigned char *gftbls
,
188 unsigned char **src
, unsigned char *dest
);
191 * @brief GF(2^8) vector multiply accumulate, runs appropriate version.
193 * Does a GF(2^8) multiply across each byte of input source with expanded
194 * constant and add to destination array. Can be used for erasure coding encode
195 * and decode update when only one source is available at a time. Function
196 * requires pre-calculation of a 32*vec byte constant array based on the input
199 * This function determines what instruction sets are enabled and selects the
200 * appropriate version at runtime.
202 * @param len Length of each vector in bytes. Must be >= 64.
203 * @param vec The number of vector sources or rows in the generator matrix
205 * @param vec_i The vector index corresponding to the single input source.
206 * @param gftbls Pointer to array of input tables generated from coding
207 * coefficients in ec_init_tables(). Must be of size 32*vec.
208 * @param src Array of pointers to source inputs.
209 * @param dest Pointer to destination data array.
213 void gf_vect_mad(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
214 unsigned char *dest
);
217 * @brief GF(2^8) vector multiply accumulate, baseline version.
219 * Baseline version of gf_vect_mad() with same parameters.
222 void gf_vect_mad_base(int len
, int vec
, int vec_i
, unsigned char *v
, unsigned char *src
,
223 unsigned char *dest
);
226 #if defined(__i386__) || defined(__x86_64__)
229 * @brief Generate or decode erasure codes on blocks of data.
231 * Arch specific version of ec_encode_data() with same parameters.
234 void ec_encode_data_sse(int len
, int k
, int rows
, unsigned char *gftbls
, unsigned char **data
,
235 unsigned char **coding
);
238 * @brief Generate or decode erasure codes on blocks of data.
240 * Arch specific version of ec_encode_data() with same parameters.
243 void ec_encode_data_avx(int len
, int k
, int rows
, unsigned char *gftbls
, unsigned char **data
,
244 unsigned char **coding
);
247 * @brief Generate or decode erasure codes on blocks of data.
249 * Arch specific version of ec_encode_data() with same parameters.
252 void ec_encode_data_avx2(int len
, int k
, int rows
, unsigned char *gftbls
, unsigned char **data
,
253 unsigned char **coding
);
256 * @brief Generate update for encode or decode of erasure codes from single source.
258 * Arch specific version of ec_encode_data_update() with same parameters.
262 void ec_encode_data_update_sse(int len
, int k
, int rows
, int vec_i
, unsigned char *g_tbls
,
263 unsigned char *data
, unsigned char **coding
);
266 * @brief Generate update for encode or decode of erasure codes from single source.
268 * Arch specific version of ec_encode_data_update() with same parameters.
272 void ec_encode_data_update_avx(int len
, int k
, int rows
, int vec_i
, unsigned char *g_tbls
,
273 unsigned char *data
, unsigned char **coding
);
276 * @brief Generate update for encode or decode of erasure codes from single source.
278 * Arch specific version of ec_encode_data_update() with same parameters.
282 void ec_encode_data_update_avx2(int len
, int k
, int rows
, int vec_i
, unsigned char *g_tbls
,
283 unsigned char *data
, unsigned char **coding
);
286 * @brief GF(2^8) vector dot product.
288 * Does a GF(2^8) dot product across each byte of the input array and a constant
289 * set of coefficients to produce each byte of the output. Can be used for
290 * erasure coding encode and decode. Function requires pre-calculation of a
291 * 32*vlen byte constant array based on the input coefficients.
294 * @param len Length of each vector in bytes. Must be >= 16.
295 * @param vlen Number of vector sources.
296 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based
297 * on the array of input coefficients.
298 * @param src Array of pointers to source inputs.
299 * @param dest Pointer to destination data array.
303 void gf_vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
304 unsigned char **src
, unsigned char *dest
);
307 * @brief GF(2^8) vector dot product.
309 * Does a GF(2^8) dot product across each byte of the input array and a constant
310 * set of coefficients to produce each byte of the output. Can be used for
311 * erasure coding encode and decode. Function requires pre-calculation of a
312 * 32*vlen byte constant array based on the input coefficients.
315 * @param len Length of each vector in bytes. Must be >= 16.
316 * @param vlen Number of vector sources.
317 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based
318 * on the array of input coefficients.
319 * @param src Array of pointers to source inputs.
320 * @param dest Pointer to destination data array.
324 void gf_vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
325 unsigned char **src
, unsigned char *dest
);
328 * @brief GF(2^8) vector dot product.
330 * Does a GF(2^8) dot product across each byte of the input array and a constant
331 * set of coefficients to produce each byte of the output. Can be used for
332 * erasure coding encode and decode. Function requires pre-calculation of a
333 * 32*vlen byte constant array based on the input coefficients.
336 * @param len Length of each vector in bytes. Must be >= 32.
337 * @param vlen Number of vector sources.
338 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based
339 * on the array of input coefficients.
340 * @param src Array of pointers to source inputs.
341 * @param dest Pointer to destination data array.
345 void gf_vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
346 unsigned char **src
, unsigned char *dest
);
349 * @brief GF(2^8) vector dot product with two outputs.
351 * Vector dot product optimized to calculate two outputs at a time. Does two
352 * GF(2^8) dot products across each byte of the input array and two constant
353 * sets of coefficients to produce each byte of the outputs. Can be used for
354 * erasure coding encode and decode. Function requires pre-calculation of a
355 * 2*32*vlen byte constant array based on the two sets of input coefficients.
358 * @param len Length of each vector in bytes. Must be >= 16.
359 * @param vlen Number of vector sources.
360 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants
361 * based on the array of input coefficients.
362 * @param src Array of pointers to source inputs.
363 * @param dest Array of pointers to destination data buffers.
367 void gf_2vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
368 unsigned char **src
, unsigned char **dest
);
371 * @brief GF(2^8) vector dot product with two outputs.
373 * Vector dot product optimized to calculate two outputs at a time. Does two
374 * GF(2^8) dot products across each byte of the input array and two constant
375 * sets of coefficients to produce each byte of the outputs. Can be used for
376 * erasure coding encode and decode. Function requires pre-calculation of a
377 * 2*32*vlen byte constant array based on the two sets of input coefficients.
380 * @param len Length of each vector in bytes. Must be >= 16.
381 * @param vlen Number of vector sources.
382 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants
383 * based on the array of input coefficients.
384 * @param src Array of pointers to source inputs.
385 * @param dest Array of pointers to destination data buffers.
389 void gf_2vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
390 unsigned char **src
, unsigned char **dest
);
393 * @brief GF(2^8) vector dot product with two outputs.
395 * Vector dot product optimized to calculate two outputs at a time. Does two
396 * GF(2^8) dot products across each byte of the input array and two constant
397 * sets of coefficients to produce each byte of the outputs. Can be used for
398 * erasure coding encode and decode. Function requires pre-calculation of a
399 * 2*32*vlen byte constant array based on the two sets of input coefficients.
402 * @param len Length of each vector in bytes. Must be >= 32.
403 * @param vlen Number of vector sources.
404 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants
405 * based on the array of input coefficients.
406 * @param src Array of pointers to source inputs.
407 * @param dest Array of pointers to destination data buffers.
411 void gf_2vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
412 unsigned char **src
, unsigned char **dest
);
415 * @brief GF(2^8) vector dot product with three outputs.
417 * Vector dot product optimized to calculate three outputs at a time. Does three
418 * GF(2^8) dot products across each byte of the input array and three constant
419 * sets of coefficients to produce each byte of the outputs. Can be used for
420 * erasure coding encode and decode. Function requires pre-calculation of a
421 * 3*32*vlen byte constant array based on the three sets of input coefficients.
424 * @param len Length of each vector in bytes. Must be >= 16.
425 * @param vlen Number of vector sources.
426 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants
427 * based on the array of input coefficients.
428 * @param src Array of pointers to source inputs.
429 * @param dest Array of pointers to destination data buffers.
433 void gf_3vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
434 unsigned char **src
, unsigned char **dest
);
437 * @brief GF(2^8) vector dot product with three outputs.
439 * Vector dot product optimized to calculate three outputs at a time. Does three
440 * GF(2^8) dot products across each byte of the input array and three constant
441 * sets of coefficients to produce each byte of the outputs. Can be used for
442 * erasure coding encode and decode. Function requires pre-calculation of a
443 * 3*32*vlen byte constant array based on the three sets of input coefficients.
446 * @param len Length of each vector in bytes. Must be >= 16.
447 * @param vlen Number of vector sources.
448 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants
449 * based on the array of input coefficients.
450 * @param src Array of pointers to source inputs.
451 * @param dest Array of pointers to destination data buffers.
455 void gf_3vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
456 unsigned char **src
, unsigned char **dest
);
459 * @brief GF(2^8) vector dot product with three outputs.
461 * Vector dot product optimized to calculate three outputs at a time. Does three
462 * GF(2^8) dot products across each byte of the input array and three constant
463 * sets of coefficients to produce each byte of the outputs. Can be used for
464 * erasure coding encode and decode. Function requires pre-calculation of a
465 * 3*32*vlen byte constant array based on the three sets of input coefficients.
468 * @param len Length of each vector in bytes. Must be >= 32.
469 * @param vlen Number of vector sources.
470 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants
471 * based on the array of input coefficients.
472 * @param src Array of pointers to source inputs.
473 * @param dest Array of pointers to destination data buffers.
477 void gf_3vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
478 unsigned char **src
, unsigned char **dest
);
481 * @brief GF(2^8) vector dot product with four outputs.
483 * Vector dot product optimized to calculate four outputs at a time. Does four
484 * GF(2^8) dot products across each byte of the input array and four constant
485 * sets of coefficients to produce each byte of the outputs. Can be used for
486 * erasure coding encode and decode. Function requires pre-calculation of a
487 * 4*32*vlen byte constant array based on the four sets of input coefficients.
490 * @param len Length of each vector in bytes. Must be >= 16.
491 * @param vlen Number of vector sources.
492 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants
493 * based on the array of input coefficients.
494 * @param src Array of pointers to source inputs.
495 * @param dest Array of pointers to destination data buffers.
499 void gf_4vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
500 unsigned char **src
, unsigned char **dest
);
503 * @brief GF(2^8) vector dot product with four outputs.
505 * Vector dot product optimized to calculate four outputs at a time. Does four
506 * GF(2^8) dot products across each byte of the input array and four constant
507 * sets of coefficients to produce each byte of the outputs. Can be used for
508 * erasure coding encode and decode. Function requires pre-calculation of a
509 * 4*32*vlen byte constant array based on the four sets of input coefficients.
512 * @param len Length of each vector in bytes. Must be >= 16.
513 * @param vlen Number of vector sources.
514 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants
515 * based on the array of input coefficients.
516 * @param src Array of pointers to source inputs.
517 * @param dest Array of pointers to destination data buffers.
521 void gf_4vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
522 unsigned char **src
, unsigned char **dest
);
525 * @brief GF(2^8) vector dot product with four outputs.
527 * Vector dot product optimized to calculate four outputs at a time. Does four
528 * GF(2^8) dot products across each byte of the input array and four constant
529 * sets of coefficients to produce each byte of the outputs. Can be used for
530 * erasure coding encode and decode. Function requires pre-calculation of a
531 * 4*32*vlen byte constant array based on the four sets of input coefficients.
534 * @param len Length of each vector in bytes. Must be >= 32.
535 * @param vlen Number of vector sources.
536 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants
537 * based on the array of input coefficients.
538 * @param src Array of pointers to source inputs.
539 * @param dest Array of pointers to destination data buffers.
543 void gf_4vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
544 unsigned char **src
, unsigned char **dest
);
547 * @brief GF(2^8) vector dot product with five outputs.
549 * Vector dot product optimized to calculate five outputs at a time. Does five
550 * GF(2^8) dot products across each byte of the input array and five constant
551 * sets of coefficients to produce each byte of the outputs. Can be used for
552 * erasure coding encode and decode. Function requires pre-calculation of a
553 * 5*32*vlen byte constant array based on the five sets of input coefficients.
556 * @param len Length of each vector in bytes. Must >= 16.
557 * @param vlen Number of vector sources.
558 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants
559 * based on the array of input coefficients.
560 * @param src Array of pointers to source inputs.
561 * @param dest Array of pointers to destination data buffers.
565 void gf_5vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
566 unsigned char **src
, unsigned char **dest
);
569 * @brief GF(2^8) vector dot product with five outputs.
571 * Vector dot product optimized to calculate five outputs at a time. Does five
572 * GF(2^8) dot products across each byte of the input array and five constant
573 * sets of coefficients to produce each byte of the outputs. Can be used for
574 * erasure coding encode and decode. Function requires pre-calculation of a
575 * 5*32*vlen byte constant array based on the five sets of input coefficients.
578 * @param len Length of each vector in bytes. Must >= 16.
579 * @param vlen Number of vector sources.
580 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants
581 * based on the array of input coefficients.
582 * @param src Array of pointers to source inputs.
583 * @param dest Array of pointers to destination data buffers.
587 void gf_5vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
588 unsigned char **src
, unsigned char **dest
);
591 * @brief GF(2^8) vector dot product with five outputs.
593 * Vector dot product optimized to calculate five outputs at a time. Does five
594 * GF(2^8) dot products across each byte of the input array and five constant
595 * sets of coefficients to produce each byte of the outputs. Can be used for
596 * erasure coding encode and decode. Function requires pre-calculation of a
597 * 5*32*vlen byte constant array based on the five sets of input coefficients.
600 * @param len Length of each vector in bytes. Must >= 32.
601 * @param vlen Number of vector sources.
602 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants
603 * based on the array of input coefficients.
604 * @param src Array of pointers to source inputs.
605 * @param dest Array of pointers to destination data buffers.
609 void gf_5vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
610 unsigned char **src
, unsigned char **dest
);
613 * @brief GF(2^8) vector dot product with six outputs.
615 * Vector dot product optimized to calculate six outputs at a time. Does six
616 * GF(2^8) dot products across each byte of the input array and six constant
617 * sets of coefficients to produce each byte of the outputs. Can be used for
618 * erasure coding encode and decode. Function requires pre-calculation of a
619 * 6*32*vlen byte constant array based on the six sets of input coefficients.
622 * @param len Length of each vector in bytes. Must be >= 16.
623 * @param vlen Number of vector sources.
624 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants
625 * based on the array of input coefficients.
626 * @param src Array of pointers to source inputs.
627 * @param dest Array of pointers to destination data buffers.
631 void gf_6vect_dot_prod_sse(int len
, int vlen
, unsigned char *gftbls
,
632 unsigned char **src
, unsigned char **dest
);
635 * @brief GF(2^8) vector dot product with six outputs.
637 * Vector dot product optimized to calculate six outputs at a time. Does six
638 * GF(2^8) dot products across each byte of the input array and six constant
639 * sets of coefficients to produce each byte of the outputs. Can be used for
640 * erasure coding encode and decode. Function requires pre-calculation of a
641 * 6*32*vlen byte constant array based on the six sets of input coefficients.
644 * @param len Length of each vector in bytes. Must be >= 16.
645 * @param vlen Number of vector sources.
646 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants
647 * based on the array of input coefficients.
648 * @param src Array of pointers to source inputs.
649 * @param dest Array of pointers to destination data buffers.
653 void gf_6vect_dot_prod_avx(int len
, int vlen
, unsigned char *gftbls
,
654 unsigned char **src
, unsigned char **dest
);
657 * @brief GF(2^8) vector dot product with six outputs.
659 * Vector dot product optimized to calculate six outputs at a time. Does six
660 * GF(2^8) dot products across each byte of the input array and six constant
661 * sets of coefficients to produce each byte of the outputs. Can be used for
662 * erasure coding encode and decode. Function requires pre-calculation of a
663 * 6*32*vlen byte constant array based on the six sets of input coefficients.
666 * @param len Length of each vector in bytes. Must be >= 32.
667 * @param vlen Number of vector sources.
668 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants
669 * based on the array of input coefficients.
670 * @param src Array of pointers to source inputs.
671 * @param dest Array of pointers to destination data buffers.
675 void gf_6vect_dot_prod_avx2(int len
, int vlen
, unsigned char *gftbls
,
676 unsigned char **src
, unsigned char **dest
);
679 * @brief GF(2^8) vector multiply accumulate, arch specific version.
681 * Arch specific version of gf_vect_mad() with same parameters.
685 void gf_vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
686 unsigned char *dest
);
688 * @brief GF(2^8) vector multiply accumulate, arch specific version.
690 * Arch specific version of gf_vect_mad() with same parameters.
694 void gf_vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
695 unsigned char *dest
);
698 * @brief GF(2^8) vector multiply accumulate, arch specific version.
700 * Arch specific version of gf_vect_mad() with same parameters.
704 void gf_vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
705 unsigned char *dest
);
709 * @brief GF(2^8) vector multiply with 2 accumulate. SSE version.
711 * Does a GF(2^8) multiply across each byte of input source with expanded
712 * constants and add to destination arrays. Can be used for erasure coding
713 * encode and decode update when only one source is available at a
714 * time. Function requires pre-calculation of a 32*vec byte constant array based
715 * on the input coefficients.
718 * @param len Length of each vector in bytes. Must be >= 32.
719 * @param vec The number of vector sources or rows in the generator matrix
721 * @param vec_i The vector index corresponding to the single input source.
722 * @param gftbls Pointer to array of input tables generated from coding
723 * coefficients in ec_init_tables(). Must be of size 32*vec.
724 * @param src Pointer to source input array.
725 * @param dest Array of pointers to destination input/outputs.
729 void gf_2vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
730 unsigned char **dest
);
733 * @brief GF(2^8) vector multiply with 2 accumulate. AVX version of gf_2vect_mad_sse().
736 void gf_2vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
737 unsigned char **dest
);
739 * @brief GF(2^8) vector multiply with 2 accumulate. AVX2 version of gf_2vect_mad_sse().
742 void gf_2vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
743 unsigned char **dest
);
746 * @brief GF(2^8) vector multiply with 3 accumulate. SSE version.
748 * Does a GF(2^8) multiply across each byte of input source with expanded
749 * constants and add to destination arrays. Can be used for erasure coding
750 * encode and decode update when only one source is available at a
751 * time. Function requires pre-calculation of a 32*vec byte constant array based
752 * on the input coefficients.
755 * @param len Length of each vector in bytes. Must be >= 32.
756 * @param vec The number of vector sources or rows in the generator matrix
758 * @param vec_i The vector index corresponding to the single input source.
759 * @param gftbls Pointer to array of input tables generated from coding
760 * coefficients in ec_init_tables(). Must be of size 32*vec.
761 * @param src Pointer to source input array.
762 * @param dest Array of pointers to destination input/outputs.
766 void gf_3vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
767 unsigned char **dest
);
770 * @brief GF(2^8) vector multiply with 3 accumulate. AVX version of gf_3vect_mad_sse().
773 void gf_3vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
774 unsigned char **dest
);
777 * @brief GF(2^8) vector multiply with 3 accumulate. AVX2 version of gf_3vect_mad_sse().
780 void gf_3vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
781 unsigned char **dest
);
784 * @brief GF(2^8) vector multiply with 4 accumulate. SSE version.
786 * Does a GF(2^8) multiply across each byte of input source with expanded
787 * constants and add to destination arrays. Can be used for erasure coding
788 * encode and decode update when only one source is available at a
789 * time. Function requires pre-calculation of a 32*vec byte constant array based
790 * on the input coefficients.
793 * @param len Length of each vector in bytes. Must be >= 32.
794 * @param vec The number of vector sources or rows in the generator matrix
796 * @param vec_i The vector index corresponding to the single input source.
797 * @param gftbls Pointer to array of input tables generated from coding
798 * coefficients in ec_init_tables(). Must be of size 32*vec.
799 * @param src Pointer to source input array.
800 * @param dest Array of pointers to destination input/outputs.
804 void gf_4vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
805 unsigned char **dest
);
808 * @brief GF(2^8) vector multiply with 4 accumulate. AVX version of gf_4vect_mad_sse().
811 void gf_4vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
812 unsigned char **dest
);
814 * @brief GF(2^8) vector multiply with 4 accumulate. AVX2 version of gf_4vect_mad_sse().
817 void gf_4vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
818 unsigned char **dest
);
821 * @brief GF(2^8) vector multiply with 5 accumulate. SSE version.
824 void gf_5vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
825 unsigned char **dest
);
828 * @brief GF(2^8) vector multiply with 5 accumulate. AVX version.
831 void gf_5vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
832 unsigned char **dest
);
834 * @brief GF(2^8) vector multiply with 5 accumulate. AVX2 version.
837 void gf_5vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
838 unsigned char **dest
);
841 * @brief GF(2^8) vector multiply with 6 accumulate. SSE version.
844 void gf_6vect_mad_sse(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
845 unsigned char **dest
);
847 * @brief GF(2^8) vector multiply with 6 accumulate. AVX version.
850 void gf_6vect_mad_avx(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
851 unsigned char **dest
);
854 * @brief GF(2^8) vector multiply with 6 accumulate. AVX2 version.
857 void gf_6vect_mad_avx2(int len
, int vec
, int vec_i
, unsigned char *gftbls
, unsigned char *src
,
858 unsigned char **dest
);
862 /**********************************************************************
863 * The remaining are lib support functions used in GF(2^8) operations.
867 * @brief Single element GF(2^8) multiply.
869 * @param a Multiplicand a
870 * @param b Multiplicand b
871 * @returns Product of a and b in GF(2^8)
874 unsigned char gf_mul(unsigned char a
, unsigned char b
);
877 * @brief Single element GF(2^8) inverse.
879 * @param a Input element
880 * @returns Field element b such that a x b = {1}
883 unsigned char gf_inv(unsigned char a
);
886 * @brief Generate a matrix of coefficients to be used for encoding.
888 * Vandermonde matrix example of encoding coefficients where high portion of
889 * matrix is identity matrix I and lower portion is constructed as 2^{i*(j-k+1)}
890 * i:{0,k-1} j:{k,m-1}. Commonly used method for choosing coefficients in
891 * erasure encoding but does not guarantee invertable for every sub matrix. For
892 * large pairs of m and k it is possible to find cases where the decode matrix
893 * chosen from sources and parity is not invertable. Users may want to adjust
894 * for certain pairs m and k. If m and k satisfy one of the following
895 * inequalities, no adjustment is required:
903 * @param a [m x k] array to hold coefficients
904 * @param m number of rows in matrix corresponding to srcs + parity.
905 * @param k number of columns in matrix corresponding to srcs.
909 void gf_gen_rs_matrix(unsigned char *a
, int m
, int k
);
912 * @brief Generate a Cauchy matrix of coefficients to be used for encoding.
914 * Cauchy matrix example of encoding coefficients where high portion of matrix
915 * is identity matrix I and lower portion is constructed as 1/(i + j) | i != j,
916 * i:{0,k-1} j:{k,m-1}. Any sub-matrix of a Cauchy matrix should be invertable.
918 * @param a [m x k] array to hold coefficients
919 * @param m number of rows in matrix corresponding to srcs + parity.
920 * @param k number of columns in matrix corresponding to srcs.
924 void gf_gen_cauchy1_matrix(unsigned char *a
, int m
, int k
);
927 * @brief Invert a matrix in GF(2^8)
929 * @param in input matrix
930 * @param out output matrix such that [in] x [out] = [I] - identity matrix
931 * @param n size of matrix [nxn]
932 * @returns 0 successful, other fail on singular input matrix
935 int gf_invert_matrix(unsigned char *in
, unsigned char *out
, const int n
);
938 /*************************************************************/
944 #endif //_ERASURE_CODE_H_