From: <xuelin.shi@freescale.com>
To: <thomas.monjalon@6wind.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] librte_lpm: use field access instead of type conversion.
Date: Wed, 11 Feb 2015 14:12:59 +0800 [thread overview]
Message-ID: <1423635179-24903-1-git-send-email-xuelin.shi@freescale.com> (raw)
From: Xuelin Shi <xuelin.shi@freescale.com>
struct tbl_entry{
uint8_t next_hop;
uint8_t valid :1;
uint8_t valid_group :1;
uint8_t depth :6
}
uint16_t tbl = (uint16_t)tbl_entry;
next_hop = (uint8_t)tbl;
next_hop cannot get the correct value of the field
if the cpu arch is BIG_ENDIAN.
change it to field access.
Signed-off-by: Xuelin Shi <xuelin.shi@freescale.com>
---
lib/librte_lpm/rte_lpm.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h
index 586300b..1af150c 100644
--- a/lib/librte_lpm/rte_lpm.h
+++ b/lib/librte_lpm/rte_lpm.h
@@ -273,6 +273,7 @@ rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint8_t *next_hop)
{
unsigned tbl24_index = (ip >> 8);
uint16_t tbl_entry;
+ struct rte_lpm_tbl8_entry *entry;
/* DEBUG: Check user input arguments. */
RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (next_hop == NULL)), -EINVAL);
@@ -290,8 +291,10 @@ rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint8_t *next_hop)
tbl_entry = *(const uint16_t *)&lpm->tbl8[tbl8_index];
}
- *next_hop = (uint8_t)tbl_entry;
- return (tbl_entry & RTE_LPM_LOOKUP_SUCCESS) ? 0 : -ENOENT;
+ entry = (struct rte_lpm_tbl8_entry *)&tbl_entry;
+ *next_hop = entry->next_hop;
+
+ return (entry->valid) ? 0 : -ENOENT;
}
/**
--
1.9.1
next reply other threads:[~2015-02-11 7:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-11 6:12 xuelin.shi [this message]
2015-02-12 11:17 ` Bruce Richardson
2015-02-13 3:42 ` Xuelin Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423635179-24903-1-git-send-email-xuelin.shi@freescale.com \
--to=xuelin.shi@freescale.com \
--cc=dev@dpdk.org \
--cc=thomas.monjalon@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).