int.uc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8. * Boston MA 02111-1307, USA; either version 2 of the License, or
  9. * (at your option) any later version; incorporated herein by reference.
  10. *
  11. * ----------------------------------------------------------------------- */
  12. /*
  13. * int$#.c
  14. *
  15. * $#-way unrolled portable integer math RAID-6 instruction set
  16. *
  17. * This file is postprocessed using unroll.awk
  18. */
  19. #include <linux/raid/pq.h>
  20. /*
  21. * This is the C data type to use
  22. */
  23. /* Change this from BITS_PER_LONG if there is something better... */
  24. #if BITS_PER_LONG == 64
  25. # define NBYTES(x) ((x) * 0x0101010101010101UL)
  26. # define NSIZE 8
  27. # define NSHIFT 3
  28. # define NSTRING "64"
  29. typedef u64 unative_t;
  30. #else
  31. # define NBYTES(x) ((x) * 0x01010101U)
  32. # define NSIZE 4
  33. # define NSHIFT 2
  34. # define NSTRING "32"
  35. typedef u32 unative_t;
  36. #endif
  37. /*
  38. * IA-64 wants insane amounts of unrolling. On other architectures that
  39. * is just a waste of space.
  40. */
  41. #if ($# <= 8) || defined(__ia64__)
  42. /*
  43. * These sub-operations are separate inlines since they can sometimes be
  44. * specially optimized using architecture-specific hacks.
  45. */
  46. /*
  47. * The SHLBYTE() operation shifts each byte left by 1, *not*
  48. * rolling over into the next byte
  49. */
  50. static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
  51. {
  52. unative_t vv;
  53. vv = (v << 1) & NBYTES(0xfe);
  54. return vv;
  55. }
  56. /*
  57. * The MASK() operation returns 0xFF in any byte for which the high
  58. * bit is 1, 0x00 for any byte for which the high bit is 0.
  59. */
  60. static inline __attribute_const__ unative_t MASK(unative_t v)
  61. {
  62. unative_t vv;
  63. vv = v & NBYTES(0x80);
  64. vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
  65. return vv;
  66. }
  67. static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
  68. {
  69. u8 **dptr = (u8 **)ptrs;
  70. u8 *p, *q;
  71. int d, z, z0;
  72. unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  73. z0 = disks - 3; /* Highest data disk */
  74. p = dptr[z0+1]; /* XOR parity */
  75. q = dptr[z0+2]; /* RS syndrome */
  76. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  77. wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
  78. for ( z = z0-1 ; z >= 0 ; z-- ) {
  79. wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
  80. wp$$ ^= wd$$;
  81. w2$$ = MASK(wq$$);
  82. w1$$ = SHLBYTE(wq$$);
  83. w2$$ &= NBYTES(0x1d);
  84. w1$$ ^= w2$$;
  85. wq$$ = w1$$ ^ wd$$;
  86. }
  87. *(unative_t *)&p[d+NSIZE*$$] = wp$$;
  88. *(unative_t *)&q[d+NSIZE*$$] = wq$$;
  89. }
  90. }
  91. static void raid6_int$#_xor_syndrome(int disks, int start, int stop,
  92. size_t bytes, void **ptrs)
  93. {
  94. u8 **dptr = (u8 **)ptrs;
  95. u8 *p, *q;
  96. int d, z, z0;
  97. unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  98. z0 = stop; /* P/Q right side optimization */
  99. p = dptr[disks-2]; /* XOR parity */
  100. q = dptr[disks-1]; /* RS syndrome */
  101. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  102. /* P/Q data pages */
  103. wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
  104. for ( z = z0-1 ; z >= start ; z-- ) {
  105. wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
  106. wp$$ ^= wd$$;
  107. w2$$ = MASK(wq$$);
  108. w1$$ = SHLBYTE(wq$$);
  109. w2$$ &= NBYTES(0x1d);
  110. w1$$ ^= w2$$;
  111. wq$$ = w1$$ ^ wd$$;
  112. }
  113. /* P/Q left side optimization */
  114. for ( z = start-1 ; z >= 0 ; z-- ) {
  115. w2$$ = MASK(wq$$);
  116. w1$$ = SHLBYTE(wq$$);
  117. w2$$ &= NBYTES(0x1d);
  118. wq$$ = w1$$ ^ w2$$;
  119. }
  120. *(unative_t *)&p[d+NSIZE*$$] ^= wp$$;
  121. *(unative_t *)&q[d+NSIZE*$$] ^= wq$$;
  122. }
  123. }
  124. const struct raid6_calls raid6_intx$# = {
  125. raid6_int$#_gen_syndrome,
  126. raid6_int$#_xor_syndrome,
  127. NULL, /* always valid */
  128. "int" NSTRING "x$#",
  129. 0
  130. };
  131. #endif