[PATCH] libosmocore[master]: Prefer bitvec_set_u64() over bitvec_set_uint()

Max gerrit-no-reply at lists.osmocom.org
Tue Oct 24 10:14:39 UTC 2017


Hello Neels Hofmeyr, Harald Welte, Jenkins Builder,

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

    https://gerrit.osmocom.org/4338

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

Prefer bitvec_set_u64() over bitvec_set_uint()

The bitvec_set_uint() is just a compatibility wrapper around
bitvec_set_u64() anyway.

Change-Id: I2fd8d17f9fa6c51ef51f4294882cca5944d71df2
---
M src/bitcomp.c
M src/bitvec.c
M src/gsm/gsm_utils.c
M tests/bits/bitcomp_test.c
M tests/bitvec/bitvec_test.c
5 files changed, 83 insertions(+), 83 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/38/4338/4

diff --git a/src/bitcomp.c b/src/bitcomp.c
index 94f60eb..db5a43e 100644
--- a/src/bitcomp.c
+++ b/src/bitcomp.c
@@ -227,81 +227,81 @@
 static inline int t4_rle(struct bitvec *bv, unsigned len, bool b)
 {
 	if (len >= 960) {
-		bitvec_set_uint(bv, t4_make_up[b][14], t4_make_up_length[b][14]);
-		return bitvec_set_uint(bv, t4_term[b][len - 960], t4_term_length[b][len - 960]);
+		bitvec_set_u64(bv, t4_make_up[b][14], t4_make_up_length[b][14], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 960], t4_term_length[b][len - 960], false);
 	}
 
 	if (len >= 896) {
-		bitvec_set_uint(bv, t4_make_up[b][13], t4_make_up_length[b][13]);
-		return bitvec_set_uint(bv, t4_term[b][len - 896], t4_term_length[b][len - 896]);
+		bitvec_set_u64(bv, t4_make_up[b][13], t4_make_up_length[b][13], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 896], t4_term_length[b][len - 896], false);
 	}
 
 	if (len >= 832) {
-		bitvec_set_uint(bv, t4_make_up[b][12], t4_make_up_length[b][12]);
-		return bitvec_set_uint(bv, t4_term[b][len - 832], t4_term_length[b][len - 832]);
+		bitvec_set_u64(bv, t4_make_up[b][12], t4_make_up_length[b][12], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 832], t4_term_length[b][len - 832], false);
 	}
 
 	if (len >= 768) {
-		bitvec_set_uint(bv, t4_make_up[b][11], t4_make_up_length[b][11]);
-		return bitvec_set_uint(bv, t4_term[b][len - 768], t4_term_length[b][len - 768]);
+		bitvec_set_u64(bv, t4_make_up[b][11], t4_make_up_length[b][11], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 768], t4_term_length[b][len - 768], false);
 	}
 
 	if (len >= 704) {
-		bitvec_set_uint(bv, t4_make_up[b][10], t4_make_up_length[b][10]);
-		return bitvec_set_uint(bv, t4_term[b][len - 704], t4_term_length[b][len - 704]);
+		bitvec_set_u64(bv, t4_make_up[b][10], t4_make_up_length[b][10], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 704], t4_term_length[b][len - 704], false);
 	}
 
 	if (len >= 640) {
-		bitvec_set_uint(bv, t4_make_up[b][9], t4_make_up_length[b][9]);
-		return bitvec_set_uint(bv, t4_term[b][len - 640], t4_term_length[b][len - 640]);
+		bitvec_set_u64(bv, t4_make_up[b][9], t4_make_up_length[b][9], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 640], t4_term_length[b][len - 640], false);
 	}
 
 	if (len >= 576) {
-		bitvec_set_uint(bv, t4_make_up[b][8], t4_make_up_length[b][8]);
-		return bitvec_set_uint(bv, t4_term[b][len - 576], t4_term_length[b][len - 576]);
+		bitvec_set_u64(bv, t4_make_up[b][8], t4_make_up_length[b][8], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 576], t4_term_length[b][len - 576], false);
 	}
 
 	if (len >= 512) {
-		bitvec_set_uint(bv, t4_make_up[b][7], t4_make_up_length[b][7]);
-		return bitvec_set_uint(bv, t4_term[b][len - 512], t4_term_length[b][len - 512]);
+		bitvec_set_u64(bv, t4_make_up[b][7], t4_make_up_length[b][7], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 512], t4_term_length[b][len - 512], false);
 	}
 
 	if (len >= 448) {
-		bitvec_set_uint(bv, t4_make_up[b][6], t4_make_up_length[b][6]);
-		return bitvec_set_uint(bv, t4_term[b][len - 448], t4_term_length[b][len - 448]);
+		bitvec_set_u64(bv, t4_make_up[b][6], t4_make_up_length[b][6], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 448], t4_term_length[b][len - 448], false);
 	}
 
 	if (len >= 384) {
-		bitvec_set_uint(bv, t4_make_up[b][5], t4_make_up_length[b][5]);
-		return bitvec_set_uint(bv, t4_term[b][len - 384], t4_term_length[b][len - 384]);
+		bitvec_set_u64(bv, t4_make_up[b][5], t4_make_up_length[b][5], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 384], t4_term_length[b][len - 384], false);
 	}
 
 	if (len >= 320) {
-		bitvec_set_uint(bv, t4_make_up[b][4], t4_make_up_length[b][4]);
-		return bitvec_set_uint(bv, t4_term[b][len - 320], t4_term_length[b][len - 320]);
+		bitvec_set_u64(bv, t4_make_up[b][4], t4_make_up_length[b][4], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 320], t4_term_length[b][len - 320], false);
 	}
 
 	if (len >= 256) {
-		bitvec_set_uint(bv, t4_make_up[b][3], t4_make_up_length[b][3]);
-		return bitvec_set_uint(bv, t4_term[b][len - 256], t4_term_length[b][len - 256]);
+		bitvec_set_u64(bv, t4_make_up[b][3], t4_make_up_length[b][3], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 256], t4_term_length[b][len - 256], false);
 	}
 
 	if (len >= 192) {
-		bitvec_set_uint(bv, t4_make_up[b][2], t4_make_up_length[b][2]);
-		return bitvec_set_uint(bv, t4_term[b][len - 192], t4_term_length[b][len - 192]);
+		bitvec_set_u64(bv, t4_make_up[b][2], t4_make_up_length[b][2], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 192], t4_term_length[b][len - 192], false);
 	}
 
 	if (len >= 128) {
-		bitvec_set_uint(bv, t4_make_up[b][1], t4_make_up_length[b][1]);
-		return bitvec_set_uint(bv, t4_term[b][len - 128], t4_term_length[b][len - 128]);
+		bitvec_set_u64(bv, t4_make_up[b][1], t4_make_up_length[b][1], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 128], t4_term_length[b][len - 128], false);
 	}
 
 	if (len >= 64) {
-		bitvec_set_uint(bv, t4_make_up[b][0], t4_make_up_length[b][0]);
-		return bitvec_set_uint(bv, t4_term[b][len - 64], t4_term_length[b][len - 64]);
+		bitvec_set_u64(bv, t4_make_up[b][0], t4_make_up_length[b][0], false);
+		return bitvec_set_u64(bv, t4_term[b][len - 64], t4_term_length[b][len - 64], false);
 	}
 
-	return bitvec_set_uint(bv, t4_term[b][len], t4_term_length[b][len]);
+	return bitvec_set_u64(bv, t4_term[b][len], t4_term_length[b][len], false);
 }
 
 /*! encode bit vector in-place using T4 encoding
diff --git a/src/bitvec.c b/src/bitvec.c
index 09aca21..2dec4f9 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -706,7 +706,7 @@
 			bits += (1 + num_bits);
 		} else {
 			bitvec_set_bit(bv, 1);
-			bitvec_set_uint(bv, array[i], num_bits);
+			bitvec_set_u64(bv, array[i], num_bits, false);
 		}
 	}
 
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index e3f792e..6e49bb4 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -836,35 +836,35 @@
  *  \param[in] r Input Range1024 sructure */
 void bitvec_add_range1024(struct bitvec *bv, const struct gsm48_range_1024 *r)
 {
-	bitvec_set_uint(bv, r->w1_hi, 2);
-	bitvec_set_uint(bv, r->w1_lo, 8);
-	bitvec_set_uint(bv, r->w2_hi, 8);
-	bitvec_set_uint(bv, r->w2_lo, 1);
-	bitvec_set_uint(bv, r->w3_hi, 7);
-	bitvec_set_uint(bv, r->w3_lo, 2);
-	bitvec_set_uint(bv, r->w4_hi, 6);
-	bitvec_set_uint(bv, r->w4_lo, 2);
-	bitvec_set_uint(bv, r->w5_hi, 6);
-	bitvec_set_uint(bv, r->w5_lo, 2);
-	bitvec_set_uint(bv, r->w6_hi, 6);
-	bitvec_set_uint(bv, r->w6_lo, 2);
-	bitvec_set_uint(bv, r->w7_hi, 6);
-	bitvec_set_uint(bv, r->w7_lo, 2);
-	bitvec_set_uint(bv, r->w8_hi, 6);
-	bitvec_set_uint(bv, r->w8_lo, 1);
-	bitvec_set_uint(bv, r->w9, 7);
-	bitvec_set_uint(bv, r->w10, 7);
-	bitvec_set_uint(bv, r->w11_hi, 1);
-	bitvec_set_uint(bv, r->w11_lo, 6);
-	bitvec_set_uint(bv, r->w12_hi, 2);
-	bitvec_set_uint(bv, r->w12_lo, 5);
-	bitvec_set_uint(bv, r->w13_hi, 3);
-	bitvec_set_uint(bv, r->w13_lo, 4);
-	bitvec_set_uint(bv, r->w14_hi, 4);
-	bitvec_set_uint(bv, r->w14_lo, 3);
-	bitvec_set_uint(bv, r->w15_hi, 5);
-	bitvec_set_uint(bv, r->w15_lo, 2);
-	bitvec_set_uint(bv, r->w16, 6);
+	bitvec_set_u64(bv, r->w1_hi, 2, false);
+	bitvec_set_u64(bv, r->w1_lo, 8, false);
+	bitvec_set_u64(bv, r->w2_hi, 8, false);
+	bitvec_set_u64(bv, r->w2_lo, 1, false);
+	bitvec_set_u64(bv, r->w3_hi, 7, false);
+	bitvec_set_u64(bv, r->w3_lo, 2, false);
+	bitvec_set_u64(bv, r->w4_hi, 6, false);
+	bitvec_set_u64(bv, r->w4_lo, 2, false);
+	bitvec_set_u64(bv, r->w5_hi, 6, false);
+	bitvec_set_u64(bv, r->w5_lo, 2, false);
+	bitvec_set_u64(bv, r->w6_hi, 6, false);
+	bitvec_set_u64(bv, r->w6_lo, 2, false);
+	bitvec_set_u64(bv, r->w7_hi, 6, false);
+	bitvec_set_u64(bv, r->w7_lo, 2, false);
+	bitvec_set_u64(bv, r->w8_hi, 6, false);
+	bitvec_set_u64(bv, r->w8_lo, 1, false);
+	bitvec_set_u64(bv, r->w9, 7, false);
+	bitvec_set_u64(bv, r->w10, 7, false);
+	bitvec_set_u64(bv, r->w11_hi, 1, false);
+	bitvec_set_u64(bv, r->w11_lo, 6, false);
+	bitvec_set_u64(bv, r->w12_hi, 2, false);
+	bitvec_set_u64(bv, r->w12_lo, 5, false);
+	bitvec_set_u64(bv, r->w13_hi, 3, false);
+	bitvec_set_u64(bv, r->w13_lo, 4, false);
+	bitvec_set_u64(bv, r->w14_hi, 4, false);
+	bitvec_set_u64(bv, r->w14_lo, 3, false);
+	bitvec_set_u64(bv, r->w15_hi, 5, false);
+	bitvec_set_u64(bv, r->w15_lo, 2, false);
+	bitvec_set_u64(bv, r->w16, 6, false);
 }
 
 /*! Determine GPRS TLLI Type (TS 23.003 Chapter 2.6) */
diff --git a/tests/bits/bitcomp_test.c b/tests/bits/bitcomp_test.c
index 587dd72..de59aa6 100644
--- a/tests/bits/bitcomp_test.c
+++ b/tests/bits/bitcomp_test.c
@@ -31,22 +31,22 @@
 
 	printf("\nTEST1:\n 00110111 01000111 10000001 1111\n");
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0x374781F, 28); bitvec_to_string_r(&bv, lol); printf("%s", lol);
+	bitvec_set_u64(&bv, 0x374781F, 28, false); 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:\n0 11011110 10001000 01110101 01100101 100 [35]\n", bv.cur_bit);
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xDE887565, 32);
-	bitvec_set_uint(&bv, 4, 3);
+	bitvec_set_u64(&bv, 0xDE887565, 32, false);
+	bitvec_set_u64(&bv, 4, 3, false);
 	bitvec_to_string_r(&bv, lol);
 	printf(" %s [%d]\n", lol, bv.cur_bit);
 
 	printf("\nTEST2:\n 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00\n");
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xFFFFFFFF, 32);
-	bitvec_set_uint(&bv, 0xFFFFFFFF, 32);
-	bitvec_set_uint(&bv, 0xFFFFFC00, 26); bitvec_to_string_r(&bv, lol); printf("%s", lol);
+	bitvec_set_u64(&bv, 0xFFFFFFFF, 32, false);
+	bitvec_set_u64(&bv, 0xFFFFFFFF, 32, false);
+	bitvec_set_u64(&bv, 0xFFFFFC00, 26, false); 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);
 
diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c
index d0bc30c..15c0f2b 100644
--- a/tests/bitvec/bitvec_test.c
+++ b/tests/bitvec/bitvec_test.c
@@ -88,11 +88,11 @@
 		/* Write to bitvec */
 		memset(data, 0x00, sizeof(data));
 		bv.cur_bit = i;
-		rc = bitvec_set_uint(&bv, 0x7e, 8);
+		rc = bitvec_set_u64(&bv, 0x7e, 8, false);
 		OSMO_ASSERT(rc >= 0);
 		rc = bitvec_set_bytes(&bv, in, in_size);
 		OSMO_ASSERT(rc >= 0);
-		rc = bitvec_set_uint(&bv, 0x7e, 8);
+		rc = bitvec_set_u64(&bv, 0x7e, 8, false);
 		OSMO_ASSERT(rc >= 0);
 
 		printf("bitvec: %s\n", osmo_hexdump(bv.data, bv.data_len));
@@ -193,29 +193,29 @@
 
 	printf("test shifting...\n");
 
-	bitvec_set_uint(&bv, 0x0E, 7);
+	bitvec_set_u64(&bv, 0x0E, 7, false);
 	test_shift(&bv, 3);
 	test_shift(&bv, 17);
-	bitvec_set_uint(&bv, 0, 32);
-	bitvec_set_uint(&bv, 0x0A, 7);
+	bitvec_set_u64(&bv, 0, 32, false);
+	bitvec_set_u64(&bv, 0x0A, 7, false);
 	test_shift(&bv, 24);
 
 	printf("checking RL functions...\n");
 
 	bitvec_zero(&bv);
 	test_rl(&bv);
-	bitvec_set_uint(&bv, 0x000F, 32);
+	bitvec_set_u64(&bv, 0x000F, 32, false);
 	test_rl(&bv);
 	bitvec_shiftl(&bv, 18);
 	test_rl(&bv);
-	bitvec_set_uint(&bv, 0x0F, 8);
+	bitvec_set_u64(&bv, 0x0F, 8, false);
 	test_rl(&bv);
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xFF, 8);
+	bitvec_set_u64(&bv, 0xFF, 8, false);
 	test_rl(&bv);
-	bitvec_set_uint(&bv, 0xFE, 7);
+	bitvec_set_u64(&bv, 0xFE, 7, false);
 	test_rl(&bv);
-	bitvec_set_uint(&bv, 0, 17);
+	bitvec_set_u64(&bv, 0, 17, false);
 	test_rl(&bv);
 	bitvec_shiftl(&bv, 18);
 	test_rl(&bv);
@@ -223,7 +223,7 @@
 	printf("probing bit access...\n");
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0x3747817, 32);
+	bitvec_set_u64(&bv, 0x3747817, 32, false);
 	bitvec_shiftl(&bv, 10);
 
 	test_get(&bv, 2);
@@ -260,12 +260,12 @@
 	printf("\nbitvec_runlength....\n");
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xff, 8);
+	bitvec_set_u64(&bv, 0xff, 8, false);
 	bv.cur_bit -= 8;
 	test_bitvec_rl_curbit(&bv, 1, 64, 8);
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xfc, 8);
+	bitvec_set_u64(&bv, 0xfc, 8, false);
 	bv.cur_bit -= 8;
 	test_bitvec_rl_curbit(&bv, 1, 64, 6);
 
@@ -273,13 +273,13 @@
 	test_bitvec_rl_curbit(&bv, 0, 52, 52);
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0xfc, 8);
+	bitvec_set_u64(&bv, 0xfc, 8, false);
 	bv.cur_bit -= 2;
 	test_bitvec_rl_curbit(&bv, 0, 64, 58);
 
 	bitvec_zero(&bv);
-	bitvec_set_uint(&bv, 0x07, 8);
-	bitvec_set_uint(&bv, 0xf8, 8);
+	bitvec_set_u64(&bv, 0x07, 8, false);
+	bitvec_set_u64(&bv, 0xf8, 8, false);
 	bv.cur_bit -= 11;
 	test_bitvec_rl_curbit(&bv, 1, 64, 8);
 

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I2fd8d17f9fa6c51ef51f4294882cca5944d71df2
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Minh-Quang Nguyen <minh-quang.nguyen at nutaq.com>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list