Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:02:13

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 #ifndef _GF_VECT_MUL_H
0031 #define _GF_VECT_MUL_H
0032 
0033 /**
0034  *  @file gf_vect_mul.h
0035  *  @brief Interface to functions for vector (block) multiplication in GF(2^8).
0036  *
0037  *  This file defines the interface to routines used in fast RAID rebuild and
0038  *  erasure codes.
0039  */
0040 
0041 #ifdef __cplusplus
0042 extern "C" {
0043 #endif
0044 
0045 // x86 only
0046 #if defined(__i386__) || defined(__x86_64__)
0047 
0048 /**
0049  * @brief GF(2^8) vector multiply by constant.
0050  *
0051  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
0052  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
0053  * and partial write functions. Function requires pre-calculation of a
0054  * 32-element constant array based on constant C. gftbl(C) = {C{00},
0055  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
0056  * and src must be aligned to 32B.
0057  * @requires SSE4.1
0058  *
0059  * @param len   Length of vector in bytes. Must be aligned to 32B.
0060  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
0061  * @param src   Pointer to src data array. Must be aligned to 32B.
0062  * @param dest  Pointer to destination data array. Must be aligned to 32B.
0063  * @returns 0 pass, other fail
0064  */
0065 
0066 int
0067 gf_vect_mul_sse(int len, unsigned char *gftbl, void *src, void *dest);
0068 
0069 /**
0070  * @brief GF(2^8) vector multiply by constant.
0071  *
0072  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
0073  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
0074  * and partial write functions. Function requires pre-calculation of a
0075  * 32-element constant array based on constant C. gftbl(C) = {C{00},
0076  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
0077  * and src must be aligned to 32B.
0078  * @requires AVX
0079  *
0080  * @param len   Length of vector in bytes. Must be aligned to 32B.
0081  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
0082  * @param src   Pointer to src data array. Must be aligned to 32B.
0083  * @param dest  Pointer to destination data array. Must be aligned to 32B.
0084  * @returns 0 pass, other fail
0085  */
0086 
0087 int
0088 gf_vect_mul_avx(int len, unsigned char *gftbl, void *src, void *dest);
0089 
0090 #endif
0091 
0092 /**
0093  * @brief GF(2^8) vector multiply by constant, runs appropriate version.
0094  *
0095  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
0096  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
0097  * and partial write functions. Function requires pre-calculation of a
0098  * 32-element constant array based on constant C. gftbl(C) = {C{00},
0099  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }.
0100  * Len and src must be aligned to 32B.
0101  *
0102  * This function determines what instruction sets are enabled
0103  * and selects the appropriate version at runtime.
0104  *
0105  * @param len   Length of vector in bytes. Must be aligned to 32B.
0106  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
0107  * @param src   Pointer to src data array. Must be aligned to 32B.
0108  * @param dest  Pointer to destination data array. Must be aligned to 32B.
0109  * @returns 0 pass, other fail
0110  */
0111 
0112 int
0113 gf_vect_mul(int len, unsigned char *gftbl, void *src, void *dest);
0114 
0115 /**
0116  * @brief Initialize 32-byte constant array for GF(2^8) vector multiply
0117  *
0118  * Calculates array {C{00}, C{01}, C{02}, ... , C{0f} }, {C{00}, C{10},
0119  * C{20}, ... , C{f0} } as required by other fast vector multiply
0120  * functions.
0121  * @param c     Constant input.
0122  * @param gftbl Table output.
0123  */
0124 
0125 void
0126 gf_vect_mul_init(unsigned char c, unsigned char *gftbl);
0127 
0128 /**
0129  * @brief GF(2^8) vector multiply by constant, runs baseline version.
0130  *
0131  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
0132  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
0133  * and partial write functions. Function requires pre-calculation of a
0134  * 32-element constant array based on constant C. gftbl(C) = {C{00},
0135  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
0136  * and src must be aligned to 32B.
0137  *
0138  * @param len   Length of vector in bytes. Must be aligned to 32B.
0139  * @param a     Pointer to 32-byte array of pre-calculated constants based on C.
0140  *      only use 2nd element is used.
0141  * @param src   Pointer to src data array. Must be aligned to 32B.
0142  * @param dest  Pointer to destination data array. Must be aligned to 32B.
0143  * @returns 0 pass, other fail
0144  */
0145 
0146 int
0147 gf_vect_mul_base(int len, unsigned char *a, unsigned char *src, unsigned char *dest);
0148 
0149 #ifdef __cplusplus
0150 }
0151 #endif
0152 
0153 #endif //_GF_VECT_MUL_H