WP Software Developer

ifunc - GNU Indirect Function


ifunc General Idea:

ifunc is a special feature provided by GNUC which can help you to optimize your function call. It allows to create multiple implementations of one function. A best implementation can be selected during runtime for particular procesor.

ifunc Limintation

It is limited to to standard C language. It also need all code to be one compiliation. So if you plan to write a software which requires multiple. It also requires all code to be one compiliation.

ifunc Process

  1. get cpu capability
  2. populate function pointer tables
  3. call function via pointer tables

Example:

void *my_memcpy (void *dst, const void *src, size_t length)
    attribute ((ifunc ("resolve_memcpy")));

    // Return a function pointer
static void (resolve_memcpy (void)) (void)
{
    cpu_features = cpuinfo(); 

    if (cpu_has_neon(cpu_features))
        return &memcpy_neon;
    else if(cpu_has_vfp(cpu_features))
        return &memcpy_vfp;
    return &memcpy_generic_arm;
}

Similar Posts

Comments