On the intrinsics reference site, the _subborrow_u64() intrinsic says it computes "b - a". But in both ICC and MSVC, the intrinsic does "a - b".
So the documentation contradicts what the intrinsic actually does in ICC and MSVC. Unfortunately, GCC's implementation of the intrinsic follows the documentation rather than ICC/MSVC's behavior. And this is causing a bit of a headache when porting some Windows code to Linux/GCC.
The following code prints 23 in ICC/MSVC. But it prints 18446744073709551593 in GCC. I don't know who's "right" or "wrong", but this inconsistency should probably be fixed.
#include <stdint.h> #include <iostream> using namespace std; #if __GNUC__ #include <x86intrin.h> #else #include <intrin.h> #endif int main(){ unsigned char carry = 0; uint64_t a = 123; uint64_t b = 100; uint64_t c; carry = _subborrow_u64(carry, a, b, (unsigned long long*)&c); cout << c << endl; system("pause"); }
Thanks Alex, I'll look into this and update you accordingly and could be an issue in the doc, thanks.
Kittur
Hi Alex,
Thanks for bringing this to our attention, much appreciated. Yes, the documentation needs to be fixed and apparently GCC too. I do find that the word description is correct in the doc but the formula is apparently not right. I'll file an issue with the documentation team. I'll also keep you updated as soon as the release with the fix is out - appreciate much.
Regards,
Kittur
Alex, the issue filed is DPD200410409 and will keep you updated as soon as the release with the fix is out, thanks.
Kittur
Please fix this page too.
https://software.intel.com/en-us/node/523869
It is also wrong but in different way.
Hi Michael,
Yes, will do. Thanks for letting me know and I've already passed on that info as well to the doc team - appreciate much.
Kittur
One month later: nothing done.
You are not very quick, guys :(
Hi Michael,
Yes, I notice that it's not in the update 2 version :-( I've again pinged the doc team to find out as the issue is being addressed per notes in the tracker. I'll update you as soon as I hear from the team.
Thanks,
Kittur
3 months later: nothing done.
I am starting to suspect that it will never be fixed.
5 months later: Intel Intrinsics Guide is finally fixed.
I didn't check if the fix propagated to the latest gcc.
"Intel® C++ Compiler 17.0 Developer Guide and Reference" is correct.
https://software.intel.com/en-us/node/683526
"Intel® C++ Compiler 16.0 User and Reference Guide" is correct.
https://software.intel.com/en-us/node/694996
But "User and Reference Guide for the Intel® C++ Compiler 15.0" is still wrong.
https://software.intel.com/en-us/node/523869
For more complete information about compiler optimizations, see our Optimization Notice.