Discuss the RVC implementation

yangfei at iscas.ac.cn yangfei at iscas.ac.cn
Sat Sep 24 08:06:46 UTC 2022




Hi Xiaolin,




Thanks for the explaination.

From your codesize metrics, I see a very low possibility of compressing those branch instructions (beq/bne). 

So it looks to me that another way to consider here would be not compress these sort of instructions at all.

Then the case will be simplified and we won't lose much here.




Thanks,

Fei


-----Original Messages-----
From:"Xiaolin Zheng" <yunyao.zxl at alibaba-inc.com>
Sent Time:2022-09-23 21:11:57 (Friday)
To: yangfei <yangfei at iscas.ac.cn>
Cc: riscv-port-dev <riscv-port-dev at openjdk.org>
Subject: Re: Re: Discuss the RVC implementation


I forgot to describe something about MachBranchNodes.


The thing is, C2 needs to calculate node sizes to allocate buffers, so it has a scratch_emit phase to estimate node size first. It uses a clever strategy to measure MachBranchNodes' size. When estimating the size, we could find only the MacnBranchNode itself matters, not the Label. The labels are just tools for generating branch instructions. So there has "fake label"[1] instead, directly placed at the same pc as the MachBranchNode's to simplify code logic.


On other platforms like x86 and aarch64, the size of branch instructions is not changed, and these platforms don't have a code size reduction extension as RISC-V. For example, on other platforms, the jcc is jcc, and the bl is bl. In our implementation, we have:


```
#define INSN(NAME)                                                                           \
  void NAME(Register Rd, const int32_t offset) {                                             \
    /* jal -> c.j */                                                                         \
    if (do_compress() ...) {                                                                 \
      c_j(offset);                                                                           \
      return;                                                                                \
    }                                                                                        \
    _jal(Rd, offset);                                                                        \
  }
  INSN(jal);
#undef INSN
```


The size of an emitted instruction is determined by the `offset`. Though reasonable, it is not compatible with the "fake label" strategy. For example, with the "fake label", the offset is always 0 when scratch-emitting a MachBranchNode. The offset does not match the real offset. Therefore, In scratch_emit and the real emission, the size of MachBranchNode might be different, which will break the assumption of C2's strategy.


To emit the code that we want, a basic approach is to pass the real offset into the MachBranchNode, and let us read it instead of the "0" every time.


So currently in these patches, all MachBranchNodes are temporarily incompressible in C2 when RVC is enabled.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/riscv-port-dev/attachments/20220924/e92ca772/attachment.htm>


More information about the riscv-port-dev mailing list