cmov (was Re: Instance private data)



On Fri, 2003-02-14 at 12:30, Owen Taylor wrote:

> (*) lookup_type_node_I looks like prime cmov terrority, but
>     even compiling for i686, gcc-3.2/3.3 doesn't take advantage.
>     Project for aspiring compiler hackers - find out why, and
>     if fixing it makes a noticeable difference to GObject
>     performance.

Picking up my own question here. The reason why cmov isn't 
used is fairly obvious looking at the code:

====
static inline TypeNode*
lookup_type_node_I (register GType utype)
{
  if (utype > G_TYPE_FUNDAMENTAL_MAX)
    return (TypeNode*) (utype & ~TYPE_ID_MASK);
  else
    return static_fundamental_type_nodes[utype >>
G_TYPE_FUNDAMENTAL_SHIFT];
}
====

The read from the static_fundamental_type_nodes array
can't be speculatively executed because it might
cause an illegal access.

If we rewrite as something like:

===
static inline TypeNode *
lookup_type_node_I (register GType utype)
{
  unsigned long index = (utype >> G_TYPE_FUNDAMENTAL_SHIFT) & 255;
  GTypeNode *tmp_result = static_fundamental_type_nodes[index];
  if (type > G_TYPE_FUNDAMENTAL_MAX)
    return (TypeNode*) (utype & ~TYPE_ID_MASK);
  else
    return tmp_result;
}
===

cmov gets used, Quick testing didn't indicate much either
way whether it actually helped performance.

Regards,
                                      Owen





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