From 1fb3cdd87ec61715a5684925fb6d6a6cf53bb97c Mon Sep 17 00:00:00 2001 From: mengqinggang Date: Sun, 24 Sep 2023 14:53:28 +0800 Subject: LoongArch/GAS: Add support for branch relaxation For the instructions of R_LARCH_B16/B21, if the immediate overflow, add a B instruction and R_LARCH_B26 relocation. For example: .L1 ... blt $t0, $t1, .L1 R_LARCH_B16 change to: .L1 ... bge $t0, $t1, .L2 b .L1 R_LARCH_B26 .L2 --- include/opcode/loongarch.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/opcode') diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h index 2ed4082..f358ff4 100644 --- a/include/opcode/loongarch.h +++ b/include/opcode/loongarch.h @@ -29,6 +29,18 @@ extern "C" #endif #define LARCH_NOP 0x03400000 + #define LARCH_B 0x50000000 + /* BCEQZ/BCNEZ. */ + #define LARCH_FLOAT_BRANCH 0x48000000 + #define LARCH_BRANCH_OPCODE_MASK 0xfc000000 + #define LARCH_BRANCH_INVERT_BIT 0x04000000 + #define LARCH_FLOAT_BRANCH_INVERT_BIT 0x00000100 + + #define ENCODE_BRANCH16_IMM(x) (((x) >> 2) << 10) + + #define OUT_OF_RANGE(value, bits, align) \ + ((value) < (-(1 << ((bits) - 1) << align)) \ + || (value) > ((((1 << ((bits) - 1)) - 1) << align))) typedef uint32_t insn_t; -- cgit v1.1