aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-10-29 21:36:02 +0200
committerHarald Welte <laforge@gnumonks.org>2016-11-10 17:07:45 +0000
commitbf173a3df5dce2c875f057bcfbffcf4b8c642fe5 (patch)
tree291878a5c3556dce0a2094c0332efdce916bedff
parent3de97e192688b75a24077bb7072030f4a4dc5ef3 (diff)
bitcomp: Remove the t4 decoding from libosmocore
As outlined by mail on the 13th of July the tree based approach to decoding in the PCU is faster by order of magnitude. Instead of having a slow implementation in the library and a quick one in the PCU, let's only have a quick one in the PCU and at some point in the future move it to libosmocore. Execute the plan and remove t4_decode. Change-Id: I021424444625a097560d086c217c81eac4a5ee44
-rw-r--r--include/osmocom/core/bitcomp.h1
-rw-r--r--src/bitcomp.c128
-rw-r--r--tests/bits/bitcomp_test.c12
-rw-r--r--tests/bits/bitcomp_test.ok10
4 files changed, 0 insertions, 151 deletions
diff --git a/include/osmocom/core/bitcomp.h b/include/osmocom/core/bitcomp.h
index 89eccbce..e87c0e10 100644
--- a/include/osmocom/core/bitcomp.h
+++ b/include/osmocom/core/bitcomp.h
@@ -37,6 +37,5 @@
int osmo_t4_encode(struct bitvec *bv);
-int osmo_t4_decode(const struct bitvec *in, bool cc, struct bitvec *out);
/*! @} */
diff --git a/src/bitcomp.c b/src/bitcomp.c
index 8b3090e6..9c01246b 100644
--- a/src/bitcomp.c
+++ b/src/bitcomp.c
@@ -180,19 +180,11 @@ static const unsigned t4_term_length[2][64] = {
{8, 6, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
};
-static const unsigned t4_min_term_length[] = {2, 4};
-static const unsigned t4_min_make_up_length[] = {10, 5};
-
-static const unsigned t4_max_term_length[] = {12, 8};
-static const unsigned t4_max_make_up_length[] = {13, 9};
-
static const unsigned t4_make_up_length[2][15] = {
{10, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13},
{5, 5, 6, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9}
};
-static const unsigned t4_make_up_ind[15] = {64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960};
-
static const unsigned t4_make_up[2][15] = {
{
0b0000001111,
@@ -230,30 +222,6 @@ static const unsigned t4_make_up[2][15] = {
}
};
-/*! \brief Attempt to decode compressed bit vector
- *
- * \return length of RLE according to modified ITU-T T.4 from TS 44.060
- * Table 9.1.10.2 or -1 if no applicable RLE found N. B: we need
- * explicit bit length to make decoding unambiguous
-*/
-static inline int t4_rle_term(unsigned w, bool b, unsigned bits)
-{
- unsigned i;
- for (i = 0; i < 64; i++)
- if (w == t4_term[b][i] && bits == t4_term_length[b][i])
- return i;
- return -1;
-}
-
-static inline int t4_rle_makeup(unsigned w, bool b, unsigned bits)
-{
- unsigned i;
- for (i = 0; i < 15; i++)
- if (w == t4_make_up[b][i] && bits == t4_make_up_length[b][i])
- return t4_make_up_ind[i];
- return -1;
-}
-
/*! \brief Make-up codes for a given length
*
* \return Return proper make-up code word for an uninterrupted
@@ -339,102 +307,6 @@ static inline int t4_rle(struct bitvec *bv, unsigned len, bool b)
return bitvec_set_uint(bv, t4_term[b][len], t4_term_length[b][len]);
}
-enum dec_state {
- EXPECT_TERM,
- TOO_LONG,
- NEED_MORE_BITS,
- CORRUPT,
- OK
-};
-
-static inline enum dec_state _t4_step(struct bitvec *v, uint16_t w, bool b, unsigned bits, bool term_only)
-{
- if (bits > t4_max_make_up_length[b])
- return TOO_LONG;
- if (bits < t4_min_term_length[b])
- return NEED_MORE_BITS;
-
- if (term_only) {
- if (bits > t4_max_term_length[b])
- return CORRUPT;
- int t = t4_rle_term(w, b, bits);
- if (-1 != t) {
- bitvec_fill(v, t, b ? ONE : ZERO);
- return OK;
- }
- return NEED_MORE_BITS;
- }
-
- int m = t4_rle_makeup(w, b, bits);
- if (-1 != m) {
- bitvec_fill(v, m, b ? ONE : ZERO);
- return EXPECT_TERM;
- }
-
- m = t4_rle_term(w, b, bits);
- if (-1 != m) {
- bitvec_fill(v, m, b ? ONE : ZERO);
- return OK;
- }
-
- return NEED_MORE_BITS;
-}
-
-/*! \brief decode T4-encoded bit vector
- * Assumes MSB first encoding.
- * \param[in] in bit vector with encoded data
- * \param[in] cc color code (whether decoding should start with 1 or 0)
- * \param[out] out the bit vector to store result into
- * \return 0 on success, negative value otherwise
- */
-int osmo_t4_decode(const struct bitvec *in, bool cc, struct bitvec *out)
-{
- uint8_t orig[in->data_len];
- struct bitvec vec;
- vec.data = orig;
- vec.data_len = in->data_len;
- bitvec_zero(&vec);
- memcpy(vec.data, in->data, in->data_len);
- vec.cur_bit = in->cur_bit;
-
- /* init decoder using known color code: */
- unsigned bits = t4_min_term_length[cc];
- enum dec_state d;
- int16_t w = bitvec_get_int16_msb(&vec, bits);
- bool b = cc;
- bool term_only = false;
-
- while (vec.cur_bit > 0) {
- d = _t4_step(out, w, b, bits, term_only);
-
- switch (d) {
- case EXPECT_TERM:
- bitvec_shiftl(&vec, bits);
- bits = t4_min_term_length[b];
- w = bitvec_get_int16_msb(&vec, bits);
- term_only = true;
- break;
- case OK:
- bitvec_shiftl(&vec, bits);
- bits = t4_min_term_length[!b];
- w = bitvec_get_int16_msb(&vec, bits);
- b = !b;
- term_only = false;
- break;
- case NEED_MORE_BITS:
- bits++;
- w = bitvec_get_int16_msb(&vec, bits);
- break;
- case TOO_LONG:
- return -E2BIG;
- case CORRUPT:
- return -EINVAL;
- }
- }
-
- return 0;
-}
-
/*! \brief encode bit vector in-place using T4 encoding
* Assumes MSB first encoding.
* \param[in] bv bit vector to be encoded
diff --git a/tests/bits/bitcomp_test.c b/tests/bits/bitcomp_test.c
index f6895cf9..587dd72b 100644
--- a/tests/bits/bitcomp_test.c
+++ b/tests/bits/bitcomp_test.c
@@ -41,11 +41,6 @@ int main(int argc, char **argv)
bitvec_set_uint(&bv, 4, 3);
bitvec_to_string_r(&bv, lol);
printf(" %s [%d]\n", lol, bv.cur_bit);
- int d = osmo_t4_decode(&bv, 0, &out);
- printf("\nDecoded:\n%d", d);
- bitvec_to_string_r(&out, lol);
- printf("%s [%d]\n", lol, out.cur_bit);
- printf("Expected:\n 00110111 01000111 10000001 1111 \n");
printf("\nTEST2:\n 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00\n");
bitvec_zero(&bv);
@@ -55,12 +50,5 @@ int main(int argc, char **argv)
printf("\nEncoded:\n%d", osmo_t4_encode(&bv)); bitvec_to_string_r(&bv, lol); printf("%s", lol);
printf(" [%d]\nExpected:\n1 11011101 01000001 00 [18]\n", bv.cur_bit);
- bitvec_zero(&out);
- d = osmo_t4_decode(&bv, 1, &out);
- printf("\nDecoded:\n%d", d);
- bitvec_to_string_r(&out, lol);
- printf("%s [%d]\n", lol, out.cur_bit);
- printf("Expected:\n 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00\n");
-
return 0;
}
diff --git a/tests/bits/bitcomp_test.ok b/tests/bits/bitcomp_test.ok
index 238f3c47..d2ac16a2 100644
--- a/tests/bits/bitcomp_test.ok
+++ b/tests/bits/bitcomp_test.ok
@@ -10,11 +10,6 @@ Expected:
0 11011110 10001000 01110101 01100101 100 [35]
11011110 10001000 01110101 01100101 100 [35]
-Decoded:
-0 00110111 01000111 10000001 1111 [28]
-Expected:
- 00110111 01000111 10000001 1111
-
TEST2:
11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00
11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00
@@ -22,8 +17,3 @@ Encoded:
1 11011101 01000001 00 [18]
Expected:
1 11011101 01000001 00 [18]
-
-Decoded:
-0 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00 [90]
-Expected:
- 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00