[02/16] hash: remove use of VLAs for Windows built code
Checks
Commit Message
MSVC does not support VLAs, replace VLAs with standard C arrays
or alloca(). alloca() is available for all toolchain/platform
combinations officially supported by DPDK.
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
lib/hash/rte_cuckoo_hash.c | 4 ++--
lib/hash/rte_thash.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
Comments
> - int32_t positions[num_keys];
> + int32_t *positions = alloca(sizeof(int32_t) * num_keys);
A general comment, using this patch as an example...
I wonder if adding const has any effect on the compilers' optimizers:
int32_t * const positions = alloca(sizeof(int32_t) * num_keys);
Perhaps not in this specific case, but maybe elsewhere.
Especially if passing the array by reference.
We're not good at adding const and restrict to function parameters, so declaring the alloca()'d arrays const might compensate for that.
@@ -2359,7 +2359,7 @@ struct rte_hash *
(num_keys > RTE_HASH_LOOKUP_BULK_MAX) ||
(hit_mask == NULL)), -EINVAL);
- int32_t positions[num_keys];
+ int32_t *positions = alloca(sizeof(int32_t) * num_keys);
__rte_hash_lookup_bulk(h, keys, num_keys, positions, hit_mask, data);
@@ -2475,7 +2475,7 @@ struct rte_hash *
(num_keys > RTE_HASH_LOOKUP_BULK_MAX) ||
(hit_mask == NULL)), -EINVAL);
- int32_t positions[num_keys];
+ int32_t *positions = alloca(sizeof(int32_t) * num_keys);
__rte_hash_lookup_with_hash_bulk(h, keys, sig, num_keys,
positions, hit_mask, data);
@@ -771,7 +771,7 @@ struct rte_thash_subtuple_helper *
uint32_t desired_value, unsigned int attempts,
rte_thash_check_tuple_t fn, void *userdata)
{
- uint32_t tmp_tuple[tuple_len / sizeof(uint32_t)];
+ uint32_t *tmp_tuple = alloca(tuple_len);
unsigned int i, j, ret = 0;
uint32_t hash, adj_bits;
const uint8_t *hash_key;