[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: |
Sat, 25 Jul 2020 02:02:35 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
Florian Weimer wrote:
> On s390x, all three variants use conditional
> branches, but the first one is the shortest.
Indeed. Surprising.
> There is also this:
>
> int sign4 (long n1, long n2)
> {
> return (char) ((n1 > n2) - (n1 < n2));
> }
The case should be towards (signed char). Otherwise, on arm-linux-gnueabi
and powerpc-linux-gnu the 3 values are 0, 1, 255, not 0, 1, -1.
> It's one instruction shorter on x86-64 than sign3, but it's worse on
> other architectures. (One of the x86-64 quirks is that conditional sets
> do not affect the full register, only a byte.)
Indeed. But IMO, the conditional jumps matter more than an immediate
instruction.
Bruno