updated on Tue Jan 10 04:01:21 UTC 2012
[aur-mirror.git] / par2cmdline / 07-Optimization-by-inlining.patch
blob70577f67232c1c7fe515bd98912e0ef33e68a66d
1 --- a/reedsolomon.cpp
2 +++ b/reedsolomon.cpp
3 @@ -51,7 +51,7 @@ u32 gcd(u32 a, u32 b)
7 -bool ReedSolomon<Galois8>::SetInput(const vector<bool> &present)
8 +template<> bool ReedSolomon<Galois8>::SetInput(const vector<bool> &present)
10 inputcount = (u32)present.size();
12 @@ -80,7 +80,7 @@ bool ReedSolomon<Galois8>::SetInput(const vector<bool> &present)
13 return true;
16 -bool ReedSolomon<Galois8>::SetInput(u32 count)
17 +template<> bool ReedSolomon<Galois8>::SetInput(u32 count)
19 inputcount = count;
21 @@ -101,15 +101,8 @@ bool ReedSolomon<Galois8>::SetInput(u32 count)
22 return true;
25 -bool ReedSolomon<Galois8>::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
26 +template<> bool ReedSolomon<Galois8>::InternalProcess(const Galois8 &factor, size_t size, const void *inputbuffer, void *outputbuffer)
28 - // Look up the appropriate element in the RS matrix
29 - Galois8 factor = leftmatrix[outputindex * (datapresent + datamissing) + inputindex];
31 - // Do nothing if the factor happens to be 0
32 - if (factor == 0)
33 - return eSuccess;
35 #ifdef LONGMULTIPLY
36 // The 8-bit long multiplication tables
37 Galois8 *table = glmt->tables;
38 @@ -189,7 +182,7 @@ bool ReedSolomon<Galois8>::Process(size_t size, u32 inputindex, const void *inpu
40 // Set which of the source files are present and which are missing
41 // and compute the base values to use for the vandermonde matrix.
42 -bool ReedSolomon<Galois16>::SetInput(const vector<bool> &present)
43 +template<> bool ReedSolomon<Galois16>::SetInput(const vector<bool> &present)
45 inputcount = (u32)present.size();
47 @@ -233,7 +226,7 @@ bool ReedSolomon<Galois16>::SetInput(const vector<bool> &present)
49 // Record that the specified number of source files are all present
50 // and compute the base values to use for the vandermonde matrix.
51 -bool ReedSolomon<Galois16>::SetInput(u32 count)
52 +template<> bool ReedSolomon<Galois16>::SetInput(u32 count)
54 inputcount = count;
56 @@ -267,15 +260,8 @@ bool ReedSolomon<Galois16>::SetInput(u32 count)
57 return true;
60 -bool ReedSolomon<Galois16>::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
61 +template<> bool ReedSolomon<Galois16>::InternalProcess(const Galois16 &factor, size_t size, const void *inputbuffer, void *outputbuffer)
63 - // Look up the appropriate element in the RS matrix
65 - Galois16 factor = leftmatrix[outputindex * (datapresent + datamissing) + inputindex];
66 - // Do nothing if the factor happens to be 0
67 - if (factor == 0)
68 - return eSuccess;
70 #ifdef LONGMULTIPLY
71 // The 8-bit long multiplication tables
72 Galois16 *table = glmt->tables;
73 --- a/reedsolomon.h
74 +++ b/reedsolomon.h
75 @@ -64,7 +64,8 @@ public:
76 const void *inputbuffer, // Buffer containing input data
77 u32 outputindex, // The row in the RS matrix
78 void *outputbuffer); // Buffer containing output data
80 +private:
81 + bool InternalProcess(const g &factor, size_t size, const void *inputbuffer, void *outputbuffer); // Optimization
82 protected:
83 // Perform Gaussian Elimination
84 bool GaussElim(CommandLine::NoiseLevel noiselevel,
85 @@ -146,6 +147,20 @@ inline ReedSolomon<g>::~ReedSolomon(void)
86 #endif
89 +template<class g>
90 +inline bool ReedSolomon<g>::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
92 + // Optimization: it occurs frequently the function exits early on, so inline the start.
93 + // This resulted in a speed gain of approx. 8% in repairing.
95 + // Look up the appropriate element in the RS matrix
96 + g factor = leftmatrix[outputindex * (datapresent + datamissing) + inputindex];
97 + // Do nothing if the factor happens to be 0
98 + if (factor == 0)
99 + return eSuccess;
100 + return this->InternalProcess (factor, size, inputbuffer, outputbuffer);
103 u32 gcd(u32 a, u32 b);
105 // Record whether the recovery block with the specified
106 @@ -242,11 +257,14 @@ inline bool ReedSolomon<g>::Compute(CommandLine::NoiseLevel noiselevel)
107 // One row for each present recovery block that will be used for a missing data block
108 for (unsigned int row=0; row<datamissing; row++)
110 + // Define MPDL to skip reporting and speed things up
111 +#ifndef MPDL
112 if (noiselevel > CommandLine::nlQuiet)
114 int progress = row * 1000 / (datamissing+parmissing);
115 cout << "Constructing: " << progress/10 << '.' << progress%10 << "%\r" << flush;
117 +#endif
119 // Get the exponent of the next present recovery block
120 while (!outputrow->present)
121 @@ -286,11 +304,14 @@ inline bool ReedSolomon<g>::Compute(CommandLine::NoiseLevel noiselevel)
122 outputrow = outputrows.begin();
123 for (unsigned int row=0; row<parmissing; row++)
125 + // Define MPDL to skip reporting and speed things up
126 +#ifndef MPDL
127 if (noiselevel > CommandLine::nlQuiet)
129 int progress = (row+datamissing) * 1000 / (datamissing+parmissing);
130 cout << "Constructing: " << progress/10 << '.' << progress%10 << "%\r" << flush;
132 +#endif
134 // Get the exponent of the next missing recovery block
135 while (outputrow->present)
136 @@ -420,6 +441,8 @@ inline bool ReedSolomon<g>::GaussElim(CommandLine::NoiseLevel noiselevel, unsign
137 // For every other row in the matrix
138 for (unsigned int row2=0; row2<rows; row2++)
140 + // Define MPDL to skip reporting and speed things up
141 +#ifndef MPDL
142 if (noiselevel > CommandLine::nlQuiet)
144 int newprogress = (row*rows+row2) * 1000 / (datamissing*rows);
145 @@ -429,6 +452,7 @@ inline bool ReedSolomon<g>::GaussElim(CommandLine::NoiseLevel noiselevel, unsign
146 cout << "Solving: " << progress/10 << '.' << progress%10 << "%\r" << flush;
149 +#endif
151 if (row != row2)