From: Bruce Richardson <bruce.richardson@intel.com>
To: Radu Nicolau <radu.nicolau@intel.com>
Cc: Marat Khalili <marat.khalili@huawei.com>,
"stable@dpdk.org" <stable@dpdk.org>,
"stephen@networkplumber.org" <stephen@networkplumber.org>,
Yipeng Wang <yipeng1.wang@intel.com>,
Sameh Gobriel <sameh.gobriel@intel.com>,
Vladimir Medvedkin <vladimir.medvedkin@intel.com>,
Pablo de Lara <pablo.de.lara.guarch@intel.com>,
Yerden Zhumabekov <e_zhumabekov@sts.kz>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [PATCH] hash: fix pointer alignment
Date: Thu, 26 Feb 2026 19:47:18 +0000 [thread overview]
Message-ID: <aaCjRvcjabv2PFuO@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <b28a0e99-8642-499d-95a8-a6ed30f939d4@intel.com>
On Thu, Feb 26, 2026 at 04:43:26PM +0000, Radu Nicolau wrote:
>
> On 26-Feb-26 4:22 PM, Marat Khalili wrote:
> > > diff --git a/lib/hash/rte_hash_crc.h b/lib/hash/rte_hash_crc.h
> > > index fa07c97685..66f11fafcd 100644
> > > --- a/lib/hash/rte_hash_crc.h
> > > +++ b/lib/hash/rte_hash_crc.h
> > > @@ -127,6 +127,24 @@ rte_hash_crc(const void *data, uint32_t data_len, uint32_t init_val)
> > > unsigned i;
> > > uintptr_t pd = (uintptr_t) data;
> > >
> > > + /* align input to 8 byte boundary if needed */
> > > + if ((pd & 0x7) && data_len >= 8) {
> > Perhaps the case data_len < 8 should also be included, with each of the if's below checking and correcting data_len individually?
>
> No need to include this case; if data_len < 8 it will skip the for loop and
> fall through those 3 if's, and get processed there.
>
>
> >
> > > + uintptr_t unaligned_bytes = 8 - (pd & 0x7);
> > > + data_len -= unaligned_bytes;
> > > + if (unaligned_bytes & 0x4) {
> > > + init_val = rte_hash_crc_4byte(*(const uint32_t *)pd, init_val);
> > > + pd += 4;
> > > + }
> > > + if (unaligned_bytes & 0x2) {
> > > + init_val = rte_hash_crc_2byte(*(const uint16_t *)pd, init_val);
> > > + pd += 2;
> > > + }
> > > + if (unaligned_bytes & 0x1) {
> > > + init_val = rte_hash_crc_1byte(*(const uint8_t *)pd, init_val);
> > > + pd += 1;
> > > + }
> > Shouldn't the order be the opposite?
> As long as we process the right number of bytes the order doesn't matter.
But if we reverse the order we get more natural alignment. If the data
pointer is off-by-one, e.g. 0x65, and unaligned_bytes == 7, if we do as
here, we calculate the 4-byte version and 2-byte versions with 1-byte
alignment of the data. By reversing the order, we would do the 2-byte
calculation on 2-byte aligned data, and the 4-byte calc on 4-byte aligned
data etc.
next prev parent reply other threads:[~2026-02-26 19:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 14:22 [PATCH] hash: fix pointer alignment Radu Nicolau
2026-02-26 16:22 ` Marat Khalili
2026-02-26 16:43 ` Radu Nicolau
2026-02-26 19:47 ` Bruce Richardson [this message]
2026-02-27 9:44 ` Radu Nicolau
2026-02-27 9:48 ` [PATCH v2] " Radu Nicolau
2026-02-27 12:37 ` Marat Khalili
2026-02-27 13:00 ` Radu Nicolau
2026-02-27 13:59 ` [PATCH v3] " Radu Nicolau
2026-02-27 15:55 ` Marat Khalili
2026-03-05 12:18 ` David Marchand
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=aaCjRvcjabv2PFuO@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=e_zhumabekov@sts.kz \
--cc=marat.khalili@huawei.com \
--cc=pablo.de.lara.guarch@intel.com \
--cc=radu.nicolau@intel.com \
--cc=sameh.gobriel@intel.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=vladimir.medvedkin@intel.com \
--cc=yipeng1.wang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.