bpf, riscv: Add encodings for compressed instructions
authorLuke Nelson <lukenels@cs.washington.edu>
Tue, 21 Jul 2020 02:52:39 +0000 (19:52 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 21 Jul 2020 20:26:25 +0000 (13:26 -0700)
commit804ec72c68c8477b8713a1e8f8eda120d3471031
tree840d9967eae77dca98a37655859a18c040d30069
parentbfabff3cb0fef366086c64f24be8ab316a355b99
bpf, riscv: Add encodings for compressed instructions

This patch adds functions for encoding and emitting compressed riscv
(RVC) instructions to the BPF JIT.

Some regular riscv instructions can be compressed into an RVC instruction
if the instruction fields meet some requirements. For example, "add rd,
rs1, rs2" can be compressed into "c.add rd, rs2" when rd == rs1.

To make using RVC encodings simpler, this patch also adds helper
functions that selectively emit either a regular instruction or a
compressed instruction if possible.

For example, emit_add will produce a "c.add" if possible and regular
"add" otherwise.

Signed-off-by: Luke Nelson <luke.r.nels@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200721025241.8077-3-luke.r.nels@gmail.com
arch/riscv/net/bpf_jit.h