diff --git a/raid.c b/raid.c index 292925ae..0f9cf9f1 100644 --- a/raid.c +++ b/raid.c @@ -321,7 +321,8 @@ void raid5_sse2(unsigned char** vbuf, unsigned data, unsigned size) /** * Multiply each byte of a uint32 by 2 in the GF(2^8). */ -__attribute__((always_inline)) static inline uint32_t x2_32(uint32_t v) +__attribute__((always_inline)) +static inline uint32_t x2_32(uint32_t v) { uint32_t mask = v & 0x80808080U; mask = (mask << 1) - (mask >> 7); @@ -333,7 +334,8 @@ __attribute__((always_inline)) static inline uint32_t x2_32(uint32_t v) /** * Multiply each byte of a uint64 by 2 in the GF(2^8). */ -__attribute__((always_inline)) static inline uint64_t x2_64(uint64_t v) +__attribute__((always_inline)) +static inline uint64_t x2_64(uint64_t v) { uint64_t mask = v & 0x8080808080808080ULL; mask = (mask << 1) - (mask >> 7); @@ -1831,6 +1833,7 @@ void raid_gen(unsigned level, unsigned char** vbuf, unsigned data, unsigned size /** * GF a*b. */ +__attribute__((always_inline)) static inline unsigned char mul(unsigned char a, unsigned char b) { return gfmul[a][b]; @@ -1840,6 +1843,7 @@ static inline unsigned char mul(unsigned char a, unsigned char b) * GF 1/a. * Not defined for a == 0. */ +__attribute__((always_inline)) static inline unsigned char inv(unsigned char v) { if (v == 0) { @@ -1853,6 +1857,7 @@ static inline unsigned char inv(unsigned char v) /** * GF 2^a. */ +__attribute__((always_inline)) static inline unsigned char pow2(int v) { if (v < 0 || v > 254) { @@ -1866,6 +1871,7 @@ static inline unsigned char pow2(int v) /** * Gets the multiplication table for a specified value. */ +__attribute__((always_inline)) static inline const unsigned char* table(unsigned char v) { return gfmul[v]; @@ -1881,7 +1887,7 @@ static inline const unsigned char* table(unsigned char v) * Note that all the other parities not in the c[] vector * are destroyed. */ -static void raid_delta_gen(unsigned level, const int* d, const int* c, unsigned char** vbuf, unsigned data, unsigned char* zero, unsigned size) +static inline void raid_delta_gen(unsigned level, const int* d, const int* c, unsigned char** vbuf, unsigned data, unsigned char* zero, unsigned size) { unsigned char* p[RAID_PARITY_MAX]; unsigned char* pa[RAID_PARITY_MAX]; @@ -2027,7 +2033,7 @@ static unsigned char A(unsigned p, unsigned d) * Inverts the square matrix M of size nxn into V. * We use Gauss elimination to invert. */ -static void invert(unsigned char* M, unsigned char* V, unsigned n) +static inline void invert(unsigned char* M, unsigned char* V, unsigned n) { unsigned i,j,k; @@ -2084,7 +2090,7 @@ static void invert(unsigned char* M, unsigned char* V, unsigned n) } /** - * Recover failure of one data block d[0] using parity c[0] for any RAID level. + * Recover failure of one data block at index d[0] using parity at index c[0] for any RAID level. * * Starting from the equation: * @@ -2121,15 +2127,12 @@ static void raid_recov_1data(const int* d, const int* c, unsigned char** vbuf, u unsigned char Pd = p[i] ^ pa[i]; /* reconstruct */ - unsigned char Dx = T[0][Pd]; - - /* set */ - pa[i] = Dx; + pa[i] = T[0][Pd]; } } /** - * Recover failure of two data blocks d[0],d[1] using parity c[0],c[1] for any RAID level. + * Recover failure of two data blocks at indexes d[0],d[1] using parity at indexes c[0],c[1] for any RAID level. * * Starting from the equations: * @@ -2187,341 +2190,74 @@ static void raid_recov_2data(const int* d, const int* c, unsigned char** vbuf, u unsigned char Qd = q[i] ^ qa[i]; /* reconstruct */ - unsigned char Dx = T[0][0][Pd] ^ T[0][1][Qd]; - unsigned char Dy = T[1][0][Pd] ^ T[1][1][Qd]; - - /* set */ - pa[i] = Dx; - qa[i] = Dy; + pa[i] = T[0][0][Pd] ^ T[0][1][Qd]; + qa[i] = T[1][0][Pd] ^ T[1][1][Qd]; } } /** - * Recover failure of three data blocks d[0],d[1],d[2] using parity c[0],c[1],c[2] for any RAID level. + * Recover failure of N data blocks at indexes d[N] using parity at indexes c[N] for any RAID level. * - * Starting from the equations: + * Starting from the N equations, with 0<=i