-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.h
86 lines (73 loc) · 2.19 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef utils_h
#define utils_h
#include <stdint.h>
#include <stdlib.h>
#define LEN(x) (sizeof(x)/sizeof(*x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define DO_PRAGMA(x) _Pragma(#x)
/* Portable unroll pragma, for some reason clang defines __GNUC__ but uses the
* non-GCC unroll pragma format */
#if defined(__clang__)
#define PRAGMA_UNROLL(x) DO_PRAGMA(unroll x)
#elif defined(__GNUC__)
#define PRAGMA_UNROLL(x) DO_PRAGMA(GCC unroll x)
#else
#define PRAGMA_UNROLL(x) DO_PRAGMA(unroll x)
#endif
enum phase {
PHASE_0=0, PHASE_90=1, PHASE_180=2, PHASE_270=3, // TODO might also need I<->Q swaps?
PHASE_INV_0=4, PHASE_INV_90=5, PHASE_INV_180=6, PHASE_INV_270=7
};
/**
* Convert soft samples into hard samples
*
* @param hard pointer to the destination buffer that will hold the hard
* samples. Must be at least len/8 bytes long
* @param soft pointer to the soft samples to convert
* @param len numebr of soft samples to convert
*/
void soft_to_hard(uint8_t *hard, int8_t *soft, int len);
/**
* Undo a rotation on a set of soft samples.
*
* @param soft the samples to rotate in-place
* @param len number of samples to rotate
* @param phase the phase rotation to undo
*/
void soft_derotate(int8_t *soft, int len, enum phase phase);
/**
* Count bits set inside of a variable
*
* @param v variable to count the bits of
* @return number of bits set in the variable
*/
int count_ones(uint64_t v);
/**
* Read up to 32 misaligned bits from a byte buffer
*
* @param src pointer to the byte buffer to read bits from
* @param offset_bits offset from the beginning of the pointer from which to
* start reading
* @param bitcount number of bits to read
* @return bits read
*/
uint32_t read_bits(const uint8_t *src, int offset_bits, int bitcount);
/**
* Generate an automatic filename based on the current date and time
*
* @param buf buffer to write the filename to
* @param len max length of the allocated buffer
*/
void gen_fname(char *buf, size_t len);
/**
* Print usage information
*
* @param execname name of the executable
*/
void usage(char *execname);
/**
* Print version information
*/
void version();
#endif /* utils_h */