]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
MIPS/BFD: Use branchless code for sign-extension
authorMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 11 Mar 2026 16:30:29 +0000 (16:30 +0000)
committerMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 11 Mar 2026 16:30:29 +0000 (16:30 +0000)
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

index 6feaa706029a0a5364697abd59661cf60d245170..24a08436d055cf490395be21b6733d7cfed0bdb3 100644 (file)
@@ -5239,11 +5239,8 @@ mips_elf_local_relocation_p (bfd *input_bfd,
 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