bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimize three-valued comparison between integers


From: Bruno Haible
Subject: Re: Optimize three-valued comparison between integers
Date: Fri, 31 Jul 2020 11:24:30 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

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

[Prev in Thread] Current Thread [Next in Thread]