gf_vect_mul.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**********************************************************************
  2. Copyright(c) 2011-2015 Intel Corporation All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the
  11. distribution.
  12. * Neither the name of Intel Corporation nor the names of its
  13. contributors may be used to endorse or promote products derived
  14. from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. **********************************************************************/
  27. #ifndef _GF_VECT_MUL_H
  28. #define _GF_VECT_MUL_H
  29. /**
  30. * @file gf_vect_mul.h
  31. * @brief Interface to functions for vector (block) multiplication in GF(2^8).
  32. *
  33. * This file defines the interface to routines used in fast RAID rebuild and
  34. * erasure codes.
  35. */
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // x86 only
  40. #if defined(__i386__) || defined(__x86_64__)
  41. /**
  42. * @brief GF(2^8) vector multiply by constant.
  43. *
  44. * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
  45. * is a single field element in GF(2^8). Can be used for RAID6 rebuild
  46. * and partial write functions. Function requires pre-calculation of a
  47. * 32-element constant array based on constant C. gftbl(C) = {C{00},
  48. * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
  49. * and src must be aligned to 32B.
  50. * @requires SSE4.1
  51. *
  52. * @param len Length of vector in bytes. Must be aligned to 32B.
  53. * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
  54. * @param src Pointer to src data array. Must be aligned to 32B.
  55. * @param dest Pointer to destination data array. Must be aligned to 32B.
  56. * @returns 0 pass, other fail
  57. */
  58. int gf_vect_mul_sse(int len, unsigned char *gftbl, void *src, void *dest);
  59. /**
  60. * @brief GF(2^8) vector multiply by constant.
  61. *
  62. * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
  63. * is a single field element in GF(2^8). Can be used for RAID6 rebuild
  64. * and partial write functions. Function requires pre-calculation of a
  65. * 32-element constant array based on constant C. gftbl(C) = {C{00},
  66. * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
  67. * and src must be aligned to 32B.
  68. * @requires AVX
  69. *
  70. * @param len Length of vector in bytes. Must be aligned to 32B.
  71. * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
  72. * @param src Pointer to src data array. Must be aligned to 32B.
  73. * @param dest Pointer to destination data array. Must be aligned to 32B.
  74. * @returns 0 pass, other fail
  75. */
  76. int gf_vect_mul_avx(int len, unsigned char *gftbl, void *src, void *dest);
  77. #endif
  78. /**
  79. * @brief GF(2^8) vector multiply by constant, runs appropriate version.
  80. *
  81. * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
  82. * is a single field element in GF(2^8). Can be used for RAID6 rebuild
  83. * and partial write functions. Function requires pre-calculation of a
  84. * 32-element constant array based on constant C. gftbl(C) = {C{00},
  85. * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }.
  86. * Len and src must be aligned to 32B.
  87. *
  88. * This function determines what instruction sets are enabled
  89. * and selects the appropriate version at runtime.
  90. *
  91. * @param len Length of vector in bytes. Must be aligned to 32B.
  92. * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
  93. * @param src Pointer to src data array. Must be aligned to 32B.
  94. * @param dest Pointer to destination data array. Must be aligned to 32B.
  95. * @returns 0 pass, other fail
  96. */
  97. int gf_vect_mul(int len, unsigned char *gftbl, void *src, void *dest);
  98. /**
  99. * @brief Initialize 32-byte constant array for GF(2^8) vector multiply
  100. *
  101. * Calculates array {C{00}, C{01}, C{02}, ... , C{0f} }, {C{00}, C{10},
  102. * C{20}, ... , C{f0} } as required by other fast vector multiply
  103. * functions.
  104. * @param c Constant input.
  105. * @param gftbl Table output.
  106. */
  107. void gf_vect_mul_init(unsigned char c, unsigned char* gftbl);
  108. /**
  109. * @brief GF(2^8) vector multiply by constant, runs baseline version.
  110. *
  111. * Does a GF(2^8) vector multiply b = Ca where a and b are arrays and C
  112. * is a single field element in GF(2^8). Can be used for RAID6 rebuild
  113. * and partial write functions. Function requires pre-calculation of a
  114. * 32-element constant array based on constant C. gftbl(C) = {C{00},
  115. * C{01}, C{02}, ... , C{0f} }, {C{00}, C{10}, C{20}, ... , C{f0} }. Len
  116. * and src must be aligned to 32B.
  117. *
  118. * @param len Length of vector in bytes. Must be aligned to 32B.
  119. * @param a Pointer to 32-byte array of pre-calculated constants based on C.
  120. * only use 2nd element is used.
  121. * @param src Pointer to src data array. Must be aligned to 32B.
  122. * @param dest Pointer to destination data array. Must be aligned to 32B.
  123. */
  124. void gf_vect_mul_base(int len, unsigned char *a, unsigned char *src,
  125. unsigned char *dest);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif //_GF_VECT_MUL_H