https://gcc.gnu.org/onlinedocs/gcc/Function-Multiversioning.html
7.8 Function Multiversioning
使用 GNU C++ 前端,对于 x86 目标,您可以指定函数的多个版本,其中每个函数专门用于特定目标功能。在运行时,会根据执行平台的特性自动执行相应版本的函数。这是一个例子。

__attribute__ ((target ("default")))
int foo ()
{
  // The default version of foo.
  return 0;
}

__attribute__ ((target ("sse4.2")))
int foo ()
{
  // foo version for SSE4.2
  return 1;
}

__attribute__ ((target ("arch=atom")))
int foo ()
{
  // foo version for the Intel ATOM processor
  return 2;
}

__attribute__ ((target ("arch=amdfam10")))
int foo ()
{
  // foo version for the AMD Family 0x10 processors.
  return 3;
}

int main ()
{
  int (*p)() = &foo;
  assert ((*p) () == foo ());
  return 0;
}

相关文章:

  • 2021-10-04
  • 2021-08-07
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-06-10
  • 2022-12-23
猜你喜欢
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案