C language > Expert questions
128-bit intrinsic math buggy?
Akko:
The following code works in MSVC (64-bit) but I cannot make it run in PC12 (64-bit console):
// Intrinsic 128-bit multiplication/division test
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <intrin.h>
int main(void) {
uint64_t upl,uph,uq,ur=7;
upl=_umul128(-1,2,&uph);
printf("\nuph=1?%d upl=-2?%d",(int)uph,(int)upl);
uq=_udiv128(uph,upl,2,&ur);
printf("\nuq=-1?%d ur=0?%d",(int)uq,(int)ur);
return 0;
}
I tried /Ze compiler flags et cetera, but PC12 always struggles with the division :-(
Multiplication is no issue.
frankie:
It seems that for the functions _umul128() and _udiv128() the compiler don't emits the intrinsic code, but emits a call to the specific function that, obviously, is missing (doesn't exist in any library).
For me is a compiler bug.
Pelle:
Confirmed.
The compiler internal intrinsic signature for __udiv128 (and _udiv128 if you insist on using the /Ze option) contains (signed) __int64 while the externally visible signature contains (the correct) unsigned __int64. The signatures will never match, so you get the default behavior of calling an external function.
AFAICT this has been broken since __udiv128 and _udiv128 were introduced in version 10 (you guys did a poor job of testing... :P). With version 12 being done, this will be fixed in some possible future version.
frankie:
--- Quote from: Pelle on May 27, 2023, 01:12:52 PM ---Confirmed.
....
AFAICT this has been broken since __udiv128 and _udiv128 were introduced in version 10 (you guys did a poor job of testing... :P).
--- End quote ---
LOL ;D :D ;D :D ;D :D ;D :D ;D
Of course you're absolutely right Pelle. ;)
Akko:
AFAICT also clang has/had similar difficulties with compiling (u)int128_t intrinsics.
Here clang lags behind gcc that has working builtins since long.
I can understand why Pelles C does not support a 64-bit assembler, but for such cases
it would be nice to have one. Long division (eg shift-subtract) in C is painfully slow.
Navigation
[0] Message Index
[#] Next page
Go to full version