line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "bit.h" |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
#include |
6
|
|
|
|
|
|
|
#include |
7
|
|
|
|
|
|
|
#include |
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
|
|
|
int bitCount (unsigned int value, int set){ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
unsigned int bit_count; |
12
|
0
|
|
|
|
|
|
unsigned int c = 0; |
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
if (set){ |
15
|
0
|
0
|
|
|
|
|
while (value != 0){ |
16
|
0
|
|
|
|
|
|
c++; |
17
|
0
|
|
|
|
|
|
value &= value - 1; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
bit_count = c; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
0
|
|
|
|
|
|
int zeros = __builtin_clz(value); |
23
|
0
|
|
|
|
|
|
bit_count = (sizeof(int) * 8) - zeros; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return bit_count; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
int bitMask (unsigned int bits, int lsb){ |
30
|
0
|
|
|
|
|
|
return ((1 << bits) - 1) << lsb; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
int bitGet (const unsigned int data, int msb, const int lsb){ |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
_checkMSB(msb); |
36
|
0
|
|
|
|
|
|
msb++; // we count from one |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
_checkLSB(msb, lsb); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return (data & (1 << msb) -1) >> lsb; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
int bitSet (unsigned int data, int lsb, int bits, int value){ |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
_checkValue(value); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
unsigned int value_bits = bitCount(value, 0); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if (value_bits != bits){ |
50
|
0
|
|
|
|
|
|
value_bits = bits; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
unsigned int mask = ((1 << value_bits) - 1) << lsb; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
data = (data & ~(mask)) | (value << lsb); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return data; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
int bitTog (unsigned int data, int bit){ |
61
|
0
|
|
|
|
|
|
return data ^= 1 << bit; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
int bitOn (unsigned int data, int bit){ |
65
|
0
|
|
|
|
|
|
return data |= 1 << bit; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
int bitOff (unsigned int data, int bit){ |
69
|
0
|
|
|
|
|
|
return data &= ~(1 << bit); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
void _checkMSB (int msb){ |
73
|
0
|
0
|
|
|
|
|
if (msb < 0){ |
74
|
0
|
|
|
|
|
|
croak("\nbit_get() $msb param must be greater than zero\n\n"); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
void _checkLSB (int msb, int lsb){ |
79
|
0
|
0
|
|
|
|
|
if (lsb < 0){ |
80
|
0
|
|
|
|
|
|
croak("\nbit_get() $lsb param can not be negative\n\n"); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if (lsb + 1 > (msb)){ |
84
|
0
|
|
|
|
|
|
croak("\nbit_get() $lsb param must be less than or equal to $msb\n\n"); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
void _checkValue (int value){ |
89
|
0
|
0
|
|
|
|
|
if (value < 0){ |
90
|
0
|
|
|
|
|
|
croak("\nbit_set() $value param must be zero or greater\n\n"); |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
} |