Last active
June 22, 2019 01:11
-
-
Save qrealka/273c4ef773ccce645c57d8c7725b9add to your computer and use it in GitHub Desktop.
div 128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <immintrin.h> | |
// https://stackoverflow.com/a/8456388 | |
// https://docs.microsoft.com/en-us/cpp/intrinsics/div128?view=vs-2019 | |
#pragma code_seg(".text") | |
const unsigned char sdiv128Data[] = | |
{ | |
0x48, 0x89, 0xD0, // mov rax,rdx | |
0x48, 0x89, 0xCA, // mov rdx,rcx | |
0x49, 0xF7, 0xF8, // idiv r8 | |
0x49, 0x89, 0x11, // mov [r9],rdx | |
0xC3 // ret | |
}; | |
__int64 (__fastcall *sdiv128)(__int64 numhi, | |
__int64 numlo, | |
__int64 den, | |
__int64* rem) = | |
(__int64 (__fastcall *)(__int64, | |
__int64, | |
__int64, | |
__int64*))&sdiv128Data; | |
__int64 div_mod(__int64 hi, __int64 low, __int64 divisor, __int64* reminder) { | |
return _div128(hi, low, divisor, reminder); | |
} | |
int main() | |
{ | |
__int64 sr; | |
sdiv128(-1, -6, -2, &sr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment