diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-12-08 20:47:09 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-12-08 20:47:09 (GMT) |
commit | cf11fcf862b98ef57935bcfccd6f2f6ae3f925f6 (patch) | |
tree | d7ae9d965b8eea03adfaf7a4d42907aae683d0f9 /src/arch | |
parent | 48ac5e6e8fe50c1ff4b9e77440a6365f8b01021f (diff) |
Improved the way vmpa_t types are compared.
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/vmpa.c | 52 | ||||
-rw-r--r-- | src/arch/vmpa.h | 3 |
2 files changed, 39 insertions, 16 deletions
diff --git a/src/arch/vmpa.c b/src/arch/vmpa.c index 6db62cc..f90ab22 100644 --- a/src/arch/vmpa.c +++ b/src/arch/vmpa.c @@ -193,8 +193,8 @@ int cmp_vmpa_by_phy(const vmpa2t *a, const vmpa2t *b) else { if (a->physical == VMPA_NO_PHYSICAL && b->physical == VMPA_NO_PHYSICAL) result = 0; - else if (a->physical == VMPA_NO_PHYSICAL) result = -1; - else result = 1; + else if (a->physical == VMPA_NO_PHYSICAL) result = 1; + else result = -1; } return result; @@ -228,8 +228,8 @@ int cmp_vmpa_by_virt(const vmpa2t *a, const vmpa2t *b) else { if (a->virtual == VMPA_NO_VIRTUAL && b->virtual == VMPA_NO_VIRTUAL) result = 0; - else if (a->virtual == VMPA_NO_VIRTUAL) result = -1; - else result = 1; + else if (a->virtual == VMPA_NO_VIRTUAL) result = 1; + else result = -1; } return result; @@ -253,22 +253,48 @@ int cmp_vmpa_by_virt(const vmpa2t *a, const vmpa2t *b) int cmp_vmpa(const vmpa2t *a, const vmpa2t *b) { int result; /* Bilan à retourner */ - bool half; /* Comparaison débutée */ + bool compared; /* Comparaison effectuée */ - result = -1; + if (a->physical == VMPA_NO_PHYSICAL && a->virtual == VMPA_NO_VIRTUAL + && b->physical == VMPA_NO_PHYSICAL && b->virtual == VMPA_NO_VIRTUAL) + { + result = 0; - half = false; + } - if (a->physical != VMPA_NO_PHYSICAL && b->physical != VMPA_NO_PHYSICAL) + else if (a->physical == VMPA_NO_PHYSICAL && a->virtual == VMPA_NO_VIRTUAL) { - result = cmp_vmpa_by_phy(a, b); - half = true; + result = 1; + } - if (a->virtual != VMPA_NO_VIRTUAL && b->virtual != VMPA_NO_VIRTUAL - && (!half || (half && result == 0))) + else if (b->physical == VMPA_NO_PHYSICAL && b->virtual == VMPA_NO_VIRTUAL) + { + result = -1; + + } + + else { - result = cmp_vmpa_by_virt(a, b); + compared = false; + + if (a->physical != VMPA_NO_PHYSICAL && b->physical != VMPA_NO_PHYSICAL) + { + result = cmp_vmpa_by_phy(a, b); + compared = true; + } + + if (a->virtual != VMPA_NO_VIRTUAL && b->virtual != VMPA_NO_VIRTUAL + && (!compared || (compared && result == 0))) + { + result = cmp_vmpa_by_virt(a, b); + compared = true; + } + + /* Cas particulier : les deux éléments n'ont aucun champ défini en commun ! */ + if (!compared) + result = cmp_vmpa_by_phy(a, b); + } return result; diff --git a/src/arch/vmpa.h b/src/arch/vmpa.h index 871e282..6ed7605 100644 --- a/src/arch/vmpa.h +++ b/src/arch/vmpa.h @@ -99,9 +99,6 @@ int cmp_vmpa_by_virt(const vmpa2t *, const vmpa2t *); /* Compare deux localisations selon leurs parties définies. */ int cmp_vmpa(const vmpa2t *, const vmpa2t *); -#define are_equal(a, b) \ - (cmp_vmpa_by_phy(a, b) == 0 && cmp_vmpa_by_virt(a, b) == 0) - #define get_phy_addr(a) (a)->physical #define get_virt_addr(a) (a)->virtual |