neon.uc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* -----------------------------------------------------------------------
  2. *
  3. * neon.uc - RAID-6 syndrome calculation using ARM NEON instructions
  4. *
  5. * Copyright (C) 2012 Rob Herring
  6. * Copyright (C) 2015 Linaro Ltd. <ard.biesheuvel@linaro.org>
  7. *
  8. * Based on altivec.uc:
  9. * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  14. * Boston MA 02111-1307, USA; either version 2 of the License, or
  15. * (at your option) any later version; incorporated herein by reference.
  16. *
  17. * ----------------------------------------------------------------------- */
  18. /*
  19. * neon$#.c
  20. *
  21. * $#-way unrolled NEON intrinsics math RAID-6 instruction set
  22. *
  23. * This file is postprocessed using unroll.awk
  24. */
  25. #include <arm_neon.h>
  26. #include "neon.h"
  27. typedef uint8x16_t unative_t;
  28. #define NSIZE sizeof(unative_t)
  29. /*
  30. * The SHLBYTE() operation shifts each byte left by 1, *not*
  31. * rolling over into the next byte
  32. */
  33. static inline unative_t SHLBYTE(unative_t v)
  34. {
  35. return vshlq_n_u8(v, 1);
  36. }
  37. /*
  38. * The MASK() operation returns 0xFF in any byte for which the high
  39. * bit is 1, 0x00 for any byte for which the high bit is 0.
  40. */
  41. static inline unative_t MASK(unative_t v)
  42. {
  43. return (unative_t)vshrq_n_s8((int8x16_t)v, 7);
  44. }
  45. static inline unative_t PMUL(unative_t v, unative_t u)
  46. {
  47. return (unative_t)vmulq_p8((poly8x16_t)v, (poly8x16_t)u);
  48. }
  49. void raid6_neon$#_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs)
  50. {
  51. uint8_t **dptr = (uint8_t **)ptrs;
  52. uint8_t *p, *q;
  53. int d, z, z0;
  54. register unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  55. const unative_t x1d = vdupq_n_u8(0x1d);
  56. z0 = disks - 3; /* Highest data disk */
  57. p = dptr[z0+1]; /* XOR parity */
  58. q = dptr[z0+2]; /* RS syndrome */
  59. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  60. wq$$ = wp$$ = vld1q_u8(&dptr[z0][d+$$*NSIZE]);
  61. for ( z = z0-1 ; z >= 0 ; z-- ) {
  62. wd$$ = vld1q_u8(&dptr[z][d+$$*NSIZE]);
  63. wp$$ = veorq_u8(wp$$, wd$$);
  64. w2$$ = MASK(wq$$);
  65. w1$$ = SHLBYTE(wq$$);
  66. w2$$ = vandq_u8(w2$$, x1d);
  67. w1$$ = veorq_u8(w1$$, w2$$);
  68. wq$$ = veorq_u8(w1$$, wd$$);
  69. }
  70. vst1q_u8(&p[d+NSIZE*$$], wp$$);
  71. vst1q_u8(&q[d+NSIZE*$$], wq$$);
  72. }
  73. }
  74. void raid6_neon$#_xor_syndrome_real(int disks, int start, int stop,
  75. unsigned long bytes, void **ptrs)
  76. {
  77. uint8_t **dptr = (uint8_t **)ptrs;
  78. uint8_t *p, *q;
  79. int d, z, z0;
  80. register unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  81. const unative_t x1d = vdupq_n_u8(0x1d);
  82. z0 = stop; /* P/Q right side optimization */
  83. p = dptr[disks-2]; /* XOR parity */
  84. q = dptr[disks-1]; /* RS syndrome */
  85. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  86. wq$$ = vld1q_u8(&dptr[z0][d+$$*NSIZE]);
  87. wp$$ = veorq_u8(vld1q_u8(&p[d+$$*NSIZE]), wq$$);
  88. /* P/Q data pages */
  89. for ( z = z0-1 ; z >= start ; z-- ) {
  90. wd$$ = vld1q_u8(&dptr[z][d+$$*NSIZE]);
  91. wp$$ = veorq_u8(wp$$, wd$$);
  92. w2$$ = MASK(wq$$);
  93. w1$$ = SHLBYTE(wq$$);
  94. w2$$ = vandq_u8(w2$$, x1d);
  95. w1$$ = veorq_u8(w1$$, w2$$);
  96. wq$$ = veorq_u8(w1$$, wd$$);
  97. }
  98. /* P/Q left side optimization */
  99. for ( z = start-1 ; z >= 3 ; z -= 4 ) {
  100. w2$$ = vshrq_n_u8(wq$$, 4);
  101. w1$$ = vshlq_n_u8(wq$$, 4);
  102. w2$$ = PMUL(w2$$, x1d);
  103. wq$$ = veorq_u8(w1$$, w2$$);
  104. }
  105. switch (z) {
  106. case 2:
  107. w2$$ = vshrq_n_u8(wq$$, 5);
  108. w1$$ = vshlq_n_u8(wq$$, 3);
  109. w2$$ = PMUL(w2$$, x1d);
  110. wq$$ = veorq_u8(w1$$, w2$$);
  111. break;
  112. case 1:
  113. w2$$ = vshrq_n_u8(wq$$, 6);
  114. w1$$ = vshlq_n_u8(wq$$, 2);
  115. w2$$ = PMUL(w2$$, x1d);
  116. wq$$ = veorq_u8(w1$$, w2$$);
  117. break;
  118. case 0:
  119. w2$$ = MASK(wq$$);
  120. w1$$ = SHLBYTE(wq$$);
  121. w2$$ = vandq_u8(w2$$, x1d);
  122. wq$$ = veorq_u8(w1$$, w2$$);
  123. }
  124. w1$$ = vld1q_u8(&q[d+NSIZE*$$]);
  125. wq$$ = veorq_u8(wq$$, w1$$);
  126. vst1q_u8(&p[d+NSIZE*$$], wp$$);
  127. vst1q_u8(&q[d+NSIZE*$$], wq$$);
  128. }
  129. }