Skip to content

Commit 2959fce

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Use common function sign_extend64()
There exists a common function sign_extend64() to sign extend a 64-bit value using specified bit as sign-bit in include/linux/bitops.h, it is more efficient, let us use it and remove the arch-specific sign_extend() under arch/loongarch. Suggested-by: Jinyang He <[email protected]> Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent d52fec8 commit 2959fce

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

arch/loongarch/include/asm/inst.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,6 @@ static inline bool unsigned_imm_check(unsigned long val, unsigned int bit)
377377
return val < (1UL << bit);
378378
}
379379

380-
static inline unsigned long sign_extend(unsigned long val, unsigned int idx)
381-
{
382-
if (!is_imm_negative(val, idx + 1))
383-
return ((1UL << idx) - 1) & val;
384-
else
385-
return ~((1UL << idx) - 1) | val;
386-
}
387-
388380
#define DEF_EMIT_REG0I26_FORMAT(NAME, OP) \
389381
static inline void emit_##NAME(union loongarch_instruction *insn, \
390382
int offset) \

arch/loongarch/kernel/alternative.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf,
7474
switch (src->reg0i26_format.opcode) {
7575
case b_op:
7676
case bl_op:
77-
jump_addr = cur_pc + sign_extend((si_h << 16 | si_l) << 2, 27);
77+
jump_addr = cur_pc + sign_extend64((si_h << 16 | si_l) << 2, 27);
7878
if (in_alt_jump(jump_addr, start, end))
7979
return;
8080
offset = jump_addr - pc;
@@ -93,7 +93,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf,
9393
fallthrough;
9494
case beqz_op:
9595
case bnez_op:
96-
jump_addr = cur_pc + sign_extend((si_h << 16 | si_l) << 2, 22);
96+
jump_addr = cur_pc + sign_extend64((si_h << 16 | si_l) << 2, 22);
9797
if (in_alt_jump(jump_addr, start, end))
9898
return;
9999
offset = jump_addr - pc;
@@ -112,7 +112,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf,
112112
case bge_op:
113113
case bltu_op:
114114
case bgeu_op:
115-
jump_addr = cur_pc + sign_extend(si << 2, 17);
115+
jump_addr = cur_pc + sign_extend64(si << 2, 17);
116116
if (in_alt_jump(jump_addr, start, end))
117117
return;
118118
offset = jump_addr - pc;

0 commit comments

Comments
 (0)