From patchwork Wed Apr 6 14:13:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 607021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 3qg73k477cz9t4T for ; Thu, 7 Apr 2016 00:13:06 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id ECF851CADC; Wed, 6 Apr 2016 14:13:03 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 385801CACC for ; Wed, 6 Apr 2016 14:13:01 +0000 (UTC) Received: from mail.sysmocom.de (mail.sysmocom.de [144.76.43.93]) by mail.sysmocom.de (Postfix) with ESMTP id C7B2C1A024E; Wed, 6 Apr 2016 14:13:01 +0000 (UTC) Received: from pbell.local (ip5b418565.dynamic.kabel-deutschland.de [91.65.133.101]) by mail.sysmocom.de (Postfix) with ESMTPSA id 853861A024D; Wed, 6 Apr 2016 14:13:01 +0000 (UTC) From: msuraev@sysmocom.de To: openbsc@lists.osmocom.org Subject: [PATCH] Add ubit <-> sbit convertors Date: Wed, 6 Apr 2016 16:13:00 +0200 Message-Id: <1459951980-6687-1-git-send-email-msuraev@sysmocom.de> X-Mailer: git-send-email 2.8.1 X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Max Move functions for conversion between soft and unpacked bits to main library as they are generally useful. --- include/osmocom/core/bits.h | 3 +++ src/bits.c | 24 ++++++++++++++++++++++++ tests/conv/conv_test.c | 23 ++--------------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/osmocom/core/bits.h b/include/osmocom/core/bits.h index 46f0c8b..e082313 100644 --- a/include/osmocom/core/bits.h +++ b/include/osmocom/core/bits.h @@ -42,6 +42,9 @@ int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits); int osmo_pbit2ubit(ubit_t *out, const pbit_t *in, unsigned int num_bits); +void osmo_ubit2sbit(sbit_t *out, const ubit_t *in, unsigned int num_bits); +void osmo_sbit2ubit(ubit_t *out, const sbit_t *in, unsigned int num_bits); + int osmo_ubit2pbit_ext(pbit_t *out, unsigned int out_ofs, const ubit_t *in, unsigned int in_ofs, unsigned int num_bits, int lsb_mode); diff --git a/src/bits.c b/src/bits.c index a0a9d9e..48314af 100644 --- a/src/bits.c +++ b/src/bits.c @@ -61,6 +61,30 @@ int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits) return outptr - out; } +/*! \brief convert unpacked bits to soft bits + * \param[out] out output buffer of soft bits + * \param[in] in input buffer of unpacked bits + * \param[in] num_bits number of bits + */ +void osmo_ubit2sbit(sbit_t *out, const ubit_t *in, unsigned int num_bits) +{ + unsigned int i; + for (i = 0; i < num_bits; i++) + out[i] = in[i] ? -127 : 127; +} + +/*! \brief convert soft bits to unpacked bits + * \param[out] out output buffer of unpacked bits + * \param[in] in input buffer of soft bits + * \param[in] num_bits number of bits + */ +void osmo_sbit2ubit(ubit_t *out, const sbit_t *in, unsigned int num_bits) +{ + unsigned int i; + for (i = 0; i < num_bits; i++) + out[i] = in[i] < 0; +} + /*! \brief convert packed bits to unpacked bits, return length in bytes * \param[out] out output buffer of unpacked bits * \param[in] in input buffer of packed bits diff --git a/tests/conv/conv_test.c b/tests/conv/conv_test.c index 182ae20..baebdbe 100644 --- a/tests/conv/conv_test.c +++ b/tests/conv/conv_test.c @@ -314,25 +314,6 @@ fill_random(ubit_t *b, int n) b[i] = random() & 1; } -static void -ubit_to_sbit(sbit_t *dst, ubit_t *src, int n) -{ - int i; - for (i=0; icode, bs, bu1); if (l != 0) { @@ -434,7 +415,7 @@ int main(int argc, char *argv[]) return -1; } - ubit_to_sbit(bs, bu1, l); + osmo_ubit2sbit(bs, bu1, l); l = osmo_conv_decode(tst->code, bs, bu1); if (l != 0) {