diff options
| author | Tyge Løvset <[email protected]> | 2023-04-21 14:41:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-04-21 14:41:47 +0200 |
| commit | feea8547482d8822a288977201e08eded1551e59 (patch) | |
| tree | 4487d54870bf4f54fb7744024fcba0d1241ead6b /include/stc/ccommon.h | |
| parent | 4375640bdf856866fa2a1e7010103736077b9738 (diff) | |
| download | STC-modified-feea8547482d8822a288977201e08eded1551e59.tar.gz STC-modified-feea8547482d8822a288977201e08eded1551e59.zip | |
Householding.
Diffstat (limited to 'include/stc/ccommon.h')
| -rw-r--r-- | include/stc/ccommon.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 0735e855..2453143c 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -216,6 +216,17 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_drop(C, ...) \ do { c_forlist (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0) +#if defined(__SIZEOF_INT128__) + #define c_umul128(a, b, lo, hi) \ + do { __uint128_t _z = (__uint128_t)(a)*(b); \ + *(lo) = (uint64_t)_z, *(hi) = (uint64_t)(_z >> 64U); } while(0) +#elif defined(_MSC_VER) && defined(_WIN64) + #include <intrin.h> + #define c_umul128(a, b, lo, hi) ((void)(*(lo) = _umul128(a, b, hi))) +#elif defined(__x86_64__) + #define c_umul128(a, b, lo, hi) \ + asm("mulq %3" : "=a"(*(lo)), "=d"(*(hi)) : "a"(a), "rm"(b)) +#endif #endif // CCOMMON_H_INCLUDED #undef STC_API |
