numam-dpdk/lib
Julien Cretin 2612a4b935 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>
2014-05-14 11:21:44 +02:00
..
librte_cmdline add FreeBSD support 2014-02-25 21:29:18 +01:00
librte_eal mem: change default per socket memory allocation 2014-05-14 11:06:49 +02:00
librte_ether ethdev: introduce if_index in device info 2014-02-26 11:07:28 +01:00
librte_hash hash: make arg for jhash2 const 2014-03-24 18:58:25 +01:00
librte_ivshmem ivshmem: library changes for mmaping using ivshmem 2014-02-25 21:29:19 +01:00
librte_kni kni: add kni close function 2014-02-25 21:29:19 +01:00
librte_kvargs devargs: use a comma instead of semicolon to separate key/values 2014-04-10 15:50:11 +02:00
librte_lpm update Intel copyright years to 2014 2014-02-25 21:29:14 +01:00
librte_malloc malloc: simplify heap initialisation 2014-04-30 11:31:22 +02:00
librte_mbuf mbuf: copy offload flags when doing attach/clone 2014-03-24 18:58:25 +01:00
librte_mempool mem: remove redundant check in optimize_object_size 2014-05-14 11:21:44 +02:00
librte_meter update Intel copyright years to 2014 2014-02-25 21:29:14 +01:00
librte_net update Intel copyright years to 2014 2014-02-25 21:29:14 +01:00
librte_pmd_e1000 igb: release software locked semaphores on initialization 2014-04-09 18:30:02 +02:00
librte_pmd_ixgbe ixgbe: release software locked semaphores on initialization 2014-04-09 18:30:02 +02:00
librte_pmd_pcap vdev: new registration API 2014-04-11 16:17:42 +02:00
librte_pmd_ring vdev: new registration API 2014-04-11 16:17:42 +02:00
librte_pmd_virtio pci: remove virtio-uio workaround 2014-05-13 13:20:35 +02:00
librte_pmd_vmxnet3 vmxnet3: rename library 2014-03-21 15:40:30 +01:00
librte_pmd_xenvirt vdev: new registration API 2014-04-11 16:17:42 +02:00
librte_power update Intel copyright years to 2014 2014-02-25 21:29:14 +01:00
librte_ring ring: allow to initialize without memzone 2014-05-13 14:40:09 +02:00
librte_sched sched: use common macro RTE_DIM 2014-02-25 21:29:18 +01:00
librte_timer timer: missing optimization flag in compile 2014-02-25 21:29:18 +01:00
Makefile kvargs: add a new library to parse key/value arguments 2014-02-26 11:01:13 +01:00