[v2,2/2] lib/hash: avoid implicit conversion to 64 bit number
Checks
Commit Message
MSVC issues the warnings below:
1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)
The code would be better off by using 64 bit numbers to begin with.
That eliminates the need for a conversion to 64 bits later.
2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)
Instead of multiplying sizeof(uint32_t) by the result of shifting
"1", sizeof(uint32_t) can be shifted directly.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/hash/rte_thash.c | 2 +-
lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
Comments
> From: Andre Muezerie [mailto:andremue@linux.microsoft.com]
> Sent: Monday, 27 January 2025 17.04
>
> MSVC issues the warnings below:
>
> 1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
> result of 32-bit shift implicitly converted to 64 bits
> (was 64-bit shift intended?)
>
> The code would be better off by using 64 bit numbers to begin with.
> That eliminates the need for a conversion to 64 bits later.
>
> 2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
> result of 32-bit shift implicitly converted to 64 bits
> (was 64-bit shift intended?)
>
> Instead of multiplying sizeof(uint32_t) by the result of shifting
> "1", sizeof(uint32_t) can be shifted directly.
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
offset;
ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
- sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+ (sizeof(uint32_t) << ctx->reta_sz_log),
RTE_CACHE_LINE_SIZE);
if (ent == NULL)
return -ENOMEM;
@@ -118,16 +118,16 @@ static uint32_t
gf2_mul(uint32_t a, uint32_t b, uint32_t r, int degree)
{
uint64_t product = 0;
- uint64_t r_poly = r|(1ULL << degree);
+ uint64_t r_poly = r | RTE_BIT64(degree);
for (; b; b &= (b - 1))
product ^= (uint64_t)a << (rte_bsf32(b));
for (int i = degree * 2 - 1; i >= degree; i--)
- if (product & (1 << i))
+ if (product & RTE_BIT64(i))
product ^= r_poly << (i - degree);
- return product;
+ return (uint32_t)product;
}
static uint32_t