Richard Sandiford via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> One thing I'd deliberately tried to avoid was converting integers
> “back” to pointers, because that seemed like a more dangerous thing.
> That's why:
>
>>> +template<typename T1, typename T2>
>>> +inline T2 *
>>> +pointer_mux<T1, T2>::second_or_null () const
>>> +{
>>> +  // Micro optimization that's effective as of GCC 11: compute the value
>>> +  // of the second pointer as an integer and test that, so that the integer
>>> +  // result can be reused as the pointer and so that all computation can
>>> +  // happen before a branch on null.  This reduces the number of branches
>>> +  // needed for loops.
>>> +  return uintptr_t (m_ptr - 1) & 1 ? nullptr : known_second ();
>>> +}
>
> is written in a somewhat indirect way.

Gah, I really should learn to read my own quotes.  In my head this was
still using integer operations, but I take your point that the final form
is probably invalid.  I'll try to achieve the same effect in some other way.

Thanks,
Richard

Reply via email to