summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Cretin <julien.cretin@trust-in-soft.com>2014-05-12 17:35:10 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2014-05-14 11:21:44 +0200
commit2612a4b935144accff34bc16e019c858677ada62 (patch)
treebbad86cd905623931f79fee47dbc56a041faf64b
parent937cca79c9b88641050ad92704997313f74f6149 (diff)
downloaddpdk-2612a4b935144accff34bc16e019c858677ada62.zip
dpdk-2612a4b935144accff34bc16e019c858677ada62.tar.gz
dpdk-2612a4b935144accff34bc16e019c858677ada62.tar.xz
mem: remove redundant check in optimize_object_size
The second condition of this logical OR: (get_gcd(new_obj_size, nrank * nchan) != 1 || get_gcd(nchan, new_obj_size) != 1) is redundant with the first condition. We can show that the first condition is equivalent to its disjunction with the second condition using these two results: - R1: For all conditions A and B, if B implies A, then (A || B) is equivalent to A. - R2: (get_gcd(nchan, new_obj_size) != 1) implies (get_gcd(new_obj_size, nrank * nchan) != 1) We can show R1 with the following truth table (0 is false, 1 is true): +-----+-----++----------+-----+-------------+ | A | B || (A || B) | A | B implies A | +-----+-----++----------+-----+-------------+ | 0 | 0 || 0 | 0 | 1 | | 0 | 1 || 1 | 0 | 0 | | 1 | 0 || 1 | 1 | 1 | | 1 | 1 || 1 | 1 | 1 | +-----+-----++----------+-----+-------------+ Truth table of (A || B) and A We can show R2 by looking at the code of optimize_object_size and get_gcd. We see that: - S1: (nchan >= 1) and (nrank >= 1). - S2: get_gcd returns 0 only when both arguments are 0. Let: - X be get_gcd(new_obj_size, nrank * nchan). - Y be get_gcd(nchan, new_obj_size). Suppose: - H1: get_gcd returns the greatest common divisor of its arguments. - H2: (nrank * nchan) does not exceed UINT_MAX. We prove (Y != 1) implies (X != 1) with the following steps: - Suppose L0: (Y != 1). We have to show (X != 1). - By H1, Y is the greatest common divisor of nchan and new_obj_size. In particular, we have L1: Y divides nchan and new_obj_size. - By H2, we have L2: nchan divides (nrank * nchan) - By L1 and L2, we have L3: Y divides (nrank * nchan) and new_obj_size. - By H1 and L3, we have L4: (Y <= X). - By S1 and S2, we have L5: (Y != 0). - By L0 and L5, we have L6: (Y > 1). - By L4 and L6, we have (X > 1) and thus (X != 1), which concludes. R2 was also tested for all values of new_obj_size, nrank, and nchan between 0 and 2000. This redundant condition was found using TrustInSoft Analyzer. Signed-off-by: Julien Cretin <julien.cretin@trust-in-soft.com> Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
-rw-r--r--lib/librte_mempool/rte_mempool.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index fdc1586..8e6c86a 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -114,8 +114,7 @@ static unsigned optimize_object_size(unsigned obj_size)
/* process new object size */
new_obj_size = (obj_size + CACHE_LINE_MASK) / CACHE_LINE_SIZE;
- while (get_gcd(new_obj_size, nrank * nchan) != 1 ||
- get_gcd(nchan, new_obj_size) != 1)
+ while (get_gcd(new_obj_size, nrank * nchan) != 1)
new_obj_size++;
return new_obj_size * CACHE_LINE_SIZE;
}