Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ inlining failed in call to always_inline "int _rdrand16_step()"

Tags:

c++

g++

I'm wrote a code using the Intel function _rdrand16_step(), on Windows(Visual Studio 2017) works fine but on Linux(g++) I can't make it work. I call that function 2 times in my code:

#include <immintrin.h>
...
unsigned short val = 0;
if (_rdrand16_step(&val))
...
_rdrand16_step(&val);
...

and the g++ output this:

/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h: In member function ‘int otp_s7c::crypt(std::__cxx11::string, std::__cxx11::string, long long unsigned int)’:
/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h:129:1: error: inlining failed in call to always_inline ‘int _rdrand16_step(short unsigned int*)’: target specific option mismatch
 _rdrand16_step (unsigned short *__P)
 ^~~~~~~~~~~~~~
otp_s7c.cpp:139:24: note: called from here
      if (_rdrand16_step(&val))
          ~~~~~~~~~~~~~~^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h:129:1: error: inlining failed in call to always_inline ‘int _rdrand16_step(short unsigned int*)’: target specific option mismatch
 _rdrand16_step (unsigned short *__P)
 ^~~~~~~~~~~~~~
otp_s7c.cpp:148:23: note: called from here
         _rdrand16_step(&val);
         ~~~~~~~~~~~~~~^~~~~~
like image 224
Samega 7Cattac Avatar asked Oct 27 '25 21:10

Samega 7Cattac


2 Answers

This is a somewhat misleading error message stemming from the fact that you are not actually telling the compiler that the RDRAND instruction is supported on your target architecture (as far as I can tell, the important part here is the "target specific option mismatch" part at the end).

Adding -mrdrnd to the compiler flags seems to fix the issue.


Compare an example on Compiler Explorer with and without the flag

like image 102
hlt Avatar answered Oct 29 '25 10:10

hlt


I had the same problem in cmake a week ago. But when the following command is added, this problem disappear.

SET(CMAKE_C_FLAGS "-mrdrnd")
like image 26
Land Avatar answered Oct 29 '25 11:10

Land



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!