libzahl
libzahl copied to clipboard
In the unlikely event that something is likely unlikely.
Can you provide rationale on your choices of likely() and unlikely()?
void zsub_nonnegative_assign(z_t a, z_t b) { if (unlikely(zzero(b))) zabs(a, a); else if (unlikely(!zcmpmag(a, b))) SET_SIGNUM(a, 0); else zsub_impl(a, b, b->used); }
What if I issue zsub_nonnegative_assign(x, "0") in an iterative process? In this example, the unlikely is very, very, very unlikely (zzero(0) is not just likely, but totally likely). (I see that zsub_nonnegative_assign() may be removed.) How do these branch predictions behave if they are more likely to be incorrect than correct for certain use cases? Perhaps you could allow the user of the library a choice on the use of likely()/unlikely().