netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hao Lan <lanhao@huawei.com>
To: <netdev@vger.kernel.org>
Cc: <yisen.zhuang@huawei.com>, <salil.mehta@huawei.com>,
	<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <richardcochran@gmail.com>,
	<lanhao@huawei.com>, <wangpeiyang1@huawei.com>,
	<shenjian15@huawei.com>, <chenhao418@huawei.com>,
	<simon.horman@corigine.com>, <wangjie125@huawei.com>,
	<yuanjilin@cdjrlc.com>, <cai.huoqing@linux.dev>,
	<xiujianfeng@huawei.com>
Subject: [PATCH net-next v3 1/3] net: hns3: refine the tcam key convert handle
Date: Wed, 21 Jun 2023 20:33:07 +0800	[thread overview]
Message-ID: <20230621123309.34381-2-lanhao@huawei.com> (raw)
In-Reply-To: <20230621123309.34381-1-lanhao@huawei.com>

From: Jian Shen <shenjian15@huawei.com>

The result of expression '(k ^ ~v)  & k' is exactly
the same with  'k & v', so simplify it.
(k ^ ~v) & k == k & v
The truth table (in non table form):
k == 0, v == 0:
  (k ^ ~v) & k == (0 ^ ~0) & 0 == (0 ^ 1) & 0 == 1 & 0 == 0
  k & v == 0 & 0 == 0

k == 0, v == 1:
  (k ^ ~v) & k == (0 ^ ~1) & 0 == (0 ^ 0) & 0 == 1 & 0 == 0
  k & v == 0 & 1 == 0

k == 1, v == 0:
  (k ^ ~v) & k == (1 ^ ~0) & 1 == (1 ^ 1) & 1 == 0 & 1 == 0
  k & v == 1 & 0 == 0

k == 1, v == 1:
  (k ^ ~v) & k == (1 ^ ~1) & 1 == (1 ^ 0) & 1 == 1 & 1 == 1
  k & v == 1 & 1 == 1
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Hao Lan <lanhao@huawei.com>
---
ChangeLog:
v1->v2:
Fixed the comment description error and added
the truth table in the comment.
suggested by Simon Horman.
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h   | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 81aa6b0facf5..6a43d1515585 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -835,15 +835,10 @@ struct hclge_vf_vlan_cfg {
  * Then for input key(k) and mask(v), we can calculate the value by
  * the formulae:
  *	x = (~k) & v
- *	y = (k ^ ~v) & k
+ *	y = k & v
  */
-#define calc_x(x, k, v) (x = ~(k) & (v))
-#define calc_y(y, k, v) \
-	do { \
-		const typeof(k) _k_ = (k); \
-		const typeof(v) _v_ = (v); \
-		(y) = (_k_ ^ ~_v_) & (_k_); \
-	} while (0)
+#define calc_x(x, k, v) ((x) = ~(k) & (v))
+#define calc_y(y, k, v) ((y) = (k) & (v))
 
 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
 #define HCLGE_STATS_READ(p, offset) (*(u64 *)((u8 *)(p) + (offset)))
-- 
2.30.0


  reply	other threads:[~2023-06-21 12:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 12:33 [PATCH net-next v3 0/3] net: hns3: There are some cleanup for the HNS3 ethernet driver Hao Lan
2023-06-21 12:33 ` Hao Lan [this message]
2023-06-21 12:33 ` [PATCH net-next v3 2/3] net: hns3: fix strncpy() not using dest-buf length as length issue Hao Lan
2023-06-21 12:33 ` [PATCH net-next v3 3/3] net: hns3: clear hns unused parameter alarm Hao Lan
2023-06-23  9:10 ` [PATCH net-next v3 0/3] net: hns3: There are some cleanup for the HNS3 ethernet driver patchwork-bot+netdevbpf

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=20230621123309.34381-2-lanhao@huawei.com \
    --to=lanhao@huawei.com \
    --cc=cai.huoqing@linux.dev \
    --cc=chenhao418@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=salil.mehta@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=simon.horman@corigine.com \
    --cc=wangjie125@huawei.com \
    --cc=wangpeiyang1@huawei.com \
    --cc=xiujianfeng@huawei.com \
    --cc=yisen.zhuang@huawei.com \
    --cc=yuanjilin@cdjrlc.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).