SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
math.cpp
Go to the documentation of this file.
1 #include "math.h"
2 
3 namespace leansdr
4 {
5 
7 {
8  static const int lut[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
9  return lut[x & 15] + lut[x >> 4];
10 }
11 
13 {
14  return hamming_weight((uint8_t)x) + hamming_weight((uint8_t)(x >> 8));
15 }
16 
18 {
19  return hamming_weight((uint16_t)x) + hamming_weight((uint16_t)(x >> 16));
20 }
21 
23 {
24  return hamming_weight((uint32_t)x) + hamming_weight((uint32_t)(x >> 32));
25 }
26 
27 unsigned char parity(uint8_t x)
28 {
29  x ^= x >> 4;
30  return (0x6996 >> (x & 15)) & 1; // 16-entry look-up table
31 }
32 
33 unsigned char parity(uint16_t x)
34 {
35  return parity((uint8_t)(x ^ (x >> 8)));
36 }
37 
38 unsigned char parity(uint32_t x)
39 {
40  return parity((uint16_t)(x ^ (x >> 16)));
41 }
42 
43 unsigned char parity(uint64_t x)
44 {
45  return parity((uint32_t)(x ^ (x >> 32)));
46 }
47 
49 {
50  int n = -1;
51  for (; x; ++n, x >>= 1)
52  ;
53  return n;
54 }
55 
56 } // leansdr
int log2i(uint64_t x)
Definition: math.cpp:48
int hamming_weight(uint8_t x)
Definition: math.cpp:6
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
unsigned char parity(uint8_t x)
Definition: math.cpp:27
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48