-
Notifications
You must be signed in to change notification settings - Fork 0
/
macro.c
executable file
·185 lines (175 loc) · 5.56 KB
/
macro.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// *** HELPERS
#include "types.h"
#define bitSetOne(ptr,offset,bitval) { \
if (bitval) \
bitOffset(ptr,offset) |= bitValue(offset); \
else \
bitOffset(ptr,offset) &= ((Char) -1) ^ bitValue(offset); \
}
#define bitSetChar(ptr,offset,end,bitval,opaque) if ((end) > (offset)) { \
if (!( ((end) ^ (offset)) / charBit )) { \
Char \
*chead = &( bitOffset(ptr,offset) ); \
\
unsigned \
latchStart = (offset) % charBit, \
latchEnd = (end) % charBit; \
\
if (bitval) { \
if (opaque) \
*(UChar *)chead = \
(((UChar) 1 << (charBit - latchStart)) - 1) & \
(UChar)((Char) -1 << (charBit - latchEnd)); \
else \
*(UChar *)chead |= \
(((UChar) 1 << (charBit - latchStart)) - 1) & \
(UChar)((Char) -1 << (charBit - latchEnd)); \
} else { \
if (opaque) \
*(UChar *)chead = \
(UChar)((Char) -1 << (charBit - latchStart)) | \
(((UChar)1 << (charBit - latchEnd)) - 1); \
else \
*(UChar *)chead &= \
(UChar)((Char) -1 << (charBit - latchStart)) | \
(((UChar) 1 << (charBit - latchEnd)) - 1); \
} \
} else { \
Char \
*i, \
*chead = (Char *)(ptr) + ((offset) / charBit), \
*ctail, \
cbitval = (bitval) ? (Char) -1 : (Char) 0; \
\
unsigned \
bits, \
latchBits; \
\
if (( latchBits = (offset) % charBit )) { \
if (bitval) { \
if (opaque) \
*(UChar *) chead = ((UChar) 1 << (charBit - latchBits)) - 1; \
else \
*(UChar *) chead |= ((UChar) 1 << (charBit - latchBits)) - 1; \
} else { \
if (opaque) \
*(Char *) chead = ((Char) -1 << (charBit - latchBits)); \
else \
*(Char *) chead &= ((Char) -1 << (charBit - latchBits)); \
} \
++chead; \
} \
\
bits = (end) - (chead - (Char *)(ptr)) * charBit; \
\
for ( \
i = ( \
ctail = chead + (bits / charBit) \
) - 1; \
i >= chead; \
--i \
) *i = (cbitval); \
\
if (( latchBits = bits % charBit )) { \
if (bitval) { \
if (opaque) \
*(Char *)ctail = ((Char) -1 << (charBit - latchBits)); \
else \
*(Char *)ctail |= ((Char) -1 << (charBit - latchBits)); \
} else { \
if (opaque) \
*(UChar *)ctail = ((UChar)1 << (charBit - latchBits)) - 1; \
else \
*(UChar *)ctail &= ((UChar)1 << (charBit - latchBits)) - 1; \
} \
} \
} \
}
#define bitSet(ptr,offset,end,bitval,opaque) if ((end) > (offset)) { \
if (!( ((end) ^ (offset)) / (sizeof(Int) * charBit) )) { \
bitSetChar(ptr, offset, end, bitval, opaque); \
} else { \
Char \
*i, \
*lhead = (Char*)(ptr) + ((offset) / (charBit * sizeof(Int))) * sizeof(Int), \
*chead = (Char*)(ptr) + ((offset) / charBit), \
*ltail, \
*ctail, \
cbitval = (bitval) ? (Char) -1 : (Char) 0; \
\
Int \
lbitval = (bitval) ? (Int) -1 : (Int) 0; \
\
unsigned \
latchBits, \
latchBytes, \
bits; \
\
if (( latchBits = (offset) % charBit )) { \
if (bitval) { \
if (opaque) \
*(UChar *) chead = ((UChar) 1 << (charBit - latchBits)) - 1; \
else \
*(UChar *) chead |= ((UChar) 1 << (charBit - latchBits)) - 1; \
} else { \
if (opaque) \
*(Char *) chead = ((Char) -1 << (charBit - latchBits)); \
else \
*(Char *) chead &= ((Char) -1 << (charBit - latchBits)); \
} \
\
++chead; \
lhead += sizeof(Int); \
} \
\
if (( latchBytes = bitsChars(offset) % sizeof(Int) )) { \
for ( i = lhead + latchBytes - sizeof(Int) ; i < lhead ; ++i ) \
*i = cbitval; \
} \
\
bits = (end) - (lhead - (Char *)(ptr)) * charBit; \
\
for ( \
i = ( \
ltail = lhead + ( bits / (charBit * sizeof(Int)) ) * sizeof(Int) \
) - sizeof(Int); \
\
i >= lhead; \
i -= sizeof(Int) \
) *(Int *) i = lbitval; \
\
for ( \
i = ( \
ctail = ltail + ( bits % (charBit * sizeof(Int)) ) / charBit \
) - 1; \
\
i >= ltail; \
--i \
) *i = cbitval; \
\
if (( latchBits = bits % charBit )) { \
if (bitval) { \
if (opaque) \
*(Char *) ctail = ((Char) -1 << (charBit - latchBits)); \
else \
*(Char *) ctail |= ((Char) -1 << (charBit - latchBits)); \
} else { \
if (opaque) \
*(UChar *) ctail = ((UChar) 1 << (charBit - latchBits)) - 1; \
else \
*(UChar *) ctail &= ((UChar) 1 << (charBit - latchBits)) - 1; \
} \
} \
} \
}
#define REM(...)
#define PStruct(name, def) typedef struct __attribute__((__packed__)) name { ARG def } name
#define Struct(name, def) typedef struct name { ARG def } name
#define QtyV_nTailOfLog(l) (((l<<2) + (l<<5) + (l<<8) + l) >> 11)
#define IntV_nTailOfLog(l) (((l<<2) + (l<<5) + (l<<8) + l + 293) >> 11)
#define QtyV_nTailOfUInt(l, n) { l = log2u(n); l = QtyV_nTailOfLog(l); }
#define IntV_nTailOfInt(l, n) { l = log2(n); l = IntV_nTailOfLog(l); }
#define IntV_nTailByHdrChar(hdr) clrSb((Int) (hdr) << ((sizeof(Int) - sizeof(hdr)) * charBit))
#define IntV_lenByHdrChar(hdr) (IntV_nTailByHdrChar(hdr) + 1)
#define IntV_hdrAndMaskByLen(len) (Int)(((Int) 1 << (sizeof(Int) * charBit - (len))) - 1)
#define IntV_hdrOrMaskByLen(len) (Int)(((Int) -1) << (sizeof(Int) * charBit - (len)))