Revision bf5f9b52 libavcodec/get_bits.h

View differences:

libavcodec/get_bits.h
127 127

  
128 128
#   define OPEN_READER(name, gb)\
129 129
        unsigned int name##_index= (gb)->index;\
130
        int name##_cache= 0;\
130
        int name##_cache= 0
131 131

  
132 132
#   define CLOSE_READER(name, gb)\
133
        (gb)->index= name##_index;\
133
        (gb)->index= name##_index
134 134

  
135 135
# ifdef ALT_BITSTREAM_READER_LE
136 136
#   define UPDATE_CACHE(name, gb)\
137
        name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
137
        name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07)
138 138

  
139 139
#   define SKIP_CACHE(name, gb, num)\
140
        name##_cache >>= (num);
140
        name##_cache >>= (num)
141 141
# else
142 142
#   define UPDATE_CACHE(name, gb)\
143
        name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
143
        name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07)
144 144

  
145 145
#   define SKIP_CACHE(name, gb, num)\
146
        name##_cache <<= (num);
146
        name##_cache <<= (num)
147 147
# endif
148 148

  
149 149
// FIXME name?
150 150
#   define SKIP_COUNTER(name, gb, num)\
151
        name##_index += (num);\
151
        name##_index += (num)
152 152

  
153 153
#   define SKIP_BITS(name, gb, num)\
154
        {\
155
            SKIP_CACHE(name, gb, num)\
156
            SKIP_COUNTER(name, gb, num)\
157
        }\
154
        do {\
155
            SKIP_CACHE(name, gb, num);\
156
            SKIP_COUNTER(name, gb, num);\
157
        } while (0)
158 158

  
159 159
#   define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
160
#   define LAST_SKIP_CACHE(name, gb, num) ;
160
#   define LAST_SKIP_CACHE(name, gb, num)
161 161

  
162 162
# ifdef ALT_BITSTREAM_READER_LE
163 163
#   define SHOW_UBITS(name, gb, num)\
......
192 192
        int name##_bit_count=(gb)->bit_count;\
193 193
        uint32_t name##_cache0= (gb)->cache0;\
194 194
        uint32_t name##_cache1= (gb)->cache1;\
195
        uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
195
        uint32_t * name##_buffer_ptr=(gb)->buffer_ptr
196 196

  
197
#   define CLOSE_READER(name, gb)\
197
#   define CLOSE_READER(name, gb) do {\
198 198
        (gb)->bit_count= name##_bit_count;\
199 199
        (gb)->cache0= name##_cache0;\
200 200
        (gb)->cache1= name##_cache1;\
201 201
        (gb)->buffer_ptr= name##_buffer_ptr;\
202
    } while (0)
202 203

  
203
#   define UPDATE_CACHE(name, gb)\
204
#   define UPDATE_CACHE(name, gb) do {\
204 205
    if(name##_bit_count > 0){\
205 206
        const uint32_t next= av_be2ne32( *name##_buffer_ptr );\
206 207
        name##_cache0 |= NEG_USR32(next,name##_bit_count);\
......
208 209
        name##_buffer_ptr++;\
209 210
        name##_bit_count-= 32;\
210 211
    }\
212
} while (0)
211 213

  
212 214
#if ARCH_X86
213 215
#   define SKIP_CACHE(name, gb, num)\
......
216 218
            "shll %2, %1               \n\t"\
217 219
            : "+r" (name##_cache0), "+r" (name##_cache1)\
218 220
            : "Ic" ((uint8_t)(num))\
219
           );
221
           )
220 222
#else
221
#   define SKIP_CACHE(name, gb, num)\
223
#   define SKIP_CACHE(name, gb, num) do {\
222 224
        name##_cache0 <<= (num);\
223 225
        name##_cache0 |= NEG_USR32(name##_cache1,num);\
224
        name##_cache1 <<= (num);
226
        name##_cache1 <<= (num);\
227
    } while (0)
225 228
#endif
226 229

  
227 230
#   define SKIP_COUNTER(name, gb, num)\
228
        name##_bit_count += (num);\
231
        name##_bit_count += (num)
229 232

  
230 233
#   define SKIP_BITS(name, gb, num)\
231
        {\
232
            SKIP_CACHE(name, gb, num)\
233
            SKIP_COUNTER(name, gb, num)\
234
        }\
234
        do {\
235
            SKIP_CACHE(name, gb, num);\
236
            SKIP_COUNTER(name, gb, num);\
237
        } while (0)
235 238

  
236 239
#   define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
237 240
#   define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
......
250 253
}
251 254

  
252 255
static inline void skip_bits_long(GetBitContext *s, int n){
253
    OPEN_READER(re, s)
256
    OPEN_READER(re, s);
254 257
    re_bit_count += n;
255 258
    re_buffer_ptr += re_bit_count>>5;
256 259
    re_bit_count &= 31;
257 260
    re_cache0 = av_be2ne32( re_buffer_ptr[-1] ) << re_bit_count;
258 261
    re_cache1 = 0;
259
    UPDATE_CACHE(re, s)
260
    CLOSE_READER(re, s)
262
    UPDATE_CACHE(re, s);
263
    CLOSE_READER(re, s);
261 264
}
262 265

  
263 266
#endif
......
271 274
static inline int get_xbits(GetBitContext *s, int n){
272 275
    register int sign;
273 276
    register int32_t cache;
274
    OPEN_READER(re, s)
275
    UPDATE_CACHE(re, s)
277
    OPEN_READER(re, s);
278
    UPDATE_CACHE(re, s);
276 279
    cache = GET_CACHE(re,s);
277 280
    sign=(~cache)>>31;
278
    LAST_SKIP_BITS(re, s, n)
279
    CLOSE_READER(re, s)
281
    LAST_SKIP_BITS(re, s, n);
282
    CLOSE_READER(re, s);
280 283
    return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
281 284
}
282 285

  
283 286
static inline int get_sbits(GetBitContext *s, int n){
284 287
    register int tmp;
285
    OPEN_READER(re, s)
286
    UPDATE_CACHE(re, s)
288
    OPEN_READER(re, s);
289
    UPDATE_CACHE(re, s);
287 290
    tmp= SHOW_SBITS(re, s, n);
288
    LAST_SKIP_BITS(re, s, n)
289
    CLOSE_READER(re, s)
291
    LAST_SKIP_BITS(re, s, n);
292
    CLOSE_READER(re, s);
290 293
    return tmp;
291 294
}
292 295

  
......
295 298
 */
296 299
static inline unsigned int get_bits(GetBitContext *s, int n){
297 300
    register int tmp;
298
    OPEN_READER(re, s)
299
    UPDATE_CACHE(re, s)
301
    OPEN_READER(re, s);
302
    UPDATE_CACHE(re, s);
300 303
    tmp= SHOW_UBITS(re, s, n);
301
    LAST_SKIP_BITS(re, s, n)
302
    CLOSE_READER(re, s)
304
    LAST_SKIP_BITS(re, s, n);
305
    CLOSE_READER(re, s);
303 306
    return tmp;
304 307
}
305 308

  
......
308 311
 */
309 312
static inline unsigned int show_bits(GetBitContext *s, int n){
310 313
    register int tmp;
311
    OPEN_READER(re, s)
312
    UPDATE_CACHE(re, s)
314
    OPEN_READER(re, s);
315
    UPDATE_CACHE(re, s);
313 316
    tmp= SHOW_UBITS(re, s, n);
314 317
//    CLOSE_READER(re, s)
315 318
    return tmp;
......
317 320

  
318 321
static inline void skip_bits(GetBitContext *s, int n){
319 322
 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
320
    OPEN_READER(re, s)
321
    UPDATE_CACHE(re, s)
322
    LAST_SKIP_BITS(re, s, n)
323
    CLOSE_READER(re, s)
323
    OPEN_READER(re, s);
324
    UPDATE_CACHE(re, s);
325
    LAST_SKIP_BITS(re, s, n);
326
    CLOSE_READER(re, s);
324 327
}
325 328

  
326 329
static inline unsigned int get_bits1(GetBitContext *s){
......
449 452
void free_vlc(VLC *vlc);
450 453

  
451 454
#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
452
{\
455
do {\
453 456
    static VLC_TYPE table[static_size][2];\
454 457
    (vlc)->table= table;\
455 458
    (vlc)->table_allocated= static_size;\
456 459
    init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
457
}
460
} while (0)
458 461

  
459 462

  
460 463
/**
......
464 467
 * is undefined.
465 468
 */
466 469
#define GET_VLC(code, name, gb, table, bits, max_depth)\
467
{\
470
do {\
468 471
    int n, nb_bits;\
469 472
    unsigned int index;\
470 473
\
......
473 476
    n    = table[index][1];\
474 477
\
475 478
    if(max_depth > 1 && n < 0){\
476
        LAST_SKIP_BITS(name, gb, bits)\
477
        UPDATE_CACHE(name, gb)\
479
        LAST_SKIP_BITS(name, gb, bits);\
480
        UPDATE_CACHE(name, gb);\
478 481
\
479 482
        nb_bits = -n;\
480 483
\
......
482 485
        code = table[index][0];\
483 486
        n    = table[index][1];\
484 487
        if(max_depth > 2 && n < 0){\
485
            LAST_SKIP_BITS(name, gb, nb_bits)\
486
            UPDATE_CACHE(name, gb)\
488
            LAST_SKIP_BITS(name, gb, nb_bits);\
489
            UPDATE_CACHE(name, gb);\
487 490
\
488 491
            nb_bits = -n;\
489 492
\
......
492 495
            n    = table[index][1];\
493 496
        }\
494 497
    }\
495
    SKIP_BITS(name, gb, n)\
496
}
498
    SKIP_BITS(name, gb, n);\
499
} while (0)
497 500

  
498 501
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
499
{\
502
do {\
500 503
    int n, nb_bits;\
501 504
    unsigned int index;\
502 505
\
......
505 508
    n     = table[index].len;\
506 509
\
507 510
    if(max_depth > 1 && n < 0){\
508
        SKIP_BITS(name, gb, bits)\
511
        SKIP_BITS(name, gb, bits);\
509 512
        if(need_update){\
510
            UPDATE_CACHE(name, gb)\
513
            UPDATE_CACHE(name, gb);\
511 514
        }\
512 515
\
513 516
        nb_bits = -n;\
......
517 520
        n     = table[index].len;\
518 521
    }\
519 522
    run= table[index].run;\
520
    SKIP_BITS(name, gb, n)\
521
}
523
    SKIP_BITS(name, gb, n);\
524
} while (0)
522 525

  
523 526

  
524 527
/**
......
534 537
{
535 538
    int code;
536 539

  
537
    OPEN_READER(re, s)
538
    UPDATE_CACHE(re, s)
540
    OPEN_READER(re, s);
541
    UPDATE_CACHE(re, s);
539 542

  
540
    GET_VLC(code, re, s, table, bits, max_depth)
543
    GET_VLC(code, re, s, table, bits, max_depth);
541 544

  
542
    CLOSE_READER(re, s)
545
    CLOSE_READER(re, s);
543 546
    return code;
544 547
}
545 548

  

Also available in: Unified diff