]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/isa-l/include/gf_vect_mul.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / isa-l / include / gf_vect_mul.h
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
31 #ifndef _GF_VECT_MUL_H
32 #define _GF_VECT_MUL_H
33
34 /**
35 * @file gf_vect_mul.h
36 * @brief Interface to functions for vector (block) multiplication in GF(2^8).
37 *
38 * This file defines the interface to routines used in fast RAID rebuild and
39 * erasure codes.
40 */
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 // x86 only
47 #if defined(__i386__) || defined(__x86_64__)
48
49 /**
50 * @brief GF(2^8) vector multiply by constant.
51 *
52 * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
53 * is a single field element in GF(2^8). Can be used for RAID6 rebuild
54 * and partial write functions. Function requires pre-calculation of a
55 * 32-element constant array based on constant C. gftbl(C) = {C{00},
56 * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
57 * and src must be aligned to 32B.
58 * @requires SSE4.1
59 *
60 * @param len Length of vector in bytes. Must be aligned to 32B.
61 * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
62 * @param src Pointer to src data array. Must be aligned to 32B.
63 * @param dest Pointer to destination data array. Must be aligned to 32B.
64 * @returns 0 pass, other fail
65 */
66
67 int gf_vect_mul_sse(int len, unsigned char *gftbl, void *src, void *dest);
68
69
70 /**
71 * @brief GF(2^8) vector multiply by constant.
72 *
73 * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
74 * is a single field element in GF(2^8). Can be used for RAID6 rebuild
75 * and partial write functions. Function requires pre-calculation of a
76 * 32-element constant array based on constant C. gftbl(C) = {C{00},
77 * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
78 * and src must be aligned to 32B.
79 * @requires AVX
80 *
81 * @param len Length of vector in bytes. Must be aligned to 32B.
82 * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
83 * @param src Pointer to src data array. Must be aligned to 32B.
84 * @param dest Pointer to destination data array. Must be aligned to 32B.
85 * @returns 0 pass, other fail
86 */
87
88 int 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 gf_vect_mul(int len, unsigned char *gftbl, void *src, void *dest);
113
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 gf_vect_mul_init(unsigned char c, unsigned char* gftbl);
126
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 */
144
145 void gf_vect_mul_base(int len, unsigned char *a, unsigned char *src,
146 unsigned char *dest);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif //_GF_VECT_MUL_H