Skip to content

Commit 36aacfa

Browse files
authored
Use size_t for round_*_to_simd() calls (#557)
1 parent 31e4baa commit 36aacfa

5 files changed

+31
-55
lines changed

Source/astcenc_block_sizes.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// ----------------------------------------------------------------------------
3-
// Copyright 2011-2023 Arm Limited
3+
// Copyright 2011-2025 Arm Limited
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
66
// use this file except in compliance with the License. You may obtain a copy
@@ -384,12 +384,12 @@ static void init_decimation_info_2d(
384384
}
385385

386386
// Initialize array tail so we can over-fetch with SIMD later to avoid loop tails
387-
unsigned int texels_per_block_simd = round_up_to_simd_multiple_vla(texels_per_block);
388-
for (unsigned int i = texels_per_block; i < texels_per_block_simd; i++)
387+
size_t texels_per_block_simd = round_up_to_simd_multiple_vla(texels_per_block);
388+
for (size_t i = texels_per_block; i < texels_per_block_simd; i++)
389389
{
390390
di.texel_weight_count[i] = 0;
391391

392-
for (unsigned int j = 0; j < 4; j++)
392+
for (size_t j = 0; j < 4; j++)
393393
{
394394
di.texel_weight_contribs_float_tr[j][i] = 0;
395395
di.texel_weights_tr[j][i] = 0;
@@ -402,12 +402,12 @@ static void init_decimation_info_2d(
402402
unsigned int last_texel_count_wt = wb.texel_count_of_weight[weights_per_block - 1];
403403
uint8_t last_texel = di.weight_texels_tr[last_texel_count_wt - 1][weights_per_block - 1];
404404

405-
unsigned int weights_per_block_simd = round_up_to_simd_multiple_vla(weights_per_block);
406-
for (unsigned int i = weights_per_block; i < weights_per_block_simd; i++)
405+
size_t weights_per_block_simd = round_up_to_simd_multiple_vla(weights_per_block);
406+
for (size_t i = weights_per_block; i < weights_per_block_simd; i++)
407407
{
408408
di.weight_texel_count[i] = 0;
409409

410-
for (unsigned int j = 0; j < max_texel_count_of_weight; j++)
410+
for (size_t j = 0; j < max_texel_count_of_weight; j++)
411411
{
412412
di.weight_texels_tr[j][i] = last_texel;
413413
di.weights_texel_contribs_tr[j][i] = 0.0f;
@@ -640,12 +640,12 @@ static void init_decimation_info_3d(
640640
}
641641

642642
// Initialize array tail so we can over-fetch with SIMD later to avoid loop tails
643-
unsigned int texels_per_block_simd = round_up_to_simd_multiple_vla(texels_per_block);
644-
for (unsigned int i = texels_per_block; i < texels_per_block_simd; i++)
643+
size_t texels_per_block_simd = round_up_to_simd_multiple_vla(texels_per_block);
644+
for (size_t i = texels_per_block; i < texels_per_block_simd; i++)
645645
{
646646
di.texel_weight_count[i] = 0;
647647

648-
for (unsigned int j = 0; j < 4; j++)
648+
for (size_t j = 0; j < 4; j++)
649649
{
650650
di.texel_weight_contribs_float_tr[j][i] = 0;
651651
di.texel_weights_tr[j][i] = 0;
@@ -658,12 +658,12 @@ static void init_decimation_info_3d(
658658
int last_texel_count_wt = wb.texel_count_of_weight[weights_per_block - 1];
659659
uint8_t last_texel = di.weight_texels_tr[last_texel_count_wt - 1][weights_per_block - 1];
660660

661-
unsigned int weights_per_block_simd = round_up_to_simd_multiple_vla(weights_per_block);
662-
for (unsigned int i = weights_per_block; i < weights_per_block_simd; i++)
661+
size_t weights_per_block_simd = round_up_to_simd_multiple_vla(weights_per_block);
662+
for (size_t i = weights_per_block; i < weights_per_block_simd; i++)
663663
{
664664
di.weight_texel_count[i] = 0;
665665

666-
for (int j = 0; j < max_texel_count_of_weight; j++)
666+
for (size_t j = 0; j < max_texel_count_of_weight; j++)
667667
{
668668
di.weight_texels_tr[j][i] = last_texel;
669669
di.weights_texel_contribs_tr[j][i] = 0.0f;

Source/astcenc_ideal_endpoints_and_weights.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ static void compute_ideal_colors_and_weights_1_comp(
195195
}
196196

197197
// Zero initialize any SIMD over-fetch
198-
unsigned int texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
199-
for (unsigned int i = texel_count; i < texel_count_simd; i++)
198+
size_t texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
199+
for (size_t i = texel_count; i < texel_count_simd; i++)
200200
{
201201
ei.weights[i] = 0.0f;
202202
ei.weight_error_scale[i] = 0.0f;
@@ -333,8 +333,8 @@ static void compute_ideal_colors_and_weights_2_comp(
333333
}
334334

335335
// Zero initialize any SIMD over-fetch
336-
unsigned int texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
337-
for (unsigned int i = texel_count; i < texel_count_simd; i++)
336+
size_t texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
337+
for (size_t i = texel_count; i < texel_count_simd; i++)
338338
{
339339
ei.weights[i] = 0.0f;
340340
ei.weight_error_scale[i] = 0.0f;
@@ -500,8 +500,8 @@ static void compute_ideal_colors_and_weights_3_comp(
500500
}
501501

502502
// Zero initialize any SIMD over-fetch
503-
unsigned int texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
504-
for (unsigned int i = texel_count; i < texel_count_simd; i++)
503+
size_t texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
504+
for (size_t i = texel_count; i < texel_count_simd; i++)
505505
{
506506
ei.weights[i] = 0.0f;
507507
ei.weight_error_scale[i] = 0.0f;
@@ -598,8 +598,8 @@ static void compute_ideal_colors_and_weights_4_comp(
598598
}
599599

600600
// Zero initialize any SIMD over-fetch
601-
unsigned int texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
602-
for (unsigned int i = texel_count; i < texel_count_simd; i++)
601+
size_t texel_count_simd = round_up_to_simd_multiple_vla(texel_count);
602+
for (size_t i = texel_count; i < texel_count_simd; i++)
603603
{
604604
ei.weights[i] = 0.0f;
605605
ei.weight_error_scale[i] = 0.0f;

Source/astcenc_partition_tables.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ static bool generate_one_partition_info_entry(
304304
// Fill loop tail so we can overfetch later
305305
for (unsigned int i = 0; i < partition_count; i++)
306306
{
307-
int ptex_count = counts[i];
308-
int ptex_count_simd = round_up_to_simd_multiple_vla(ptex_count);
309-
for (int j = ptex_count; j < ptex_count_simd; j++)
307+
size_t ptex_count = counts[i];
308+
size_t ptex_count_simd = round_up_to_simd_multiple_vla(ptex_count);
309+
for (size_t j = ptex_count; j < ptex_count_simd; j++)
310310
{
311311
pi.texels_of_partition[i][j] = pi.texels_of_partition[i][ptex_count - 1];
312312
}

Source/astcenc_pick_best_endpoint_format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,13 +1135,13 @@ unsigned int compute_ideal_endpoint_formats(
11351135
vfloat clear_error(ERROR_CALC_DEFAULT);
11361136
vint clear_quant(0);
11371137

1138-
unsigned int packed_start_block_mode = round_down_to_simd_multiple_vla(start_block_mode);
1138+
size_t packed_start_block_mode = round_down_to_simd_multiple_vla(start_block_mode);
11391139
storea(clear_error, errors_of_best_combination + packed_start_block_mode);
11401140
store_nbytes(clear_quant, best_quant_levels + packed_start_block_mode);
11411141
store_nbytes(clear_quant, best_quant_levels_mod + packed_start_block_mode);
11421142

11431143
// Ensure that last iteration overstep contains data that will never be picked
1144-
unsigned int packed_end_block_mode = round_down_to_simd_multiple_vla(end_block_mode - 1);
1144+
size_t packed_end_block_mode = round_down_to_simd_multiple_vla(end_block_mode - 1);
11451145
storea(clear_error, errors_of_best_combination + packed_end_block_mode);
11461146
store_nbytes(clear_quant, best_quant_levels + packed_end_block_mode);
11471147
store_nbytes(clear_quant, best_quant_levels_mod + packed_end_block_mode);

Source/astcenc_vecmathlib.h

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// ----------------------------------------------------------------------------
3-
// Copyright 2019-2024 Arm Limited
3+
// Copyright 2019-2025 Arm Limited
44
// Copyright 2008 Jose Fonseca
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -211,30 +211,6 @@ template<typename T> T gatherf_byte_inds(const float* base, const uint8_t* indic
211211
constexpr auto load1 = vfloat4::load1;
212212
#endif
213213

214-
/**
215-
* @brief Round a count down to the largest multiple of 8.
216-
*
217-
* @param count The unrounded value.
218-
*
219-
* @return The rounded value.
220-
*/
221-
ASTCENC_SIMD_INLINE unsigned int round_down_to_simd_multiple_8(unsigned int count)
222-
{
223-
return count & static_cast<unsigned int>(~(8 - 1));
224-
}
225-
226-
/**
227-
* @brief Round a count down to the largest multiple of 4.
228-
*
229-
* @param count The unrounded value.
230-
*
231-
* @return The rounded value.
232-
*/
233-
ASTCENC_SIMD_INLINE unsigned int round_down_to_simd_multiple_4(unsigned int count)
234-
{
235-
return count & static_cast<unsigned int>(~(4 - 1));
236-
}
237-
238214
/**
239215
* @brief Round a count down to the largest multiple of the SIMD width.
240216
*
@@ -244,9 +220,9 @@ ASTCENC_SIMD_INLINE unsigned int round_down_to_simd_multiple_4(unsigned int coun
244220
*
245221
* @return The rounded value.
246222
*/
247-
ASTCENC_SIMD_INLINE unsigned int round_down_to_simd_multiple_vla(unsigned int count)
223+
ASTCENC_SIMD_INLINE size_t round_down_to_simd_multiple_vla(size_t count)
248224
{
249-
return count & static_cast<unsigned int>(~(ASTCENC_SIMD_WIDTH - 1));
225+
return count & static_cast<size_t>(~(ASTCENC_SIMD_WIDTH - 1));
250226
}
251227

252228
/**
@@ -258,9 +234,9 @@ ASTCENC_SIMD_INLINE unsigned int round_down_to_simd_multiple_vla(unsigned int co
258234
*
259235
* @return The rounded value.
260236
*/
261-
ASTCENC_SIMD_INLINE unsigned int round_up_to_simd_multiple_vla(unsigned int count)
237+
ASTCENC_SIMD_INLINE size_t round_up_to_simd_multiple_vla(size_t count)
262238
{
263-
unsigned int multiples = (count + ASTCENC_SIMD_WIDTH - 1) / ASTCENC_SIMD_WIDTH;
239+
size_t multiples = (count + ASTCENC_SIMD_WIDTH - 1) / ASTCENC_SIMD_WIDTH;
264240
return multiples * ASTCENC_SIMD_WIDTH;
265241
}
266242

0 commit comments

Comments
 (0)