[PATCH] libosmocore[master]: bitcomp: Remove the t4 decoding from libosmocore

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Holger Freyther gerrit-no-reply at lists.osmocom.org
Sun Oct 30 22:16:29 UTC 2016


Hello Neels Hofmeyr, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1176

to look at the new patch set (#2).

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 magnitudes. 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
---
M include/osmocom/core/bitcomp.h
M src/bitcomp.c
M tests/bits/bitcomp_test.c
M tests/bits/bitcomp_test.ok
4 files changed, 0 insertions(+), 151 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/76/1176/2

diff --git a/include/osmocom/core/bitcomp.h b/include/osmocom/core/bitcomp.h
index 89eccbc..e87c0e1 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 8b3090e..9c01246 100644
--- a/src/bitcomp.c
+++ b/src/bitcomp.c
@@ -180,18 +180,10 @@
 	{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] = {
 	{
@@ -229,30 +221,6 @@
 		0b011010100
 	 }
 };
-
-/*! \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
  *
@@ -337,102 +305,6 @@
 	}
 
 	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
diff --git a/tests/bits/bitcomp_test.c b/tests/bits/bitcomp_test.c
index f6895cf..587dd72 100644
--- a/tests/bits/bitcomp_test.c
+++ b/tests/bits/bitcomp_test.c
@@ -41,11 +41,6 @@
 	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);
@@ -54,13 +49,6 @@
 	bitvec_set_uint(&bv, 0xFFFFFC00, 26); bitvec_to_string_r(&bv, lol); printf("%s", lol);
 	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 238f3c4..d2ac16a 100644
--- a/tests/bits/bitcomp_test.ok
+++ b/tests/bits/bitcomp_test.ok
@@ -10,11 +10,6 @@
 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 @@
 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

-- 
To view, visit https://gerrit.osmocom.org/1176
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I021424444625a097560d086c217c81eac4a5ee44
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list