Skip to content

Commit b0f380e

Browse files
authored
Merge pull request #503 from penglei0/perf/optimize-gf-inversion-calculate
[=]: optimize the gf inversion calculation
2 parents 863cf59 + c358b54 commit b0f380e

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/transport/fec_schemes/xqc_galois_calculation.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,7 @@ xqc_galois_divide(unsigned char a, unsigned char b, unsigned char *res)
6868
unsigned char
6969
xqc_galois_inversion(unsigned char a)
7070
{
71-
int i = 0;
72-
if (a == 0) {
73-
return 0;
74-
}
75-
for (i = 1; i < 256; i++) {
76-
if (xqc_galois_multiply(a, i) == 1) {
77-
return i;
78-
}
79-
}
80-
return 0;
71+
return xqc_galois_inv_table[a];
8172
}
8273

8374

src/transport/fec_schemes/xqc_galois_calculation.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
* The following table stands for log_a(x) and exp_a(x),
18-
* where a is the polynomial(here we use 29, (2^8 +) 2^4 + 2^3 + 2^2 + 1) used to generate a Galois field of 256 elements.
18+
* where a is the polynomial(here we use 285 (0x11D), 2^8 + 2^4 + 2^3 + 2^2 + 1) used to generate a Galois field of 256 elements.
1919
* and x is in [0, 255].
2020
*/
2121
static const unsigned char xqc_rs_log_table[256] = {
@@ -122,6 +122,30 @@ static const unsigned char xqc_rs_exp_table[510] = {
122122
27, 54, 108, -40, -83, 71, -114
123123
};
124124

125+
/**
126+
* inversion table based on irreducible polynomial 285 (0x11D) where F(x) = x^8
127+
* + x^4 + x^3 + x^2 + 1, minimum primitive element α = x = 2.
128+
*/
129+
static const unsigned char xqc_galois_inv_table[256] = {
130+
0, 1, 142, 244, 71, 167, 122, 186, 173, 157, 221, 152, 61, 170, 93,
131+
150, 216, 114, 192, 88, 224, 62, 76, 102, 144, 222, 85, 128, 160, 131,
132+
75, 42, 108, 237, 57, 81, 96, 86, 44, 138, 112, 208, 31, 74, 38,
133+
139, 51, 110, 72, 137, 111, 46, 164, 195, 64, 94, 80, 34, 207, 169,
134+
171, 12, 21, 225, 54, 95, 248, 213, 146, 78, 166, 4, 48, 136, 43,
135+
30, 22, 103, 69, 147, 56, 35, 104, 140, 129, 26, 37, 97, 19, 193,
136+
203, 99, 151, 14, 55, 65, 36, 87, 202, 91, 185, 196, 23, 77, 82,
137+
141, 239, 179, 32, 236, 47, 50, 40, 209, 17, 217, 233, 251, 218, 121,
138+
219, 119, 6, 187, 132, 205, 254, 252, 27, 84, 161, 29, 124, 204, 228,
139+
176, 73, 49, 39, 45, 83, 105, 2, 245, 24, 223, 68, 79, 155, 188,
140+
15, 92, 11, 220, 189, 148, 172, 9, 199, 162, 28, 130, 159, 198, 52,
141+
194, 70, 5, 206, 59, 13, 60, 156, 8, 190, 183, 135, 229, 238, 107,
142+
235, 242, 191, 175, 197, 100, 7, 123, 149, 154, 174, 182, 18, 89, 165,
143+
53, 101, 184, 163, 158, 210, 247, 98, 90, 133, 125, 168, 58, 41, 113,
144+
200, 246, 249, 67, 215, 214, 16, 115, 118, 120, 153, 10, 25, 145, 20,
145+
63, 230, 240, 134, 177, 226, 241, 250, 116, 243, 180, 109, 33, 178, 106,
146+
227, 231, 181, 234, 3, 143, 211, 201, 66, 212, 232, 117, 127, 255, 126,
147+
253};
148+
125149
unsigned char xqc_galois_multiply(unsigned char a, unsigned char b);
126150
unsigned char xqc_galois_exp(unsigned char a, unsigned char n);
127151

0 commit comments

Comments
 (0)