Issue: Unrecognized opcode addw when building for RV32 with Zalrsc
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- c
- Domain
- operating-systems
Research direction
Inspect lib/sbi/riscv_atomic.c around line 51, focusing on the SIZEOF_LONG == 4 branch of the Zalrsc implementation and its inline assembly. Re-run the supplied RV32 build command and confirm the build completes without an unrecognized addw opcode.
Written by the indexing model from the issue text.
Description
Hello,
I am experiencing an error when building with 32-bit compiler using LR/SC extension. According to the platform requirements documentation, I can skip Zaamo extension and use Zalrsc. On 32-bit environment, using this command:
make PLATFORM=generic PLATFORM_RISCV_XLEN=32 CROSS_COMPILE=riscv32-unknown-linux-gnu- PLATFORM_RISCV_ISA=rv32imc_zalrsc
I get the following error:
/tmp/opensbi/lib/sbi/riscv_atomic.c: Assembler messages:
/tmp/opensbi/lib/sbi/riscv_atomic.c:51: Error: unrecognized opcode `addw a4,a5,a1'
/tmp/opensbi/lib/sbi/riscv_atomic.c:51: Error: unrecognized opcode `addw a3,a4,a5'
The error is correct because, according to RISCV documentation (Instruct Set Manual) pages 42-43:
Most integer computational instructions operate on XLEN-bit values. Additional instruction variants are
provided to manipulate 32-bit values in RV64I, indicated by a 'W' suffix to the opcode. These "*W"
instructions ignore the upper 32 bits of their inputs and always produce 32-bit signed values, sign-
extending them to 64 bits, i.e. bits XLEN-1 through 31 are equal.
ADDW and SUBW are RV64I-only instructions that are defined analogously to ADD and SUB but
operate on 32-bit values and produce signed 32-bit results.
So addw should not appear on 32-bit. The error appears to be in this function:
#elif __riscv_zalrsc
long ret, temp;
#if __SIZEOF_LONG__ == 4
__asm__ __volatile__("1:lr.w.aqrl %1,%0\n"
" addw %2,%1,%3\n"
" sc.w.aqrl %2,%2,%0\n"
" bnez %2,1b"
: "+A"(atom->counter), "=&r"(ret), "=&r"(temp)
: "r"(value)
: "memory");
#elif __SIZEOF_LONG__ == 8
__asm__ __volatile__("1:lr.d.aqrl %1,%0\n"
" add %2,%1,%3\n"
" sc.d.aqrl %2,%2,%0\n"
" bnez %2,1b"
: "+A"(atom->counter), "=&r"(ret), "=&r"(temp)
: "r"(value)
: "memory");
Am I missing something?
- Dominant language
- C
- Stars
- 1.6k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from riscv-software-src/opensbi
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
riscv-software-src/opensbi#425 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
riscv-software-src/opensbi#424 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
riscv-software-src/opensbi#439 ·
-
sbi_trap_redirect() does not clear SPELP when the interrupted context had no landing pad expectedOpen
Difficulty 3/5 1-2 days Newbie friendliness 67/100
riscv-software-src/opensbi#438 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
riscv-software-src/opensbi#436 · 3 comments ·
All issues in riscv-software-src/opensbi
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libreswan/libreswan#3185 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
llvm:instcombine
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
llvm/llvm-project#246503 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day