libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
Loading...
Searching...
No Matches
soft, unpacked and packed bits

Files

file  bits.h
 Osmocom bit level support code.
 
file  bits.c
 Osmocom bit level support code.
 

Macros

#define OSMO_BIN_SPEC   "%d%d%d%d%d%d%d%d"
 
#define OSMO_BIN_PRINT(byte)
 
#define OSMO_BIT_SPEC   "%c%c%c%c%c%c%c%c"
 
#define OSMO_BIT_PRINT(byte)
 

Typedefs

typedef int8_t sbit_t
 soft bit (-127...127)
 
typedef uint8_t ubit_t
 unpacked bit (0 or 1)
 
typedef uint8_t pbit_t
 packed bis (8 bits in a byte)
 

Enumerations

enum  osmo_br_mode { OSMO_BR_BITS_IN_DWORD = 31 , OSMO_BR_BYTES_IN_DWORD = 24 , OSMO_BR_BITS_IN_BYTE = 7 , OSMO_BR_WORD_SWAP = 16 }
 bit-reversal mode for osmo_bit_reversal() More...
 

Functions

static unsigned int osmo_pbit_bytesize (unsigned int num_bits)
 determine how many bytes we would need for num_bits packed bits
 
int osmo_ubit2pbit (pbit_t *out, const ubit_t *in, unsigned int num_bits)
 convert unpacked bits to packed bits, return length in bytes
 
int osmo_pbit2ubit (ubit_t *out, const pbit_t *in, unsigned int num_bits)
 convert packed bits to unpacked bits, return length in bytes
 
void osmo_nibble_shift_right (uint8_t *out, const uint8_t *in, unsigned int num_nibbles)
 Shift unaligned input to octet-aligned output.
 
void osmo_nibble_shift_left_unal (uint8_t *out, const uint8_t *in, unsigned int num_nibbles)
 Shift unaligned input to octet-aligned output.
 
void osmo_ubit2sbit (sbit_t *out, const ubit_t *in, unsigned int num_bits)
 convert unpacked bits to soft bits
 
void osmo_sbit2ubit (ubit_t *out, const sbit_t *in, unsigned int num_bits)
 convert soft bits to unpacked 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)
 convert unpacked bits to packed bits (extended options)
 
int osmo_pbit2ubit_ext (ubit_t *out, unsigned int out_ofs, const pbit_t *in, unsigned int in_ofs, unsigned int num_bits, int lsb_mode)
 convert packed bits to unpacked bits (extended options)
 
uint32_t osmo_bit_reversal (uint32_t x, enum osmo_br_mode k)
 generic bit reversal function
 
uint32_t osmo_revbytebits_32 (uint32_t x)
 reverse the bit-order in each byte of a dword
 
uint32_t osmo_revbytebits_8 (uint8_t x)
 reverse the bit order in a byte
 
void osmo_revbytebits_buf (uint8_t *buf, int len)
 reverse bit-order of each byte in a buffer
 
static uint16_t osmo_rol16 (uint16_t in, unsigned shift)
 left circular shift
 

Detailed Description

Macro Definition Documentation

◆ OSMO_BIN_PRINT

#define OSMO_BIN_PRINT ( byte)
Value:
(byte & 0x80 ? 1 : 0), \
(byte & 0x40 ? 1 : 0), \
(byte & 0x20 ? 1 : 0), \
(byte & 0x10 ? 1 : 0), \
(byte & 0x08 ? 1 : 0), \
(byte & 0x04 ? 1 : 0), \
(byte & 0x02 ? 1 : 0), \
(byte & 0x01 ? 1 : 0)

◆ OSMO_BIT_PRINT

#define OSMO_BIT_PRINT ( byte)
Value:
(byte & 0x80 ? '1' : '.'), \
(byte & 0x40 ? '1' : '.'), \
(byte & 0x20 ? '1' : '.'), \
(byte & 0x10 ? '1' : '.'), \
(byte & 0x08 ? '1' : '.'), \
(byte & 0x04 ? '1' : '.'), \
(byte & 0x02 ? '1' : '.'), \
(byte & 0x01 ? '1' : '.')

Enumeration Type Documentation

◆ osmo_br_mode

bit-reversal mode for osmo_bit_reversal()

Enumerator
OSMO_BR_BITS_IN_DWORD 

reverse all bits in a 32bit dword

OSMO_BR_BYTES_IN_DWORD 

reverse byte order in a 32bit dword

OSMO_BR_BITS_IN_BYTE 

reverse bits of each byte in a 32bit dword

OSMO_BR_WORD_SWAP 

swap the two 16bit words in a 32bit dword

Function Documentation

◆ osmo_bit_reversal()

uint32_t osmo_bit_reversal ( uint32_t x,
enum osmo_br_mode k )

generic bit reversal function

generalized bit reversal function

Parameters
[in]xthe 32bit value to be reversed
[in]kthe type of reversal requested
Returns
the reversed 32bit dword

This function reverses the bit order within a 32bit word. Depending on "k", it either reverses all bits in a 32bit dword, or the bytes in the dword, or the bits in each byte of a dword, or simply swaps the two 16bit words in a dword. See Chapter 7 "Hackers Delight"

◆ osmo_nibble_shift_left_unal()

void osmo_nibble_shift_left_unal ( uint8_t * out,
const uint8_t * in,
unsigned int num_nibbles )

Shift unaligned input to octet-aligned output.

Parameters
[out]outoutput buffer, octet-aligned
[in]ininput buffer, unaligned
[in]num_nibblesnumber of nibbles

◆ osmo_nibble_shift_right()

void osmo_nibble_shift_right ( uint8_t * out,
const uint8_t * in,
unsigned int num_nibbles )

Shift unaligned input to octet-aligned output.

Parameters
[out]outoutput buffer, unaligned
[in]ininput buffer, octet-aligned
[in]num_nibblesnumber of nibbles

◆ osmo_pbit2ubit()

int osmo_pbit2ubit ( ubit_t * out,
const pbit_t * in,
unsigned int num_bits )

convert packed bits to unpacked bits, return length in bytes

Parameters
[out]outoutput buffer of unpacked bits
[in]ininput buffer of packed bits
[in]num_bitsnumber of bits
Returns
number of bytes used in out

◆ osmo_pbit2ubit_ext()

int osmo_pbit2ubit_ext ( ubit_t * out,
unsigned int out_ofs,
const pbit_t * in,
unsigned int in_ofs,
unsigned int num_bits,
int lsb_mode )

convert packed bits to unpacked bits (extended options)

Parameters
[out]outoutput buffer of unpacked bits
[in]out_ofsoffset into output buffer
[in]ininput buffer of packed bits
[in]in_ofsoffset into input buffer
[in]num_bitsnumber of bits
[in]lsb_modeEncode bits in LSB orde instead of MSB
Returns
length in bytes (max written offset of output buffer + 1)

◆ osmo_pbit_bytesize()

static unsigned int osmo_pbit_bytesize ( unsigned int num_bits)
inlinestatic

determine how many bytes we would need for num_bits packed bits

Parameters
[in]num_bitsNumber of packed bits
Returns
number of bytes needed for num_bits packed bits

◆ osmo_revbytebits_32()

uint32_t osmo_revbytebits_32 ( uint32_t x)

reverse the bit-order in each byte of a dword

Parameters
[in]x32bit input value
Returns
32bit value where bits of each byte have been reversed

See Chapter 7 "Hackers Delight"

Referenced by osmo_revbytebits_buf().

◆ osmo_revbytebits_8()

uint32_t osmo_revbytebits_8 ( uint8_t x)

reverse the bit order in a byte

Parameters
[in]x8bit input value
Returns
8bit value where bits order has been reversed

See Chapter 7 "Hackers Delight"

Referenced by osmo_revbytebits_buf().

◆ osmo_revbytebits_buf()

void osmo_revbytebits_buf ( uint8_t * buf,
int len )

reverse bit-order of each byte in a buffer

Parameters
[in]bufbuffer containing bytes to be bit-reversed
[in]lenlength of buffer in bytes

This function reverses the bits in each byte of the buffer

References osmo_revbytebits_32(), and osmo_revbytebits_8().

◆ osmo_rol16()

static uint16_t osmo_rol16 ( uint16_t in,
unsigned shift )
inlinestatic

left circular shift

Parameters
[in]inThe 16 bit unsigned integer to be rotated
[in]shiftNumber of bits to shift in to, [0;16] bits
Returns
shifted value

◆ osmo_sbit2ubit()

void osmo_sbit2ubit ( ubit_t * out,
const sbit_t * in,
unsigned int num_bits )

convert soft bits to unpacked bits

Parameters
[out]outoutput buffer of unpacked bits
[in]ininput buffer of soft bits
[in]num_bitsnumber of bits

◆ osmo_ubit2pbit()

int osmo_ubit2pbit ( pbit_t * out,
const ubit_t * in,
unsigned int num_bits )

convert unpacked bits to packed bits, return length in bytes

Parameters
[out]outoutput buffer of packed bits
[in]ininput buffer of unpacked bits
[in]num_bitsnumber of bits

◆ osmo_ubit2pbit_ext()

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 )

convert unpacked bits to packed bits (extended options)

Parameters
[out]outoutput buffer of packed bits
[in]out_ofsoffset into output buffer
[in]ininput buffer of unpacked bits
[in]in_ofsoffset into input buffer
[in]num_bitsnumber of bits
[in]lsb_modeEncode bits in LSB orde instead of MSB
Returns
length in bytes (max written offset of output buffer + 1)

◆ osmo_ubit2sbit()

void osmo_ubit2sbit ( sbit_t * out,
const ubit_t * in,
unsigned int num_bits )

convert unpacked bits to soft bits

Parameters
[out]outoutput buffer of soft bits
[in]ininput buffer of unpacked bits
[in]num_bitsnumber of bits