Skip to content

Commit c1474bb

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: BPF: Adjust the parameter of emit_jirl()
The branch instructions beq, bne, blt, bge, bltu, bgeu and jirl belong to the format reg2i16, but the sequence of oprand is different for the instruction jirl. So adjust the parameter order of emit_jirl() to make it more readable correspond with the Instruction Set Architecture manual. Here are the instruction formats: beq rj, rd, offs16 bne rj, rd, offs16 blt rj, rd, offs16 bge rj, rd, offs16 bltu rj, rd, offs16 bgeu rj, rd, offs16 jirl rd, rj, offs16 Link: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#branch-instructions Suggested-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 7cd1f5f commit c1474bb

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

arch/loongarch/include/asm/inst.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,17 @@ DEF_EMIT_REG2I16_FORMAT(blt, blt_op)
683683
DEF_EMIT_REG2I16_FORMAT(bge, bge_op)
684684
DEF_EMIT_REG2I16_FORMAT(bltu, bltu_op)
685685
DEF_EMIT_REG2I16_FORMAT(bgeu, bgeu_op)
686-
DEF_EMIT_REG2I16_FORMAT(jirl, jirl_op)
686+
687+
static inline void emit_jirl(union loongarch_instruction *insn,
688+
enum loongarch_gpr rd,
689+
enum loongarch_gpr rj,
690+
int offset)
691+
{
692+
insn->reg2i16_format.opcode = jirl_op;
693+
insn->reg2i16_format.immediate = offset;
694+
insn->reg2i16_format.rd = rd;
695+
insn->reg2i16_format.rj = rj;
696+
}
687697

688698
#define DEF_EMIT_REG2BSTRD_FORMAT(NAME, OP) \
689699
static inline void emit_##NAME(union loongarch_instruction *insn, \

arch/loongarch/kernel/inst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
332332
return INSN_BREAK;
333333
}
334334

335-
emit_jirl(&insn, rj, rd, imm >> 2);
335+
emit_jirl(&insn, rd, rj, imm >> 2);
336336

337337
return insn.word;
338338
}

arch/loongarch/net/bpf_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ static void __build_epilogue(struct jit_ctx *ctx, bool is_tail_call)
181181
/* Set return value */
182182
emit_insn(ctx, addiw, LOONGARCH_GPR_A0, regmap[BPF_REG_0], 0);
183183
/* Return to the caller */
184-
emit_insn(ctx, jirl, LOONGARCH_GPR_RA, LOONGARCH_GPR_ZERO, 0);
184+
emit_insn(ctx, jirl, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_RA, 0);
185185
} else {
186186
/*
187187
* Call the next bpf prog and skip the first instruction
188188
* of TCC initialization.
189189
*/
190-
emit_insn(ctx, jirl, LOONGARCH_GPR_T3, LOONGARCH_GPR_ZERO, 1);
190+
emit_insn(ctx, jirl, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_T3, 1);
191191
}
192192
}
193193

@@ -904,7 +904,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
904904
return ret;
905905

906906
move_addr(ctx, t1, func_addr);
907-
emit_insn(ctx, jirl, t1, LOONGARCH_GPR_RA, 0);
907+
emit_insn(ctx, jirl, LOONGARCH_GPR_RA, t1, 0);
908908
move_reg(ctx, regmap[BPF_REG_0], LOONGARCH_GPR_A0);
909909
break;
910910

0 commit comments

Comments
 (0)