Florian Weimer wrote:
> int sign4 (long n1, long n2)
> {
>   return (char) ((n1 > n2) - (n1 < n2));
> }
> 
> It's one instruction shorter on x86-64 than sign3, but it's worse on
> other architectures.

Yes. In particular with floating-point numbers (and GCC 5), when I compare


int sign3 (double n1, double n2)
{
  return (n1 > n2) - (n1 < n2);
}

int sign4 (double n1, double n2)
{
  return (signed char) ((n1 > n2) - (n1 < n2));
}


the code of sign4 contains conditional jumps that the code of sign3 does not
have, on mips, mips64, s390x.

Bruno


Reply via email to