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