xref: /aosp_15_r20/external/libaom/tools/aom_entropy_optimizer.c (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker // This tool is a gadget for offline probability training.
13*77c1e3ccSAndroid Build Coastguard Worker // A binary executable aom_entropy_optimizer will be generated in tools/. It
14*77c1e3ccSAndroid Build Coastguard Worker // parses a binary file consisting of counts written in the format of
15*77c1e3ccSAndroid Build Coastguard Worker // FRAME_COUNTS in entropymode.h, and computes optimized probability tables
16*77c1e3ccSAndroid Build Coastguard Worker // and CDF tables, which will be written to a new c file optimized_probs.c
17*77c1e3ccSAndroid Build Coastguard Worker // according to format in the codebase.
18*77c1e3ccSAndroid Build Coastguard Worker //
19*77c1e3ccSAndroid Build Coastguard Worker // Command line: ./aom_entropy_optimizer [directory of the count file]
20*77c1e3ccSAndroid Build Coastguard Worker //
21*77c1e3ccSAndroid Build Coastguard Worker // The input file can either be generated by encoding a single clip by
22*77c1e3ccSAndroid Build Coastguard Worker // turning on entropy_stats experiment, or be collected at a larger scale at
23*77c1e3ccSAndroid Build Coastguard Worker // which a python script which will be provided soon can be used to aggregate
24*77c1e3ccSAndroid Build Coastguard Worker // multiple stats output.
25*77c1e3ccSAndroid Build Coastguard Worker 
26*77c1e3ccSAndroid Build Coastguard Worker #include <assert.h>
27*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
28*77c1e3ccSAndroid Build Coastguard Worker 
29*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/encoder.h"
32*77c1e3ccSAndroid Build Coastguard Worker 
33*77c1e3ccSAndroid Build Coastguard Worker #define SPACES_PER_TAB 2
34*77c1e3ccSAndroid Build Coastguard Worker #define CDF_MAX_SIZE 16
35*77c1e3ccSAndroid Build Coastguard Worker 
36*77c1e3ccSAndroid Build Coastguard Worker typedef unsigned int aom_count_type;
37*77c1e3ccSAndroid Build Coastguard Worker // A log file recording parsed counts
38*77c1e3ccSAndroid Build Coastguard Worker static FILE *logfile;  // TODO(yuec): make it a command line option
39*77c1e3ccSAndroid Build Coastguard Worker 
counts_to_cdf(const aom_count_type * counts,aom_cdf_prob * cdf,int modes)40*77c1e3ccSAndroid Build Coastguard Worker static void counts_to_cdf(const aom_count_type *counts, aom_cdf_prob *cdf,
41*77c1e3ccSAndroid Build Coastguard Worker                           int modes) {
42*77c1e3ccSAndroid Build Coastguard Worker   int64_t csum[CDF_MAX_SIZE];
43*77c1e3ccSAndroid Build Coastguard Worker   assert(modes <= CDF_MAX_SIZE);
44*77c1e3ccSAndroid Build Coastguard Worker 
45*77c1e3ccSAndroid Build Coastguard Worker   csum[0] = counts[0] + 1;
46*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 1; i < modes; ++i) csum[i] = counts[i] + 1 + csum[i - 1];
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < modes; ++i) fprintf(logfile, "%d ", counts[i]);
49*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "\n");
50*77c1e3ccSAndroid Build Coastguard Worker 
51*77c1e3ccSAndroid Build Coastguard Worker   int64_t sum = csum[modes - 1];
52*77c1e3ccSAndroid Build Coastguard Worker   const int64_t round_shift = sum >> 1;
53*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < modes; ++i) {
54*77c1e3ccSAndroid Build Coastguard Worker     cdf[i] = (csum[i] * CDF_PROB_TOP + round_shift) / sum;
55*77c1e3ccSAndroid Build Coastguard Worker     cdf[i] = AOMMIN(cdf[i], CDF_PROB_TOP - (modes - 1 + i) * 4);
56*77c1e3ccSAndroid Build Coastguard Worker     cdf[i] = (i == 0) ? AOMMAX(cdf[i], 4) : AOMMAX(cdf[i], cdf[i - 1] + 4);
57*77c1e3ccSAndroid Build Coastguard Worker   }
58*77c1e3ccSAndroid Build Coastguard Worker }
59*77c1e3ccSAndroid Build Coastguard Worker 
parse_counts_for_cdf_opt(aom_count_type ** ct_ptr,FILE * const probsfile,int tabs,int dim_of_cts,int * cts_each_dim)60*77c1e3ccSAndroid Build Coastguard Worker static int parse_counts_for_cdf_opt(aom_count_type **ct_ptr,
61*77c1e3ccSAndroid Build Coastguard Worker                                     FILE *const probsfile, int tabs,
62*77c1e3ccSAndroid Build Coastguard Worker                                     int dim_of_cts, int *cts_each_dim) {
63*77c1e3ccSAndroid Build Coastguard Worker   if (dim_of_cts < 1) {
64*77c1e3ccSAndroid Build Coastguard Worker     fprintf(stderr, "The dimension of a counts vector should be at least 1!\n");
65*77c1e3ccSAndroid Build Coastguard Worker     return 1;
66*77c1e3ccSAndroid Build Coastguard Worker   }
67*77c1e3ccSAndroid Build Coastguard Worker   const int total_modes = cts_each_dim[0];
68*77c1e3ccSAndroid Build Coastguard Worker   if (dim_of_cts == 1) {
69*77c1e3ccSAndroid Build Coastguard Worker     assert(total_modes <= CDF_MAX_SIZE);
70*77c1e3ccSAndroid Build Coastguard Worker     aom_cdf_prob cdfs[CDF_MAX_SIZE];
71*77c1e3ccSAndroid Build Coastguard Worker     aom_count_type *counts1d = *ct_ptr;
72*77c1e3ccSAndroid Build Coastguard Worker 
73*77c1e3ccSAndroid Build Coastguard Worker     counts_to_cdf(counts1d, cdfs, total_modes);
74*77c1e3ccSAndroid Build Coastguard Worker     (*ct_ptr) += total_modes;
75*77c1e3ccSAndroid Build Coastguard Worker 
76*77c1e3ccSAndroid Build Coastguard Worker     if (tabs > 0) fprintf(probsfile, "%*c", tabs * SPACES_PER_TAB, ' ');
77*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "AOM_CDF%d(", total_modes);
78*77c1e3ccSAndroid Build Coastguard Worker     for (int k = 0; k < total_modes - 1; ++k) {
79*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, "%d", cdfs[k]);
80*77c1e3ccSAndroid Build Coastguard Worker       if (k < total_modes - 2) fprintf(probsfile, ", ");
81*77c1e3ccSAndroid Build Coastguard Worker     }
82*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, ")");
83*77c1e3ccSAndroid Build Coastguard Worker   } else {
84*77c1e3ccSAndroid Build Coastguard Worker     for (int k = 0; k < total_modes; ++k) {
85*77c1e3ccSAndroid Build Coastguard Worker       int tabs_next_level;
86*77c1e3ccSAndroid Build Coastguard Worker 
87*77c1e3ccSAndroid Build Coastguard Worker       if (dim_of_cts == 2)
88*77c1e3ccSAndroid Build Coastguard Worker         fprintf(probsfile, "%*c{ ", tabs * SPACES_PER_TAB, ' ');
89*77c1e3ccSAndroid Build Coastguard Worker       else
90*77c1e3ccSAndroid Build Coastguard Worker         fprintf(probsfile, "%*c{\n", tabs * SPACES_PER_TAB, ' ');
91*77c1e3ccSAndroid Build Coastguard Worker       tabs_next_level = dim_of_cts == 2 ? 0 : tabs + 1;
92*77c1e3ccSAndroid Build Coastguard Worker 
93*77c1e3ccSAndroid Build Coastguard Worker       if (parse_counts_for_cdf_opt(ct_ptr, probsfile, tabs_next_level,
94*77c1e3ccSAndroid Build Coastguard Worker                                    dim_of_cts - 1, cts_each_dim + 1)) {
95*77c1e3ccSAndroid Build Coastguard Worker         return 1;
96*77c1e3ccSAndroid Build Coastguard Worker       }
97*77c1e3ccSAndroid Build Coastguard Worker 
98*77c1e3ccSAndroid Build Coastguard Worker       if (dim_of_cts == 2) {
99*77c1e3ccSAndroid Build Coastguard Worker         if (k == total_modes - 1)
100*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, " }\n");
101*77c1e3ccSAndroid Build Coastguard Worker         else
102*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, " },\n");
103*77c1e3ccSAndroid Build Coastguard Worker       } else {
104*77c1e3ccSAndroid Build Coastguard Worker         if (k == total_modes - 1)
105*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, "%*c}\n", tabs * SPACES_PER_TAB, ' ');
106*77c1e3ccSAndroid Build Coastguard Worker         else
107*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
108*77c1e3ccSAndroid Build Coastguard Worker       }
109*77c1e3ccSAndroid Build Coastguard Worker     }
110*77c1e3ccSAndroid Build Coastguard Worker   }
111*77c1e3ccSAndroid Build Coastguard Worker   return 0;
112*77c1e3ccSAndroid Build Coastguard Worker }
113*77c1e3ccSAndroid Build Coastguard Worker 
optimize_cdf_table(aom_count_type * counts,FILE * const probsfile,int dim_of_cts,int * cts_each_dim,char * prefix)114*77c1e3ccSAndroid Build Coastguard Worker static void optimize_cdf_table(aom_count_type *counts, FILE *const probsfile,
115*77c1e3ccSAndroid Build Coastguard Worker                                int dim_of_cts, int *cts_each_dim,
116*77c1e3ccSAndroid Build Coastguard Worker                                char *prefix) {
117*77c1e3ccSAndroid Build Coastguard Worker   aom_count_type *ct_ptr = counts;
118*77c1e3ccSAndroid Build Coastguard Worker 
119*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%s = {\n", prefix);
120*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "%s\n", prefix);
121*77c1e3ccSAndroid Build Coastguard Worker   if (parse_counts_for_cdf_opt(&ct_ptr, probsfile, 1, dim_of_cts,
122*77c1e3ccSAndroid Build Coastguard Worker                                cts_each_dim)) {
123*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "Optimizer failed!\n");
124*77c1e3ccSAndroid Build Coastguard Worker   }
125*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "};\n\n");
126*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "============================\n");
127*77c1e3ccSAndroid Build Coastguard Worker }
128*77c1e3ccSAndroid Build Coastguard Worker 
optimize_uv_mode(aom_count_type * counts,FILE * const probsfile,int dim_of_cts,int * cts_each_dim,char * prefix)129*77c1e3ccSAndroid Build Coastguard Worker static void optimize_uv_mode(aom_count_type *counts, FILE *const probsfile,
130*77c1e3ccSAndroid Build Coastguard Worker                              int dim_of_cts, int *cts_each_dim, char *prefix) {
131*77c1e3ccSAndroid Build Coastguard Worker   aom_count_type *ct_ptr = counts;
132*77c1e3ccSAndroid Build Coastguard Worker 
133*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%s = {\n", prefix);
134*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%*c{\n", SPACES_PER_TAB, ' ');
135*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "%s\n", prefix);
136*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = UV_INTRA_MODES - 1;
137*77c1e3ccSAndroid Build Coastguard Worker   for (int k = 0; k < cts_each_dim[1]; ++k) {
138*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "%*c{ ", 2 * SPACES_PER_TAB, ' ');
139*77c1e3ccSAndroid Build Coastguard Worker     parse_counts_for_cdf_opt(&ct_ptr, probsfile, 0, dim_of_cts - 2,
140*77c1e3ccSAndroid Build Coastguard Worker                              cts_each_dim + 2);
141*77c1e3ccSAndroid Build Coastguard Worker     if (k + 1 == cts_each_dim[1]) {
142*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, " }\n");
143*77c1e3ccSAndroid Build Coastguard Worker     } else {
144*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, " },\n");
145*77c1e3ccSAndroid Build Coastguard Worker     }
146*77c1e3ccSAndroid Build Coastguard Worker     ++ct_ptr;
147*77c1e3ccSAndroid Build Coastguard Worker   }
148*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%*c},\n", SPACES_PER_TAB, ' ');
149*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%*c{\n", SPACES_PER_TAB, ' ');
150*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = UV_INTRA_MODES;
151*77c1e3ccSAndroid Build Coastguard Worker   parse_counts_for_cdf_opt(&ct_ptr, probsfile, 2, dim_of_cts - 1,
152*77c1e3ccSAndroid Build Coastguard Worker                            cts_each_dim + 1);
153*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%*c}\n", SPACES_PER_TAB, ' ');
154*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "};\n\n");
155*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "============================\n");
156*77c1e3ccSAndroid Build Coastguard Worker }
157*77c1e3ccSAndroid Build Coastguard Worker 
optimize_cdf_table_var_modes_2d(aom_count_type * counts,FILE * const probsfile,int dim_of_cts,int * cts_each_dim,int * modes_each_ctx,char * prefix)158*77c1e3ccSAndroid Build Coastguard Worker static void optimize_cdf_table_var_modes_2d(aom_count_type *counts,
159*77c1e3ccSAndroid Build Coastguard Worker                                             FILE *const probsfile,
160*77c1e3ccSAndroid Build Coastguard Worker                                             int dim_of_cts, int *cts_each_dim,
161*77c1e3ccSAndroid Build Coastguard Worker                                             int *modes_each_ctx, char *prefix) {
162*77c1e3ccSAndroid Build Coastguard Worker   aom_count_type *ct_ptr = counts;
163*77c1e3ccSAndroid Build Coastguard Worker 
164*77c1e3ccSAndroid Build Coastguard Worker   assert(dim_of_cts == 2);
165*77c1e3ccSAndroid Build Coastguard Worker   (void)dim_of_cts;
166*77c1e3ccSAndroid Build Coastguard Worker 
167*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%s = {\n", prefix);
168*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "%s\n", prefix);
169*77c1e3ccSAndroid Build Coastguard Worker 
170*77c1e3ccSAndroid Build Coastguard Worker   for (int d0_idx = 0; d0_idx < cts_each_dim[0]; ++d0_idx) {
171*77c1e3ccSAndroid Build Coastguard Worker     int num_of_modes = modes_each_ctx[d0_idx];
172*77c1e3ccSAndroid Build Coastguard Worker 
173*77c1e3ccSAndroid Build Coastguard Worker     if (num_of_modes > 0) {
174*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, "%*c{ ", SPACES_PER_TAB, ' ');
175*77c1e3ccSAndroid Build Coastguard Worker       parse_counts_for_cdf_opt(&ct_ptr, probsfile, 0, 1, &num_of_modes);
176*77c1e3ccSAndroid Build Coastguard Worker       ct_ptr += cts_each_dim[1] - num_of_modes;
177*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, " },\n");
178*77c1e3ccSAndroid Build Coastguard Worker     } else {
179*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, "%*c{ 0 },\n", SPACES_PER_TAB, ' ');
180*77c1e3ccSAndroid Build Coastguard Worker       fprintf(logfile, "dummy cdf, no need to optimize\n");
181*77c1e3ccSAndroid Build Coastguard Worker       ct_ptr += cts_each_dim[1];
182*77c1e3ccSAndroid Build Coastguard Worker     }
183*77c1e3ccSAndroid Build Coastguard Worker   }
184*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "};\n\n");
185*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "============================\n");
186*77c1e3ccSAndroid Build Coastguard Worker }
187*77c1e3ccSAndroid Build Coastguard Worker 
optimize_cdf_table_var_modes_3d(aom_count_type * counts,FILE * const probsfile,int dim_of_cts,int * cts_each_dim,int * modes_each_ctx,char * prefix)188*77c1e3ccSAndroid Build Coastguard Worker static void optimize_cdf_table_var_modes_3d(aom_count_type *counts,
189*77c1e3ccSAndroid Build Coastguard Worker                                             FILE *const probsfile,
190*77c1e3ccSAndroid Build Coastguard Worker                                             int dim_of_cts, int *cts_each_dim,
191*77c1e3ccSAndroid Build Coastguard Worker                                             int *modes_each_ctx, char *prefix) {
192*77c1e3ccSAndroid Build Coastguard Worker   aom_count_type *ct_ptr = counts;
193*77c1e3ccSAndroid Build Coastguard Worker 
194*77c1e3ccSAndroid Build Coastguard Worker   assert(dim_of_cts == 3);
195*77c1e3ccSAndroid Build Coastguard Worker   (void)dim_of_cts;
196*77c1e3ccSAndroid Build Coastguard Worker 
197*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%s = {\n", prefix);
198*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "%s\n", prefix);
199*77c1e3ccSAndroid Build Coastguard Worker 
200*77c1e3ccSAndroid Build Coastguard Worker   for (int d0_idx = 0; d0_idx < cts_each_dim[0]; ++d0_idx) {
201*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "%*c{\n", SPACES_PER_TAB, ' ');
202*77c1e3ccSAndroid Build Coastguard Worker     for (int d1_idx = 0; d1_idx < cts_each_dim[1]; ++d1_idx) {
203*77c1e3ccSAndroid Build Coastguard Worker       int num_of_modes = modes_each_ctx[d0_idx];
204*77c1e3ccSAndroid Build Coastguard Worker 
205*77c1e3ccSAndroid Build Coastguard Worker       if (num_of_modes > 0) {
206*77c1e3ccSAndroid Build Coastguard Worker         fprintf(probsfile, "%*c{ ", 2 * SPACES_PER_TAB, ' ');
207*77c1e3ccSAndroid Build Coastguard Worker         parse_counts_for_cdf_opt(&ct_ptr, probsfile, 0, 1, &num_of_modes);
208*77c1e3ccSAndroid Build Coastguard Worker         ct_ptr += cts_each_dim[2] - num_of_modes;
209*77c1e3ccSAndroid Build Coastguard Worker         fprintf(probsfile, " },\n");
210*77c1e3ccSAndroid Build Coastguard Worker       } else {
211*77c1e3ccSAndroid Build Coastguard Worker         fprintf(probsfile, "%*c{ 0 },\n", 2 * SPACES_PER_TAB, ' ');
212*77c1e3ccSAndroid Build Coastguard Worker         fprintf(logfile, "dummy cdf, no need to optimize\n");
213*77c1e3ccSAndroid Build Coastguard Worker         ct_ptr += cts_each_dim[2];
214*77c1e3ccSAndroid Build Coastguard Worker       }
215*77c1e3ccSAndroid Build Coastguard Worker     }
216*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "%*c},\n", SPACES_PER_TAB, ' ');
217*77c1e3ccSAndroid Build Coastguard Worker   }
218*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "};\n\n");
219*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "============================\n");
220*77c1e3ccSAndroid Build Coastguard Worker }
221*77c1e3ccSAndroid Build Coastguard Worker 
optimize_cdf_table_var_modes_4d(aom_count_type * counts,FILE * const probsfile,int dim_of_cts,int * cts_each_dim,int * modes_each_ctx,char * prefix)222*77c1e3ccSAndroid Build Coastguard Worker static void optimize_cdf_table_var_modes_4d(aom_count_type *counts,
223*77c1e3ccSAndroid Build Coastguard Worker                                             FILE *const probsfile,
224*77c1e3ccSAndroid Build Coastguard Worker                                             int dim_of_cts, int *cts_each_dim,
225*77c1e3ccSAndroid Build Coastguard Worker                                             int *modes_each_ctx, char *prefix) {
226*77c1e3ccSAndroid Build Coastguard Worker   aom_count_type *ct_ptr = counts;
227*77c1e3ccSAndroid Build Coastguard Worker 
228*77c1e3ccSAndroid Build Coastguard Worker   assert(dim_of_cts == 4);
229*77c1e3ccSAndroid Build Coastguard Worker   (void)dim_of_cts;
230*77c1e3ccSAndroid Build Coastguard Worker 
231*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "%s = {\n", prefix);
232*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "%s\n", prefix);
233*77c1e3ccSAndroid Build Coastguard Worker 
234*77c1e3ccSAndroid Build Coastguard Worker   for (int d0_idx = 0; d0_idx < cts_each_dim[0]; ++d0_idx) {
235*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "%*c{\n", SPACES_PER_TAB, ' ');
236*77c1e3ccSAndroid Build Coastguard Worker     for (int d1_idx = 0; d1_idx < cts_each_dim[1]; ++d1_idx) {
237*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, "%*c{\n", 2 * SPACES_PER_TAB, ' ');
238*77c1e3ccSAndroid Build Coastguard Worker       for (int d2_idx = 0; d2_idx < cts_each_dim[2]; ++d2_idx) {
239*77c1e3ccSAndroid Build Coastguard Worker         int num_of_modes = modes_each_ctx[d0_idx];
240*77c1e3ccSAndroid Build Coastguard Worker 
241*77c1e3ccSAndroid Build Coastguard Worker         if (num_of_modes > 0) {
242*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, "%*c{ ", 3 * SPACES_PER_TAB, ' ');
243*77c1e3ccSAndroid Build Coastguard Worker           parse_counts_for_cdf_opt(&ct_ptr, probsfile, 0, 1, &num_of_modes);
244*77c1e3ccSAndroid Build Coastguard Worker           ct_ptr += cts_each_dim[3] - num_of_modes;
245*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, " },\n");
246*77c1e3ccSAndroid Build Coastguard Worker         } else {
247*77c1e3ccSAndroid Build Coastguard Worker           fprintf(probsfile, "%*c{ 0 },\n", 3 * SPACES_PER_TAB, ' ');
248*77c1e3ccSAndroid Build Coastguard Worker           fprintf(logfile, "dummy cdf, no need to optimize\n");
249*77c1e3ccSAndroid Build Coastguard Worker           ct_ptr += cts_each_dim[3];
250*77c1e3ccSAndroid Build Coastguard Worker         }
251*77c1e3ccSAndroid Build Coastguard Worker       }
252*77c1e3ccSAndroid Build Coastguard Worker       fprintf(probsfile, "%*c},\n", 2 * SPACES_PER_TAB, ' ');
253*77c1e3ccSAndroid Build Coastguard Worker     }
254*77c1e3ccSAndroid Build Coastguard Worker     fprintf(probsfile, "%*c},\n", SPACES_PER_TAB, ' ');
255*77c1e3ccSAndroid Build Coastguard Worker   }
256*77c1e3ccSAndroid Build Coastguard Worker   fprintf(probsfile, "};\n\n");
257*77c1e3ccSAndroid Build Coastguard Worker   fprintf(logfile, "============================\n");
258*77c1e3ccSAndroid Build Coastguard Worker }
259*77c1e3ccSAndroid Build Coastguard Worker 
main(int argc,const char ** argv)260*77c1e3ccSAndroid Build Coastguard Worker int main(int argc, const char **argv) {
261*77c1e3ccSAndroid Build Coastguard Worker   if (argc < 2) {
262*77c1e3ccSAndroid Build Coastguard Worker     fprintf(stderr, "Please specify the input stats file!\n");
263*77c1e3ccSAndroid Build Coastguard Worker     exit(EXIT_FAILURE);
264*77c1e3ccSAndroid Build Coastguard Worker   }
265*77c1e3ccSAndroid Build Coastguard Worker 
266*77c1e3ccSAndroid Build Coastguard Worker   FILE *const statsfile = fopen(argv[1], "rb");
267*77c1e3ccSAndroid Build Coastguard Worker   if (statsfile == NULL) {
268*77c1e3ccSAndroid Build Coastguard Worker     fprintf(stderr, "Failed to open input file!\n");
269*77c1e3ccSAndroid Build Coastguard Worker     exit(EXIT_FAILURE);
270*77c1e3ccSAndroid Build Coastguard Worker   }
271*77c1e3ccSAndroid Build Coastguard Worker 
272*77c1e3ccSAndroid Build Coastguard Worker   FRAME_COUNTS fc;
273*77c1e3ccSAndroid Build Coastguard Worker   const size_t bytes = fread(&fc, sizeof(FRAME_COUNTS), 1, statsfile);
274*77c1e3ccSAndroid Build Coastguard Worker   if (!bytes) {
275*77c1e3ccSAndroid Build Coastguard Worker     fclose(statsfile);
276*77c1e3ccSAndroid Build Coastguard Worker     return 1;
277*77c1e3ccSAndroid Build Coastguard Worker   }
278*77c1e3ccSAndroid Build Coastguard Worker 
279*77c1e3ccSAndroid Build Coastguard Worker   FILE *const probsfile = fopen("optimized_probs.c", "w");
280*77c1e3ccSAndroid Build Coastguard Worker   if (probsfile == NULL) {
281*77c1e3ccSAndroid Build Coastguard Worker     fprintf(stderr,
282*77c1e3ccSAndroid Build Coastguard Worker             "Failed to create output file for optimized entropy tables!\n");
283*77c1e3ccSAndroid Build Coastguard Worker     exit(EXIT_FAILURE);
284*77c1e3ccSAndroid Build Coastguard Worker   }
285*77c1e3ccSAndroid Build Coastguard Worker 
286*77c1e3ccSAndroid Build Coastguard Worker   logfile = fopen("aom_entropy_optimizer_parsed_counts.log", "w");
287*77c1e3ccSAndroid Build Coastguard Worker   if (logfile == NULL) {
288*77c1e3ccSAndroid Build Coastguard Worker     fprintf(stderr, "Failed to create log file for parsed counts!\n");
289*77c1e3ccSAndroid Build Coastguard Worker     exit(EXIT_FAILURE);
290*77c1e3ccSAndroid Build Coastguard Worker   }
291*77c1e3ccSAndroid Build Coastguard Worker 
292*77c1e3ccSAndroid Build Coastguard Worker   int cts_each_dim[10];
293*77c1e3ccSAndroid Build Coastguard Worker 
294*77c1e3ccSAndroid Build Coastguard Worker   /* Intra mode (keyframe luma) */
295*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = KF_MODE_CONTEXTS;
296*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = KF_MODE_CONTEXTS;
297*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = INTRA_MODES;
298*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.kf_y_mode[0][0][0], probsfile, 3, cts_each_dim,
299*77c1e3ccSAndroid Build Coastguard Worker                      "const aom_cdf_prob\n"
300*77c1e3ccSAndroid Build Coastguard Worker                      "default_kf_y_mode_cdf[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS]"
301*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(INTRA_MODES)]");
302*77c1e3ccSAndroid Build Coastguard Worker 
303*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = DIRECTIONAL_MODES;
304*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2 * MAX_ANGLE_DELTA + 1;
305*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.angle_delta[0][0], probsfile, 2, cts_each_dim,
306*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_angle_delta_cdf"
307*77c1e3ccSAndroid Build Coastguard Worker                      "[DIRECTIONAL_MODES][CDF_SIZE(2 * MAX_ANGLE_DELTA + 1)]");
308*77c1e3ccSAndroid Build Coastguard Worker 
309*77c1e3ccSAndroid Build Coastguard Worker   /* Intra mode (non-keyframe luma) */
310*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZE_GROUPS;
311*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = INTRA_MODES;
312*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
313*77c1e3ccSAndroid Build Coastguard Worker       &fc.y_mode[0][0], probsfile, 2, cts_each_dim,
314*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
315*77c1e3ccSAndroid Build Coastguard Worker       "default_if_y_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(INTRA_MODES)]");
316*77c1e3ccSAndroid Build Coastguard Worker 
317*77c1e3ccSAndroid Build Coastguard Worker   /* Intra mode (chroma) */
318*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = CFL_ALLOWED_TYPES;
319*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = INTRA_MODES;
320*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = UV_INTRA_MODES;
321*77c1e3ccSAndroid Build Coastguard Worker   optimize_uv_mode(&fc.uv_mode[0][0][0], probsfile, 3, cts_each_dim,
322*77c1e3ccSAndroid Build Coastguard Worker                    "static const aom_cdf_prob\n"
323*77c1e3ccSAndroid Build Coastguard Worker                    "default_uv_mode_cdf[CFL_ALLOWED_TYPES][INTRA_MODES]"
324*77c1e3ccSAndroid Build Coastguard Worker                    "[CDF_SIZE(UV_INTRA_MODES)]");
325*77c1e3ccSAndroid Build Coastguard Worker 
326*77c1e3ccSAndroid Build Coastguard Worker   /* block partition */
327*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PARTITION_CONTEXTS;
328*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = EXT_PARTITION_TYPES;
329*77c1e3ccSAndroid Build Coastguard Worker   int part_types_each_ctx[PARTITION_CONTEXTS] = { 4,  4,  4,  4,  10, 10, 10,
330*77c1e3ccSAndroid Build Coastguard Worker                                                   10, 10, 10, 10, 10, 10, 10,
331*77c1e3ccSAndroid Build Coastguard Worker                                                   10, 10, 8,  8,  8,  8 };
332*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_2d(
333*77c1e3ccSAndroid Build Coastguard Worker       &fc.partition[0][0], probsfile, 2, cts_each_dim, part_types_each_ctx,
334*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob default_partition_cdf[PARTITION_CONTEXTS]"
335*77c1e3ccSAndroid Build Coastguard Worker       "[CDF_SIZE(EXT_PARTITION_TYPES)]");
336*77c1e3ccSAndroid Build Coastguard Worker 
337*77c1e3ccSAndroid Build Coastguard Worker   /* tx type */
338*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = EXT_TX_SETS_INTRA;
339*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = EXT_TX_SIZES;
340*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = INTRA_MODES;
341*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = TX_TYPES;
342*77c1e3ccSAndroid Build Coastguard Worker   int intra_ext_tx_types_each_ctx[EXT_TX_SETS_INTRA] = { 0, 7, 5 };
343*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_4d(
344*77c1e3ccSAndroid Build Coastguard Worker       &fc.intra_ext_tx[0][0][0][0], probsfile, 4, cts_each_dim,
345*77c1e3ccSAndroid Build Coastguard Worker       intra_ext_tx_types_each_ctx,
346*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob default_intra_ext_tx_cdf[EXT_TX_SETS_INTRA]"
347*77c1e3ccSAndroid Build Coastguard Worker       "[EXT_TX_SIZES][INTRA_MODES][CDF_SIZE(TX_TYPES)]");
348*77c1e3ccSAndroid Build Coastguard Worker 
349*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = EXT_TX_SETS_INTER;
350*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = EXT_TX_SIZES;
351*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = TX_TYPES;
352*77c1e3ccSAndroid Build Coastguard Worker   int inter_ext_tx_types_each_ctx[EXT_TX_SETS_INTER] = { 0, 16, 12, 2 };
353*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_3d(
354*77c1e3ccSAndroid Build Coastguard Worker       &fc.inter_ext_tx[0][0][0], probsfile, 3, cts_each_dim,
355*77c1e3ccSAndroid Build Coastguard Worker       inter_ext_tx_types_each_ctx,
356*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob default_inter_ext_tx_cdf[EXT_TX_SETS_INTER]"
357*77c1e3ccSAndroid Build Coastguard Worker       "[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)]");
358*77c1e3ccSAndroid Build Coastguard Worker 
359*77c1e3ccSAndroid Build Coastguard Worker   /* Chroma from Luma */
360*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = CFL_JOINT_SIGNS;
361*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.cfl_sign[0], probsfile, 1, cts_each_dim,
362*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
363*77c1e3ccSAndroid Build Coastguard Worker                      "default_cfl_sign_cdf[CDF_SIZE(CFL_JOINT_SIGNS)]");
364*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = CFL_ALPHA_CONTEXTS;
365*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = CFL_ALPHABET_SIZE;
366*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.cfl_alpha[0][0], probsfile, 2, cts_each_dim,
367*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
368*77c1e3ccSAndroid Build Coastguard Worker                      "default_cfl_alpha_cdf[CFL_ALPHA_CONTEXTS]"
369*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(CFL_ALPHABET_SIZE)]");
370*77c1e3ccSAndroid Build Coastguard Worker 
371*77c1e3ccSAndroid Build Coastguard Worker   /* Interpolation filter */
372*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = SWITCHABLE_FILTER_CONTEXTS;
373*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = SWITCHABLE_FILTERS;
374*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.switchable_interp[0][0], probsfile, 2, cts_each_dim,
375*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
376*77c1e3ccSAndroid Build Coastguard Worker                      "default_switchable_interp_cdf[SWITCHABLE_FILTER_CONTEXTS]"
377*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(SWITCHABLE_FILTERS)]");
378*77c1e3ccSAndroid Build Coastguard Worker 
379*77c1e3ccSAndroid Build Coastguard Worker   /* Motion vector referencing */
380*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = NEWMV_MODE_CONTEXTS;
381*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
382*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.newmv_mode[0][0], probsfile, 2, cts_each_dim,
383*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
384*77c1e3ccSAndroid Build Coastguard Worker                      "default_newmv_cdf[NEWMV_MODE_CONTEXTS][CDF_SIZE(2)]");
385*77c1e3ccSAndroid Build Coastguard Worker 
386*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = GLOBALMV_MODE_CONTEXTS;
387*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
388*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.zeromv_mode[0][0], probsfile, 2, cts_each_dim,
389*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
390*77c1e3ccSAndroid Build Coastguard Worker                      "default_zeromv_cdf[GLOBALMV_MODE_CONTEXTS][CDF_SIZE(2)]");
391*77c1e3ccSAndroid Build Coastguard Worker 
392*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = REFMV_MODE_CONTEXTS;
393*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
394*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.refmv_mode[0][0], probsfile, 2, cts_each_dim,
395*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
396*77c1e3ccSAndroid Build Coastguard Worker                      "default_refmv_cdf[REFMV_MODE_CONTEXTS][CDF_SIZE(2)]");
397*77c1e3ccSAndroid Build Coastguard Worker 
398*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = DRL_MODE_CONTEXTS;
399*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
400*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.drl_mode[0][0], probsfile, 2, cts_each_dim,
401*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
402*77c1e3ccSAndroid Build Coastguard Worker                      "default_drl_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)]");
403*77c1e3ccSAndroid Build Coastguard Worker 
404*77c1e3ccSAndroid Build Coastguard Worker   /* ext_inter experiment */
405*77c1e3ccSAndroid Build Coastguard Worker   /* New compound mode */
406*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = INTER_MODE_CONTEXTS;
407*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = INTER_COMPOUND_MODES;
408*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.inter_compound_mode[0][0], probsfile, 2, cts_each_dim,
409*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
410*77c1e3ccSAndroid Build Coastguard Worker                      "default_inter_compound_mode_cdf[INTER_MODE_CONTEXTS][CDF_"
411*77c1e3ccSAndroid Build Coastguard Worker                      "SIZE(INTER_COMPOUND_MODES)]");
412*77c1e3ccSAndroid Build Coastguard Worker 
413*77c1e3ccSAndroid Build Coastguard Worker   /* Interintra */
414*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZE_GROUPS;
415*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
416*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.interintra[0][0], probsfile, 2, cts_each_dim,
417*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
418*77c1e3ccSAndroid Build Coastguard Worker                      "default_interintra_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(2)]");
419*77c1e3ccSAndroid Build Coastguard Worker 
420*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZE_GROUPS;
421*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = INTERINTRA_MODES;
422*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.interintra_mode[0][0], probsfile, 2, cts_each_dim,
423*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
424*77c1e3ccSAndroid Build Coastguard Worker                      "default_interintra_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE("
425*77c1e3ccSAndroid Build Coastguard Worker                      "INTERINTRA_MODES)]");
426*77c1e3ccSAndroid Build Coastguard Worker 
427*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
428*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
429*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
430*77c1e3ccSAndroid Build Coastguard Worker       &fc.wedge_interintra[0][0], probsfile, 2, cts_each_dim,
431*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
432*77c1e3ccSAndroid Build Coastguard Worker       "default_wedge_interintra_cdf[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
433*77c1e3ccSAndroid Build Coastguard Worker 
434*77c1e3ccSAndroid Build Coastguard Worker   /* Compound type */
435*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
436*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = COMPOUND_TYPES - 1;
437*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.compound_type[0][0], probsfile, 2, cts_each_dim,
438*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_compound_type_cdf"
439*77c1e3ccSAndroid Build Coastguard Worker                      "[BLOCK_SIZES_ALL][CDF_SIZE(COMPOUND_TYPES - 1)]");
440*77c1e3ccSAndroid Build Coastguard Worker 
441*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
442*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 16;
443*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.wedge_idx[0][0], probsfile, 2, cts_each_dim,
444*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
445*77c1e3ccSAndroid Build Coastguard Worker                      "default_wedge_idx_cdf[BLOCK_SIZES_ALL][CDF_SIZE(16)]");
446*77c1e3ccSAndroid Build Coastguard Worker 
447*77c1e3ccSAndroid Build Coastguard Worker   /* motion_var and warped_motion experiments */
448*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
449*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = MOTION_MODES;
450*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
451*77c1e3ccSAndroid Build Coastguard Worker       &fc.motion_mode[0][0], probsfile, 2, cts_each_dim,
452*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
453*77c1e3ccSAndroid Build Coastguard Worker       "default_motion_mode_cdf[BLOCK_SIZES_ALL][CDF_SIZE(MOTION_MODES)]");
454*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
455*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
456*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.obmc[0][0], probsfile, 2, cts_each_dim,
457*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
458*77c1e3ccSAndroid Build Coastguard Worker                      "default_obmc_cdf[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
459*77c1e3ccSAndroid Build Coastguard Worker 
460*77c1e3ccSAndroid Build Coastguard Worker   /* Intra/inter flag */
461*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = INTRA_INTER_CONTEXTS;
462*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
463*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
464*77c1e3ccSAndroid Build Coastguard Worker       &fc.intra_inter[0][0], probsfile, 2, cts_each_dim,
465*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
466*77c1e3ccSAndroid Build Coastguard Worker       "default_intra_inter_cdf[INTRA_INTER_CONTEXTS][CDF_SIZE(2)]");
467*77c1e3ccSAndroid Build Coastguard Worker 
468*77c1e3ccSAndroid Build Coastguard Worker   /* Single/comp ref flag */
469*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = COMP_INTER_CONTEXTS;
470*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
471*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
472*77c1e3ccSAndroid Build Coastguard Worker       &fc.comp_inter[0][0], probsfile, 2, cts_each_dim,
473*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
474*77c1e3ccSAndroid Build Coastguard Worker       "default_comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)]");
475*77c1e3ccSAndroid Build Coastguard Worker 
476*77c1e3ccSAndroid Build Coastguard Worker   /* ext_comp_refs experiment */
477*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = COMP_REF_TYPE_CONTEXTS;
478*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
479*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
480*77c1e3ccSAndroid Build Coastguard Worker       &fc.comp_ref_type[0][0], probsfile, 2, cts_each_dim,
481*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
482*77c1e3ccSAndroid Build Coastguard Worker       "default_comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][CDF_SIZE(2)]");
483*77c1e3ccSAndroid Build Coastguard Worker 
484*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = UNI_COMP_REF_CONTEXTS;
485*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = UNIDIR_COMP_REFS - 1;
486*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
487*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.uni_comp_ref[0][0][0], probsfile, 3, cts_each_dim,
488*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob\n"
489*77c1e3ccSAndroid Build Coastguard Worker                      "default_uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_"
490*77c1e3ccSAndroid Build Coastguard Worker                      "COMP_REFS - 1][CDF_SIZE(2)]");
491*77c1e3ccSAndroid Build Coastguard Worker 
492*77c1e3ccSAndroid Build Coastguard Worker   /* Reference frame (single ref) */
493*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = REF_CONTEXTS;
494*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = SINGLE_REFS - 1;
495*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
496*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
497*77c1e3ccSAndroid Build Coastguard Worker       &fc.single_ref[0][0][0], probsfile, 3, cts_each_dim,
498*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
499*77c1e3ccSAndroid Build Coastguard Worker       "default_single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)]");
500*77c1e3ccSAndroid Build Coastguard Worker 
501*77c1e3ccSAndroid Build Coastguard Worker   /* ext_refs experiment */
502*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = REF_CONTEXTS;
503*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = FWD_REFS - 1;
504*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
505*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
506*77c1e3ccSAndroid Build Coastguard Worker       &fc.comp_ref[0][0][0], probsfile, 3, cts_each_dim,
507*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
508*77c1e3ccSAndroid Build Coastguard Worker       "default_comp_ref_cdf[REF_CONTEXTS][FWD_REFS - 1][CDF_SIZE(2)]");
509*77c1e3ccSAndroid Build Coastguard Worker 
510*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = REF_CONTEXTS;
511*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = BWD_REFS - 1;
512*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
513*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
514*77c1e3ccSAndroid Build Coastguard Worker       &fc.comp_bwdref[0][0][0], probsfile, 3, cts_each_dim,
515*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
516*77c1e3ccSAndroid Build Coastguard Worker       "default_comp_bwdref_cdf[REF_CONTEXTS][BWD_REFS - 1][CDF_SIZE(2)]");
517*77c1e3ccSAndroid Build Coastguard Worker 
518*77c1e3ccSAndroid Build Coastguard Worker   /* palette */
519*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALATTE_BSIZE_CTXS;
520*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PALETTE_SIZES;
521*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.palette_y_size[0][0], probsfile, 2, cts_each_dim,
522*77c1e3ccSAndroid Build Coastguard Worker                      "const aom_cdf_prob default_palette_y_size_cdf"
523*77c1e3ccSAndroid Build Coastguard Worker                      "[PALATTE_BSIZE_CTXS][CDF_SIZE(PALETTE_SIZES)]");
524*77c1e3ccSAndroid Build Coastguard Worker 
525*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALATTE_BSIZE_CTXS;
526*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PALETTE_SIZES;
527*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.palette_uv_size[0][0], probsfile, 2, cts_each_dim,
528*77c1e3ccSAndroid Build Coastguard Worker                      "const aom_cdf_prob default_palette_uv_size_cdf"
529*77c1e3ccSAndroid Build Coastguard Worker                      "[PALATTE_BSIZE_CTXS][CDF_SIZE(PALETTE_SIZES)]");
530*77c1e3ccSAndroid Build Coastguard Worker 
531*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALATTE_BSIZE_CTXS;
532*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PALETTE_Y_MODE_CONTEXTS;
533*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
534*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.palette_y_mode[0][0][0], probsfile, 3, cts_each_dim,
535*77c1e3ccSAndroid Build Coastguard Worker                      "const aom_cdf_prob default_palette_y_mode_cdf"
536*77c1e3ccSAndroid Build Coastguard Worker                      "[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS]"
537*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(2)]");
538*77c1e3ccSAndroid Build Coastguard Worker 
539*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALETTE_UV_MODE_CONTEXTS;
540*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
541*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.palette_uv_mode[0][0], probsfile, 2, cts_each_dim,
542*77c1e3ccSAndroid Build Coastguard Worker                      "const aom_cdf_prob default_palette_uv_mode_cdf"
543*77c1e3ccSAndroid Build Coastguard Worker                      "[PALETTE_UV_MODE_CONTEXTS][CDF_SIZE(2)]");
544*77c1e3ccSAndroid Build Coastguard Worker 
545*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALETTE_SIZES;
546*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PALETTE_COLOR_INDEX_CONTEXTS;
547*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PALETTE_COLORS;
548*77c1e3ccSAndroid Build Coastguard Worker   int palette_color_indexes_each_ctx[PALETTE_SIZES] = { 2, 3, 4, 5, 6, 7, 8 };
549*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_3d(
550*77c1e3ccSAndroid Build Coastguard Worker       &fc.palette_y_color_index[0][0][0], probsfile, 3, cts_each_dim,
551*77c1e3ccSAndroid Build Coastguard Worker       palette_color_indexes_each_ctx,
552*77c1e3ccSAndroid Build Coastguard Worker       "const aom_cdf_prob default_palette_y_color_index_cdf[PALETTE_SIZES]"
553*77c1e3ccSAndroid Build Coastguard Worker       "[PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)]");
554*77c1e3ccSAndroid Build Coastguard Worker 
555*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = PALETTE_SIZES;
556*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PALETTE_COLOR_INDEX_CONTEXTS;
557*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PALETTE_COLORS;
558*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_3d(
559*77c1e3ccSAndroid Build Coastguard Worker       &fc.palette_uv_color_index[0][0][0], probsfile, 3, cts_each_dim,
560*77c1e3ccSAndroid Build Coastguard Worker       palette_color_indexes_each_ctx,
561*77c1e3ccSAndroid Build Coastguard Worker       "const aom_cdf_prob default_palette_uv_color_index_cdf[PALETTE_SIZES]"
562*77c1e3ccSAndroid Build Coastguard Worker       "[PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)]");
563*77c1e3ccSAndroid Build Coastguard Worker 
564*77c1e3ccSAndroid Build Coastguard Worker   /* Transform size */
565*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TXFM_PARTITION_CONTEXTS;
566*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
567*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
568*77c1e3ccSAndroid Build Coastguard Worker       &fc.txfm_partition[0][0], probsfile, 2, cts_each_dim,
569*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob\n"
570*77c1e3ccSAndroid Build Coastguard Worker       "default_txfm_partition_cdf[TXFM_PARTITION_CONTEXTS][CDF_SIZE(2)]");
571*77c1e3ccSAndroid Build Coastguard Worker 
572*77c1e3ccSAndroid Build Coastguard Worker   /* Skip flag */
573*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = SKIP_CONTEXTS;
574*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
575*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.skip_txfm[0][0], probsfile, 2, cts_each_dim,
576*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
577*77c1e3ccSAndroid Build Coastguard Worker                      "default_skip_txfm_cdfs[SKIP_CONTEXTS][CDF_SIZE(2)]");
578*77c1e3ccSAndroid Build Coastguard Worker 
579*77c1e3ccSAndroid Build Coastguard Worker   /* Skip mode flag */
580*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = SKIP_MODE_CONTEXTS;
581*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
582*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.skip_mode[0][0], probsfile, 2, cts_each_dim,
583*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
584*77c1e3ccSAndroid Build Coastguard Worker                      "default_skip_mode_cdfs[SKIP_MODE_CONTEXTS][CDF_SIZE(2)]");
585*77c1e3ccSAndroid Build Coastguard Worker 
586*77c1e3ccSAndroid Build Coastguard Worker   /* joint compound flag */
587*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = COMP_INDEX_CONTEXTS;
588*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
589*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.compound_index[0][0], probsfile, 2, cts_each_dim,
590*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_compound_idx_cdfs"
591*77c1e3ccSAndroid Build Coastguard Worker                      "[COMP_INDEX_CONTEXTS][CDF_SIZE(2)]");
592*77c1e3ccSAndroid Build Coastguard Worker 
593*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = COMP_GROUP_IDX_CONTEXTS;
594*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
595*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.comp_group_idx[0][0], probsfile, 2, cts_each_dim,
596*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_comp_group_idx_cdfs"
597*77c1e3ccSAndroid Build Coastguard Worker                      "[COMP_GROUP_IDX_CONTEXTS][CDF_SIZE(2)]");
598*77c1e3ccSAndroid Build Coastguard Worker 
599*77c1e3ccSAndroid Build Coastguard Worker   /* intrabc */
600*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = 2;
601*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
602*77c1e3ccSAndroid Build Coastguard Worker       &fc.intrabc[0], probsfile, 1, cts_each_dim,
603*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob default_intrabc_cdf[CDF_SIZE(2)]");
604*77c1e3ccSAndroid Build Coastguard Worker 
605*77c1e3ccSAndroid Build Coastguard Worker   /* filter_intra experiment */
606*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = FILTER_INTRA_MODES;
607*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
608*77c1e3ccSAndroid Build Coastguard Worker       &fc.filter_intra_mode[0], probsfile, 1, cts_each_dim,
609*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob "
610*77c1e3ccSAndroid Build Coastguard Worker       "default_filter_intra_mode_cdf[CDF_SIZE(FILTER_INTRA_MODES)]");
611*77c1e3ccSAndroid Build Coastguard Worker 
612*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = BLOCK_SIZES_ALL;
613*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = 2;
614*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.filter_intra[0][0], probsfile, 2, cts_each_dim,
615*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
616*77c1e3ccSAndroid Build Coastguard Worker                      "default_filter_intra_cdfs[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
617*77c1e3ccSAndroid Build Coastguard Worker 
618*77c1e3ccSAndroid Build Coastguard Worker   /* restoration type */
619*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = RESTORE_SWITCHABLE_TYPES;
620*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.switchable_restore[0], probsfile, 1, cts_each_dim,
621*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_switchable_restore_cdf"
622*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(RESTORE_SWITCHABLE_TYPES)]");
623*77c1e3ccSAndroid Build Coastguard Worker 
624*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = 2;
625*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.wiener_restore[0], probsfile, 1, cts_each_dim,
626*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_wiener_restore_cdf"
627*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(2)]");
628*77c1e3ccSAndroid Build Coastguard Worker 
629*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = 2;
630*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.sgrproj_restore[0], probsfile, 1, cts_each_dim,
631*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob default_sgrproj_restore_cdf"
632*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(2)]");
633*77c1e3ccSAndroid Build Coastguard Worker 
634*77c1e3ccSAndroid Build Coastguard Worker   /* intra tx size */
635*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = MAX_TX_CATS;
636*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZE_CONTEXTS;
637*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = MAX_TX_DEPTH + 1;
638*77c1e3ccSAndroid Build Coastguard Worker   int intra_tx_sizes_each_ctx[MAX_TX_CATS] = { 2, 3, 3, 3 };
639*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table_var_modes_3d(
640*77c1e3ccSAndroid Build Coastguard Worker       &fc.intra_tx_size[0][0][0], probsfile, 3, cts_each_dim,
641*77c1e3ccSAndroid Build Coastguard Worker       intra_tx_sizes_each_ctx,
642*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob default_tx_size_cdf"
643*77c1e3ccSAndroid Build Coastguard Worker       "[MAX_TX_CATS][TX_SIZE_CONTEXTS][CDF_SIZE(MAX_TX_DEPTH + 1)]");
644*77c1e3ccSAndroid Build Coastguard Worker 
645*77c1e3ccSAndroid Build Coastguard Worker   /* transform coding */
646*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
647*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZES;
648*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = TXB_SKIP_CONTEXTS;
649*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 2;
650*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.txb_skip[0][0][0][0], probsfile, 4, cts_each_dim,
651*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
652*77c1e3ccSAndroid Build Coastguard Worker                      "av1_default_txb_skip_cdfs[TOKEN_CDF_Q_CTXS][TX_SIZES]"
653*77c1e3ccSAndroid Build Coastguard Worker                      "[TXB_SKIP_CONTEXTS][CDF_SIZE(2)]");
654*77c1e3ccSAndroid Build Coastguard Worker 
655*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
656*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZES;
657*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PLANE_TYPES;
658*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = EOB_COEF_CONTEXTS;
659*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[4] = 2;
660*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
661*77c1e3ccSAndroid Build Coastguard Worker       &fc.eob_extra[0][0][0][0][0], probsfile, 5, cts_each_dim,
662*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob av1_default_eob_extra_cdfs "
663*77c1e3ccSAndroid Build Coastguard Worker       "[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS]"
664*77c1e3ccSAndroid Build Coastguard Worker       "[CDF_SIZE(2)]");
665*77c1e3ccSAndroid Build Coastguard Worker 
666*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
667*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
668*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
669*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 5;
670*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi16[0][0][0][0], probsfile, 4, cts_each_dim,
671*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi16_cdfs"
672*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(5)]");
673*77c1e3ccSAndroid Build Coastguard Worker 
674*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
675*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
676*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
677*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 6;
678*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi32[0][0][0][0], probsfile, 4, cts_each_dim,
679*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi32_cdfs"
680*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(6)]");
681*77c1e3ccSAndroid Build Coastguard Worker 
682*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
683*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
684*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
685*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 7;
686*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi64[0][0][0][0], probsfile, 4, cts_each_dim,
687*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi64_cdfs"
688*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(7)]");
689*77c1e3ccSAndroid Build Coastguard Worker 
690*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
691*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
692*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
693*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 8;
694*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi128[0][0][0][0], probsfile, 4, cts_each_dim,
695*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi128_cdfs"
696*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(8)]");
697*77c1e3ccSAndroid Build Coastguard Worker 
698*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
699*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
700*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
701*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 9;
702*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi256[0][0][0][0], probsfile, 4, cts_each_dim,
703*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi256_cdfs"
704*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(9)]");
705*77c1e3ccSAndroid Build Coastguard Worker 
706*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
707*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
708*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
709*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 10;
710*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi512[0][0][0][0], probsfile, 4, cts_each_dim,
711*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi512_cdfs"
712*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(10)]");
713*77c1e3ccSAndroid Build Coastguard Worker 
714*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
715*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = PLANE_TYPES;
716*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = 2;
717*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = 11;
718*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.eob_multi1024[0][0][0][0], probsfile, 4, cts_each_dim,
719*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob av1_default_eob_multi1024_cdfs"
720*77c1e3ccSAndroid Build Coastguard Worker                      "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(11)]");
721*77c1e3ccSAndroid Build Coastguard Worker 
722*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
723*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZES;
724*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PLANE_TYPES;
725*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = LEVEL_CONTEXTS;
726*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[4] = BR_CDF_SIZE;
727*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(&fc.coeff_lps_multi[0][0][0][0][0], probsfile, 5,
728*77c1e3ccSAndroid Build Coastguard Worker                      cts_each_dim,
729*77c1e3ccSAndroid Build Coastguard Worker                      "static const aom_cdf_prob "
730*77c1e3ccSAndroid Build Coastguard Worker                      "av1_default_coeff_lps_multi_cdfs[TOKEN_CDF_Q_CTXS]"
731*77c1e3ccSAndroid Build Coastguard Worker                      "[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS]"
732*77c1e3ccSAndroid Build Coastguard Worker                      "[CDF_SIZE(BR_CDF_SIZE)]");
733*77c1e3ccSAndroid Build Coastguard Worker 
734*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
735*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZES;
736*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PLANE_TYPES;
737*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = SIG_COEF_CONTEXTS;
738*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[4] = NUM_BASE_LEVELS + 2;
739*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
740*77c1e3ccSAndroid Build Coastguard Worker       &fc.coeff_base_multi[0][0][0][0][0], probsfile, 5, cts_each_dim,
741*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob av1_default_coeff_base_multi_cdfs"
742*77c1e3ccSAndroid Build Coastguard Worker       "[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS]"
743*77c1e3ccSAndroid Build Coastguard Worker       "[CDF_SIZE(NUM_BASE_LEVELS + 2)]");
744*77c1e3ccSAndroid Build Coastguard Worker 
745*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
746*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[1] = TX_SIZES;
747*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[2] = PLANE_TYPES;
748*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[3] = SIG_COEF_CONTEXTS_EOB;
749*77c1e3ccSAndroid Build Coastguard Worker   cts_each_dim[4] = NUM_BASE_LEVELS + 1;
750*77c1e3ccSAndroid Build Coastguard Worker   optimize_cdf_table(
751*77c1e3ccSAndroid Build Coastguard Worker       &fc.coeff_base_eob_multi[0][0][0][0][0], probsfile, 5, cts_each_dim,
752*77c1e3ccSAndroid Build Coastguard Worker       "static const aom_cdf_prob av1_default_coeff_base_eob_multi_cdfs"
753*77c1e3ccSAndroid Build Coastguard Worker       "[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS_EOB]"
754*77c1e3ccSAndroid Build Coastguard Worker       "[CDF_SIZE(NUM_BASE_LEVELS + 1)]");
755*77c1e3ccSAndroid Build Coastguard Worker 
756*77c1e3ccSAndroid Build Coastguard Worker   fclose(statsfile);
757*77c1e3ccSAndroid Build Coastguard Worker   fclose(logfile);
758*77c1e3ccSAndroid Build Coastguard Worker   fclose(probsfile);
759*77c1e3ccSAndroid Build Coastguard Worker 
760*77c1e3ccSAndroid Build Coastguard Worker   return 0;
761*77c1e3ccSAndroid Build Coastguard Worker }
762