This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C.ADDI x0, 4: illegal instruction ?

On Wed, Jun 26, 2019 at 9:45 AM Alex Rocha Prado <> wrote:
>     I noticed binuntils 2.32 assembles the instruction c.addi x0, 4 without any error but from my understanding RISC-V spec defines that as an illegal instruction.
>     Latest official user-level  spec version is 2.2, on page 82, C.ADDI instruction are not allowed to have rs1/rd equal to 0 if nzimm field different from 0. If both rd/rs1 and nzimm are 0, then instruction is actually C.NOP. So, "c.addi x0, 4" is an illegal instruction and assembler should give an error.
>     Am I missing anything ?

What exactly is a c.nop and what exactly is a c.addi has been asked
multiple times in multiple places and hasn't been decided yet.  I
can't fix binutils until I get an official answer to this question.
See for instance
and see also the full discussion at!topic/sw-dev/18ObEKnn4mE

Technically it is a legal encoding because it is a valid hint
instruction, but it isn't clear if it is supposed to be a c.nop hint
or a c.addi hint.  The ISA documentation is ambiguous.  And so is the
RISC-V reader.  The ISA docs for hint instructions were improved at
one point, and they now have their own section instead of being hidden
among other info.  If you have an old copy of the docs, you might not
have the new hint docs.  See for instance
and see the Hint instruction section.  This says that this is a c.nop
hint now, but I think that is different from the older text, and is
different than what has been discussed in other places.

I don't think anyone really cares enough to fix the ISA spec and RISC
V reader to make this unambiguous.  Meanwhile, I can't really fix
binutils until the ISA spec is fixed, and even if the ISA spec is
fixed I may not be able to fix binutils without breaking existing
uses, so I think we are stuck with this indefinitely.

I suppose we could make this depend on the exact ISA version, and one
can specify an ISA version via -march using the long form, but no one
really does that yet, and it seems like overkilll for this
c.nop/c.addi confusion problem.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]