From: 'Amey Narkhede' <ameynarkhede03@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: aoe: replace use of __constant_htons to htons
Date: Mon, 21 Dec 2020 16:33:56 +0530 [thread overview]
Message-ID: <20201221110356.6x2h2ip6o3hlwztd@archlinux> (raw)
In-Reply-To: <c5df63bdc5a94ebdac9505a64f2cece5@AcuMS.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 2682 bytes --]
On 20/12/21 09:23AM, David Laight wrote:
> From: 'Amey Narkhede' <ameynarkhede03@gmail.com>
> > Sent: 20 December 2020 20:20
> > To: David Laight <David.Laight@ACULAB.COM>
> > Subject: Re: [PATCH] block: aoe: replace use of __constant_htons to htons
> >
> > On 20/12/20 07:35PM, David Laight wrote:
> > > From: Amey Narkhede
> > > > Sent: 20 December 2020 16:46
> > > >
> > > > The macro htons expands to __swab16 which has special
> > > > case for constants in little endian case. In big
> > > > endian case both __constant_htons and htons macros
> > > > expand to the same code. So, replace __constant_htons
> > > > with htons to get rid of the definition of __constant_htons
> > > > completely.
> > > >
> > > ...
> > > > static struct packet_type aoe_pt __read_mostly = {
> > > > - .type = __constant_htons(ETH_P_AOE),
> > > > + .type = htons(ETH_P_AOE),
> > > > .func = aoenet_rcv,
> > >
> > > Does this cause grief if someone is doing a COMPILE_TEST on LE?
> > >
> > > David
> > >
> > > -
> > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> > > Registration No: 1397386 (Wales)
> > >
> > I did COMPILE_TEST on my x86_64 machine and it compiled
> > without any problems.
> > I assume that was the point or am I missing
> > something? I'm a beginner contributor so please
> > let me know if there any mistakes.
>
> It depends on exactly how the bswap functions are defined.
>
> You can't have anything that contains a function call (or asm) for a
> static initialiser or case label.
> The bswap functions have used the builtin_constant() check to switch
> between an asm block and C expression.
> So the C expression is used for constants - so evaluated by the compiler,
> and the asm for variables.
> Last I looked this wasn't valid for initialisers - so the __constant_bswap()
> exists for these cases.
>
> Now, it might be that, on more recent gcc __builtin_bswap() is used.
> This might be valid for constants in initialisers.
> Whether the same is true for CLANG is another issue.
>
> Basically it is all complex and partially historic.
>
> So you may need to use __constant_htons() for initialisers
> and case labels.
> For constants in code it doesn't matter whether you use the __constant form.
> For variables in code the __constant form is likely to generate horrid code.
>
> FWIW you'll get more credit for finding real bugs than stylistic changes.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
Thanks for thee detail explanation.
Actually I was submitting stylistic changes to get
familiar with email and patch based workflows
Amey
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-12-21 11:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-20 16:46 [PATCH] block: aoe: replace use of __constant_htons to htons Amey Narkhede
2020-12-20 19:35 ` David Laight
[not found] ` <20201220202019.j7x64yahapgilr7u@archlinux>
[not found] ` <c5df63bdc5a94ebdac9505a64f2cece5@AcuMS.aculab.com>
2020-12-21 11:03 ` 'Amey Narkhede' [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-12-20 20:56 'Amey Narkhede'
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=20201221110356.6x2h2ip6o3hlwztd@archlinux \
--to=ameynarkhede03@gmail.com \
--cc=David.Laight@aculab.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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