The RISC-V architecture has support for compressed instructions - these are effectively a subset of the standard 4 byte long instructions, which fit in 2 bytes. These compressed instructions have limited functionality, however require half the code size.
Adding support to the assembler is relatively straight forward and from a code generation perspective, things work as expected and the binary runs. However, I keep hitting problems relating to the pcdatavalue
tables while building toolchain3 - this is in the form of deadlock loops while generating tracebacks for inline functions, "runtime: invalid pc-encoded table" from symtab.go while handling async pre-empt, etc.
These all seems to suggest that the various PCDATA tables are wrong/broken, however as far as I can tell p.Pc
is being set correctly in cmd/internal/obj/riscv
. I would also expect that we handle variable instruction sizes (and variable p.Pc
steps), given CISC architectures like x86.
Overall it seems like I'm missing something obvious - should things work if p.Pc
is set correctly on a per *obj.Prog
basis (even with multiple machine instructions with various widths being generated)?
Any suggestions regarding what else I should check?
(will mail out the work in progress code shortly)
Comment From: 4a6f656c
/cc @cherrymui
Comment From: gopherbot
Change https://golang.org/cl/340151 mentions this issue: cmd/internal/obj/riscv: compressed instruction support for riscv64
Comment From: randall77
You probably want to look at MinLC
in cmd/internal/sys/arch.go
. The PCs in pcln tables are expressed as multiples of this constant.
Comment From: 4a6f656c
@randall77 thanks - turns out it was MinLC
and PCQuantum
- adjusting those, along with a change to runtime.goexit
(smaller NOP slots) and we have working code.
Comment From: gopherbot
Change https://go.dev/cl/639658 mentions this issue: cmd/obj/riscv: compress NOP instructions
Comment From: gopherbot
Change https://go.dev/cl/639656 mentions this issue: cmd/obj/riscv: add support for the Compressed extension
Comment From: gopherbot
Change https://go.dev/cl/639657 mentions this issue: cmd/obj/riscv: compress ADD instructions
Comment From: wenchangping
@Jorropo We encountered a similar issue. so you resolved it afterwards?
Comment From: Jorropo
Hey what issue are we talking about ?
Comment From: wenchangping
@Jorropo We tried to implement C compression instructions, but encountered the same problem as you reported "https://go.dev/cl/639657". Since we are just starting to work on the GO compiler, we would like to ask if you have solved this problem.
Comment From: Jorropo
? I do not have a solution.
Comment From: wenchangping
@Jorropo That's a pity to hear—we were really hoping to get this issue resolved. Our team is still committed to working on it, so understanding the root cause would be incredibly helpful for us to move forward. Could you share a bit about why it couldn't be resolved? We’d greatly appreciate any insights you can offer.
Comment From: mengzhuo
I think it needs resolve first: - https://github.com/riscv/riscv-opcodes/pull/332 - https://go-review.googlesource.com/c/go/+/637940/3?tab=comments
FYI all riscv builders supports C extension