diff --git a/contrib/single_file_libs/zstd-in.c b/contrib/single_file_libs/zstd-in.c index 7e1d68fa..4f0fb56a 100644 --- a/contrib/single_file_libs/zstd-in.c +++ b/contrib/single_file_libs/zstd-in.c @@ -45,6 +45,7 @@ /* Include zstd_deps.h first with all the options we need enabled. */ #define ZSTD_DEPS_NEED_MALLOC +#define ZSTD_DEPS_NEED_MATH64 #include "common/zstd_deps.h" #include "common/debug.c" diff --git a/lib/common/zstd_deps.h b/lib/common/zstd_deps.h index e7b8a467..3b4db187 100644 --- a/lib/common/zstd_deps.h +++ b/lib/common/zstd_deps.h @@ -93,6 +93,22 @@ #endif /* ZSTD_DEPS_MALLOC */ #endif /* ZSTD_DEPS_NEED_MALLOC */ +/* + * Provides 64-bit math support. + * Need: + * U64 ZSTD_div64(U64 dividend, U32 divisor) + */ +#ifdef ZSTD_DEPS_NEED_MATH64 +#ifndef ZSTD_DEPS_MATH64 +#define ZSTD_DEPS_MATH64 + +static U64 ZSTD_div64(U64 dividend, U32 divisor) { + return dividend / divisor; +} + +#endif /* ZSTD_DEPS_MATH64 */ +#endif /* ZSTD_DEPS_NEED_MATH64 */ + /* Need: * assert() */ diff --git a/lib/compress/fse_compress.c b/lib/compress/fse_compress.c index a2622c5e..8b6ddc19 100644 --- a/lib/compress/fse_compress.c +++ b/lib/compress/fse_compress.c @@ -24,6 +24,7 @@ #include "../common/fse.h" #include "../common/error_private.h" #define ZSTD_DEPS_NEED_MALLOC +#define ZSTD_DEPS_NEED_MATH64 #include "../common/zstd_deps.h" /* ZSTD_malloc, ZSTD_free, ZSTD_memcpy, ZSTD_memset */ @@ -415,7 +416,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, { U64 const vStepLog = 62 - tableLog; U64 const mid = (1ULL << (vStepLog-1)) - 1; - U64 const rStep = ((((U64)1<