From: Zi Shen Lim <zlim.lnx@gmail.com>
To: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <Catalin.Marinas@arm.com>,
Jiang Liu <liuj97@gmail.com>,
AKASHI Takahiro <takahiro.akashi@linaro.org>,
"David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <dborkman@redhat.com>,
Alexei Starovoitov <ast@plumgrid.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH RFCv3 01/14] arm64: introduce aarch64_insn_gen_comp_branch_imm()
Date: Wed, 16 Jul 2014 14:19:31 -0700 [thread overview]
Message-ID: <20140716211931.GA18109@gup76> (raw)
In-Reply-To: <20140716160450.GT29414@arm.com>
On Wed, Jul 16, 2014 at 05:04:50PM +0100, Will Deacon wrote:
> On Tue, Jul 15, 2014 at 07:24:59AM +0100, Zi Shen Lim wrote:
[...]
> > +enum aarch64_insn_register {
> > + AARCH64_INSN_REG_0 = 0,
> > + AARCH64_INSN_REG_1 = 1,
> > + AARCH64_INSN_REG_2 = 2,
> > + AARCH64_INSN_REG_3 = 3,
> > + AARCH64_INSN_REG_4 = 4,
> > + AARCH64_INSN_REG_5 = 5,
> > + AARCH64_INSN_REG_6 = 6,
> > + AARCH64_INSN_REG_7 = 7,
> > + AARCH64_INSN_REG_8 = 8,
> > + AARCH64_INSN_REG_9 = 9,
> > + AARCH64_INSN_REG_10 = 10,
> > + AARCH64_INSN_REG_11 = 11,
> > + AARCH64_INSN_REG_12 = 12,
> > + AARCH64_INSN_REG_13 = 13,
> > + AARCH64_INSN_REG_14 = 14,
> > + AARCH64_INSN_REG_15 = 15,
> > + AARCH64_INSN_REG_16 = 16,
> > + AARCH64_INSN_REG_17 = 17,
> > + AARCH64_INSN_REG_18 = 18,
> > + AARCH64_INSN_REG_19 = 19,
> > + AARCH64_INSN_REG_20 = 20,
> > + AARCH64_INSN_REG_21 = 21,
> > + AARCH64_INSN_REG_22 = 22,
> > + AARCH64_INSN_REG_23 = 23,
> > + AARCH64_INSN_REG_24 = 24,
> > + AARCH64_INSN_REG_25 = 25,
> > + AARCH64_INSN_REG_26 = 26,
> > + AARCH64_INSN_REG_27 = 27,
> > + AARCH64_INSN_REG_28 = 28,
> > + AARCH64_INSN_REG_29 = 29,
> > + AARCH64_INSN_REG_FP = 29, /* Frame pointer */
> > + AARCH64_INSN_REG_30 = 30,
> > + AARCH64_INSN_REG_LR = 30, /* Link register */
> > + AARCH64_INSN_REG_ZR = 31, /* Zero: as source register */
> > + AARCH64_INSN_REG_SP = 31 /* Stack pointer: as load/store base reg */
>
> Can you just #define AARCH64_INSN_REG(x) instead, then have some magic
> values like ARM64_REG_LR which are defined as the appropriate numbers?
I actually had something like what you mentioned in the beginning, but
decided to go with the above - thinking that it's clearer to present
the complete set of valid register definitions.
The #define can still be added for convenience, though I think it's also a
potential source of errors - it's much easier to typo something like
AARCH64_INSN_REG(32) and not get caught.
[...]
> > + switch (variant) {
> > + case AARCH64_INSN_VARIANT_32BIT:
> > + break;
> > + case AARCH64_INSN_VARIANT_64BIT:
> > + insn |= BIT(31);
>
> FWIW, that bit (31) is referred to as the `SF' bit in the instruction
> encodings (for Sixty-Four). You could have a #define for that to help people
> match up the bitfield, if you like.
Something like this?
#define AARCH64_INSN_SF_BIT BIT(31)
...
case AARCH64_INSN_VARIANT_64BIT:
insn |= AARCH64_INSN_SF_BIT;
In the case of bitfield instruction, there's also an "N" bit.
So something like this?
#define AARCH64_INSN_N_BIT BIT(22)
...
case AARCH64_INSN_VARIANT_64BIT:
insn |= AARCH64_INSN_SF_BIT | AARCH64_INSN_N_BIT;
>
> > + break;
> > + default:
> > + BUG_ON(1);
>
> Is a BUG_ON justifiable here? Is there not a nicer way to fail?
In general, it'd be nice if we returned something like -EINVAL and
have all callers handle failures. Today all code gen functions return
the u32 instruction and there's no error handling by callers.
I think following the precedence (aarch64_insn_gen_branch_imm())
of failing with BUG_ON is a reasonable tradeoff.
In this case here, when we hit the default (failure) case, that means
there's a serious error of attempting to use an unsupported
variant. I think we're better off failing hard here than trying to
arbitrarily "fallback" on a default choice.
One potential option instead of switch (variant) is:
if (variant == AARCH64_INSN_VARIANT_64BIT)
/* do something */
else
/* do something else */
which would be quite reasonable to do as we only have VARIANT_{32,64}BIT
today.
However, consider the case where we add VARIANT_128BIT or other flavors
in the future. The if/else option (basically defaulting to VARIANT_32BIT)
would then make much less sense.
>
> Will
next prev parent reply other threads:[~2014-07-16 21:19 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 6:24 [PATCH RFCv3 00/14] arm64: eBPF JIT compiler Zi Shen Lim
2014-07-15 6:24 ` [PATCH RFCv3 01/14] arm64: introduce aarch64_insn_gen_comp_branch_imm() Zi Shen Lim
2014-07-16 16:04 ` Will Deacon
2014-07-16 21:19 ` Zi Shen Lim [this message]
2014-07-17 9:19 ` Will Deacon
2014-07-17 15:59 ` Alexei Starovoitov
2014-07-17 17:25 ` Will Deacon
2014-07-18 5:44 ` Z Lim
2014-07-15 6:25 ` [PATCH RFCv3 02/14] arm64: introduce aarch64_insn_gen_branch_reg() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 03/14] arm64: introduce aarch64_insn_gen_cond_branch_imm() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 04/14] arm64: introduce aarch64_insn_gen_load_store_reg() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 05/14] arm64: introduce aarch64_insn_gen_load_store_pair() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 06/14] arm64: introduce aarch64_insn_gen_add_sub_imm() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 07/14] arm64: introduce aarch64_insn_gen_bitfield() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 08/14] arm64: introduce aarch64_insn_gen_movewide() Zi Shen Lim
2014-07-16 16:17 ` Will Deacon
2014-07-16 16:25 ` David Laight
2014-07-16 22:04 ` Zi Shen Lim
2014-07-17 9:41 ` Will Deacon
2014-07-17 9:51 ` David Laight
2014-07-18 5:47 ` Z Lim
2014-07-18 8:43 ` Will Deacon
2014-07-15 6:25 ` [PATCH RFCv3 09/14] arm64: introduce aarch64_insn_gen_add_sub_shifted_reg() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 10/14] arm64: introduce aarch64_insn_gen_data1() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 11/14] arm64: introduce aarch64_insn_gen_data2() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 12/14] arm64: introduce aarch64_insn_gen_data3() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 13/14] arm64: introduce aarch64_insn_gen_logical_shifted_reg() Zi Shen Lim
2014-07-15 6:25 ` [PATCH RFCv3 14/14] arm64: eBPF JIT compiler Zi Shen Lim
2014-07-16 10:41 ` [PATCH RFCv3 00/14] " Will Deacon
2014-07-16 16:21 ` Will Deacon
2014-07-16 22:18 ` Zi Shen Lim
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=20140716211931.GA18109@gup76 \
--to=zlim.lnx@gmail.com \
--cc=Catalin.Marinas@arm.com \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuj97@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=takahiro.akashi@linaro.org \
--cc=will.deacon@arm.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).