diff options
| author | Tyge Løvset <[email protected]> | 2021-02-28 21:29:07 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-02-28 21:29:07 +0100 |
| commit | c2969d7a290eb16a21d097822ce63a89e5c313e5 (patch) | |
| tree | 1d15b981044a72428be9f0aed08f737002999ab8 /stc/ccommon.h | |
| parent | dc6b7f9517b81da984a4c795213861e8ea61ce20 (diff) | |
| download | STC-modified-c2969d7a290eb16a21d097822ce63a89e5c313e5.tar.gz STC-modified-c2969d7a290eb16a21d097822ce63a89e5c313e5.zip | |
Made it possible use full 64-bit size_t range for cmap, by defining CMAP_SIZE_T uint64_t
Diffstat (limited to 'stc/ccommon.h')
| -rw-r--r-- | stc/ccommon.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/stc/ccommon.h b/stc/ccommon.h index 77f76bf0..15a7ecdf 100644 --- a/stc/ccommon.h +++ b/stc/ccommon.h @@ -58,9 +58,9 @@ #define _c_RSEQ_N 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define _c_APPLY_ARG_N(ARGS) _c_EXPAND(_c_ARG_N ARGS)
#define _c_VA_ARG_SIZE(...) _c_EXPAND(_c_APPLY_ARG_N((__VA_ARGS__, _c_RSEQ_N)))
-#define _c_OVERLOAD_SELECT(NAME, NUM) _c_CAT( NAME ## _, NUM)
+#define _c_SELECT(NAME, NUM) _c_CAT( NAME ## _, NUM)
-#define c_MACRO_OVERLOAD(NAME, ...) _c_OVERLOAD_SELECT(NAME, _c_VA_ARG_SIZE(__VA_ARGS__))(__VA_ARGS__)
+#define c_MACRO_OVERLOAD(NAME, ...) _c_SELECT(NAME, _c_VA_ARG_SIZE(__VA_ARGS__))(__VA_ARGS__)
#define c_static_assert(cond, ...) typedef char _static_assert_[(cond) ? 1 : -1]
#define c_container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
@@ -129,4 +129,16 @@ ctype##_del(__arr[__i]); \
} 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) = _z >> 64; } while(0)
+#elif defined(_MSC_VER) && defined(_WIN64)
+ #include <intrin.h>
+ #define c_umul128(a, b, lo, hi) (*(lo) = _umul128(a, b, hi), (void)0)
+#elif defined(__x86_64__)
+ #define c_umul128(a, b, lo, hi) \
+ asm("mulq %[rhs]" : "=a" (*(lo)), "=d" (*(hi)) \
+ : [lhs] "0" (a), [rhs] "rm" (b))
+#endif
#endif
|
