DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: "Morten Brørup" <mb@smartsharesystems.com>, dev@dpdk.org
Cc: Olivier Matz <olivier.matz@6wind.com>,
	Harry Van Haaren <harry.van.haaren@intel.com>,
	Konstantin Ananyev <konstantin.ananyev@intel.com>
Subject: Re: [dpdk-dev] rte_ether_addr_copy() strange comment
Date: Fri, 26 Jun 2020 13:08:00 +0100	[thread overview]
Message-ID: <6b67ce84-92ee-550d-2fba-af8c4c1bb2aa@intel.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35C610C4@smartserver.smartshare.dk>

On 6/25/2020 4:45 PM, Morten Brørup wrote:
> The function rte_ether_addr_copy() checks for __INTEL_COMPILER and has a comment about "a strange gcc warning". It says:
> 
> static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
> 				   struct rte_ether_addr *ea_to)
> {
> #ifdef __INTEL_COMPILER
> 	uint16_t *from_words = (uint16_t *)(ea_from->addr_bytes);
> 	uint16_t *to_words   = (uint16_t *)(ea_to->addr_bytes);
> 
> 	to_words[0] = from_words[0];
> 	to_words[1] = from_words[1];
> 	to_words[2] = from_words[2];
> #else
> 	/*
> 	 * Use the common way, because of a strange gcc warning.
> 	 */
> 	*ea_to = *ea_from;
> #endif
> }
> 
> I can see that from_words discards the const qualifier. Is that the "strange" gcc warning the comment is referring to?
> 
> This goes back to before the first public release of DPDK in 2013, ref. https://git.dpdk.org/dpdk/log/lib/librte_ether/rte_ether.h
> 
> 
> It should be fixed as follows:
> 
> -	uint16_t *from_words = (uint16_t *)(ea_from->addr_bytes);
> -	uint16_t *to_words   = (uint16_t *)(ea_to->addr_bytes);
> +	const uint16_t *from_words = (const uint16_t *)ea_from;
> +	uint16_t       *to_words   = (uint16_t *)ea_to;
> 
> And the consequential question: Is copying the three shorts faster than copying the struct? In other words: Should we get rid of the #ifdef and use the first method only?


I tried to investigate this in godbolt: https://godbolt.org/z/YSmvDn

First I don't see the "strange" gcc warning with various gcc versions there.

Related to the struct copy vs word copy, struct copy seems with less instruction
[1],[2],
my vote to remove ifdef and keep struct copy.


[1] copy as individual function
[1a] gcc 10.1, struct copy:
copy:
        movdqa  (%rsi), %xmm0
        movaps  %xmm0, (%rdi)
        ret

[1b] gcc 10.1, word copy:
copy:
        movzwl  (%rsi), %eax
        movw    %ax, (%rdi)
        movzwl  2(%rsi), %eax
        movw    %ax, 2(%rdi)
        movzwl  4(%rsi), %eax
        movw    %ax, 4(%rdi)
        ret

[1c] icc 19.0.1, struct copy
copy:
        movups    (%rsi), %xmm0                                 #19.13
        movups    %xmm0, (%rdi)                                 #19.13
        ret


[2] gcc 10.1, copy as inline function that knows the data, both seems similar
// .addr = {1, 1, 1, 1, 1, 1},
[2a] struct copy:
...
        movl    $257, %eax
        movw    %ax, 4(%rsp)
        leaq    16(%rsp), %rdi
        movl    $16843009, (%rsp)
        movdqa  (%rsp), %xmm0
        movaps  %xmm0, 16(%rsp)
...

[2b] word copy:
        movl    $257, %eax
        movq    %rsp, %rdi
        movw    %ax, 4(%rsp)
        movl    $16843009, (%rsp)

> 
> PS: I will provide a patch which improves rte_is_broadcast_ether_addr() too. The magic formula here is: return (w[0] & w[1] & w[2]) == 0xFFFF;
> 
> 
> Med venlig hilsen / kind regards
> - Morten Brørup
> 
> 


  reply	other threads:[~2020-06-26 12:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 15:45 Morten Brørup
2020-06-26 12:08 ` Ferruh Yigit [this message]
2020-06-26 12:34   ` Morten Brørup
2020-06-26 14:37     ` Jerin Jacob
2020-06-26 12:41   ` Van Haaren, Harry
2020-06-26 15:54     ` Ferruh Yigit
2020-06-26 17:28       ` Van Haaren, Harry
2020-06-26 18:04         ` Stephen Hemminger

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=6b67ce84-92ee-550d-2fba-af8c4c1bb2aa@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=dev@dpdk.org \
    --cc=harry.van.haaren@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=mb@smartsharesystems.com \
    --cc=olivier.matz@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).