1

I'm working on GCC111 from the compile farm. The machine is AIX 7.1, POWER7 with IBM XLC 12.1. I'm trying to use __rotatel4:

$ cat test.cxx
#include <cstdlib>

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

A compile results in:

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

According to the compiler manual IBM XL C/C++ for AIX, V12.1 (p. 486) the intrinsics should be available. Here is the prototype, and it does not have restrictions like POWER6:

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

Adding -qarch=pwr7 and/or -D_XOPEN_SOURCE=600 resulted in the same error. I found Unexpected name lookup error "1540-0274 (S)" when compiling code with templates, but it does not seem to apply here.

How does one use __rotatel4 in a program?


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
jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

2

For XL C/C++ V12.1, you'll need to include <builtins.h>:

$ 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
$

For the upcoming 16.1 release, which is in beta, you don't need it. (It will work with and without it.)

jww
  • 97,681
  • 90
  • 411
  • 885
Rafik Zurob
  • 361
  • 2
  • 6
  • Thanks again @Rafik. What, exactly, does `__rotatel4` do? The description says *"Rotate Left Word"* but does not say more. I thought it was an intrinsic for a customary C rotate, but judging from the number of failed self tests it does something else. – jww Nov 21 '18 at 16:57
  • 1
    It rotates the first argument by the number of arguments specified by the second argument. Here is an example: ```#include #include int main() { unsigned int a, b, c; a = 0xabcdef01; for (int i=0; i < 8; ++i) { b = __rotatel4(a, 4 * i); printf("0x%08x\n", b); } return 0; }``` Prints: ```0xabcdef01 0xbcdef01a 0xcdef01ab 0xdef01abc 0xef01abcd 0xf01abcde 0x01abcdef 0x1abcdef0``` – Rafik Zurob Nov 21 '18 at 23:00