summaryrefslogtreecommitdiff
path: root/vp8/encoder/encodemv.c
blob: 0ba8848a0ce620d8f2c35bd1c33a51903b322f8b (plain)
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


#include "vp8/common/common.h"
#include "encodemv.h"
#include "vp8/common/entropymode.h"
#include "vp8/common/systemdependent.h"

#include <math.h>

#ifdef ENTROPY_STATS
extern unsigned int active_section;
#endif

//#define DEBUG_ENC_MV
#ifdef DEBUG_ENC_MV
int enc_mvcount = 0;
#endif

static void encode_mvcomponent(
    vp8_writer *const w,
    const int v,
    const struct mv_context *mvc
)
{
    const vp8_prob *p = mvc->prob;
    const int x = v < 0 ? -v : v;

    if (x < mvnum_short)     // Small
    {
        vp8_write(w, 0, p [mvpis_short]);
        vp8_treed_write(w, vp8_small_mvtree, p + MVPshort, x, mvnum_short_bits);
        if (!x)
            return;         // no sign bit
    }
    else                    // Large
    {
        int i = 0;

        vp8_write(w, 1, p [mvpis_short]);

        do
            vp8_write(w, (x >> i) & 1, p [MVPbits + i]);

        while (++i < mvnum_short_bits);

        i = mvlong_width - 1;  /* Skip bit 3, which is sometimes implicit */

        do
            vp8_write(w, (x >> i) & 1, p [MVPbits + i]);

        while (--i > mvnum_short_bits);

        if (x & ~((2<<mvnum_short_bits)-1))
            vp8_write(w, (x >> mvnum_short_bits) & 1, p [MVPbits + mvnum_short_bits]);
    }

    vp8_write(w, v < 0, p [MVPsign]);
}
#if 0
static int max_mv_r = 0;
static int max_mv_c = 0;
#endif
void vp8_encode_motion_vector(vp8_writer *w, const MV *mv, const MV_CONTEXT *mvc)
{

#if 0
    {
        if (abs(mv->row >> 1) > max_mv_r)
        {
            FILE *f = fopen("maxmv.stt", "a");
            max_mv_r = abs(mv->row >> 1);
            fprintf(f, "New Mv Row Max %6d\n", (mv->row >> 1));

            if ((abs(mv->row) / 2) != max_mv_r)
                fprintf(f, "MV Row conversion error %6d\n", abs(mv->row) / 2);

            fclose(f);
        }

        if (abs(mv->col >> 1) > max_mv_c)
        {
            FILE *f = fopen("maxmv.stt", "a");
            fprintf(f, "New Mv Col Max %6d\n", (mv->col >> 1));
            max_mv_c = abs(mv->col >> 1);
            fclose(f);
        }
    }
#endif
    encode_mvcomponent(w, mv->row >> 1, &mvc[0]);
    encode_mvcomponent(w, mv->col >> 1, &mvc[1]);
#ifdef DEBUG_ENC_MV
    {
    int i;
    printf("%d (np): %d %d\n", enc_mvcount++,
           (mv->row >> 1)<<1, (mv->col >> 1)<<1);
    //for (i=0; i<MVPcount;++i) printf("  %d", (&mvc[0])->prob[i]);
    //printf("\n");
    //for (i=0; i<MVPcount;++i) printf("  %d", (&mvc[1])->prob[i]);
    //printf("\n");
    fflush(stdout);
    }
#endif
}


static unsigned int cost_mvcomponent(const int v, const struct mv_context *mvc)
{
    const vp8_prob *p = mvc->prob;
    const int x = v;   //v<0? -v:v;
    unsigned int cost;

    if (x < mvnum_short)
    {
        cost = vp8_cost_zero(p [mvpis_short])
               + vp8_treed_cost(vp8_small_mvtree, p + MVPshort, x, mvnum_short_bits);

        if (!x)
            return cost;
    }
    else
    {
        int i = 0;
        cost = vp8_cost_one(p [mvpis_short]);

        do
            cost += vp8_cost_bit(p [MVPbits + i], (x >> i) & 1);

        while (++i < mvnum_short_bits);

        i = mvlong_width - 1;  /* Skip bit 3, which is sometimes implicit */

        do
            cost += vp8_cost_bit(p [MVPbits + i], (x >> i) & 1);

        while (--i > mvnum_short_bits);

        if (x & ~((2<<mvnum_short_bits)-1))
            cost += vp8_cost_bit(p [MVPbits + mvnum_short_bits], (x >> mvnum_short_bits) & 1);
    }

    return cost;   // + vp8_cost_bit( p [MVPsign], v < 0);
}

void vp8_build_component_cost_table(int *mvcost[2], const MV_CONTEXT *mvc, int mvc_flag[2])
{
    int i = 1;   //-mv_max;
    unsigned int cost0 = 0;
    unsigned int cost1 = 0;

    vp8_clear_system_state();

    i = 1;

    if (mvc_flag[0])
    {
        mvcost [0] [0] = cost_mvcomponent(0, &mvc[0]);

        do
        {
            //mvcost [0] [i] = cost_mvcomponent( i, &mvc[0]);
            cost0 = cost_mvcomponent(i, &mvc[0]);

            mvcost [0] [i] = cost0 + vp8_cost_zero(mvc[0].prob[MVPsign]);
            mvcost [0] [-i] = cost0 + vp8_cost_one(mvc[0].prob[MVPsign]);
        }
        while (++i <= mv_max);
    }

    i = 1;

    if (mvc_flag[1])
    {
        mvcost [1] [0] = cost_mvcomponent(0, &mvc[1]);

        do
        {
            //mvcost [1] [i] = cost_mvcomponent( i, mvc[1]);
            cost1 = cost_mvcomponent(i, &mvc[1]);

            mvcost [1] [i] = cost1 + vp8_cost_zero(mvc[1].prob[MVPsign]);
            mvcost [1] [-i] = cost1 + vp8_cost_one(mvc[1].prob[MVPsign]);
        }
        while (++i <= mv_max);
    }
}


// Motion vector probability table update depends on benefit.
// Small correction allows for the fact that an update to an MV probability
// may have benefit in subsequent frames as well as the current one.

#define MV_PROB_UPDATE_CORRECTION   -1


__inline static void calc_prob(vp8_prob *p, const unsigned int ct[2])
{
    const unsigned int tot = ct[0] + ct[1];

    if (tot)
    {
        const vp8_prob x = ((ct[0] * 255) / tot) & -2;
        *p = x ? x : 1;
    }
}

static void update(
    vp8_writer *const w,
    const unsigned int ct[2],
    vp8_prob *const cur_p,
    const vp8_prob new_p,
    const vp8_prob update_p,
    int *updated
)
{
    const int cur_b = vp8_cost_branch(ct, *cur_p);
    const int new_b = vp8_cost_branch(ct, new_p);
    const int cost = 7 + MV_PROB_UPDATE_CORRECTION + ((vp8_cost_one(update_p) - vp8_cost_zero(update_p) + 128) >> 8);

    if (cur_b - new_b > cost)
    {
        *cur_p = new_p;
        vp8_write(w, 1, update_p);
        vp8_write_literal(w, new_p >> 1, 7);
        *updated = 1;

    }
    else
        vp8_write(w, 0, update_p);
}

static void write_component_probs(
    vp8_writer *const w,
    struct mv_context *cur_mvc,
    const struct mv_context *default_mvc_,
    const struct mv_context *update_mvc,
    const unsigned int events [MVvals],
    unsigned int rc,
    int *updated
)
{
    vp8_prob *Pcur = cur_mvc->prob;
    const vp8_prob *default_mvc = default_mvc_->prob;
    const vp8_prob *Pupdate = update_mvc->prob;
    unsigned int is_short_ct[2], sign_ct[2];

    unsigned int bit_ct [mvlong_width] [2];

    unsigned int short_ct  [mvnum_short];
    unsigned int short_bct [mvnum_short-1] [2];

    vp8_prob Pnew [MVPcount];

    (void) rc;
    vp8_copy_array(Pnew, default_mvc, MVPcount);

    vp8_zero(is_short_ct)
    vp8_zero(sign_ct)
    vp8_zero(bit_ct)
    vp8_zero(short_ct)
    vp8_zero(short_bct)


    //j=0
    {
        const int c = events [mv_max];

        is_short_ct [0] += c;    // Short vector
        short_ct [0] += c;       // Magnitude distribution
    }

    //j: 1 ~ mv_max (1023)
    {
        int j = 1;

        do
        {
            const int c1 = events [mv_max + j];  //positive
            const int c2 = events [mv_max - j];  //negative
            const int c  = c1 + c2;
            int a = j;

            sign_ct [0] += c1;
            sign_ct [1] += c2;

            if (a < mvnum_short)
            {
                is_short_ct [0] += c;     // Short vector
                short_ct [a] += c;       // Magnitude distribution
            }
            else
            {
                int k = mvlong_width - 1;
                is_short_ct [1] += c;     // Long vector

                /*  bit 3 not always encoded. */
                do
                    bit_ct [k] [(a >> k) & 1] += c;

                while (--k >= 0);
            }
        }
        while (++j <= mv_max);
    }

    /*
    {
        int j = -mv_max;
        do
        {

            const int c = events [mv_max + j];
            int a = j;

            if( j < 0)
            {
                sign_ct [1] += c;
                a = -j;
            }
            else if( j)
                sign_ct [0] += c;

            if( a < mvnum_short)
            {
                is_short_ct [0] += c;     // Short vector
                short_ct [a] += c;       // Magnitude distribution
            }
            else
            {
                int k = mvlong_width - 1;
                is_short_ct [1] += c;     // Long vector

                //  bit 3 not always encoded.

                do
                    bit_ct [k] [(a >> k) & 1] += c;
                while( --k >= 0);
            }
        } while( ++j <= mv_max);
    }
    */

    calc_prob(Pnew + mvpis_short, is_short_ct);

    calc_prob(Pnew + MVPsign, sign_ct);

    {
        vp8_prob p [mvnum_short - 1];    /* actually only need branch ct */
        int j = 0;

        vp8_tree_probs_from_distribution(
            mvnum_short, vp8_small_mvencodings, vp8_small_mvtree,
            p, short_bct, short_ct,
            256, 1
        );

        do
            calc_prob(Pnew + MVPshort + j, short_bct[j]);

        while (++j < mvnum_short - 1);
    }

    {
        int j = 0;

        do
            calc_prob(Pnew + MVPbits + j, bit_ct[j]);

        while (++j < mvlong_width);
    }

    update(w, is_short_ct, Pcur + mvpis_short, Pnew[mvpis_short], *Pupdate++, updated);

    update(w, sign_ct, Pcur + MVPsign, Pnew[MVPsign], *Pupdate++, updated);

    {
        const vp8_prob *const new_p = Pnew + MVPshort;
        vp8_prob *const cur_p = Pcur + MVPshort;

        int j = 0;

        do

            update(w, short_bct[j], cur_p + j, new_p[j], *Pupdate++, updated);

        while (++j < mvnum_short - 1);
    }

    {
        const vp8_prob *const new_p = Pnew + MVPbits;
        vp8_prob *const cur_p = Pcur + MVPbits;

        int j = 0;

        do

            update(w, bit_ct[j], cur_p + j, new_p[j], *Pupdate++, updated);

        while (++j < mvlong_width);
    }
}

void vp8_write_mvprobs(VP8_COMP *cpi)
{
    vp8_writer *const w  = & cpi->bc;
    MV_CONTEXT *mvc = cpi->common.fc.mvc;
    int flags[2] = {0, 0};
#ifdef ENTROPY_STATS
    active_section = 4;
#endif
    write_component_probs(
        w, &mvc[0], &vp8_default_mv_context[0], &vp8_mv_update_probs[0], cpi->MVcount[0], 0, &flags[0]
    );
    write_component_probs(
        w, &mvc[1], &vp8_default_mv_context[1], &vp8_mv_update_probs[1], cpi->MVcount[1], 1, &flags[1]
    );

    if (flags[0] || flags[1])
        vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cpi->common.fc.mvc, flags);

#ifdef ENTROPY_STATS
    active_section = 5;
#endif
}

#if CONFIG_HIGH_PRECISION_MV

static void encode_mvcomponent_hp(
    vp8_writer *const w,
    const int v,
    const struct mv_context_hp *mvc
)
{
    const vp8_prob *p = mvc->prob;
    const int x = v < 0 ? -v : v;

    if (x < mvnum_short_hp)     // Small
    {
        vp8_write(w, 0, p [mvpis_short_hp]);
        vp8_treed_write(w, vp8_small_mvtree_hp, p + MVPshort_hp, x,
                        mvnum_short_bits_hp);
        if (!x)
            return;         // no sign bit
    }
    else                    // Large
    {
        int i = 0;

        vp8_write(w, 1, p [mvpis_short_hp]);

        do
            vp8_write(w, (x >> i) & 1, p [MVPbits_hp + i]);

        while (++i < mvnum_short_bits_hp);

        i = mvlong_width_hp - 1;  /* Skip bit 3, which is sometimes implicit */

        do
            vp8_write(w, (x >> i) & 1, p [MVPbits_hp + i]);

        while (--i > mvnum_short_bits_hp);

        if (x & ~((2<<mvnum_short_bits_hp)-1))
            vp8_write(w, (x >> mvnum_short_bits_hp) & 1,
                      p [MVPbits_hp + mvnum_short_bits_hp]);
    }

    vp8_write(w, v < 0, p [MVPsign_hp]);
}
#if 0
static int max_mv_r = 0;
static int max_mv_c = 0;
#endif
void vp8_encode_motion_vector_hp(vp8_writer *w, const MV *mv,
                                 const MV_CONTEXT_HP *mvc)
{

#if 0
    {
        if (abs(mv->row >> 1) > max_mv_r)
        {
            FILE *f = fopen("maxmv.stt", "a");
            max_mv_r = abs(mv->row >> 1);
            fprintf(f, "New Mv Row Max %6d\n", (mv->row >> 1));

            if ((abs(mv->row) / 2) != max_mv_r)
                fprintf(f, "MV Row conversion error %6d\n", abs(mv->row) / 2);

            fclose(f);
        }

        if (abs(mv->col >> 1) > max_mv_c)
        {
            FILE *f = fopen("maxmv.stt", "a");
            fprintf(f, "New Mv Col Max %6d\n", (mv->col >> 1));
            max_mv_c = abs(mv->col >> 1);
            fclose(f);
        }
    }
#endif
    encode_mvcomponent_hp(w, mv->row, &mvc[0]);
    encode_mvcomponent_hp(w, mv->col, &mvc[1]);
#ifdef DEBUG_ENC_MV
    {
    int i;
    printf("%d (hp): %d %d\n", enc_mvcount++, mv->row, mv->col);
    //for (i=0; i<MVPcount_hp;++i) printf("  %d", (&mvc[0])->prob[i]);
    //printf("\n");
    //for (i=0; i<MVPcount_hp;++i) printf("  %d", (&mvc[1])->prob[i]);
    //printf("\n");
    fflush(stdout);
    }
#endif
}


static unsigned int cost_mvcomponent_hp(const int v,
                                        const struct mv_context_hp *mvc)
{
    const vp8_prob *p = mvc->prob;
    const int x = v;   //v<0? -v:v;
    unsigned int cost;

    if (x < mvnum_short_hp)
    {
        cost = vp8_cost_zero(p [mvpis_short_hp])
               + vp8_treed_cost(vp8_small_mvtree_hp, p + MVPshort_hp, x,
                                mvnum_short_bits_hp);

        if (!x)
            return cost;
    }
    else
    {
        int i = 0;
        cost = vp8_cost_one(p [mvpis_short_hp]);

        do
            cost += vp8_cost_bit(p [MVPbits_hp + i], (x >> i) & 1);

        while (++i < mvnum_short_bits_hp);

        i = mvlong_width_hp - 1;  /* Skip bit 3, which is sometimes implicit */

        do
            cost += vp8_cost_bit(p [MVPbits_hp + i], (x >> i) & 1);

        while (--i > mvnum_short_bits_hp);

        if (x & ~((2<<mvnum_short_bits_hp)-1))
            cost += vp8_cost_bit(p [MVPbits_hp + mvnum_short_bits_hp],
                                 (x >> mvnum_short_bits_hp) & 1);
    }

    return cost;   // + vp8_cost_bit( p [MVPsign], v < 0);
}

void vp8_build_component_cost_table_hp(int *mvcost[2],
                                       const MV_CONTEXT_HP *mvc,
                                       int mvc_flag[2])
{
    int i = 1;   //-mv_max;
    unsigned int cost0 = 0;
    unsigned int cost1 = 0;

    vp8_clear_system_state();

    i = 1;

    if (mvc_flag[0])
    {
        mvcost [0] [0] = cost_mvcomponent_hp(0, &mvc[0]);

        do
        {
            //mvcost [0] [i] = cost_mvcomponent( i, &mvc[0]);
            cost0 = cost_mvcomponent_hp(i, &mvc[0]);

            mvcost [0] [i] = cost0 + vp8_cost_zero(mvc[0].prob[MVPsign_hp]);
            mvcost [0] [-i] = cost0 + vp8_cost_one(mvc[0].prob[MVPsign_hp]);
        }
        while (++i <= mv_max_hp);
    }

    i = 1;

    if (mvc_flag[1])
    {
        mvcost [1] [0] = cost_mvcomponent_hp(0, &mvc[1]);

        do
        {
            //mvcost [1] [i] = cost_mvcomponent( i, mvc[1]);
            cost1 = cost_mvcomponent_hp(i, &mvc[1]);

            mvcost [1] [i] = cost1 + vp8_cost_zero(mvc[1].prob[MVPsign_hp]);
            mvcost [1] [-i] = cost1 + vp8_cost_one(mvc[1].prob[MVPsign_hp]);
        }
        while (++i <= mv_max_hp);
    }
}


static void write_component_probs_hp(
    vp8_writer *const w,
    struct mv_context_hp *cur_mvc,
    const struct mv_context_hp *default_mvc_,
    const struct mv_context_hp *update_mvc,
    const unsigned int events [MVvals_hp],
    unsigned int rc,
    int *updated
)
{
    vp8_prob *Pcur = cur_mvc->prob;
    const vp8_prob *default_mvc = default_mvc_->prob;
    const vp8_prob *Pupdate = update_mvc->prob;
    unsigned int is_short_ct[2], sign_ct[2];

    unsigned int bit_ct [mvlong_width_hp] [2];

    unsigned int short_ct  [mvnum_short_hp];
    unsigned int short_bct [mvnum_short_hp-1] [2];

    vp8_prob Pnew [MVPcount_hp];

    (void) rc;
    vp8_copy_array(Pnew, default_mvc, MVPcount_hp);

    vp8_zero(is_short_ct)
    vp8_zero(sign_ct)
    vp8_zero(bit_ct)
    vp8_zero(short_ct)
    vp8_zero(short_bct)


    //j=0
    {
        const int c = events [mv_max_hp];

        is_short_ct [0] += c;    // Short vector
        short_ct [0] += c;       // Magnitude distribution
    }

    //j: 1 ~ mv_max (1023)
    {
        int j = 1;

        do
        {
            const int c1 = events [mv_max_hp + j];  //positive
            const int c2 = events [mv_max_hp - j];  //negative
            const int c  = c1 + c2;
            int a = j;

            sign_ct [0] += c1;
            sign_ct [1] += c2;

            if (a < mvnum_short_hp)
            {
                is_short_ct [0] += c;     // Short vector
                short_ct [a] += c;       // Magnitude distribution
            }
            else
            {
                int k = mvlong_width_hp - 1;
                is_short_ct [1] += c;     // Long vector

                /*  bit 3 not always encoded. */
                do
                    bit_ct [k] [(a >> k) & 1] += c;

                while (--k >= 0);
            }
        }
        while (++j <= mv_max_hp);
    }

    calc_prob(Pnew + mvpis_short_hp, is_short_ct);

    calc_prob(Pnew + MVPsign_hp, sign_ct);

    {
        vp8_prob p [mvnum_short_hp - 1];    /* actually only need branch ct */
        int j = 0;

        vp8_tree_probs_from_distribution(
            mvnum_short_hp, vp8_small_mvencodings_hp, vp8_small_mvtree_hp,
            p, short_bct, short_ct,
            256, 1
        );

        do
            calc_prob(Pnew + MVPshort_hp + j, short_bct[j]);

        while (++j < mvnum_short_hp - 1);
    }

    {
        int j = 0;

        do
            calc_prob(Pnew + MVPbits_hp + j, bit_ct[j]);

        while (++j < mvlong_width_hp);
    }

    update(w, is_short_ct, Pcur + mvpis_short_hp, Pnew[mvpis_short_hp],
           *Pupdate++, updated);

    update(w, sign_ct, Pcur + MVPsign_hp, Pnew[MVPsign_hp], *Pupdate++,
           updated);

    {
        const vp8_prob *const new_p = Pnew + MVPshort_hp;
        vp8_prob *const cur_p = Pcur + MVPshort_hp;

        int j = 0;

        do

            update(w, short_bct[j], cur_p + j, new_p[j], *Pupdate++, updated);

        while (++j < mvnum_short_hp - 1);
    }

    {
        const vp8_prob *const new_p = Pnew + MVPbits_hp;
        vp8_prob *const cur_p = Pcur + MVPbits_hp;

        int j = 0;

        do

            update(w, bit_ct[j], cur_p + j, new_p[j], *Pupdate++, updated);

        while (++j < mvlong_width_hp);
    }
}

void vp8_write_mvprobs_hp(VP8_COMP *cpi)
{
    vp8_writer *const w  = & cpi->bc;
    MV_CONTEXT_HP *mvc = cpi->common.fc.mvc_hp;
    int flags[2] = {0, 0};
#ifdef ENTROPY_STATS
    active_section = 4;
#endif
    write_component_probs_hp(
        w, &mvc[0], &vp8_default_mv_context_hp[0], &vp8_mv_update_probs_hp[0],
        cpi->MVcount_hp[0], 0, &flags[0]
    );
    write_component_probs_hp(
        w, &mvc[1], &vp8_default_mv_context_hp[1], &vp8_mv_update_probs_hp[1],
        cpi->MVcount_hp[1], 1, &flags[1]
    );

    if (flags[0] || flags[1])
        vp8_build_component_cost_table_hp(cpi->mb.mvcost_hp,
                                          (const MV_CONTEXT_HP *)
                                          cpi->common.fc.mvc_hp, flags);

#ifdef ENTROPY_STATS
    active_section = 5;
#endif
}
#endif  /* CONFIG_HIGH_PRECISION_MV */