int.uc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * raid6int$#.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. const struct raid6_calls raid6_intx$# = {
  92. raid6_int$#_gen_syndrome,
  93. NULL, /* always valid */
  94. "int" NSTRING "x$#",
  95. 0
  96. };
  97. #endif