@@ -124,11 +124,11 @@ static bool decode_block_mode_2d(
124124 }
125125 }
126126
127- int weight_count = x_weights * y_weights * (D + 1 );
127+ unsigned int weight_count = x_weights * y_weights * (D + 1 );
128128 quant_mode = (base_quant_mode - 2 ) + 6 * H;
129129 is_dual_plane = D != 0 ;
130130
131- int weight_bits = get_ise_sequence_bitcount (weight_count, (quant_method)quant_mode);
131+ unsigned int weight_bits = get_ise_sequence_bitcount (weight_count, (quant_method)quant_mode);
132132 return (weight_count <= MAX_WEIGHTS_PER_BLOCK &&
133133 weight_bits >= MIN_WEIGHT_BITS_PER_BLOCK &&
134134 weight_bits <= MAX_WEIGHT_BITS_PER_BLOCK);
@@ -225,11 +225,11 @@ static int decode_block_mode_3d(
225225 }
226226 }
227227
228- int weight_count = x_weights * y_weights * z_weights * (D + 1 );
228+ unsigned int weight_count = x_weights * y_weights * z_weights * (D + 1 );
229229 quant_mode = (base_quant_mode - 2 ) + 6 * H;
230230 is_dual_plane = D != 0 ;
231231
232- int weight_bits = get_ise_sequence_bitcount (weight_count, (quant_method)quant_mode);
232+ unsigned int weight_bits = get_ise_sequence_bitcount (weight_count, (quant_method)quant_mode);
233233 return (weight_count <= MAX_WEIGHTS_PER_BLOCK &&
234234 weight_bits >= MIN_WEIGHT_BITS_PER_BLOCK &&
235235 weight_bits <= MAX_WEIGHT_BITS_PER_BLOCK);
@@ -245,14 +245,14 @@ static int decode_block_mode_3d(
245245 * @param[out] di The decimation info structure to populate.
246246 */
247247static void init_decimation_info_2d (
248- int x_texels,
249- int y_texels,
250- int x_weights,
251- int y_weights,
248+ unsigned int x_texels,
249+ unsigned int y_texels,
250+ unsigned int x_weights,
251+ unsigned int y_weights,
252252 decimation_info& di
253253) {
254- int texels_per_block = x_texels * y_texels;
255- int weights_per_block = x_weights * y_weights;
254+ unsigned int texels_per_block = x_texels * y_texels;
255+ unsigned int weights_per_block = x_weights * y_weights;
256256
257257 uint8_t weight_count_of_texel[MAX_TEXELS_PER_BLOCK];
258258 uint8_t grid_weights_of_texel[MAX_TEXELS_PER_BLOCK][4 ];
@@ -263,45 +263,46 @@ static void init_decimation_info_2d(
263263 uint8_t texels_of_weight[MAX_WEIGHTS_PER_BLOCK][MAX_TEXELS_PER_BLOCK];
264264 int texel_weights_of_weight[MAX_WEIGHTS_PER_BLOCK][MAX_TEXELS_PER_BLOCK];
265265
266- for (int i = 0 ; i < weights_per_block; i++)
266+ for (unsigned int i = 0 ; i < weights_per_block; i++)
267267 {
268268 texel_count_of_weight[i] = 0 ;
269269 }
270270
271- for (int i = 0 ; i < texels_per_block; i++)
271+ for (unsigned int i = 0 ; i < texels_per_block; i++)
272272 {
273273 weight_count_of_texel[i] = 0 ;
274274 }
275275
276- for (int y = 0 ; y < y_texels; y++)
276+ for (unsigned int y = 0 ; y < y_texels; y++)
277277 {
278- for (int x = 0 ; x < x_texels; x++)
278+ for (unsigned int x = 0 ; x < x_texels; x++)
279279 {
280- int texel = y * x_texels + x;
280+ unsigned int texel = y * x_texels + x;
281+
282+ unsigned int x_weight = (((1024 + x_texels / 2 ) / (x_texels - 1 )) * x * (x_weights - 1 ) + 32 ) >> 6 ;
283+ unsigned int y_weight = (((1024 + y_texels / 2 ) / (y_texels - 1 )) * y * (y_weights - 1 ) + 32 ) >> 6 ;
281284
282- int x_weight = (((1024 + x_texels / 2 ) / (x_texels - 1 )) * x * (x_weights - 1 ) + 32 ) >> 6 ;
283- int y_weight = (((1024 + y_texels / 2 ) / (y_texels - 1 )) * y * (y_weights - 1 ) + 32 ) >> 6 ;
285+ unsigned int x_weight_frac = x_weight & 0xF ;
286+ unsigned int y_weight_frac = y_weight & 0xF ;
287+ unsigned int x_weight_int = x_weight >> 4 ;
288+ unsigned int y_weight_int = y_weight >> 4 ;
284289
285- int x_weight_frac = x_weight & 0xF ;
286- int y_weight_frac = y_weight & 0xF ;
287- int x_weight_int = x_weight >> 4 ;
288- int y_weight_int = y_weight >> 4 ;
289- int qweight[4 ];
290+ unsigned int qweight[4 ];
290291 qweight[0 ] = x_weight_int + y_weight_int * x_weights;
291292 qweight[1 ] = qweight[0 ] + 1 ;
292293 qweight[2 ] = qweight[0 ] + x_weights;
293294 qweight[3 ] = qweight[2 ] + 1 ;
294295
295296 // Truncated-precision bilinear interpolation
296- int prod = x_weight_frac * y_weight_frac;
297+ unsigned int prod = x_weight_frac * y_weight_frac;
297298
298- int weight[4 ];
299+ unsigned int weight[4 ];
299300 weight[3 ] = (prod + 8 ) >> 4 ;
300301 weight[1 ] = x_weight_frac - weight[3 ];
301302 weight[2 ] = y_weight_frac - weight[3 ];
302303 weight[0 ] = 16 - x_weight_frac - y_weight_frac + weight[3 ];
303304
304- for (int i = 0 ; i < 4 ; i++)
305+ for (unsigned int i = 0 ; i < 4 ; i++)
305306 {
306307 if (weight[i] != 0 )
307308 {
@@ -317,7 +318,7 @@ static void init_decimation_info_2d(
317318 }
318319 }
319320
320- for (int i = 0 ; i < texels_per_block; i++)
321+ for (unsigned int i = 0 ; i < texels_per_block; i++)
321322 {
322323 di.texel_weight_count [i] = weight_count_of_texel[i];
323324
@@ -329,20 +330,20 @@ static void init_decimation_info_2d(
329330 }
330331
331332 // Init all 4 entries so we can rely on zeros for vectorization
332- for (int j = weight_count_of_texel[i]; j < 4 ; j++)
333+ for (unsigned int j = weight_count_of_texel[i]; j < 4 ; j++)
333334 {
334335 di.texel_weights_int_4t [j][i] = 0 ;
335336 di.texel_weights_float_4t [j][i] = 0 .0f ;
336337 di.texel_weights_4t [j][i] = 0 ;
337338 }
338339 }
339340
340- for (int i = 0 ; i < weights_per_block; i++)
341+ for (unsigned int i = 0 ; i < weights_per_block; i++)
341342 {
342- int texel_count_wt = texel_count_of_weight[i];
343+ unsigned int texel_count_wt = texel_count_of_weight[i];
343344 di.weight_texel_count [i] = (uint8_t )texel_count_wt;
344345
345- for (int j = 0 ; j < texel_count_wt; j++)
346+ for (unsigned int j = 0 ; j < texel_count_wt; j++)
346347 {
347348 uint8_t texel = texels_of_weight[i][j];
348349
@@ -380,16 +381,16 @@ static void init_decimation_info_2d(
380381 // Initialize array tail so we can over-fetch with SIMD later to avoid loop tails
381382 // Match last texel in active lane in SIMD group, for better gathers
382383 uint8_t last_texel = di.weight_texel [texel_count_wt - 1 ][i];
383- for (int j = texel_count_wt; j < max_texel_count_of_weight; j++)
384+ for (unsigned int j = texel_count_wt; j < max_texel_count_of_weight; j++)
384385 {
385386 di.weight_texel [j][i] = last_texel;
386387 di.weights_flt [j][i] = 0 .0f ;
387388 }
388389 }
389390
390391 // Initialize array tail so we can over-fetch with SIMD later to avoid loop tails
391- int texels_per_block_simd = round_up_to_simd_multiple_vla (texels_per_block);
392- for (int i = texels_per_block; i < texels_per_block_simd; i++)
392+ unsigned int texels_per_block_simd = round_up_to_simd_multiple_vla (texels_per_block);
393+ for (unsigned int i = texels_per_block; i < texels_per_block_simd; i++)
393394 {
394395 di.texel_weight_count [i] = 0 ;
395396
@@ -706,7 +707,7 @@ static void assign_kmeans_texels(
706707 // Use all texels for kmeans on a small block
707708 if (bsd.texel_count <= MAX_KMEANS_TEXELS)
708709 {
709- for (int i = 0 ; i < bsd.texel_count ; i++)
710+ for (unsigned int i = 0 ; i < bsd.texel_count ; i++)
710711 {
711712 bsd.kmeans_texels [i] = i;
712713 }
@@ -721,13 +722,13 @@ static void assign_kmeans_texels(
721722
722723 // Initialize array used for tracking used indices
723724 bool seen[MAX_TEXELS_PER_BLOCK];
724- for (int i = 0 ; i < bsd.texel_count ; i++)
725+ for (unsigned int i = 0 ; i < bsd.texel_count ; i++)
725726 {
726727 seen[i] = false ;
727728 }
728729
729730 // Assign 64 random indices, retrying if we see repeats
730- int arr_elements_set = 0 ;
731+ unsigned int arr_elements_set = 0 ;
731732 while (arr_elements_set < MAX_KMEANS_TEXELS)
732733 {
733734 unsigned int texel = (unsigned int )astc::rand (rng_state);
@@ -760,7 +761,7 @@ static int construct_dt_entry_2d(
760761 block_size_descriptor& bsd
761762) {
762763 int dm_index = bsd.decimation_mode_count ;
763- int weight_count = x_weights * y_weights;
764+ unsigned int weight_count = x_weights * y_weights;
764765 assert (weight_count <= MAX_WEIGHTS_PER_BLOCK);
765766
766767 bool try_2planes = (2 * weight_count) <= MAX_WEIGHTS_PER_BLOCK;
@@ -772,15 +773,15 @@ static int construct_dt_entry_2d(
772773 int maxprec_2planes = -1 ;
773774 for (int i = 0 ; i < 12 ; i++)
774775 {
775- int bits_1plane = get_ise_sequence_bitcount (weight_count, (quant_method)i);
776+ unsigned int bits_1plane = get_ise_sequence_bitcount (weight_count, (quant_method)i);
776777 if (bits_1plane >= MIN_WEIGHT_BITS_PER_BLOCK && bits_1plane <= MAX_WEIGHT_BITS_PER_BLOCK)
777778 {
778779 maxprec_1plane = i;
779780 }
780781
781782 if (try_2planes)
782783 {
783- int bits_2planes = get_ise_sequence_bitcount (2 * weight_count, (quant_method)i);
784+ unsigned int bits_2planes = get_ise_sequence_bitcount (2 * weight_count, (quant_method)i);
784785 if (bits_2planes >= MIN_WEIGHT_BITS_PER_BLOCK && bits_2planes <= MAX_WEIGHT_BITS_PER_BLOCK)
785786 {
786787 maxprec_2planes = i;
@@ -976,7 +977,7 @@ static void construct_block_size_descriptor_3d(
976977 {
977978 for (int z_weights = 2 ; z_weights <= z_texels; z_weights++)
978979 {
979- int weight_count = x_weights * y_weights * z_weights;
980+ unsigned int weight_count = x_weights * y_weights * z_weights;
980981 if (weight_count > MAX_WEIGHTS_PER_BLOCK)
981982 {
982983 continue ;
@@ -990,14 +991,13 @@ static void construct_block_size_descriptor_3d(
990991 int maxprec_2planes = -1 ;
991992 for (int i = 0 ; i < 12 ; i++)
992993 {
993- int bits_1plane = get_ise_sequence_bitcount (weight_count, (quant_method)i);
994- int bits_2planes = get_ise_sequence_bitcount (2 * weight_count, (quant_method)i);
995-
994+ unsigned int bits_1plane = get_ise_sequence_bitcount (weight_count, (quant_method)i);
996995 if (bits_1plane >= MIN_WEIGHT_BITS_PER_BLOCK && bits_1plane <= MAX_WEIGHT_BITS_PER_BLOCK)
997996 {
998997 maxprec_1plane = i;
999998 }
1000999
1000+ unsigned int bits_2planes = get_ise_sequence_bitcount (2 * weight_count, (quant_method)i);
10011001 if (bits_2planes >= MIN_WEIGHT_BITS_PER_BLOCK && bits_2planes <= MAX_WEIGHT_BITS_PER_BLOCK)
10021002 {
10031003 maxprec_2planes = i;
@@ -1082,9 +1082,9 @@ static void construct_block_size_descriptor_3d(
10821082
10831083/* See header for documentation. */
10841084void init_block_size_descriptor (
1085- int x_texels,
1086- int y_texels,
1087- int z_texels,
1085+ unsigned int x_texels,
1086+ unsigned int y_texels,
1087+ unsigned int z_texels,
10881088 bool can_omit_modes,
10891089 float mode_cutoff,
10901090 block_size_descriptor& bsd
@@ -1105,7 +1105,7 @@ void init_block_size_descriptor(
11051105void term_block_size_descriptor (
11061106 block_size_descriptor& bsd
11071107) {
1108- for (int i = 0 ; i < bsd.decimation_mode_count ; i++)
1108+ for (unsigned int i = 0 ; i < bsd.decimation_mode_count ; i++)
11091109 {
11101110 aligned_free<const decimation_info>(bsd.decimation_tables [i]);
11111111 }
0 commit comments