2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

multipath: Correctly calculate number of required destination bits.

The previous calculation was wrong when n_links was a power of 2.

Reported-by: Paul Ingram <paul@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2011-12-27 13:37:43 -08:00
parent 90bf1e0732
commit 300c69464c
3 changed files with 10 additions and 1 deletions

View File

@@ -664,6 +664,14 @@ log_2_floor(uint32_t n)
#endif
}
/* Given a 32 bit word 'n', calculates ceil(log_2('n')). It is an error to
* call this function with 'n' == 0. */
int
log_2_ceil(uint32_t n)
{
return log_2_floor(n) + !IS_POW2(n);
}
/* Returns the number of trailing 0-bits in 'n', or 32 if 'n' is 0. */
int
ctz(uint32_t n)