[committed] MIPS/BFD: Use branchless code for sign-extension
Maciej W. Rozycki
macro@orcam.me.uk
Wed Mar 11 16:32:17 GMT 2026
Use common branchless code for `_bfd_mips_elf_sign_extend', typically
avoiding the branch penalty and also reducing code size when inlined in
elfxx-mips.c.
---
bfd/elfxx-mips.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
binutils-bfd-mips-elf-sign-extend.diff
Index: binutils-gdb/bfd/elfxx-mips.c
===================================================================
--- binutils-gdb.orig/bfd/elfxx-mips.c
+++ binutils-gdb/bfd/elfxx-mips.c
@@ -5239,11 +5239,8 @@ mips_elf_local_relocation_p (bfd *input_
bfd_vma
_bfd_mips_elf_sign_extend (bfd_vma value, int bits)
{
- if (value & ((bfd_vma) 1 << (bits - 1)))
- /* VALUE is negative. */
- value |= ((bfd_vma) - 1) << bits;
-
- return value;
+ bfd_vma sign = (bfd_vma) 1 << (bits - 1);
+ return (value ^ sign) - sign;
}
/* Return non-zero if the indicated VALUE has overflowed the maximum
More information about the Binutils
mailing list