ec_highlevel_func.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. #include <limits.h>
  28. #include "erasure_code.h"
  29. #if __x86_64__ || __i386__ || _M_X64 || _M_IX86
  30. void ec_encode_data_sse(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
  31. unsigned char **coding)
  32. {
  33. if (len < 16) {
  34. ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  35. return;
  36. }
  37. while (rows >= 4) {
  38. gf_4vect_dot_prod_sse(len, k, g_tbls, data, coding);
  39. g_tbls += 4 * k * 32;
  40. coding += 4;
  41. rows -= 4;
  42. }
  43. switch (rows) {
  44. case 3:
  45. gf_3vect_dot_prod_sse(len, k, g_tbls, data, coding);
  46. break;
  47. case 2:
  48. gf_2vect_dot_prod_sse(len, k, g_tbls, data, coding);
  49. break;
  50. case 1:
  51. gf_vect_dot_prod_sse(len, k, g_tbls, data, *coding);
  52. break;
  53. case 0:
  54. break;
  55. }
  56. }
  57. void ec_encode_data_avx(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
  58. unsigned char **coding)
  59. {
  60. if (len < 16) {
  61. ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  62. return;
  63. }
  64. while (rows >= 4) {
  65. gf_4vect_dot_prod_avx(len, k, g_tbls, data, coding);
  66. g_tbls += 4 * k * 32;
  67. coding += 4;
  68. rows -= 4;
  69. }
  70. switch (rows) {
  71. case 3:
  72. gf_3vect_dot_prod_avx(len, k, g_tbls, data, coding);
  73. break;
  74. case 2:
  75. gf_2vect_dot_prod_avx(len, k, g_tbls, data, coding);
  76. break;
  77. case 1:
  78. gf_vect_dot_prod_avx(len, k, g_tbls, data, *coding);
  79. break;
  80. case 0:
  81. break;
  82. }
  83. }
  84. void ec_encode_data_avx2(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
  85. unsigned char **coding)
  86. {
  87. if (len < 32) {
  88. ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  89. return;
  90. }
  91. while (rows >= 4) {
  92. gf_4vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  93. g_tbls += 4 * k * 32;
  94. coding += 4;
  95. rows -= 4;
  96. }
  97. switch (rows) {
  98. case 3:
  99. gf_3vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  100. break;
  101. case 2:
  102. gf_2vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  103. break;
  104. case 1:
  105. gf_vect_dot_prod_avx2(len, k, g_tbls, data, *coding);
  106. break;
  107. case 0:
  108. break;
  109. }
  110. }
  111. #ifdef HAVE_AS_KNOWS_AVX512
  112. extern int gf_vect_dot_prod_avx512(int len, int k, unsigned char *g_tbls, unsigned char **data,
  113. unsigned char *dest);
  114. extern int gf_2vect_dot_prod_avx512(int len, int k, unsigned char *g_tbls,
  115. unsigned char **data, unsigned char **coding);
  116. extern int gf_3vect_dot_prod_avx512(int len, int k, unsigned char *g_tbls,
  117. unsigned char **data, unsigned char **coding);
  118. extern int gf_4vect_dot_prod_avx512(int len, int k, unsigned char *g_tbls,
  119. unsigned char **data, unsigned char **coding);
  120. extern void gf_vect_mad_avx512(int len, int vec, int vec_i, unsigned char *gftbls,
  121. unsigned char *src, unsigned char *dest);
  122. extern void gf_2vect_mad_avx512(int len, int vec, int vec_i, unsigned char *gftbls,
  123. unsigned char *src, unsigned char **dest);
  124. extern void gf_3vect_mad_avx512(int len, int vec, int vec_i, unsigned char *gftbls,
  125. unsigned char *src, unsigned char **dest);
  126. extern void gf_4vect_mad_avx512(int len, int vec, int vec_i, unsigned char *gftbls,
  127. unsigned char *src, unsigned char **dest);
  128. void ec_encode_data_avx512(int len, int k, int rows, unsigned char *g_tbls,
  129. unsigned char **data, unsigned char **coding)
  130. {
  131. if (len < 64) {
  132. ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  133. return;
  134. }
  135. while (rows >= 4) {
  136. gf_4vect_dot_prod_avx512(len, k, g_tbls, data, coding);
  137. g_tbls += 4 * k * 32;
  138. coding += 4;
  139. rows -= 4;
  140. }
  141. switch (rows) {
  142. case 3:
  143. gf_3vect_dot_prod_avx512(len, k, g_tbls, data, coding);
  144. break;
  145. case 2:
  146. gf_2vect_dot_prod_avx512(len, k, g_tbls, data, coding);
  147. break;
  148. case 1:
  149. gf_vect_dot_prod_avx512(len, k, g_tbls, data, *coding);
  150. break;
  151. case 0:
  152. break;
  153. }
  154. }
  155. void ec_encode_data_update_avx512(int len, int k, int rows, int vec_i, unsigned char *g_tbls,
  156. unsigned char *data, unsigned char **coding)
  157. {
  158. if (len < 64) {
  159. ec_encode_data_update_base(len, k, rows, vec_i, g_tbls, data, coding);
  160. return;
  161. }
  162. while (rows >= 4) {
  163. gf_4vect_mad_avx512(len, k, vec_i, g_tbls, data, coding);
  164. g_tbls += 4 * k * 32;
  165. coding += 4;
  166. rows -= 4;
  167. }
  168. switch (rows) {
  169. case 3:
  170. gf_3vect_mad_avx512(len, k, vec_i, g_tbls, data, coding);
  171. break;
  172. case 2:
  173. gf_2vect_mad_avx512(len, k, vec_i, g_tbls, data, coding);
  174. break;
  175. case 1:
  176. gf_vect_mad_avx512(len, k, vec_i, g_tbls, data, *coding);
  177. break;
  178. case 0:
  179. break;
  180. }
  181. }
  182. #endif // HAVE_AS_KNOWS_AVX512
  183. #if __WORDSIZE == 64 || _WIN64 || __x86_64__
  184. void ec_encode_data_update_sse(int len, int k, int rows, int vec_i, unsigned char *g_tbls,
  185. unsigned char *data, unsigned char **coding)
  186. {
  187. if (len < 16) {
  188. ec_encode_data_update_base(len, k, rows, vec_i, g_tbls, data, coding);
  189. return;
  190. }
  191. while (rows > 6) {
  192. gf_6vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  193. g_tbls += 6 * k * 32;
  194. coding += 6;
  195. rows -= 6;
  196. }
  197. switch (rows) {
  198. case 6:
  199. gf_6vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  200. break;
  201. case 5:
  202. gf_5vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  203. break;
  204. case 4:
  205. gf_4vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  206. break;
  207. case 3:
  208. gf_3vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  209. break;
  210. case 2:
  211. gf_2vect_mad_sse(len, k, vec_i, g_tbls, data, coding);
  212. break;
  213. case 1:
  214. gf_vect_mad_sse(len, k, vec_i, g_tbls, data, *coding);
  215. break;
  216. case 0:
  217. break;
  218. }
  219. }
  220. void ec_encode_data_update_avx(int len, int k, int rows, int vec_i, unsigned char *g_tbls,
  221. unsigned char *data, unsigned char **coding)
  222. {
  223. if (len < 16) {
  224. ec_encode_data_update_base(len, k, rows, vec_i, g_tbls, data, coding);
  225. return;
  226. }
  227. while (rows > 6) {
  228. gf_6vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  229. g_tbls += 6 * k * 32;
  230. coding += 6;
  231. rows -= 6;
  232. }
  233. switch (rows) {
  234. case 6:
  235. gf_6vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  236. break;
  237. case 5:
  238. gf_5vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  239. break;
  240. case 4:
  241. gf_4vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  242. break;
  243. case 3:
  244. gf_3vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  245. break;
  246. case 2:
  247. gf_2vect_mad_avx(len, k, vec_i, g_tbls, data, coding);
  248. break;
  249. case 1:
  250. gf_vect_mad_avx(len, k, vec_i, g_tbls, data, *coding);
  251. break;
  252. case 0:
  253. break;
  254. }
  255. }
  256. void ec_encode_data_update_avx2(int len, int k, int rows, int vec_i, unsigned char *g_tbls,
  257. unsigned char *data, unsigned char **coding)
  258. {
  259. if (len < 32) {
  260. ec_encode_data_update_base(len, k, rows, vec_i, g_tbls, data, coding);
  261. return;
  262. }
  263. while (rows > 6) {
  264. gf_6vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  265. g_tbls += 6 * k * 32;
  266. coding += 6;
  267. rows -= 6;
  268. }
  269. switch (rows) {
  270. case 6:
  271. gf_6vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  272. break;
  273. case 5:
  274. gf_5vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  275. break;
  276. case 4:
  277. gf_4vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  278. break;
  279. case 3:
  280. gf_3vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  281. break;
  282. case 2:
  283. gf_2vect_mad_avx2(len, k, vec_i, g_tbls, data, coding);
  284. break;
  285. case 1:
  286. gf_vect_mad_avx2(len, k, vec_i, g_tbls, data, *coding);
  287. break;
  288. case 0:
  289. break;
  290. }
  291. }
  292. #endif //__WORDSIZE == 64 || _WIN64 || __x86_64__
  293. #endif //__x86_64__ || __i386__ || _M_X64 || _M_IX86
  294. struct slver {
  295. unsigned short snum;
  296. unsigned char ver;
  297. unsigned char core;
  298. };
  299. // Version info
  300. struct slver ec_init_tables_slver_00010068;
  301. struct slver ec_init_tables_slver = { 0x0068, 0x01, 0x00 };
  302. struct slver ec_encode_data_sse_slver_00020069;
  303. struct slver ec_encode_data_sse_slver = { 0x0069, 0x02, 0x00 };