int.uc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * These sub-operations are separate inlines since they can sometimes be
  39. * specially optimized using architecture-specific hacks.
  40. */
  41. /*
  42. * The SHLBYTE() operation shifts each byte left by 1, *not*
  43. * rolling over into the next byte
  44. */
  45. static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
  46. {
  47. unative_t vv;
  48. vv = (v << 1) & NBYTES(0xfe);
  49. return vv;
  50. }
  51. /*
  52. * The MASK() operation returns 0xFF in any byte for which the high
  53. * bit is 1, 0x00 for any byte for which the high bit is 0.
  54. */
  55. static inline __attribute_const__ unative_t MASK(unative_t v)
  56. {
  57. unative_t vv;
  58. vv = v & NBYTES(0x80);
  59. vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
  60. return vv;
  61. }
  62. static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
  63. {
  64. u8 **dptr = (u8 **)ptrs;
  65. u8 *p, *q;
  66. int d, z, z0;
  67. unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  68. z0 = disks - 3; /* Highest data disk */
  69. p = dptr[z0+1]; /* XOR parity */
  70. q = dptr[z0+2]; /* RS syndrome */
  71. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  72. wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
  73. for ( z = z0-1 ; z >= 0 ; z-- ) {
  74. wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
  75. wp$$ ^= wd$$;
  76. w2$$ = MASK(wq$$);
  77. w1$$ = SHLBYTE(wq$$);
  78. w2$$ &= NBYTES(0x1d);
  79. w1$$ ^= w2$$;
  80. wq$$ = w1$$ ^ wd$$;
  81. }
  82. *(unative_t *)&p[d+NSIZE*$$] = wp$$;
  83. *(unative_t *)&q[d+NSIZE*$$] = wq$$;
  84. }
  85. }
  86. static void raid6_int$#_xor_syndrome(int disks, int start, int stop,
  87. size_t bytes, void **ptrs)
  88. {
  89. u8 **dptr = (u8 **)ptrs;
  90. u8 *p, *q;
  91. int d, z, z0;
  92. unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
  93. z0 = stop; /* P/Q right side optimization */
  94. p = dptr[disks-2]; /* XOR parity */
  95. q = dptr[disks-1]; /* RS syndrome */
  96. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  97. /* P/Q data pages */
  98. wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
  99. for ( z = z0-1 ; z >= start ; z-- ) {
  100. wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
  101. wp$$ ^= wd$$;
  102. w2$$ = MASK(wq$$);
  103. w1$$ = SHLBYTE(wq$$);
  104. w2$$ &= NBYTES(0x1d);
  105. w1$$ ^= w2$$;
  106. wq$$ = w1$$ ^ wd$$;
  107. }
  108. /* P/Q left side optimization */
  109. for ( z = start-1 ; z >= 0 ; z-- ) {
  110. w2$$ = MASK(wq$$);
  111. w1$$ = SHLBYTE(wq$$);
  112. w2$$ &= NBYTES(0x1d);
  113. wq$$ = w1$$ ^ w2$$;
  114. }
  115. *(unative_t *)&p[d+NSIZE*$$] ^= wp$$;
  116. *(unative_t *)&q[d+NSIZE*$$] ^= wq$$;
  117. }
  118. }
  119. const struct raid6_calls raid6_intx$# = {
  120. raid6_int$#_gen_syndrome,
  121. raid6_int$#_xor_syndrome,
  122. NULL, /* always valid */
  123. "int" NSTRING "x$#",
  124. 0
  125. };