【问题标题】:The name lookup for "__rotatel4" did not find a declaration“__rotatel4”的名称查找未找到声明
【发布时间】:2019-04-24 05:48:11
【问题描述】:

我正在编译农场的 GCC111 上工作。该机器是 AIX 7.1、POWER7 和 IBM XLC 12.1。我正在尝试使用__rotatel4:

$ cat test.cxx
#include <cstdlib>

unsigned int Foo (unsigned int x)
{
  return __rotatel4(x, 4U);
}

编译结果:

$ xlC -O3 -c test.cxx
"test.cxx", line 5.10: 1540-0274 (S) The name lookup for "__rotatel4" did not find a declaration.

根据编译器手册IBM XL C/C++ for AIX, V12.1 (p. 486),内在函数应该可用。这里是原型,没有POWER6那样的限制:

unsigned int __rotatel4 (unsigned int rs, unsigned int shift)

添加-qarch=pwr7 和/或-D_XOPEN_SOURCE=600 会导致相同的错误。我找到了Unexpected name lookup error "1540-0274 (S)" when compiling code with templates,但在这里似乎并不适用。

如何在程序中使用__rotatel4


gcc111$ oslevel -s
7100-03-02-1412

gcc111$ xlC -qversion
IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72)
Version: 12.01.0000.0000

【问题讨论】:

    标签: c++ aix intrinsics xlc


    【解决方案1】:

    对于 XL C/C++ V12.1,您需要包含 &lt;builtins.h&gt;

    $ cat aaa.cpp
    #include <cstdlib>
    
    unsigned int Foo (unsigned int x)
    {
      return __rotatel4(x, 4U);
    }
    $ xlC aaa.cpp -c
    "aaa.cpp", line 5.10: 1540-0274 (S) The name lookup for "__rotatel4" did not find a declaration.
    $ cat aaa.cpp
    #include <cstdlib>
    #include <builtins.h>
    
    unsigned int Foo (unsigned int x)
    {
      return __rotatel4(x, 4U);
    }
    $ xlC aaa.cpp -c
    $
    

    对于即将发布的 16.1 版本(处于测试阶段),您不需要它。 (不管有没有它都可以工作。)

    【讨论】:

    • 再次感谢@Rafik。 __rotatel4 到底是做什么的?描述说“Rotate Left Word”,但没有说更多。我认为这是习惯 C 轮换的内在因素,但从失败的自测次数来看,它还有其他作用。
    • 它将第一个参数旋转第二个参数指定的参数数量。这是一个示例:#include &lt;stdio.h&gt; #include &lt;builtins.h&gt; int main() { unsigned int a, b, c; a = 0xabcdef01; for (int i=0; i &lt; 8; ++i) { b = __rotatel4(a, 4 * i); printf("0x%08x\n", b); } return 0; } 打印:0xabcdef01 0xbcdef01a 0xcdef01ab 0xdef01abc 0xef01abcd 0xf01abcde 0x01abcdef 0x1abcdef0