-
Notifications
You must be signed in to change notification settings - Fork 6
/
mb_vint.h
301 lines (263 loc) · 18.5 KB
/
mb_vint.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**
Copyright (C) powturbo 2013-2022
GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
//-------------------- Variable Length Codes: Gamma Coding (1..MAX_UINT) --------------------------------------------------
#include "mb_o0.h"
/* predictor definition.
mg0: first bit
mgu: length encoded in unary
mgb: mantissa value with length as context encoded in binary
minimum value to encode with gamma coding must be >= 1
_gau_ : max. unary length (= max. integer size in bits + 1)
_gab_ : max. binary length (= max. integer size in bits + 1)
*/
// Order 0
#define MBG_DEF( _mg0_, _mgu_, _mgb_, _gau_, _gab_) mbu _mg0_, _mgu_[_gau_], _mgb_[_gau_][_gab_]
#define MBG_INIT( _mg0_, _mgu_, _mgb_, _gau_, _gab_) mbu_init(&_mg0_, mbu_probinit()); mbu_init1(_mgu_, _gau_); mbu_init2(_mgb_, _gau_, _gab_) // predictor init
#define MBG_DEC( _mg0_, _mgu_, _mgb_, _gau_, _gab_) MBG_DEF( _mg0_, _mgu_, _mgb_, _gau_, _gab_); MBG_INIT( _mg0_, _mgu_, _mgb_, _gau_, _gab_) // predictor definition+init
// Order 1: context only for first bit mg0
#define MBG_DEF0( _mg0_, _g0b_, _mgu_, _mgb_, _gau_, _gab_) mbu _mg0_[_g0b_], _mgu_[_gau_], _mgb_[_gau_][_gab_]
#define MBG_INIT0(_mg0_, _g0b_, _mgu_, _mgb_, _gau_, _gab_) mbu_init1(_mg0_, _g0b_); mbu_init1(_mgu_, _gau_); mbu_init2(_mgb_, _gau_, _gab_)
#define MBG_DEC0( _mg0_, _g0b_, _mgu_, _mgb_, _gau_, _gab_) MBG_DEF0(_mg0_, _g0b_, _mgu_, _mgb_, _gau_, _gab_); MBG_INIT0(_mg0_, _g0b_, _mgu_, _mgb_, _gau_, _gab_)
// Order 1: context for mg0 + mgu
#define MBG_DEF1( _mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gau_, _gab_) mbu _mg0_[_g0b_], _mgu_[_g1b_][_gau_], _mgb_[_gau_][_gab_]
#define MBG_INIT1(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gau_, _gab_) mbu_init1(_mg0_, _g0b_); mbu_init2(_mgu_, _g1b_, _gau_); mbu_init2(_mgb_, _gau_, _gab_)
#define MBG_DEC1( _mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gau_, _gab_) MBG_DEF1( _mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gau_, _gab_); MBG_INIT1(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gau_, _gab_)
// Order 1: context for mg0 + mgu + mgb
#define MBG_DEF2(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gbb_, _gau_, _gab_) mbu _mg0_[_g0b_], _mgu_[_g1b_][_gau_], _mgb_[_gbb_][_gau_][_gab_]
#define MBG_INI2(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gbb_, _gau_, _gab_) mbu_init1(_mg0_, _g0b_); mbu_init2(_mgu_, _g1b_, _gau_); mbu_init3(_mgb_, _gbb_, _gau_, _gab_)
#define MBG_DEC2(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gbb_, _gau_, _gab_) MBG_DEF2( _mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gbb_, _gau_, _gab_); MBG_INI2(_mg0_, _g0b_, _mgu_, _g1b_, _mgb_, _gbb_, _gau_, _gab_)
// unary
#define _mbgue(_rcrange_,_rclow_,_rcilow_, _mg_,_prm0_,_prm1_, _op_, _gb_) do { mbu *_mg = _mg_,*_mgp;\
for(_mgp = _mg; _mgp < _mg+(_gb_); _mgp++)\
mbu_enc(_rcrange_,_rclow_,_rcilow_, _mgp,_prm0_,_prm1_,_op_, 0);\
mbu_enc( _rcrange_,_rclow_,_rcilow_, _mgp,_prm0_,_prm1_,_op_, 1);\
} while(0)
#define _mbgud(_rcrange_,_rccode_, _mgu_, _prm0_,_prm1_, _ip_, _ub_) do {\
mbu *_mgu = _mgu_;\
for(;;) { /*read the gamma length in unary */\
if_rc0(_rcrange_,_rccode_, mbu_p(_mgu,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0, _mgu,_prm0_,_prm1_); ++_mgu;}\
else { rcupdate1(_rcrange_,_rccode_, mbu_update1, _mgu,_prm0_,_prm1_); _ub_ = _mgu - (_mgu_); break; }\
}\
} while(0)
// binary
#define _mbgbe(_rcrange_,_rclow_,_rcilow_, _mg_,_prm0_,_prm1_, _op_, _x_, _gb_) do {\
int _gi; mbu *_mga = _mg_;\
for(_gi = (_gb_)-1; _gi >= 0; --_gi) {\
mbu *_mg = _mga + _gi;\
mbu_enc(_rcrange_,_rclow_,_rcilow_, _mg,_prm0_,_prm1_,_op_, RCB((_x_),_gi));\
}\
} while(0)
#define _mbgbd(_rcrange_,_rccode_, _mgb_, _prm0_,_prm1_,_ip_, _x_,_ub_) do {\
mbu *_mga = _mgb_, *_mgp = _mga+(_ub_);\
while(--_mgp >= _mga) mbu_dec(_rcrange_,_rccode_, _mgp,_prm0_,_prm1_,_ip_, _x_);\
} while(0)
// Gamma Coding: 0..0xfffffffe
#define mbgenc(_rcrange_,_rclow_,_rcilow_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_op_, _x_) do {\
unsigned _x = (_x_)+1; AS(_x != 0, "mbgenc: can't encode 0xffffffffu in gamma");\
mbu *_mg0 = _mg0_;\
if(_x == 1) mbu_enc(_rcrange_,_rclow_,_rcilow_, _mg0,_prm0_,_prm1_,_op_, 1); /*value 1*/\
else { mbu_enc(_rcrange_,_rclow_,_rcilow_, _mg0,_prm0_,_prm1_,_op_, 0);\
unsigned _gb = __bsr32(_x);\
_mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_, _prm0_,_prm1_,_op_, _gb-1); /*encode the length in unary */\
_mbgbe(_rcrange_,_rclow_,_rcilow_, (_mgb_)[_gb-1],_prm0_,_prm1_,_op_,_x, _gb); /* encode the value in binary with lengt gb as context*/\
}\
} while(0)
#define _mbgdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_, _act0_, _act1_) {\
unsigned _x = 1,_ub;\
mbu *_mg0 = _mg0_;\
if_rc0(_rcrange_,_rccode_, mbu_p(_mg0,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0,_mg0,_prm0_,_prm1_);\
_mbgud(_rcrange_,_rccode_, _mgu_, _prm0_,_prm1_,_ip_, _ub); /*get the length in unary */\
_mbgbd(_rcrange_,_rccode_, (_mgb_)[_ub], _prm0_,_prm1_,_ip_, _x,_ub+1); /*get the value in binary */\
_x_ = _x-1; _act1_;\
} else { rcupdate1(_rcrange_,_rccode_, mbu_update1,_mg0,_prm0_,_prm1_); _x_ = _x-1; _act0_; } \
}
#define mbgdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_) _mbgdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_, ;, ;)
//---Gamma coding lower 5 bits values encoded in context ----------------------
#define mbgxenc(_rcrange_,_rclow_,_rcilow_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_op_, _x_) do {\
unsigned _x = (_x_)+1; AS(_x != 0, "mbgenc: can't encode 0xffffffffu in gamma");\
mbu *_mg0 = _mg0_;\
if(_x == 1) mbu_enc(_rcrange_,_rclow_,_rcilow_, _mg0,_prm0_,_prm1_,_op_, 1); /*value 1*/\
else { mbu_enc(_rcrange_,_rclow_,_rcilow_, _mg0,_prm0_,_prm1_,_op_, 0);\
unsigned _gb = __bsr32(_x);\
_mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_,_prm0_,_prm1_, _op_, _gb-1); /*encode the length in unary */\
if(_gb < 6) mbnenc(_rcrange_,_rclow_,_rcilow_, (_mgb_)[_gb-1], _prm0_,_prm1_, _op_, _x, _gb); /*encode the value (context = gb) as integer */\
else _mbgbe(_rcrange_,_rclow_,_rcilow_, (_mgb_)[_gb-1], _prm0_,_prm1_, _op_, _x, _gb); /*encode the value (context = gb) in binary */\
}\
} while(0)
#define _mbgxdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_, _act0_, _act1_) {\
unsigned _x = 1, _ub;\
mbu *_mg0 = _mg0_;\
if_rc0(_rcrange_,_rccode_, mbu_p(_mg0,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0,_mg0,_prm0_,_prm1_);\
_mbgud(_rcrange_,_rccode_, _mgu_, _prm0_,_prm1_, _ip_, _ub);\
mbu *_mbg = (_mgb_)[_ub]; _ub++; \
if(_ub < 6) { /*read the value in binary */\
mbndec(_rcrange_,_rccode_, _mbg, _prm0_,_prm1_,_ip_, _x,_ub); \
} else _mbgbd(_rcrange_,_rccode_, _mbg, _prm0_,_prm1_,_ip_, _x,_ub);\
_x_ = _x-1; _act1_;\
}\
else { rcupdate1(_rcrange_,_rccode_, mbu_update1, _mg0,_prm0_,_prm1_); _x_ = _x-1; _act0_; } \
}
#define mbgxdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_) _mbgxdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_, ;, ;)
//**** Limited length Gamma Coding. Full 32 bit range 0..UINT_MAX + 64 bits (expect last 64 bits value) ****----------------------------
#define mbgenc32(_rcrange_,_rclow_,_rcilow_, _mgu_, _mgb_,_prm0_,_prm1_,_op_, _x_, _qmax_) do {\
uint64_t _x = (uint64_t)(_x_)+1, \
_q = __bsr64(_x), _log2m_ = _q; /*_x >> _log2m_;*/\
if(_q > _qmax_) { /* quotient greater than limit _qmax_*/\
unsigned _qx = _q - _qmax_, _qb = __bsr32(_qx)+1; /* (_q - _qmax_) size in bits*/\
_mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_, _prm0_,_prm1_, _op_, _qmax_+_qb); /* encode (_qmax_+_qb) in unary coding*/\
_mbgbe(_rcrange_,_rclow_,_rcilow_, (_mgb_)[0],_prm0_,_prm1_, _op_, _qx, _qb-1); /* encode _qb-1 lsb bits (without the msb bit)*/\
} else _mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_,_prm0_,_prm1_, _op_, _q); /* _q in unary coding*/\
_mbgbe(_rcrange_,_rclow_,_rcilow_, _mgb_[__bsr32(_q+1)+1],_prm0_,_prm1_, _op_,_x, _log2m_); /* _log2m_ lsb bits of the remainder*/\
} while(0)
#define mbgdec32(_rcrange_,_rccode_, _mgu_,_mgb_,_prm0_,_prm1_, _ip_, _x_, _qmax_) do {\
unsigned _q; \
_mbgud(_rcrange_,_rccode_, _mgu_, _prm0_,_prm1_, _ip_, _q);\
if(_q > _qmax_) { unsigned _qb = _q - _qmax_; _q = 1; /* lsb bits length of the quotient */\
if(_qb>1) {\
_mbgbd(_rcrange_,_rccode_, _mgb_[0], _prm0_,_prm1_,_ip_, _q,_qb-1); /* decode lsb bits (msb always 1)*/\
_q = 1<<(_qb-1) | _q;\
}\
_q += _qmax_; /* build the quotient*/\
}\
uint64_t _x = 1; _mbgbd(_rcrange_,_rccode_, &(_mgb_)[__bsr32(_q+1)+1], _prm0_,_prm1_,_ip_, _x, _q); /* decode mantissa _q bits */\
_x_ = _x - 1;\
} while(0)
//-- Golomb Rice Coding : _qmax_ length limited rice coding with rice parameter _log2m_ -----------------------------------------------
#define mbrenc32(_rcrange_,_rclow_,_rcilow_, _mgu_,_mgb_,_prm0_,_prm1_, _op_, _x_, _qmax_, _log2m_) {\
unsigned _x = _x_, _q = _x >> _log2m_;\
if(_q > _qmax_) { /* quotient greater than limit _qmax_ */\
unsigned _qx = _q - _qmax_; int _qb = __bsr32(_qx)+1; /*AS(_qmax_+_qb+1 < 46,"mbrenc32: Fatal %d\n", _qmax_+_qb+1);*/ /* (_q - _qmax_) size in bits */\
_mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_, _prm0_,_prm1_, _op_, _qmax_+_qb); /* encode (_qmax_+_qb) in unary coding */\
_mbgbe(_rcrange_,_rclow_,_rcilow_, &(_mgb_)[0],_prm0_,_prm1_, _op_, _qx, _qb-1); \
} else _mbgue(_rcrange_,_rclow_,_rcilow_, _mgu_, _prm0_,_prm1_, _op_, _q); /* _q in unary coding*/\
_mbgbe(_rcrange_,_rclow_,_rcilow_, &(_mgb_)[__bsr32(_q+1)+1],_prm0_,_prm1_, _op_, _x, _log2m_);/* _log2m_ lsb bits of the remainder*/\
}
#define mbrdec32(_rcrange_, _rccode_, _mgu_,_mgb_,_prm0_,_prm1_, _ip_, _x_, _qmax_, _log2m_) {\
unsigned _x,_q;\
_mbgud(_rcrange_,_rccode_, _mgu_, _prm0_,_prm1_, _ip_, _q);\
if(_q > _qmax_) {\
int _qb = _q - _qmax_; /* lsb bits length of the quotient */\
_x = 1; _mbgbd(_rcrange_,_rccode_, &(_mgb_)[0], _prm0_,_prm1_,_ip_, _x, _qb-1); /* decode lsb bits (msb always 1) */\
_x += _qmax_; /* build the quotient*/\
_q = _x;\
} else _x = _q;\
_mbgbd(_rcrange_,_rccode_, &(_mgb_)[__bsr32(_q+1)+1], _prm0_,_prm1_,_ip_, _x, _log2m_);/* decode mantissa _log2m_ bits */\
_x_ = _x; \
}
//-------------------------------
#define VB_B2 4 //max. integer: VB_B2=6: 4276351=41407f VB_B2=5: 2171071=2120bf VB_B2=4:1118431=1110df VB_B2=3:592111=908ef
#define VB_BA2 (255 - (1<<VB_B2))
#define VB_OFS1 (VB_BA2 - (1<<VB_B2))
#define VB_OFS2 (VB_OFS1 + (1 << (8+VB_B2)))
#define mbvenc24(_rcrange_,_rclow_,_rcilow_,_mb0_,_mb1_,_mb2_, _prm0_,_prm1_, _op_,_x_) { unsigned _x = _x_;\
if(likely((_x_) < VB_OFS1)){ mb8enc(_rcrange_,_rclow_,_rcilow_, _mb0_,_prm0_,_prm1_, _op_, _x); }\
else if ((_x_) < VB_OFS2) { uint16_t _y = (VB_OFS1<<8) + (_x-VB_OFS1);\
_x = _y>>8; mb8enc(_rcrange_,_rclow_,_rcilow_, _mb0_,_prm0_,_prm1_, _op_, _x);\
_x = (unsigned char)_x; mb8enc(_rcrange_,_rclow_,_rcilow_, _mb1_,_prm0_,_prm1_, _op_, _x);\
} else { unsigned _y = VB_BA2 + ((_x -= VB_OFS2) >> 16);\
mb8enc(_rcrange_,_rclow_,_rcilow_, _mb0_,_prm0_,_prm1_, _op_, _y);\
_y = (unsigned char)_x; mb8enc(_rcrange_,_rclow_,_rcilow_, _mb1_,_prm0_,_prm1_, _op_, _y);\
_y = (unsigned char)(_x>>8); mb8enc(_rcrange_,_rclow_,_rcilow_, _mb2_,_prm0_,_prm1_, _op_, _y);\
}\
}
#define mbvenc24(_rcrange_,_rclow_,_rcilow_,_mb0_,_mb1_,_mb2_, _prm0_,_prm1_, _ip_,_x_) do { \
_x_ = *_ip_++;\
if(likely(_x_ < VB_OFS1));\
else if(likely(_x_ < VB_BA2)) { _x_ = ((_x_<<8) + (*_ip_)) + (VB_OFS1 - (VB_OFS1 << 8)); _ip_++;} \
else { _x_ = ctou16(_ip_) + ((_x_ - VB_BA2 ) << 16) + VB_OFS2; _ip_ += 2;}\
} while(0)
//------------------------------- Turbo VLC with exponent coded in gamma range coder and mantissa in bitio --------------------------------------------------------
#define mbvenc(_rcrange_,_rclow_,_rcilow_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_op_, _x_, _bw_, _br_,_vn_, _vb_) do { unsigned _vx = _x_;\
if(_vx >= vlcfirst(_vn_)+_vb_) { \
unsigned _expo, _ma, _mb;\
vlcenc(_vx-_vb_, _vn_, _expo, _mb, _ma); \
_vx = _expo+(_vb_); bitput(_bw_,_br_, _mb, _ma);\
}\
mbgenc(_rcrange_,_rclow_,_rcilow_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_op_, _vx);\
} while(0)
#define mbvdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _x_, _bw_, _br_, _vn_, _vb_) {\
unsigned _vx; \
mbgdec(_rcrange_,_rccode_, _mg0_,_mgu_,_mgb_,_prm0_,_prm1_,_ip_, _vx);\
if(_vx >= vlcfirst(_vn_)+_vb_) {\
_vx -= _vb_; \
int _mb = vlcmbits(_vx, _vn_), _ma;\
bitget(_bw_,_br_, _mb,_ma); \
_vx = vlcdec(_vx, _mb, _ma, _vn_)+_vb_; \
} _x_ = _vx;\
}
//------------------------------ Structured/Segmented encoding: encode/decode small integers up to MBU3LEN -----------------------------------------
/*Example : nb0=3 bits, nb1=5 bits, nb2=8 bits
1 : 0 1
01xxx : 1 - 9 = 1+ 8 8
000xxxxx : 9 - 41 = 9+ 32 32
001xxxxxxxx: 42 - 296 =41+256 256*/
#define MBU3LEN(_nb0_,_nb1_,_nb2_) (1 + (1 << _nb0_) + (1 << _nb1_) + (1 << _nb2_))
#define MBU3_DEF(_mbf_, _mb0_, _nb0_, _mb1_, _nb1_, _mb2_, _nb2_) mbu _mbf_[3], _mb0_[1<<(_nb0_)], _mb1_[1<<(_nb1_)], _mb2_[1<<(_nb2_)]
#define MBU3_INI(_mbf_, _mb0_, _nb0_, _mb1_, _nb1_, _mb2_, _nb2_) {\
mbu_init1(_mbf_, 3);\
mbu_init1(_mb0_, (1<<(_nb0_)));\
mbu_init1(_mb1_, (1<<(_nb1_)));\
mbu_init1(_mb2_, (1<<(_nb2_)));\
}
/* with cxb bits context */
#define MBU3_DEF1( _mbf_, _mb0_, _nb0_, _mb1_, _nb1_, _mb2_, _nb2_, _cxb_) mbu _mbf_[_cxb_][3], _mb0_[_cxb_][1<<_nb0_], _mb1_[_cxb_][1<<_nb1_], _mb2_[_cxb_][1<<_nb2_];
#define MBU3_INI1( _mbf_, _mb0_, _nb0_, _mb1_, _nb1_, _mb2_, _nb2_, _cxb_) {\
mbu_init2(_mbf_, _cxb_, 3 );\
mbu_init2(_mb0_, _cxb_, (1<<(_nb0_)));\
mbu_init2(_mb1_, _cxb_, (1<<(_nb1_)));\
mbu_init1(_mb2_, _cxb_, (1<<(_nb2_)));\
}
#define MBU3_DEC( _mbf_, _mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_) MBU3_DEF( _mbf_, _mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_);\
MBU3_INI( _mbf_, _mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_)
#define MBU3_DEC1(_mbf_, _mb0_, _nb0_, _mb1_, _nb1_, _mb2_, _nb2_, _cxb_) MBU3_DEF1(_mbf_, _mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_, _cxb_);\
MBU3_INI1(_mbf_, _mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_, _cxb_);
#define mbu3enc(_rcrange_,_rclow_,_rcilow_, _mbf_,_mb0_,_nb0_, _mb1_,_nb1_, _mb2_,_nb2_, _prm0_,_prm1_,_op_, _x_) do { unsigned _xx = _x_;\
if(!_xx) { mbu_enc(_rcrange_,_rclow_,_rcilow_, &_mbf_[0],_prm0_,_prm1_,_op_, 1); /* 1*/}\
else { _xx -= 1; mbu_enc(_rcrange_,_rclow_,_rcilow_, &_mbf_[0],_prm0_,_prm1_,_op_, 0);\
if( _xx < (1 << _nb0_)) { mbu_enc( _rcrange_,_rclow_,_rcilow_, &_mbf_[1],_prm0_,_prm1_,_op_, 1); /* 01*/\
T3(mb,_nb0_,enc)(_rcrange_,_rclow_,_rcilow_, _mb0_,_prm0_,_prm1_,_op_, _xx);\
} else { _xx -= (1 << _nb0_); mbu_enc( _rcrange_,_rclow_,_rcilow_, &_mbf_[1],_prm0_,_prm1_,_op_, 0); \
if( _xx < (1 << _nb1_)) { mbu_enc( _rcrange_,_rclow_,_rcilow_, &_mbf_[2],_prm0_,_prm1_,_op_, 0); /*000*/\
T3(mb,_nb1_,enc)(_rcrange_,_rclow_,_rcilow_, _mb1_,_prm0_,_prm1_,_op_, _xx); \
} else { _xx -= (1 << _nb1_); mbu_enc( _rcrange_,_rclow_,_rcilow_, &_mbf_[2],_prm0_,_prm1_,_op_, 1);\
T3(mb,_nb2_,enc)(_rcrange_,_rclow_,_rcilow_, _mb2_,_prm0_,_prm1_,_op_, _xx); /*001*/\
}\
}\
}\
} while(0)
#define _mbu3dec(_rcrange_,_rccode_, _mbf_,_mb0_,_nb0_,_mb1_,_nb1_,_mb2_,_nb2_,_prm0_,_prm1_,_ip_, _x_, _act0_, _act1_) do { unsigned _xx = 0;\
mbu *_m0 = &_mbf_[0];\
if_rc0(_rcrange_,_rccode_, mbu_p(_m0,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0,_m0,_prm0_,_prm1_);\
mbu *_m1 = &_mbf_[1];\
if_rc0(_rcrange_,_rccode_, mbu_p(_m1,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0,_m1,_prm0_,_prm1_);\
mbu *_m2 = &_mbf_[2];\
if_rc0(_rcrange_,_rccode_, mbu_p(_m2,_prm0_),_ip_) { rcupdate0(_rcrange_,_rccode_, mbu_update0,_m2,_prm0_,_prm1_); \
T3(mb,_nb1_,dec)(_rcrange_, _rccode_, _mb1_,RCPRM0,RCPRM1,_ip_, _xx); _xx&= (1<<_nb1_)-1; _xx+=(1 << _nb0_)+1;\
} else { rcupdate1(_rcrange_,_rccode_, mbu_update1,_m2,_prm0_,_prm1_);\
T3(mb,_nb2_,dec)(_rcrange_, _rccode_, _mb2_,RCPRM0,RCPRM1,_ip_, _xx); _xx&= (1<<_nb2_)-1; _xx+=(1 << _nb0_)+(1 << _nb1_)+1;\
}\
} else { rcupdate1(_rcrange_,_rccode_, mbu_update1,_m1,_prm0_,_prm1_);\
T3(mb,_nb0_,dec)(_rcrange_, _rccode_, _mb0_,RCPRM0,RCPRM1,_ip_, _xx); _xx+= 1;\
} _x_ = _xx; _act1_; \
} else { rcupdate1(_rcrange_,_rccode_, mbu_update1,_m0,_prm0_,_prm1_); /*1*/\
_x_ = _xx; _act0_;\
}\
} while(0)
#define mbu3dec(_rcrange_,_rccode_, _mbf_,_mb0_,_nb0_,_mb1_,_nb1_,_mb2_,_nb2_,_prm0_,_prm1_,_ip_, _x_) _mbu3dec(_rcrange_,_rccode_, _mbf_,_mb0_,_nb0_,_mb1_,_nb1_,_mb2_,_nb2_,_prm0_,_prm1_,_ip_, _x_, ;, ;)