On Thu, 25 May 2023, Paolo Bonzini wrote:
On 5/23/23 16:33, Richard Henderson wrote:
The tests are poorly ordered, testing many unlikely things before the most
likely thing (normal). A better ordering would be
if (likely(tp##_is_normal(arg))) {
} else if (tp##_is_zero(arg)) {
} else if (tp##_is_zero_or_denormal(arg)) {
} else if (tp##_is_infinity(arg)) {
} else {
// nan case
}
Might also benefit from a is_finite (true if zero or normal or denormal)
predicate, to do
if (tp##_is_finite(arg)) {
There seems to be only is_infinity but I'm not sure if is_finite would be
the same as !is_infinity so could not try this. But it seems having any
branches kills performance so adding more branches may not help (also
because infinite values may be less frequent so not sure why this would
be better).
Regards,
BALATON Zoltan
if (!tp##_is_zero_or_denormal(arg)) {
// normal
} else if (tp##_is_zero(arg)) {
} else {
// denormal
}
} else if (tp##_is_infinity(arg)) {
} else {
// nan
}
since is_normal is a bit more complex and inefficient than the others. The
compiler should easily reuse the result of masking away the sign bit.
Paolo