Skip to content

Commit

Permalink
test: icache_perf: fix potential integer overflow
Browse files Browse the repository at this point in the history
Fix OVERFLOW_BEFORE_WIDEN warning from Coverity.

Signed-off-by: Matias Elo <[email protected]>
Reviewed-by: Petri Savolainen <[email protected]>
  • Loading branch information
MatiasElo committed Jul 4, 2024
1 parent 2b4a53e commit 254ef4f
Showing 1 changed file with 154 additions and 153 deletions.
307 changes: 154 additions & 153 deletions test/performance/odp_icache_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,182 +79,182 @@ static test_global_t *test_global;

static inline INLINE_ALWAYS uint64_t mac_28(uint64_t a, uint32_t b[], uint32_t c[])
{
a += b[0] * c[0];
a += b[1] * c[1];
a += b[2] * c[2];
a += b[3] * c[3];
a += b[4] * c[4];
a += b[5] * c[5];
a += b[6] * c[6];
a += b[7] * c[7];
a += b[8] * c[8];
a += b[9] * c[9];
a += b[10] * c[10];
a += b[11] * c[11];
a += b[12] * c[12];
a += b[13] * c[13];
a += b[14] * c[14];
a += b[15] * c[15];
a += b[16] * c[16];
a += b[17] * c[17];
a += b[18] * c[18];
a += b[19] * c[19];
a += b[20] * c[20];
a += b[21] * c[21];
a += b[22] * c[22];
a += b[23] * c[23];
a += b[24] * c[24];
a += b[25] * c[25];
a += b[26] * c[26];
a += b[27] * c[27];
a += (uint64_t)b[0] * c[0];
a += (uint64_t)b[1] * c[1];
a += (uint64_t)b[2] * c[2];
a += (uint64_t)b[3] * c[3];
a += (uint64_t)b[4] * c[4];
a += (uint64_t)b[5] * c[5];
a += (uint64_t)b[6] * c[6];
a += (uint64_t)b[7] * c[7];
a += (uint64_t)b[8] * c[8];
a += (uint64_t)b[9] * c[9];
a += (uint64_t)b[10] * c[10];
a += (uint64_t)b[11] * c[11];
a += (uint64_t)b[12] * c[12];
a += (uint64_t)b[13] * c[13];
a += (uint64_t)b[14] * c[14];
a += (uint64_t)b[15] * c[15];
a += (uint64_t)b[16] * c[16];
a += (uint64_t)b[17] * c[17];
a += (uint64_t)b[18] * c[18];
a += (uint64_t)b[19] * c[19];
a += (uint64_t)b[20] * c[20];
a += (uint64_t)b[21] * c[21];
a += (uint64_t)b[22] * c[22];
a += (uint64_t)b[23] * c[23];
a += (uint64_t)b[24] * c[24];
a += (uint64_t)b[25] * c[25];
a += (uint64_t)b[26] * c[26];
a += (uint64_t)b[27] * c[27];

return a;
}

static inline INLINE_ALWAYS uint64_t mac_30(uint64_t a, uint32_t b[], uint32_t c[])
{
a += b[0] * c[0];
a += b[1] * c[1];
a += b[2] * c[2];
a += b[3] * c[3];
a += b[4] * c[4];
a += b[5] * c[5];
a += b[6] * c[6];
a += b[7] * c[7];
a += b[8] * c[8];
a += b[9] * c[9];
a += b[10] * c[10];
a += b[11] * c[11];
a += b[12] * c[12];
a += b[13] * c[13];
a += b[14] * c[14];
a += b[15] * c[15];
a += b[16] * c[16];
a += b[17] * c[17];
a += b[18] * c[18];
a += b[19] * c[19];
a += b[20] * c[20];
a += b[21] * c[21];
a += b[22] * c[22];
a += b[23] * c[23];
a += b[24] * c[24];
a += b[25] * c[25];
a += b[26] * c[26];
a += b[27] * c[27];
a += b[28] * c[28];
a += b[29] * c[29];
a += (uint64_t)b[0] * c[0];
a += (uint64_t)b[1] * c[1];
a += (uint64_t)b[2] * c[2];
a += (uint64_t)b[3] * c[3];
a += (uint64_t)b[4] * c[4];
a += (uint64_t)b[5] * c[5];
a += (uint64_t)b[6] * c[6];
a += (uint64_t)b[7] * c[7];
a += (uint64_t)b[8] * c[8];
a += (uint64_t)b[9] * c[9];
a += (uint64_t)b[10] * c[10];
a += (uint64_t)b[11] * c[11];
a += (uint64_t)b[12] * c[12];
a += (uint64_t)b[13] * c[13];
a += (uint64_t)b[14] * c[14];
a += (uint64_t)b[15] * c[15];
a += (uint64_t)b[16] * c[16];
a += (uint64_t)b[17] * c[17];
a += (uint64_t)b[18] * c[18];
a += (uint64_t)b[19] * c[19];
a += (uint64_t)b[20] * c[20];
a += (uint64_t)b[21] * c[21];
a += (uint64_t)b[22] * c[22];
a += (uint64_t)b[23] * c[23];
a += (uint64_t)b[24] * c[24];
a += (uint64_t)b[25] * c[25];
a += (uint64_t)b[26] * c[26];
a += (uint64_t)b[27] * c[27];
a += (uint64_t)b[28] * c[28];
a += (uint64_t)b[29] * c[29];

return a;
}

static inline INLINE_ALWAYS uint64_t mac_32(uint64_t a, uint32_t b[], uint32_t c[])
{
a += b[0] * c[0];
a += b[1] * c[1];
a += b[2] * c[2];
a += b[3] * c[3];
a += b[4] * c[4];
a += b[5] * c[5];
a += b[6] * c[6];
a += b[7] * c[7];
a += b[8] * c[8];
a += b[9] * c[9];
a += b[10] * c[10];
a += b[11] * c[11];
a += b[12] * c[12];
a += b[13] * c[13];
a += b[14] * c[14];
a += b[15] * c[15];
a += b[16] * c[16];
a += b[17] * c[17];
a += b[18] * c[18];
a += b[19] * c[19];
a += b[20] * c[20];
a += b[21] * c[21];
a += b[22] * c[22];
a += b[23] * c[23];
a += b[24] * c[24];
a += b[25] * c[25];
a += b[26] * c[26];
a += b[27] * c[27];
a += b[28] * c[28];
a += b[29] * c[29];
a += b[30] * c[30];
a += b[31] * c[31];
a += (uint64_t)b[0] * c[0];
a += (uint64_t)b[1] * c[1];
a += (uint64_t)b[2] * c[2];
a += (uint64_t)b[3] * c[3];
a += (uint64_t)b[4] * c[4];
a += (uint64_t)b[5] * c[5];
a += (uint64_t)b[6] * c[6];
a += (uint64_t)b[7] * c[7];
a += (uint64_t)b[8] * c[8];
a += (uint64_t)b[9] * c[9];
a += (uint64_t)b[10] * c[10];
a += (uint64_t)b[11] * c[11];
a += (uint64_t)b[12] * c[12];
a += (uint64_t)b[13] * c[13];
a += (uint64_t)b[14] * c[14];
a += (uint64_t)b[15] * c[15];
a += (uint64_t)b[16] * c[16];
a += (uint64_t)b[17] * c[17];
a += (uint64_t)b[18] * c[18];
a += (uint64_t)b[19] * c[19];
a += (uint64_t)b[20] * c[20];
a += (uint64_t)b[21] * c[21];
a += (uint64_t)b[22] * c[22];
a += (uint64_t)b[23] * c[23];
a += (uint64_t)b[24] * c[24];
a += (uint64_t)b[25] * c[25];
a += (uint64_t)b[26] * c[26];
a += (uint64_t)b[27] * c[27];
a += (uint64_t)b[28] * c[28];
a += (uint64_t)b[29] * c[29];
a += (uint64_t)b[30] * c[30];
a += (uint64_t)b[31] * c[31];

return a;
}

static inline INLINE_ALWAYS uint64_t mac_const_30(uint64_t a, uint32_t b[], uint32_t c)
{
a += b[0] * c;
a += b[1] * c;
a += b[2] * c;
a += b[3] * c;
a += b[4] * c;
a += b[5] * c;
a += b[6] * c;
a += b[7] * c;
a += b[8] * c;
a += b[9] * c;
a += b[10] * c;
a += b[11] * c;
a += b[12] * c;
a += b[13] * c;
a += b[14] * c;
a += b[15] * c;
a += b[16] * c;
a += b[17] * c;
a += b[18] * c;
a += b[19] * c;
a += b[20] * c;
a += b[21] * c;
a += b[22] * c;
a += b[23] * c;
a += b[24] * c;
a += b[25] * c;
a += b[26] * c;
a += b[27] * c;
a += b[28] * c;
a += b[29] * c;
a += (uint64_t)b[0] * c;
a += (uint64_t)b[1] * c;
a += (uint64_t)b[2] * c;
a += (uint64_t)b[3] * c;
a += (uint64_t)b[4] * c;
a += (uint64_t)b[5] * c;
a += (uint64_t)b[6] * c;
a += (uint64_t)b[7] * c;
a += (uint64_t)b[8] * c;
a += (uint64_t)b[9] * c;
a += (uint64_t)b[10] * c;
a += (uint64_t)b[11] * c;
a += (uint64_t)b[12] * c;
a += (uint64_t)b[13] * c;
a += (uint64_t)b[14] * c;
a += (uint64_t)b[15] * c;
a += (uint64_t)b[16] * c;
a += (uint64_t)b[17] * c;
a += (uint64_t)b[18] * c;
a += (uint64_t)b[19] * c;
a += (uint64_t)b[20] * c;
a += (uint64_t)b[21] * c;
a += (uint64_t)b[22] * c;
a += (uint64_t)b[23] * c;
a += (uint64_t)b[24] * c;
a += (uint64_t)b[25] * c;
a += (uint64_t)b[26] * c;
a += (uint64_t)b[27] * c;
a += (uint64_t)b[28] * c;
a += (uint64_t)b[29] * c;

return a;
}

static inline INLINE_ALWAYS uint64_t mac_const_32(uint64_t a, uint32_t b[], uint32_t c)
{
a += b[0] * c;
a += b[1] * c;
a += b[2] * c;
a += b[3] * c;
a += b[4] * c;
a += b[5] * c;
a += b[6] * c;
a += b[7] * c;
a += b[8] * c;
a += b[9] * c;
a += b[10] * c;
a += b[11] * c;
a += b[12] * c;
a += b[13] * c;
a += b[14] * c;
a += b[15] * c;
a += b[16] * c;
a += b[17] * c;
a += b[18] * c;
a += b[19] * c;
a += b[20] * c;
a += b[21] * c;
a += b[22] * c;
a += b[23] * c;
a += b[24] * c;
a += b[25] * c;
a += b[26] * c;
a += b[27] * c;
a += b[28] * c;
a += b[29] * c;
a += b[30] * c;
a += b[31] * c;
a += (uint64_t)b[0] * c;
a += (uint64_t)b[1] * c;
a += (uint64_t)b[2] * c;
a += (uint64_t)b[3] * c;
a += (uint64_t)b[4] * c;
a += (uint64_t)b[5] * c;
a += (uint64_t)b[6] * c;
a += (uint64_t)b[7] * c;
a += (uint64_t)b[8] * c;
a += (uint64_t)b[9] * c;
a += (uint64_t)b[10] * c;
a += (uint64_t)b[11] * c;
a += (uint64_t)b[12] * c;
a += (uint64_t)b[13] * c;
a += (uint64_t)b[14] * c;
a += (uint64_t)b[15] * c;
a += (uint64_t)b[16] * c;
a += (uint64_t)b[17] * c;
a += (uint64_t)b[18] * c;
a += (uint64_t)b[19] * c;
a += (uint64_t)b[20] * c;
a += (uint64_t)b[21] * c;
a += (uint64_t)b[22] * c;
a += (uint64_t)b[23] * c;
a += (uint64_t)b[24] * c;
a += (uint64_t)b[25] * c;
a += (uint64_t)b[26] * c;
a += (uint64_t)b[27] * c;
a += (uint64_t)b[28] * c;
a += (uint64_t)b[29] * c;
a += (uint64_t)b[30] * c;
a += (uint64_t)b[31] * c;

return a;
}
Expand Down Expand Up @@ -15649,7 +15649,8 @@ int main(int argc, char **argv)
if (test_options->pattern) {
uint64_t max = NUM_WORK * global->max_func * (sizeof(uint16_t) + sizeof(void *));

max_table_size = NUM_WORK * test_options->num_func * 2 * ODP_CACHE_LINE_SIZE;
max_table_size = NUM_WORK * (uint64_t)test_options->num_func * 2 *
ODP_CACHE_LINE_SIZE;
if (max_table_size > max)
max_table_size = max;
}
Expand Down

0 comments on commit 254ef4f

Please sign in to comment.