tilegx.uc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright 2002 H. Peter Anvin - All Rights Reserved
  4. * Copyright 2012 Tilera Corporation - All Rights Reserved
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  9. * Boston MA 02111-1307, USA; either version 2 of the License, or
  10. * (at your option) any later version; incorporated herein by reference.
  11. *
  12. * ----------------------------------------------------------------------- */
  13. /*
  14. * tilegx$#.c
  15. *
  16. * $#-way unrolled TILE-Gx SIMD for RAID-6 math.
  17. *
  18. * This file is postprocessed using unroll.awk.
  19. *
  20. */
  21. #include <linux/raid/pq.h>
  22. /* Create 8 byte copies of constant byte */
  23. # define NBYTES(x) (__insn_v1addi(0, x))
  24. # define NSIZE 8
  25. /*
  26. * The SHLBYTE() operation shifts each byte left by 1, *not*
  27. * rolling over into the next byte
  28. */
  29. static inline __attribute_const__ u64 SHLBYTE(u64 v)
  30. {
  31. /* Vector One Byte Shift Left Immediate. */
  32. return __insn_v1shli(v, 1);
  33. }
  34. /*
  35. * The MASK() operation returns 0xFF in any byte for which the high
  36. * bit is 1, 0x00 for any byte for which the high bit is 0.
  37. */
  38. static inline __attribute_const__ u64 MASK(u64 v)
  39. {
  40. /* Vector One Byte Shift Right Signed Immediate. */
  41. return __insn_v1shrsi(v, 7);
  42. }
  43. void raid6_tilegx$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
  44. {
  45. u8 **dptr = (u8 **)ptrs;
  46. u64 *p, *q;
  47. int d, z, z0;
  48. u64 wd$$, wq$$, wp$$, w1$$, w2$$;
  49. u64 x1d = NBYTES(0x1d);
  50. u64 * z0ptr;
  51. z0 = disks - 3; /* Highest data disk */
  52. p = (u64 *)dptr[z0+1]; /* XOR parity */
  53. q = (u64 *)dptr[z0+2]; /* RS syndrome */
  54. z0ptr = (u64 *)&dptr[z0][0];
  55. for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
  56. wq$$ = wp$$ = *z0ptr++;
  57. for ( z = z0-1 ; z >= 0 ; z-- ) {
  58. wd$$ = *(u64 *)&dptr[z][d+$$*NSIZE];
  59. wp$$ = wp$$ ^ wd$$;
  60. w2$$ = MASK(wq$$);
  61. w1$$ = SHLBYTE(wq$$);
  62. w2$$ = w2$$ & x1d;
  63. w1$$ = w1$$ ^ w2$$;
  64. wq$$ = w1$$ ^ wd$$;
  65. }
  66. *p++ = wp$$;
  67. *q++ = wq$$;
  68. }
  69. }
  70. const struct raid6_calls raid6_tilegx$# = {
  71. raid6_tilegx$#_gen_syndrome,
  72. NULL, /* XOR not yet implemented */
  73. NULL,
  74. "tilegx$#",
  75. 0
  76. };