xref: /isa-l/include/gf_vect_mul.h (revision 9ab5a9e579c4fb4e2a3c92d73ccd6d97291d0e80)
1 /**********************************************************************
2   Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
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
12       distribution.
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.
16 
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 **********************************************************************/
29 
30 #ifndef _GF_VECT_MUL_H
31 #define _GF_VECT_MUL_H
32 
33 /**
34  *  @file gf_vect_mul.h
35  *  @brief Interface to functions for vector (block) multiplication in GF(2^8).
36  *
37  *  This file defines the interface to routines used in fast RAID rebuild and
38  *  erasure codes.
39  */
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 // x86 only
46 #if defined(__i386__) || defined(__x86_64__)
47 
48 /**
49  * @brief GF(2^8) vector multiply by constant.
50  *
51  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
52  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
53  * and partial write functions. Function requires pre-calculation of a
54  * 32-element constant array based on constant C. gftbl(C) = {C{00},
55  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
56  * and src must be aligned to 32B.
57  * @requires SSE4.1
58  *
59  * @param len   Length of vector in bytes. Must be aligned to 32B.
60  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
61  * @param src   Pointer to src data array. Must be aligned to 32B.
62  * @param dest  Pointer to destination data array. Must be aligned to 32B.
63  * @returns 0 pass, other fail
64  */
65 
66 int
67 gf_vect_mul_sse(int len, unsigned char *gftbl, void *src, void *dest);
68 
69 /**
70  * @brief GF(2^8) vector multiply by constant.
71  *
72  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
73  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
74  * and partial write functions. Function requires pre-calculation of a
75  * 32-element constant array based on constant C. gftbl(C) = {C{00},
76  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
77  * and src must be aligned to 32B.
78  * @requires AVX
79  *
80  * @param len   Length of vector in bytes. Must be aligned to 32B.
81  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
82  * @param src   Pointer to src data array. Must be aligned to 32B.
83  * @param dest  Pointer to destination data array. Must be aligned to 32B.
84  * @returns 0 pass, other fail
85  */
86 
87 int
88 gf_vect_mul_avx(int len, unsigned char *gftbl, void *src, void *dest);
89 
90 #endif
91 
92 /**
93  * @brief GF(2^8) vector multiply by constant, runs appropriate version.
94  *
95  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
96  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
97  * and partial write functions. Function requires pre-calculation of a
98  * 32-element constant array based on constant C. gftbl(C) = {C{00},
99  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }.
100  * Len and src must be aligned to 32B.
101  *
102  * This function determines what instruction sets are enabled
103  * and selects the appropriate version at runtime.
104  *
105  * @param len   Length of vector in bytes. Must be aligned to 32B.
106  * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
107  * @param src   Pointer to src data array. Must be aligned to 32B.
108  * @param dest  Pointer to destination data array. Must be aligned to 32B.
109  * @returns 0 pass, other fail
110  */
111 
112 int
113 gf_vect_mul(int len, unsigned char *gftbl, void *src, void *dest);
114 
115 /**
116  * @brief Initialize 32-byte constant array for GF(2^8) vector multiply
117  *
118  * Calculates array {C{00}, C{01}, C{02}, ... , C{0f} }, {C{00}, C{10},
119  * C{20}, ... , C{f0} } as required by other fast vector multiply
120  * functions.
121  * @param c     Constant input.
122  * @param gftbl Table output.
123  */
124 
125 void
126 gf_vect_mul_init(unsigned char c, unsigned char *gftbl);
127 
128 /**
129  * @brief GF(2^8) vector multiply by constant, runs baseline version.
130  *
131  * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
132  * is a single field element in GF(2^8). Can be used for RAID6 rebuild
133  * and partial write functions. Function requires pre-calculation of a
134  * 32-element constant array based on constant C. gftbl(C) = {C{00},
135  * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
136  * and src must be aligned to 32B.
137  *
138  * @param len   Length of vector in bytes. Must be aligned to 32B.
139  * @param a 	Pointer to 32-byte array of pre-calculated constants based on C.
140  * 		only use 2nd element is used.
141  * @param src   Pointer to src data array. Must be aligned to 32B.
142  * @param dest  Pointer to destination data array. Must be aligned to 32B.
143  * @returns 0 pass, other fail
144  */
145 
146 int
147 gf_vect_mul_base(int len, unsigned char *a, unsigned char *src, unsigned char *dest);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif //_GF_VECT_MUL_H
154