|
||||
File indexing completed on 2025-01-18 10:01:25
0001 /********************************************************************** 0002 Copyright(c) 2011-2015 Intel Corporation All rights reserved. 0003 0004 Redistribution and use in source and binary forms, with or without 0005 modification, are permitted provided that the following conditions 0006 are met: 0007 * Redistributions of source code must retain the above copyright 0008 notice, this list of conditions and the following disclaimer. 0009 * Redistributions in binary form must reproduce the above copyright 0010 notice, this list of conditions and the following disclaimer in 0011 the documentation and/or other materials provided with the 0012 distribution. 0013 * Neither the name of Intel Corporation nor the names of its 0014 contributors may be used to endorse or promote products derived 0015 from this software without specific prior written permission. 0016 0017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0018 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0019 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0020 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0021 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0022 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0024 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0025 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0026 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0028 **********************************************************************/ 0029 0030 0031 #ifndef _ERASURE_CODE_H_ 0032 #define _ERASURE_CODE_H_ 0033 0034 /** 0035 * @file erasure_code.h 0036 * @brief Interface to functions supporting erasure code encode and decode. 0037 * 0038 * This file defines the interface to optimized functions used in erasure 0039 * codes. Encode and decode of erasures in GF(2^8) are made by calculating the 0040 * dot product of the symbols (bytes in GF(2^8)) across a set of buffers and a 0041 * set of coefficients. Values for the coefficients are determined by the type 0042 * of erasure code. Using a general dot product means that any sequence of 0043 * coefficients may be used including erasure codes based on random 0044 * coefficients. 0045 * Multiple versions of dot product are supplied to calculate 1-6 output 0046 * vectors in one pass. 0047 * Base GF multiply and divide functions can be sped up by defining 0048 * GF_LARGE_TABLES at the expense of memory size. 0049 * 0050 */ 0051 0052 #include "gf_vect_mul.h" 0053 0054 #ifdef __cplusplus 0055 extern "C" { 0056 #endif 0057 0058 /** 0059 * @brief Initialize tables for fast Erasure Code encode and decode. 0060 * 0061 * Generates the expanded tables needed for fast encode or decode for erasure 0062 * codes on blocks of data. 32bytes is generated for each input coefficient. 0063 * 0064 * @param k The number of vector sources or rows in the generator matrix 0065 * for coding. 0066 * @param rows The number of output vectors to concurrently encode/decode. 0067 * @param a Pointer to sets of arrays of input coefficients used to encode 0068 * or decode data. 0069 * @param gftbls Pointer to start of space for concatenated output tables 0070 * generated from input coefficients. Must be of size 32*k*rows. 0071 * @returns none 0072 */ 0073 0074 void ec_init_tables(int k, int rows, unsigned char* a, unsigned char* gftbls); 0075 0076 /** 0077 * @brief Generate or decode erasure codes on blocks of data, runs appropriate version. 0078 * 0079 * Given a list of source data blocks, generate one or multiple blocks of 0080 * encoded data as specified by a matrix of GF(2^8) coefficients. When given a 0081 * suitable set of coefficients, this function will perform the fast generation 0082 * or decoding of Reed-Solomon type erasure codes. 0083 * 0084 * This function determines what instruction sets are enabled and 0085 * selects the appropriate version at runtime. 0086 * 0087 * @param len Length of each block of data (vector) of source or dest data. 0088 * @param k The number of vector sources or rows in the generator matrix 0089 * for coding. 0090 * @param rows The number of output vectors to concurrently encode/decode. 0091 * @param gftbls Pointer to array of input tables generated from coding 0092 * coefficients in ec_init_tables(). Must be of size 32*k*rows 0093 * @param data Array of pointers to source input buffers. 0094 * @param coding Array of pointers to coded output buffers. 0095 * @returns none 0096 */ 0097 0098 void ec_encode_data(int len, int k, int rows, unsigned char *gftbls, unsigned char **data, 0099 unsigned char **coding); 0100 0101 /** 0102 * @brief Generate or decode erasure codes on blocks of data, runs baseline version. 0103 * 0104 * Baseline version of ec_encode_data() with same parameters. 0105 */ 0106 void ec_encode_data_base(int len, int srcs, int dests, unsigned char *v, unsigned char **src, 0107 unsigned char **dest); 0108 0109 /** 0110 * @brief Generate update for encode or decode of erasure codes from single source, runs appropriate version. 0111 * 0112 * Given one source data block, update one or multiple blocks of encoded data as 0113 * specified by a matrix of GF(2^8) coefficients. When given a suitable set of 0114 * coefficients, this function will perform the fast generation or decoding of 0115 * Reed-Solomon type erasure codes from one input source at a time. 0116 * 0117 * This function determines what instruction sets are enabled and selects the 0118 * appropriate version at runtime. 0119 * 0120 * @param len Length of each block of data (vector) of source or dest data. 0121 * @param k The number of vector sources or rows in the generator matrix 0122 * for coding. 0123 * @param rows The number of output vectors to concurrently encode/decode. 0124 * @param vec_i The vector index corresponding to the single input source. 0125 * @param g_tbls Pointer to array of input tables generated from coding 0126 * coefficients in ec_init_tables(). Must be of size 32*k*rows 0127 * @param data Pointer to single input source used to update output parity. 0128 * @param coding Array of pointers to coded output buffers. 0129 * @returns none 0130 */ 0131 void ec_encode_data_update(int len, int k, int rows, int vec_i, unsigned char *g_tbls, 0132 unsigned char *data, unsigned char **coding); 0133 0134 /** 0135 * @brief Generate update for encode or decode of erasure codes from single source. 0136 * 0137 * Baseline version of ec_encode_data_update(). 0138 */ 0139 0140 void ec_encode_data_update_base(int len, int k, int rows, int vec_i, unsigned char *v, 0141 unsigned char *data, unsigned char **dest); 0142 0143 /** 0144 * @brief GF(2^8) vector dot product, runs baseline version. 0145 * 0146 * Does a GF(2^8) dot product across each byte of the input array and a constant 0147 * set of coefficients to produce each byte of the output. Can be used for 0148 * erasure coding encode and decode. Function requires pre-calculation of a 0149 * 32*vlen byte constant array based on the input coefficients. 0150 * 0151 * @param len Length of each vector in bytes. Must be >= 16. 0152 * @param vlen Number of vector sources. 0153 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based 0154 * on the array of input coefficients. Only elements 32*CONST*j + 1 0155 * of this array are used, where j = (0, 1, 2...) and CONST is the 0156 * number of elements in the array of input coefficients. The 0157 * elements used correspond to the original input coefficients. 0158 * @param src Array of pointers to source inputs. 0159 * @param dest Pointer to destination data array. 0160 * @returns none 0161 */ 0162 0163 0164 void gf_vect_dot_prod_base(int len, int vlen, unsigned char *gftbls, 0165 unsigned char **src, unsigned char *dest); 0166 0167 /** 0168 * @brief GF(2^8) vector dot product, runs appropriate version. 0169 * 0170 * Does a GF(2^8) dot product across each byte of the input array and a constant 0171 * set of coefficients to produce each byte of the output. Can be used for 0172 * erasure coding encode and decode. Function requires pre-calculation of a 0173 * 32*vlen byte constant array based on the input coefficients. 0174 * 0175 * This function determines what instruction sets are enabled and 0176 * selects the appropriate version at runtime. 0177 * 0178 * @param len Length of each vector in bytes. Must be >= 32. 0179 * @param vlen Number of vector sources. 0180 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based 0181 * on the array of input coefficients. 0182 * @param src Array of pointers to source inputs. 0183 * @param dest Pointer to destination data array. 0184 * @returns none 0185 */ 0186 0187 void gf_vect_dot_prod(int len, int vlen, unsigned char *gftbls, 0188 unsigned char **src, unsigned char *dest); 0189 0190 /** 0191 * @brief GF(2^8) vector multiply accumulate, runs appropriate version. 0192 * 0193 * Does a GF(2^8) multiply across each byte of input source with expanded 0194 * constant and add to destination array. Can be used for erasure coding encode 0195 * and decode update when only one source is available at a time. Function 0196 * requires pre-calculation of a 32*vec byte constant array based on the input 0197 * coefficients. 0198 * 0199 * This function determines what instruction sets are enabled and selects the 0200 * appropriate version at runtime. 0201 * 0202 * @param len Length of each vector in bytes. Must be >= 64. 0203 * @param vec The number of vector sources or rows in the generator matrix 0204 * for coding. 0205 * @param vec_i The vector index corresponding to the single input source. 0206 * @param gftbls Pointer to array of input tables generated from coding 0207 * coefficients in ec_init_tables(). Must be of size 32*vec. 0208 * @param src Array of pointers to source inputs. 0209 * @param dest Pointer to destination data array. 0210 * @returns none 0211 */ 0212 0213 void gf_vect_mad(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0214 unsigned char *dest); 0215 0216 /** 0217 * @brief GF(2^8) vector multiply accumulate, baseline version. 0218 * 0219 * Baseline version of gf_vect_mad() with same parameters. 0220 */ 0221 0222 void gf_vect_mad_base(int len, int vec, int vec_i, unsigned char *v, unsigned char *src, 0223 unsigned char *dest); 0224 0225 // x86 only 0226 #if defined(__i386__) || defined(__x86_64__) 0227 0228 /** 0229 * @brief Generate or decode erasure codes on blocks of data. 0230 * 0231 * Arch specific version of ec_encode_data() with same parameters. 0232 * @requires SSE4.1 0233 */ 0234 void ec_encode_data_sse(int len, int k, int rows, unsigned char *gftbls, unsigned char **data, 0235 unsigned char **coding); 0236 0237 /** 0238 * @brief Generate or decode erasure codes on blocks of data. 0239 * 0240 * Arch specific version of ec_encode_data() with same parameters. 0241 * @requires AVX 0242 */ 0243 void ec_encode_data_avx(int len, int k, int rows, unsigned char *gftbls, unsigned char **data, 0244 unsigned char **coding); 0245 0246 /** 0247 * @brief Generate or decode erasure codes on blocks of data. 0248 * 0249 * Arch specific version of ec_encode_data() with same parameters. 0250 * @requires AVX2 0251 */ 0252 void ec_encode_data_avx2(int len, int k, int rows, unsigned char *gftbls, unsigned char **data, 0253 unsigned char **coding); 0254 0255 /** 0256 * @brief Generate update for encode or decode of erasure codes from single source. 0257 * 0258 * Arch specific version of ec_encode_data_update() with same parameters. 0259 * @requires SSE4.1 0260 */ 0261 0262 void ec_encode_data_update_sse(int len, int k, int rows, int vec_i, unsigned char *g_tbls, 0263 unsigned char *data, unsigned char **coding); 0264 0265 /** 0266 * @brief Generate update for encode or decode of erasure codes from single source. 0267 * 0268 * Arch specific version of ec_encode_data_update() with same parameters. 0269 * @requires AVX 0270 */ 0271 0272 void ec_encode_data_update_avx(int len, int k, int rows, int vec_i, unsigned char *g_tbls, 0273 unsigned char *data, unsigned char **coding); 0274 0275 /** 0276 * @brief Generate update for encode or decode of erasure codes from single source. 0277 * 0278 * Arch specific version of ec_encode_data_update() with same parameters. 0279 * @requires AVX2 0280 */ 0281 0282 void ec_encode_data_update_avx2(int len, int k, int rows, int vec_i, unsigned char *g_tbls, 0283 unsigned char *data, unsigned char **coding); 0284 0285 /** 0286 * @brief GF(2^8) vector dot product. 0287 * 0288 * Does a GF(2^8) dot product across each byte of the input array and a constant 0289 * set of coefficients to produce each byte of the output. Can be used for 0290 * erasure coding encode and decode. Function requires pre-calculation of a 0291 * 32*vlen byte constant array based on the input coefficients. 0292 * @requires SSE4.1 0293 * 0294 * @param len Length of each vector in bytes. Must be >= 16. 0295 * @param vlen Number of vector sources. 0296 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based 0297 * on the array of input coefficients. 0298 * @param src Array of pointers to source inputs. 0299 * @param dest Pointer to destination data array. 0300 * @returns none 0301 */ 0302 0303 void gf_vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0304 unsigned char **src, unsigned char *dest); 0305 0306 /** 0307 * @brief GF(2^8) vector dot product. 0308 * 0309 * Does a GF(2^8) dot product across each byte of the input array and a constant 0310 * set of coefficients to produce each byte of the output. Can be used for 0311 * erasure coding encode and decode. Function requires pre-calculation of a 0312 * 32*vlen byte constant array based on the input coefficients. 0313 * @requires AVX 0314 * 0315 * @param len Length of each vector in bytes. Must be >= 16. 0316 * @param vlen Number of vector sources. 0317 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based 0318 * on the array of input coefficients. 0319 * @param src Array of pointers to source inputs. 0320 * @param dest Pointer to destination data array. 0321 * @returns none 0322 */ 0323 0324 void gf_vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0325 unsigned char **src, unsigned char *dest); 0326 0327 /** 0328 * @brief GF(2^8) vector dot product. 0329 * 0330 * Does a GF(2^8) dot product across each byte of the input array and a constant 0331 * set of coefficients to produce each byte of the output. Can be used for 0332 * erasure coding encode and decode. Function requires pre-calculation of a 0333 * 32*vlen byte constant array based on the input coefficients. 0334 * @requires AVX2 0335 * 0336 * @param len Length of each vector in bytes. Must be >= 32. 0337 * @param vlen Number of vector sources. 0338 * @param gftbls Pointer to 32*vlen byte array of pre-calculated constants based 0339 * on the array of input coefficients. 0340 * @param src Array of pointers to source inputs. 0341 * @param dest Pointer to destination data array. 0342 * @returns none 0343 */ 0344 0345 void gf_vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0346 unsigned char **src, unsigned char *dest); 0347 0348 /** 0349 * @brief GF(2^8) vector dot product with two outputs. 0350 * 0351 * Vector dot product optimized to calculate two outputs at a time. Does two 0352 * GF(2^8) dot products across each byte of the input array and two constant 0353 * sets of coefficients to produce each byte of the outputs. Can be used for 0354 * erasure coding encode and decode. Function requires pre-calculation of a 0355 * 2*32*vlen byte constant array based on the two sets of input coefficients. 0356 * @requires SSE4.1 0357 * 0358 * @param len Length of each vector in bytes. Must be >= 16. 0359 * @param vlen Number of vector sources. 0360 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants 0361 * based on the array of input coefficients. 0362 * @param src Array of pointers to source inputs. 0363 * @param dest Array of pointers to destination data buffers. 0364 * @returns none 0365 */ 0366 0367 void gf_2vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0368 unsigned char **src, unsigned char **dest); 0369 0370 /** 0371 * @brief GF(2^8) vector dot product with two outputs. 0372 * 0373 * Vector dot product optimized to calculate two outputs at a time. Does two 0374 * GF(2^8) dot products across each byte of the input array and two constant 0375 * sets of coefficients to produce each byte of the outputs. Can be used for 0376 * erasure coding encode and decode. Function requires pre-calculation of a 0377 * 2*32*vlen byte constant array based on the two sets of input coefficients. 0378 * @requires AVX 0379 * 0380 * @param len Length of each vector in bytes. Must be >= 16. 0381 * @param vlen Number of vector sources. 0382 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants 0383 * based on the array of input coefficients. 0384 * @param src Array of pointers to source inputs. 0385 * @param dest Array of pointers to destination data buffers. 0386 * @returns none 0387 */ 0388 0389 void gf_2vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0390 unsigned char **src, unsigned char **dest); 0391 0392 /** 0393 * @brief GF(2^8) vector dot product with two outputs. 0394 * 0395 * Vector dot product optimized to calculate two outputs at a time. Does two 0396 * GF(2^8) dot products across each byte of the input array and two constant 0397 * sets of coefficients to produce each byte of the outputs. Can be used for 0398 * erasure coding encode and decode. Function requires pre-calculation of a 0399 * 2*32*vlen byte constant array based on the two sets of input coefficients. 0400 * @requires AVX2 0401 * 0402 * @param len Length of each vector in bytes. Must be >= 32. 0403 * @param vlen Number of vector sources. 0404 * @param gftbls Pointer to 2*32*vlen byte array of pre-calculated constants 0405 * based on the array of input coefficients. 0406 * @param src Array of pointers to source inputs. 0407 * @param dest Array of pointers to destination data buffers. 0408 * @returns none 0409 */ 0410 0411 void gf_2vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0412 unsigned char **src, unsigned char **dest); 0413 0414 /** 0415 * @brief GF(2^8) vector dot product with three outputs. 0416 * 0417 * Vector dot product optimized to calculate three outputs at a time. Does three 0418 * GF(2^8) dot products across each byte of the input array and three constant 0419 * sets of coefficients to produce each byte of the outputs. Can be used for 0420 * erasure coding encode and decode. Function requires pre-calculation of a 0421 * 3*32*vlen byte constant array based on the three sets of input coefficients. 0422 * @requires SSE4.1 0423 * 0424 * @param len Length of each vector in bytes. Must be >= 16. 0425 * @param vlen Number of vector sources. 0426 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants 0427 * based on the array of input coefficients. 0428 * @param src Array of pointers to source inputs. 0429 * @param dest Array of pointers to destination data buffers. 0430 * @returns none 0431 */ 0432 0433 void gf_3vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0434 unsigned char **src, unsigned char **dest); 0435 0436 /** 0437 * @brief GF(2^8) vector dot product with three outputs. 0438 * 0439 * Vector dot product optimized to calculate three outputs at a time. Does three 0440 * GF(2^8) dot products across each byte of the input array and three constant 0441 * sets of coefficients to produce each byte of the outputs. Can be used for 0442 * erasure coding encode and decode. Function requires pre-calculation of a 0443 * 3*32*vlen byte constant array based on the three sets of input coefficients. 0444 * @requires AVX 0445 * 0446 * @param len Length of each vector in bytes. Must be >= 16. 0447 * @param vlen Number of vector sources. 0448 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants 0449 * based on the array of input coefficients. 0450 * @param src Array of pointers to source inputs. 0451 * @param dest Array of pointers to destination data buffers. 0452 * @returns none 0453 */ 0454 0455 void gf_3vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0456 unsigned char **src, unsigned char **dest); 0457 0458 /** 0459 * @brief GF(2^8) vector dot product with three outputs. 0460 * 0461 * Vector dot product optimized to calculate three outputs at a time. Does three 0462 * GF(2^8) dot products across each byte of the input array and three constant 0463 * sets of coefficients to produce each byte of the outputs. Can be used for 0464 * erasure coding encode and decode. Function requires pre-calculation of a 0465 * 3*32*vlen byte constant array based on the three sets of input coefficients. 0466 * @requires AVX2 0467 * 0468 * @param len Length of each vector in bytes. Must be >= 32. 0469 * @param vlen Number of vector sources. 0470 * @param gftbls Pointer to 3*32*vlen byte array of pre-calculated constants 0471 * based on the array of input coefficients. 0472 * @param src Array of pointers to source inputs. 0473 * @param dest Array of pointers to destination data buffers. 0474 * @returns none 0475 */ 0476 0477 void gf_3vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0478 unsigned char **src, unsigned char **dest); 0479 0480 /** 0481 * @brief GF(2^8) vector dot product with four outputs. 0482 * 0483 * Vector dot product optimized to calculate four outputs at a time. Does four 0484 * GF(2^8) dot products across each byte of the input array and four constant 0485 * sets of coefficients to produce each byte of the outputs. Can be used for 0486 * erasure coding encode and decode. Function requires pre-calculation of a 0487 * 4*32*vlen byte constant array based on the four sets of input coefficients. 0488 * @requires SSE4.1 0489 * 0490 * @param len Length of each vector in bytes. Must be >= 16. 0491 * @param vlen Number of vector sources. 0492 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants 0493 * based on the array of input coefficients. 0494 * @param src Array of pointers to source inputs. 0495 * @param dest Array of pointers to destination data buffers. 0496 * @returns none 0497 */ 0498 0499 void gf_4vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0500 unsigned char **src, unsigned char **dest); 0501 0502 /** 0503 * @brief GF(2^8) vector dot product with four outputs. 0504 * 0505 * Vector dot product optimized to calculate four outputs at a time. Does four 0506 * GF(2^8) dot products across each byte of the input array and four constant 0507 * sets of coefficients to produce each byte of the outputs. Can be used for 0508 * erasure coding encode and decode. Function requires pre-calculation of a 0509 * 4*32*vlen byte constant array based on the four sets of input coefficients. 0510 * @requires AVX 0511 * 0512 * @param len Length of each vector in bytes. Must be >= 16. 0513 * @param vlen Number of vector sources. 0514 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants 0515 * based on the array of input coefficients. 0516 * @param src Array of pointers to source inputs. 0517 * @param dest Array of pointers to destination data buffers. 0518 * @returns none 0519 */ 0520 0521 void gf_4vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0522 unsigned char **src, unsigned char **dest); 0523 0524 /** 0525 * @brief GF(2^8) vector dot product with four outputs. 0526 * 0527 * Vector dot product optimized to calculate four outputs at a time. Does four 0528 * GF(2^8) dot products across each byte of the input array and four constant 0529 * sets of coefficients to produce each byte of the outputs. Can be used for 0530 * erasure coding encode and decode. Function requires pre-calculation of a 0531 * 4*32*vlen byte constant array based on the four sets of input coefficients. 0532 * @requires AVX2 0533 * 0534 * @param len Length of each vector in bytes. Must be >= 32. 0535 * @param vlen Number of vector sources. 0536 * @param gftbls Pointer to 4*32*vlen byte array of pre-calculated constants 0537 * based on the array of input coefficients. 0538 * @param src Array of pointers to source inputs. 0539 * @param dest Array of pointers to destination data buffers. 0540 * @returns none 0541 */ 0542 0543 void gf_4vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0544 unsigned char **src, unsigned char **dest); 0545 0546 /** 0547 * @brief GF(2^8) vector dot product with five outputs. 0548 * 0549 * Vector dot product optimized to calculate five outputs at a time. Does five 0550 * GF(2^8) dot products across each byte of the input array and five constant 0551 * sets of coefficients to produce each byte of the outputs. Can be used for 0552 * erasure coding encode and decode. Function requires pre-calculation of a 0553 * 5*32*vlen byte constant array based on the five sets of input coefficients. 0554 * @requires SSE4.1 0555 * 0556 * @param len Length of each vector in bytes. Must >= 16. 0557 * @param vlen Number of vector sources. 0558 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants 0559 * based on the array of input coefficients. 0560 * @param src Array of pointers to source inputs. 0561 * @param dest Array of pointers to destination data buffers. 0562 * @returns none 0563 */ 0564 0565 void gf_5vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0566 unsigned char **src, unsigned char **dest); 0567 0568 /** 0569 * @brief GF(2^8) vector dot product with five outputs. 0570 * 0571 * Vector dot product optimized to calculate five outputs at a time. Does five 0572 * GF(2^8) dot products across each byte of the input array and five constant 0573 * sets of coefficients to produce each byte of the outputs. Can be used for 0574 * erasure coding encode and decode. Function requires pre-calculation of a 0575 * 5*32*vlen byte constant array based on the five sets of input coefficients. 0576 * @requires AVX 0577 * 0578 * @param len Length of each vector in bytes. Must >= 16. 0579 * @param vlen Number of vector sources. 0580 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants 0581 * based on the array of input coefficients. 0582 * @param src Array of pointers to source inputs. 0583 * @param dest Array of pointers to destination data buffers. 0584 * @returns none 0585 */ 0586 0587 void gf_5vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0588 unsigned char **src, unsigned char **dest); 0589 0590 /** 0591 * @brief GF(2^8) vector dot product with five outputs. 0592 * 0593 * Vector dot product optimized to calculate five outputs at a time. Does five 0594 * GF(2^8) dot products across each byte of the input array and five constant 0595 * sets of coefficients to produce each byte of the outputs. Can be used for 0596 * erasure coding encode and decode. Function requires pre-calculation of a 0597 * 5*32*vlen byte constant array based on the five sets of input coefficients. 0598 * @requires AVX2 0599 * 0600 * @param len Length of each vector in bytes. Must >= 32. 0601 * @param vlen Number of vector sources. 0602 * @param gftbls Pointer to 5*32*vlen byte array of pre-calculated constants 0603 * based on the array of input coefficients. 0604 * @param src Array of pointers to source inputs. 0605 * @param dest Array of pointers to destination data buffers. 0606 * @returns none 0607 */ 0608 0609 void gf_5vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0610 unsigned char **src, unsigned char **dest); 0611 0612 /** 0613 * @brief GF(2^8) vector dot product with six outputs. 0614 * 0615 * Vector dot product optimized to calculate six outputs at a time. Does six 0616 * GF(2^8) dot products across each byte of the input array and six constant 0617 * sets of coefficients to produce each byte of the outputs. Can be used for 0618 * erasure coding encode and decode. Function requires pre-calculation of a 0619 * 6*32*vlen byte constant array based on the six sets of input coefficients. 0620 * @requires SSE4.1 0621 * 0622 * @param len Length of each vector in bytes. Must be >= 16. 0623 * @param vlen Number of vector sources. 0624 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants 0625 * based on the array of input coefficients. 0626 * @param src Array of pointers to source inputs. 0627 * @param dest Array of pointers to destination data buffers. 0628 * @returns none 0629 */ 0630 0631 void gf_6vect_dot_prod_sse(int len, int vlen, unsigned char *gftbls, 0632 unsigned char **src, unsigned char **dest); 0633 0634 /** 0635 * @brief GF(2^8) vector dot product with six outputs. 0636 * 0637 * Vector dot product optimized to calculate six outputs at a time. Does six 0638 * GF(2^8) dot products across each byte of the input array and six constant 0639 * sets of coefficients to produce each byte of the outputs. Can be used for 0640 * erasure coding encode and decode. Function requires pre-calculation of a 0641 * 6*32*vlen byte constant array based on the six sets of input coefficients. 0642 * @requires AVX 0643 * 0644 * @param len Length of each vector in bytes. Must be >= 16. 0645 * @param vlen Number of vector sources. 0646 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants 0647 * based on the array of input coefficients. 0648 * @param src Array of pointers to source inputs. 0649 * @param dest Array of pointers to destination data buffers. 0650 * @returns none 0651 */ 0652 0653 void gf_6vect_dot_prod_avx(int len, int vlen, unsigned char *gftbls, 0654 unsigned char **src, unsigned char **dest); 0655 0656 /** 0657 * @brief GF(2^8) vector dot product with six outputs. 0658 * 0659 * Vector dot product optimized to calculate six outputs at a time. Does six 0660 * GF(2^8) dot products across each byte of the input array and six constant 0661 * sets of coefficients to produce each byte of the outputs. Can be used for 0662 * erasure coding encode and decode. Function requires pre-calculation of a 0663 * 6*32*vlen byte constant array based on the six sets of input coefficients. 0664 * @requires AVX2 0665 * 0666 * @param len Length of each vector in bytes. Must be >= 32. 0667 * @param vlen Number of vector sources. 0668 * @param gftbls Pointer to 6*32*vlen byte array of pre-calculated constants 0669 * based on the array of input coefficients. 0670 * @param src Array of pointers to source inputs. 0671 * @param dest Array of pointers to destination data buffers. 0672 * @returns none 0673 */ 0674 0675 void gf_6vect_dot_prod_avx2(int len, int vlen, unsigned char *gftbls, 0676 unsigned char **src, unsigned char **dest); 0677 0678 /** 0679 * @brief GF(2^8) vector multiply accumulate, arch specific version. 0680 * 0681 * Arch specific version of gf_vect_mad() with same parameters. 0682 * @requires SSE4.1 0683 */ 0684 0685 void gf_vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0686 unsigned char *dest); 0687 /** 0688 * @brief GF(2^8) vector multiply accumulate, arch specific version. 0689 * 0690 * Arch specific version of gf_vect_mad() with same parameters. 0691 * @requires AVX 0692 */ 0693 0694 void gf_vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0695 unsigned char *dest); 0696 0697 /** 0698 * @brief GF(2^8) vector multiply accumulate, arch specific version. 0699 * 0700 * Arch specific version of gf_vect_mad() with same parameters. 0701 * @requires AVX2 0702 */ 0703 0704 void gf_vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0705 unsigned char *dest); 0706 0707 0708 /** 0709 * @brief GF(2^8) vector multiply with 2 accumulate. SSE version. 0710 * 0711 * Does a GF(2^8) multiply across each byte of input source with expanded 0712 * constants and add to destination arrays. Can be used for erasure coding 0713 * encode and decode update when only one source is available at a 0714 * time. Function requires pre-calculation of a 32*vec byte constant array based 0715 * on the input coefficients. 0716 * @requires SSE4.1 0717 * 0718 * @param len Length of each vector in bytes. Must be >= 32. 0719 * @param vec The number of vector sources or rows in the generator matrix 0720 * for coding. 0721 * @param vec_i The vector index corresponding to the single input source. 0722 * @param gftbls Pointer to array of input tables generated from coding 0723 * coefficients in ec_init_tables(). Must be of size 32*vec. 0724 * @param src Pointer to source input array. 0725 * @param dest Array of pointers to destination input/outputs. 0726 * @returns none 0727 */ 0728 0729 void gf_2vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0730 unsigned char **dest); 0731 0732 /** 0733 * @brief GF(2^8) vector multiply with 2 accumulate. AVX version of gf_2vect_mad_sse(). 0734 * @requires AVX 0735 */ 0736 void gf_2vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0737 unsigned char **dest); 0738 /** 0739 * @brief GF(2^8) vector multiply with 2 accumulate. AVX2 version of gf_2vect_mad_sse(). 0740 * @requires AVX2 0741 */ 0742 void gf_2vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0743 unsigned char **dest); 0744 0745 /** 0746 * @brief GF(2^8) vector multiply with 3 accumulate. SSE version. 0747 * 0748 * Does a GF(2^8) multiply across each byte of input source with expanded 0749 * constants and add to destination arrays. Can be used for erasure coding 0750 * encode and decode update when only one source is available at a 0751 * time. Function requires pre-calculation of a 32*vec byte constant array based 0752 * on the input coefficients. 0753 * @requires SSE4.1 0754 * 0755 * @param len Length of each vector in bytes. Must be >= 32. 0756 * @param vec The number of vector sources or rows in the generator matrix 0757 * for coding. 0758 * @param vec_i The vector index corresponding to the single input source. 0759 * @param gftbls Pointer to array of input tables generated from coding 0760 * coefficients in ec_init_tables(). Must be of size 32*vec. 0761 * @param src Pointer to source input array. 0762 * @param dest Array of pointers to destination input/outputs. 0763 * @returns none 0764 */ 0765 0766 void gf_3vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0767 unsigned char **dest); 0768 0769 /** 0770 * @brief GF(2^8) vector multiply with 3 accumulate. AVX version of gf_3vect_mad_sse(). 0771 * @requires AVX 0772 */ 0773 void gf_3vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0774 unsigned char **dest); 0775 0776 /** 0777 * @brief GF(2^8) vector multiply with 3 accumulate. AVX2 version of gf_3vect_mad_sse(). 0778 * @requires AVX2 0779 */ 0780 void gf_3vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0781 unsigned char **dest); 0782 0783 /** 0784 * @brief GF(2^8) vector multiply with 4 accumulate. SSE version. 0785 * 0786 * Does a GF(2^8) multiply across each byte of input source with expanded 0787 * constants and add to destination arrays. Can be used for erasure coding 0788 * encode and decode update when only one source is available at a 0789 * time. Function requires pre-calculation of a 32*vec byte constant array based 0790 * on the input coefficients. 0791 * @requires SSE4.1 0792 * 0793 * @param len Length of each vector in bytes. Must be >= 32. 0794 * @param vec The number of vector sources or rows in the generator matrix 0795 * for coding. 0796 * @param vec_i The vector index corresponding to the single input source. 0797 * @param gftbls Pointer to array of input tables generated from coding 0798 * coefficients in ec_init_tables(). Must be of size 32*vec. 0799 * @param src Pointer to source input array. 0800 * @param dest Array of pointers to destination input/outputs. 0801 * @returns none 0802 */ 0803 0804 void gf_4vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0805 unsigned char **dest); 0806 0807 /** 0808 * @brief GF(2^8) vector multiply with 4 accumulate. AVX version of gf_4vect_mad_sse(). 0809 * @requires AVX 0810 */ 0811 void gf_4vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0812 unsigned char **dest); 0813 /** 0814 * @brief GF(2^8) vector multiply with 4 accumulate. AVX2 version of gf_4vect_mad_sse(). 0815 * @requires AVX2 0816 */ 0817 void gf_4vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0818 unsigned char **dest); 0819 0820 /** 0821 * @brief GF(2^8) vector multiply with 5 accumulate. SSE version. 0822 * @requires SSE4.1 0823 */ 0824 void gf_5vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0825 unsigned char **dest); 0826 0827 /** 0828 * @brief GF(2^8) vector multiply with 5 accumulate. AVX version. 0829 * @requires AVX 0830 */ 0831 void gf_5vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0832 unsigned char **dest); 0833 /** 0834 * @brief GF(2^8) vector multiply with 5 accumulate. AVX2 version. 0835 * @requires AVX2 0836 */ 0837 void gf_5vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0838 unsigned char **dest); 0839 0840 /** 0841 * @brief GF(2^8) vector multiply with 6 accumulate. SSE version. 0842 * @requires SSE4.1 0843 */ 0844 void gf_6vect_mad_sse(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0845 unsigned char **dest); 0846 /** 0847 * @brief GF(2^8) vector multiply with 6 accumulate. AVX version. 0848 * @requires AVX 0849 */ 0850 void gf_6vect_mad_avx(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0851 unsigned char **dest); 0852 0853 /** 0854 * @brief GF(2^8) vector multiply with 6 accumulate. AVX2 version. 0855 * @requires AVX2 0856 */ 0857 void gf_6vect_mad_avx2(int len, int vec, int vec_i, unsigned char *gftbls, unsigned char *src, 0858 unsigned char **dest); 0859 0860 #endif 0861 0862 /********************************************************************** 0863 * The remaining are lib support functions used in GF(2^8) operations. 0864 */ 0865 0866 /** 0867 * @brief Single element GF(2^8) multiply. 0868 * 0869 * @param a Multiplicand a 0870 * @param b Multiplicand b 0871 * @returns Product of a and b in GF(2^8) 0872 */ 0873 0874 unsigned char gf_mul(unsigned char a, unsigned char b); 0875 0876 /** 0877 * @brief Single element GF(2^8) inverse. 0878 * 0879 * @param a Input element 0880 * @returns Field element b such that a x b = {1} 0881 */ 0882 0883 unsigned char gf_inv(unsigned char a); 0884 0885 /** 0886 * @brief Generate a matrix of coefficients to be used for encoding. 0887 * 0888 * Vandermonde matrix example of encoding coefficients where high portion of 0889 * matrix is identity matrix I and lower portion is constructed as 2^{i*(j-k+1)} 0890 * i:{0,k-1} j:{k,m-1}. Commonly used method for choosing coefficients in 0891 * erasure encoding but does not guarantee invertable for every sub matrix. For 0892 * large pairs of m and k it is possible to find cases where the decode matrix 0893 * chosen from sources and parity is not invertable. Users may want to adjust 0894 * for certain pairs m and k. If m and k satisfy one of the following 0895 * inequalities, no adjustment is required: 0896 * 0897 * - k <= 3 0898 * - k = 4, m <= 25 0899 * - k = 5, m <= 10 0900 * - k <= 21, m-k = 4 0901 * - m - k <= 3. 0902 * 0903 * @param a [m x k] array to hold coefficients 0904 * @param m number of rows in matrix corresponding to srcs + parity. 0905 * @param k number of columns in matrix corresponding to srcs. 0906 * @returns none 0907 */ 0908 0909 void gf_gen_rs_matrix(unsigned char *a, int m, int k); 0910 0911 /** 0912 * @brief Generate a Cauchy matrix of coefficients to be used for encoding. 0913 * 0914 * Cauchy matrix example of encoding coefficients where high portion of matrix 0915 * is identity matrix I and lower portion is constructed as 1/(i + j) | i != j, 0916 * i:{0,k-1} j:{k,m-1}. Any sub-matrix of a Cauchy matrix should be invertable. 0917 * 0918 * @param a [m x k] array to hold coefficients 0919 * @param m number of rows in matrix corresponding to srcs + parity. 0920 * @param k number of columns in matrix corresponding to srcs. 0921 * @returns none 0922 */ 0923 0924 void gf_gen_cauchy1_matrix(unsigned char *a, int m, int k); 0925 0926 /** 0927 * @brief Invert a matrix in GF(2^8) 0928 * 0929 * Attempts to construct an n x n inverse of the input matrix. Returns non-zero 0930 * if singular. Will always destroy input matrix in process. 0931 * 0932 * @param in input matrix, destroyed by invert process 0933 * @param out output matrix such that [in] x [out] = [I] - identity matrix 0934 * @param n size of matrix [nxn] 0935 * @returns 0 successful, other fail on singular input matrix 0936 */ 0937 0938 int gf_invert_matrix(unsigned char *in, unsigned char *out, const int n); 0939 0940 0941 /*************************************************************/ 0942 0943 #ifdef __cplusplus 0944 } 0945 #endif 0946 0947 #endif //_ERASURE_CODE_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |